2; if(!$has_patch_code) return $full_str; return substr($full_str, 0, strrpos($full_str, '.')); } function game_version_code($str = null) { $str = $str === null ? game_version() : $str; $items = explode('.', $str); if(sizeof($items) < 2) throw new Exception("Bad version format: $str"); $maj = $items[0]; $min = $items[1]; $pat = isset($items[2]) ? $items[2] : 0; $num = $pat + $min*100 + $maj*1000000; return $num; } function game_patch_code() { $full_str = game_version_full_str(); $has_patch_code = substr_count($full_str, '.') > 2; if(!$has_patch_code) return 0; $code = substr($full_str, strrpos($full_str, '.')+1); if($code > 9) throw new Exception("Patch code must be <= 9"); return $code; } function get_inc_game_version() { $string = game_version(); for($i = strlen($string) - 1; $i >= 0; $i--) { if(is_numeric($string[$i])) { $most_significant_number = $i; if($string[$i] < 9) { $string[$i] = $string[$i] + 1; break; } // The number was a 9, set it to zero and continue. $string[$i] = 0; } } // If the most significant number was set to a zero it has overflowed so we // need to prefix it with a '1'. if($string[$most_significant_number] === '0') $string = substr_replace($string, '1', $most_significant_number, 0); return $string; } function get_version_file_lifetime() { global $GAME_ROOT; exec("git log --follow --format=%ad --date=format:'%Y-%m-%d %H:%M:%S' " . $GAME_ROOT . getor('VERSION_FILE', "/VERSION") , $out, $ret); if($ret != 0) throw new Exception("git error"); $minutes = (time() - strtotime($out[0])) / 60; return ceil($minutes); }