Merged server and API version

This commit is contained in:
Dylan K. Taylor 2018-06-17 12:54:18 +01:00
parent 77f3ca4d47
commit 1f9bed275a
8 changed files with 81 additions and 69 deletions

View File

@ -229,13 +229,13 @@ class CrashDump{
} }
private function generalData(){ private function generalData(){
$version = new VersionString(); $version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER);
$this->data["general"] = []; $this->data["general"] = [];
$this->data["general"]["name"] = $this->server->getName(); $this->data["general"]["name"] = $this->server->getName();
$this->data["general"]["version"] = $version->get(false); $this->data["general"]["version"] = $version->getFullVersion(false);
$this->data["general"]["build"] = $version->getBuild(); $this->data["general"]["build"] = $version->getBuild();
$this->data["general"]["protocol"] = ProtocolInfo::CURRENT_PROTOCOL; $this->data["general"]["protocol"] = ProtocolInfo::CURRENT_PROTOCOL;
$this->data["general"]["api"] = \pocketmine\API_VERSION; $this->data["general"]["api"] = \pocketmine\BASE_VERSION;
$this->data["general"]["git"] = \pocketmine\GIT_COMMIT; $this->data["general"]["git"] = \pocketmine\GIT_COMMIT;
$this->data["general"]["raklib"] = RakLib::VERSION; $this->data["general"]["raklib"] = RakLib::VERSION;
$this->data["general"]["uname"] = php_uname("a"); $this->data["general"]["uname"] = php_uname("a");
@ -243,7 +243,7 @@ class CrashDump{
$this->data["general"]["zend"] = zend_version(); $this->data["general"]["zend"] = zend_version();
$this->data["general"]["php_os"] = PHP_OS; $this->data["general"]["php_os"] = PHP_OS;
$this->data["general"]["os"] = Utils::getOS(); $this->data["general"]["os"] = Utils::getOS();
$this->addLine($this->server->getName() . " version: " . $version->get(false) . " #" . $version->getBuild() . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "; API " . API_VERSION . "]"); $this->addLine($this->server->getName() . " version: " . $version->getFullVersion(true) . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "]");
$this->addLine("Git commit: " . GIT_COMMIT); $this->addLine("Git commit: " . GIT_COMMIT);
$this->addLine("uname -a: " . php_uname("a")); $this->addLine("uname -a: " . php_uname("a"));
$this->addLine("PHP Version: " . phpversion()); $this->addLine("PHP Version: " . phpversion());

View File

@ -33,12 +33,13 @@ namespace pocketmine {
use pocketmine\utils\Terminal; use pocketmine\utils\Terminal;
use pocketmine\utils\Timezone; use pocketmine\utils\Timezone;
use pocketmine\utils\Utils; use pocketmine\utils\Utils;
use pocketmine\utils\VersionString;
use pocketmine\wizard\SetupWizard; use pocketmine\wizard\SetupWizard;
const NAME = "PocketMine-MP"; const NAME = "PocketMine-MP";
const VERSION = "1.7dev"; const BASE_VERSION = "3.0.0";
const API_VERSION = "3.0.0";
const IS_DEVELOPMENT_BUILD = true; const IS_DEVELOPMENT_BUILD = true;
const BUILD_NUMBER = 0;
const MIN_PHP_VERSION = "7.2.0"; const MIN_PHP_VERSION = "7.2.0";
@ -205,6 +206,9 @@ namespace pocketmine {
$logger->warning("Non-packaged " . \pocketmine\NAME . " installation detected. Consider using a phar in production for better performance."); $logger->warning("Non-packaged " . \pocketmine\NAME . " installation detected. Consider using a phar in production for better performance.");
} }
$version = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER);
define('pocketmine\VERSION', $version->getFullVersion(true));
$gitHash = str_repeat("00", 20); $gitHash = str_repeat("00", 20);
if(\Phar::running(true) === ""){ if(\Phar::running(true) === ""){

View File

@ -320,7 +320,7 @@ class Server{
* @return string * @return string
*/ */
public function getApiVersion() : string{ public function getApiVersion() : string{
return \pocketmine\API_VERSION; return \pocketmine\BASE_VERSION;
} }
/** /**
@ -1438,12 +1438,10 @@ class Server{
$this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR; $this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR;
$this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR; $this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR;
$version = new VersionString($this->getPocketMineVersion());
$this->logger->info("Loading pocketmine.yml..."); $this->logger->info("Loading pocketmine.yml...");
if(!file_exists($this->dataPath . "pocketmine.yml")){ if(!file_exists($this->dataPath . "pocketmine.yml")){
$content = file_get_contents(\pocketmine\RESOURCE_PATH . "pocketmine.yml"); $content = file_get_contents(\pocketmine\RESOURCE_PATH . "pocketmine.yml");
if($version->isDev()){ if(\pocketmine\IS_DEVELOPMENT_BUILD){
$content = str_replace("preferred-channel: stable", "preferred-channel: beta", $content); $content = str_replace("preferred-channel: stable", "preferred-channel: beta", $content);
} }
@file_put_contents($this->dataPath . "pocketmine.yml", $content); @file_put_contents($this->dataPath . "pocketmine.yml", $content);
@ -1611,8 +1609,7 @@ class Server{
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [ $this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [
$this->getName(), $this->getName(),
($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::RESET, (\pocketmine\IS_DEVELOPMENT_BUILD ? TextFormat::YELLOW : "") . $this->getPocketMineVersion() . TextFormat::RESET
$this->getApiVersion()
])); ]));
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()])); $this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()]));

View File

@ -50,7 +50,6 @@ class VersionCommand extends VanillaCommand{
$sender->sendMessage(new TranslationContainer("pocketmine.server.info.extended", [ $sender->sendMessage(new TranslationContainer("pocketmine.server.info.extended", [
$sender->getServer()->getName(), $sender->getServer()->getName(),
$sender->getServer()->getPocketMineVersion(), $sender->getServer()->getPocketMineVersion(),
$sender->getServer()->getApiVersion(),
$sender->getServer()->getVersion(), $sender->getServer()->getVersion(),
ProtocolInfo::CURRENT_PROTOCOL ProtocolInfo::CURRENT_PROTOCOL
])); ]));

@ -1 +1 @@
Subproject commit 5e6ccee0c1962c8b28491212c3a947fb2036e4a4 Subproject commit ac510ed32673d019d9bffede266d15ee9e287bae

View File

@ -35,10 +35,10 @@ class AutoUpdater{
protected $server; protected $server;
/** @var string */ /** @var string */
protected $endpoint; protected $endpoint;
/** @var bool */
protected $hasUpdate = false;
/** @var array|null */ /** @var array|null */
protected $updateInfo = null; protected $updateInfo = null;
/** @var VersionString|null */
protected $newVersion;
/** /**
* @param Server $server * @param Server $server
@ -67,10 +67,9 @@ class AutoUpdater{
$this->showConsoleUpdate(); $this->showConsoleUpdate();
} }
}elseif($this->server->getProperty("auto-updater.preferred-channel", true)){ }elseif($this->server->getProperty("auto-updater.preferred-channel", true)){
$version = new VersionString(); if(!\pocketmine\IS_DEVELOPMENT_BUILD and $this->getChannel() !== "stable"){
if(!$version->isDev() and $this->getChannel() !== "stable"){
$this->showChannelSuggestionStable(); $this->showChannelSuggestionStable();
}elseif($version->isDev() and $this->getChannel() === "stable"){ }elseif(\pocketmine\IS_DEVELOPMENT_BUILD and $this->getChannel() === "stable"){
$this->showChannelSuggestionBeta(); $this->showChannelSuggestionBeta();
} }
} }
@ -82,17 +81,15 @@ class AutoUpdater{
* @return bool * @return bool
*/ */
public function hasUpdate() : bool{ public function hasUpdate() : bool{
return $this->hasUpdate; return $this->newVersion !== null;
} }
/** /**
* Posts a warning to the console to tell the user there is an update available * Posts a warning to the console to tell the user there is an update available
*/ */
public function showConsoleUpdate(){ public function showConsoleUpdate(){
$newVersion = new VersionString($this->updateInfo["version"]);
$messages = [ $messages = [
"Your version of " . $this->server->getName() . " is out of date. Version " . $newVersion->get(false) . " (build #" . $this->updateInfo["build"] . ") was released on " . date("D M j h:i:s Y", $this->updateInfo["date"]) "Your version of " . $this->server->getName() . " is out of date. Version " . $this->newVersion->getFullVersion(true) . " was released on " . date("D M j h:i:s Y", $this->updateInfo["date"])
]; ];
if($this->updateInfo["details_url"] !== null){ if($this->updateInfo["details_url"] !== null){
$messages[] = "Details: " . $this->updateInfo["details_url"]; $messages[] = "Details: " . $this->updateInfo["details_url"];
@ -159,15 +156,18 @@ class AutoUpdater{
if($this->updateInfo === null){ if($this->updateInfo === null){
return; return;
} }
$currentVersion = new VersionString($this->server->getPocketMineVersion()); $currentVersion = new VersionString(\pocketmine\BASE_VERSION, \pocketmine\IS_DEVELOPMENT_BUILD, \pocketmine\BUILD_NUMBER);
$newVersion = new VersionString($this->updateInfo["version"]); try{
$newVersion = new VersionString($this->updateInfo["base_version"], $this->updateInfo["is_dev"], $this->updateInfo["build"]);
if($currentVersion->compare($newVersion) > 0 and ($currentVersion->get() !== $newVersion->get() or $currentVersion->getBuild() > 0)){ }catch(\InvalidArgumentException $e){
$this->hasUpdate = true; //Invalid version returned from API, assume there's no update
}else{ $this->server->getLogger()->debug("[AutoUpdater] Assuming no update because \"" . $e->getMessage() . "\"");
$this->hasUpdate = false; return;
} }
if($currentVersion->compare($newVersion) > 0 and ($currentVersion->getFullVersion() !== $newVersion->getFullVersion() or $currentVersion->getBuild() > 0)){
$this->newVersion = $newVersion;
}
} }
/** /**

View File

@ -52,8 +52,8 @@ class UpdateCheckTask extends AsyncTask{
$response = json_decode($response, true); $response = json_decode($response, true);
if(is_array($response)){ if(is_array($response)){
if( if(
isset($response["version"]) and isset($response["base_version"]) and
isset($response["api_version"]) and isset($response["is_dev"]) and
isset($response["build"]) and isset($response["build"]) and
isset($response["date"]) and isset($response["date"]) and
isset($response["download_url"]) isset($response["download_url"])

View File

@ -28,47 +28,62 @@ namespace pocketmine\utils;
* Manages PocketMine-MP version strings, and compares them * Manages PocketMine-MP version strings, and compares them
*/ */
class VersionString{ class VersionString{
/** @var int */ /** @var string */
private $generation; private $baseVersion;
/** @var string */
private $suffix;
/** @var int */ /** @var int */
private $major; private $major;
/** @var int */ /** @var int */
private $minor; private $minor;
/** @var int */
private $patch;
/** @var int */ /** @var int */
private $build; private $build;
/** @var bool */ /** @var bool */
private $development = false; private $development = false;
/** /**
* VersionString constructor. * @param string $baseVersion
* * @param bool $isDevBuild
* @param int|string $version * @param int $buildNumber
*/ */
public function __construct($version = \pocketmine\VERSION){ public function __construct(string $baseVersion, bool $isDevBuild = false, int $buildNumber = 0){
if(is_int($version)){ $this->baseVersion = $baseVersion;
$this->minor = $version & 0x1F; $this->development = $isDevBuild;
$this->major = ($version >> 5) & 0x0F; $this->build = $buildNumber;
$this->generation = ($version >> 9) & 0x0F;
}else{ preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)(?:-(.*))?$/', $this->baseVersion, $matches);
$version = preg_split("/([A-Za-z]*)[ _\\-]?([0-9]*)\\.([0-9]*)\\.{0,1}([0-9]*)(dev|)(-[\\0-9]{1,}|)/", $version, -1, PREG_SPLIT_DELIM_CAPTURE); if(count($matches) < 4){
$this->generation = (int) ($version[2] ?? 0); //0-15 throw new \InvalidArgumentException("Invalid base version \"$baseVersion\", should contain at least 3 version digits");
$this->major = (int) ($version[3] ?? 0); //0-15
$this->minor = (int) ($version[4] ?? 0); //0-31
$this->development = $version[5] === "dev";
if($version[6] !== ""){
$this->build = (int) substr($version[6], 1);
}else{
$this->build = 0;
}
} }
$this->major = (int) $matches[1];
$this->minor = (int) $matches[2];
$this->patch = (int) $matches[3];
$this->suffix = $matches[4] ?? "";
} }
public function getNumber() : int{ public function getNumber() : int{
return (($this->generation << 9) + ($this->major << 5) + $this->minor); return (($this->major << 9) + ($this->minor << 5) + $this->patch);
} }
public function getGeneration() : int{ public function getBaseVersion() : string{
return $this->generation; return $this->baseVersion;
}
public function getFullVersion(bool $build = false) : string{
$retval = $this->baseVersion;
if($this->development){
$retval .= "+dev";
if($build and $this->build > 0){
$retval .= "." . $this->build;
}
}
return $retval;
} }
public function getMajor() : int{ public function getMajor() : int{
@ -79,8 +94,12 @@ class VersionString{
return $this->minor; return $this->minor;
} }
public function getRelease() : string{ public function getPatch() : int{
return $this->generation . "." . $this->major . "." . $this->minor; return $this->patch;
}
public function getSuffix() : string{
return $this->suffix;
} }
public function getBuild() : int{ public function getBuild() : int{
@ -91,24 +110,17 @@ class VersionString{
return $this->development; return $this->development;
} }
public function get(bool $build = false) : string{
return $this->getRelease() . ($this->development ? "dev" : "") . (($this->build > 0 and $build) ? "-" . $this->build : "");
}
public function __toString() : string{ public function __toString() : string{
return $this->get(); return $this->getFullVersion();
} }
/** /**
* @param VersionString|int|string $target * @param VersionString $target
* @param bool $diff * @param bool $diff
* *
* @return int * @return int
*/ */
public function compare($target, bool $diff = false) : int{ public function compare(VersionString $target, bool $diff = false) : int{
if(!($target instanceof VersionString)){
$target = new VersionString($target);
}
$number = $this->getNumber(); $number = $this->getNumber();
$tNumber = $target->getNumber(); $tNumber = $target->getNumber();
if($diff){ if($diff){