Multi-update system and version numeration

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-06 13:31:30 +01:00
parent 7030f9118d
commit b3b38605b5
4 changed files with 116 additions and 5 deletions

View File

@ -121,11 +121,22 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
if($info === false or !isset($info[0])){
console("[ERROR] GitHub API Error");
}else{
$info = $info[0];
if($info["name"] != MAJOR_VERSION){
$newest = new VersionString(MAJOR_VERSION);
$newest = array(-1, $newest->getNumber());
foreach($info as $i => $tag){
$update = new VersionString($tag["name"]);
$update = $update->getNumber();
if($update > $newest[1]){
$newest = array($i, $update);
}
}
if($newest[0] !== -1){
$target = $info[$newest[0]];
console("[NOTICE] A new STABLE version of PocketMine-MP has been released");
console("[NOTICE] Version \"".$info["name"]."\" [".substr($info["commit"]["sha"], 0, 10)."]");
console("[NOTICE] Download it at ".$info["zipball_url"]);
console("[NOTICE] Version \"".(new VersionString($newest[1]))."\" #".$newest[1]." [".substr($target["commit"]["sha"], 0, 10)."]");
console("[NOTICE] Download it at ".$target["zipball_url"]);
console("[NOTICE] This message will dissapear as soon as you update");
sleep(5);
}else{

View File

@ -30,7 +30,9 @@ class PocketMinecraftServer extends stdClass{
private $database, $interface, $evCnt, $handCnt, $events, $handlers, $version, $serverType, $lastTick;
function __construct($name, $gamemode = 1, $seed = false, $port = 19132, $serverID = false){
$this->port = (int) $port; //19132 - 19135
console("[INFO] PocketMine-MP ".MAJOR_VERSION." by @shoghicp, LGPL License", true, true, 0);
$vNumber = new VersionString();
$vNumber = $vNumber->getNumber();
console("[INFO] PocketMine-MP ".MAJOR_VERSION." #".$vNumber." by @shoghicp, LGPL License", true, true, 0);
console("[DEBUG] Target Minecraft PE: ".CURRENT_MINECRAFT_VERSION, true, true, 2);
console("[INFO] Starting Minecraft PE Server at *:".$this->port);
if($this->port < 19132 or $this->port > 19135){

View File

@ -25,6 +25,8 @@ the Free Software Foundation, either version 3 of the License, or
*/
function kill($pid){
switch(Utils::getOS()){
case "win":

View File

@ -0,0 +1,96 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
class VersionString{
public static $stageOrder = array(
"alpha" => 0,
"beta" => 1,
"final" => 2,
);
private $stage, $major, $release, $minor;
public function __construct($version = MAJOR_VERSION){
if(is_int($version)){
$this->minor = $version & 0x1F;
$this->major = ($version >> 5) & 0x0F;
$this->generation = ($version >> 9) & 0x0F;
$this->stage = array_search(($version >> 13) & 0x0F, VersionString::$stageOrder, true);
}else{
$version = preg_split("/([A-Za-z]*)[ _\-]([0-9]*)\.([0-9]*)\.{0,1}([0-9]*)/", $version, -1, PREG_SPLIT_DELIM_CAPTURE);
$this->stage = strtolower($version[1]); //0-15
$this->generation = (int) $version[2]; //0-15
$this->major = (int) $version[3]; //0-15
$this->minor = (int) $version[4]; //0-31
}
}
public function getNumber(){
return (int) (VersionString::$stageOrder[$this->stage] << 13) + ($this->generation << 9) + ($this->major << 5) + $this->minor;
}
public function getStage(){
return $this->stage;
}
public function getGeneration(){
return $this->generation;
}
public function getMajor(){
return $this->major;
}
public function getMinor(){
return $this->minor;
}
public function getRelease(){
return $this->generation . "." . $this->major . "." . $this->minor;
}
public function __toString(){
return ucfirst($this->stage) . "_" . $this->generation . "." . $this->major . "." . $this->minor;
}
public function compare($target, $diff = false){
if(($target instanceof VersionString) === false){
$target = new VersionString($target);
}
$number = $this->getNumber();
$tNumber = $target->getNumber();
if($diff === true){
return $tNumber - $number;
}
if($number > $tNumber){
return -1; //Target is older
}elseif($number < $tNumber){
return 1; //Target is newer
}else{
return 0; //Same version
}
}
}