From 8da61e613f51294adb521a558cff21018514a5e8 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 11:01:45 +0200 Subject: [PATCH 01/21] Send sign text on update --- src/Player.php | 2 +- src/world/Tile.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Player.php b/src/Player.php index cdff707f..174d55c3 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1100,7 +1100,7 @@ class Player{ $this->close("Incorrect protocol #".$data["protocol1"], false); break; } - if(preg_match('#[^a-zA-Z0-9_]#', $data["username"]) == 0 && $data["username"] != ""){ + if(preg_match('#[^a-zA-Z0-9_]#', $data["username"]) == 0 and $data["username"] != ""){ $this->username = $data["username"]; $this->iusername = strtolower($this->username); }else{ diff --git a/src/world/Tile.php b/src/world/Tile.php index 8a038047..3bf934ff 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -103,6 +103,8 @@ class Tile extends Position{ $this->server->api->tile->spawnToAll($this); $this->server->api->tile->spawnToAll($tile); + $this->server->handle("tile.update", $this); + $this->server->handle("tile.update", $tile); } public function unpair(){ @@ -113,9 +115,11 @@ class Tile extends Position{ $tile = $this->getPair(); unset($this->data["pairx"], $this->data["pairz"], $tile->data["pairx"], $tile->data["pairz"]); - $this->server->api->tile->spawnToAll($this); + $this->server->api->tile->spawnToAll($this); + $this->server->handle("tile.update", $this); if($tile instanceof Tile){ $this->server->api->tile->spawnToAll($tile); + $this->server->handle("tile.update", $tile); } } @@ -438,6 +442,7 @@ class Tile extends Position{ $this->data["Text2"] = $line2; $this->data["Text3"] = $line3; $this->data["Text4"] = $line4; + $this->server->api->tile->spawnToAll($this); $this->server->handle("tile.update", $this); return true; } From 9d3379daca9368552f1eb800a8436d4123874dd7 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 14:30:27 +0200 Subject: [PATCH 02/21] Removed MobAPI Why was that here? --- src/API/MobAPI.php | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 src/API/MobAPI.php diff --git a/src/API/MobAPI.php b/src/API/MobAPI.php deleted file mode 100644 index 305aceba..00000000 --- a/src/API/MobAPI.php +++ /dev/null @@ -1,31 +0,0 @@ -server = ServerAPI::request(); - } - - public function init(){ - - } -} From f5e640c87531a1e3c94131dbcd5c6a078f9755ce Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 16:37:31 +0200 Subject: [PATCH 03/21] Oops, added class name --- .travis.yml | 2 +- src/tests/ServerSuiteTest.php | 1 + src/tests/phpunit.xml | 6 ------ 3 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 src/tests/phpunit.xml diff --git a/.travis.yml b/.travis.yml index 6c4cc803..c3559fa1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_script: - pecl install channel://pecl.php.net/pthreads-0.0.44 script: - - phpunit src/tests/ + - phpunit ServerSuiteTest src/tests/ServerSuiteTest.php notifications: email: false diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index aa938214..0418ed13 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -15,6 +15,7 @@ if(class_exists("PHPUnit_Framework_TestCase", false)){ public function testRead(){ define("NO_THREADS", true); + define("DEBUG", -1); //No output require_once(dirname(__FILE__)."/../dependencies.php"); require_once(FILE_PATH."/src/functions.php"); require_once(FILE_PATH."/src/dependencies.php"); diff --git a/src/tests/phpunit.xml b/src/tests/phpunit.xml deleted file mode 100644 index 2fa40761..00000000 --- a/src/tests/phpunit.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - ./ - - \ No newline at end of file From 29d089db5bf885f3916af292e453d77efbf664eb Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 16:41:57 +0200 Subject: [PATCH 04/21] Added default class --- src/tests/ServerSuiteTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 0418ed13..970cb37f 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -1,6 +1,8 @@ server->init(); exit(0); } - } - -} \ No newline at end of file + } \ No newline at end of file From 392c8d273e59f9f9020fb4b7eda0dd15d87d7e7c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 16:48:50 +0200 Subject: [PATCH 05/21] phpunit configuration file --- .travis.yml | 2 +- phpunit.xml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml diff --git a/.travis.yml b/.travis.yml index c3559fa1..ef870b33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_script: - pecl install channel://pecl.php.net/pthreads-0.0.44 script: - - phpunit ServerSuiteTest src/tests/ServerSuiteTest.php + - phpunit --configuration phpunit.xml notifications: email: false diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..cdfdb09c --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,7 @@ + + + + src/tests + + + \ No newline at end of file From d8124d9ddd478cb1d0d2cb3cb46ac3ac1f728650 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 16:49:18 +0200 Subject: [PATCH 06/21] Removed MobAPI from ServerAPI --- src/API/ServerAPI.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 54f8cd3b..12381ba7 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -149,7 +149,6 @@ class ServerAPI{ $this->loadAPI("tile", "TileAPI"); $this->loadAPI("player", "PlayerAPI"); $this->loadAPI("time", "TimeAPI"); - $this->loadAPI("mob", "MobAPI"); foreach($this->apiList as $ob){ if(is_callable(array($ob, "init"))){ From 5d27a40a6ed3d3e54ab8900925f3f911a6b59e97 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 16:54:04 +0200 Subject: [PATCH 07/21] Remove test suites on compile --- src/tests/ServerSuiteTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 970cb37f..fde37c16 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -1,8 +1,8 @@ server->init(); exit(0); } - } \ No newline at end of file + } +/***REM_END***/ \ No newline at end of file From feea39a97f017fa92bc8c7409e70a7cf1069a8ca Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 17:02:04 +0200 Subject: [PATCH 08/21] test again --- src/PocketMinecraftServer.php | 6 ++-- src/tests/ServerSuiteTest.php | 61 ++++++++++++++++------------------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index a2919498..91db6ac0 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -26,7 +26,9 @@ class PocketMinecraftServer{ private function load(){ $this->version = new VersionString(); - @cli_set_process_title("PocketMine-MP ".MAJOR_VERSION); + if(!defined("DEBUG") or DEBUG >= 0){ + @cli_set_process_title("PocketMine-MP ".MAJOR_VERSION); + } if($this->version->isDev()){ console("[INFO] \x1b[31;1mThis is a Development version"); } @@ -87,7 +89,7 @@ class PocketMinecraftServer{ public function titleTick(){ $time = microtime(true); - if(ENABLE_ANSI === true){ + if((!defined("DEBUG") or DEBUG >= 0) and ENABLE_ANSI === true){ echo "\x1b]0;PocketMine-MP ".MAJOR_VERSION." | Online ". count($this->clients)."/".$this->maxClients." | RAM ".round((memory_get_usage() / 1024) / 1024, 2)."MB | U ".round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." D ".round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." kB/s | TPS ".$this->getTPS()."\x07"; } $this->interface->bandwidth = array(0, 0, $time); diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index fde37c16..77bc4989 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -1,40 +1,35 @@ assertTrue(true); - $server = ServerAPI::request(); + if(!class_exists("PocketMinecraftServer", false)){ + class ServerSuiteTest extends PHPUnit_Framework_TestCase{ + private $server; + public function testStart(){ + define("NO_THREADS", true); + define("DEBUG", -1); //No output + require_once(dirname(__FILE__)."/../dependencies.php"); + require_once(FILE_PATH."/src/functions.php"); + require_once(FILE_PATH."/src/dependencies.php"); + //binary things + $this->assertTrue(Utils::readTriad("\x02\x01\x03") === 131331, "Utils::readTriad"); + $this->assertTrue(Utils::readInt("\xff\x02\x01\x03") === -16645885, "Utils::readInt"); + $this->assertTrue(abs(Utils::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, "Utils::readFloat"); + $this->assertTrue(abs(Utils::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, "Utils::readDouble"); + $this->assertTrue(Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08") === "4684309878217770760", "Utils::readLong"); + + //PocketMine-MP server startup + $server = new ServerAPI(); + $server->load(); + $this->assertTrue(is_integer($server->event("server.start", array($this, "hook")))); + $server->init(); + } - //Everything done! - $server->close(); - } - - public function testRead(){ - define("NO_THREADS", true); - define("DEBUG", -1); //No output - require_once(dirname(__FILE__)."/../dependencies.php"); - require_once(FILE_PATH."/src/functions.php"); - require_once(FILE_PATH."/src/dependencies.php"); - - //binary things - $this->assertTrue(Utils::readTriad("\x02\x01\x03") === 131331, "Utils::readTriad"); - $this->assertTrue(Utils::readInt("\xff\x02\x01\x03") === -16645885, "Utils::readInt"); - $this->assertTrue(abs(Utils::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, "Utils::readFloat"); - $this->assertTrue(abs(Utils::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, "Utils::readDouble"); - $this->assertTrue(Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08") === "4684309878217770760", "Utils::readLong"); - - //PocketMine-MP server startup - $this->server = new ServerAPI(); - $this->server->load(); - $this->assertTrue(is_integer($this->server->event("server.start", array($this, "hook")))); - $this->server->init(); - exit(0); + public function hook(){ + $this->server = ServerAPI::request(); + + //Everything done! + $this->server->close(); + } } } /***REM_END***/ \ No newline at end of file From 06ce84e275dea596e780f508852cffa90dee9f63 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 17:07:42 +0200 Subject: [PATCH 09/21] test with debug --- src/tests/ServerSuiteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 77bc4989..19e430a8 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -5,7 +5,7 @@ private $server; public function testStart(){ define("NO_THREADS", true); - define("DEBUG", -1); //No output + //define("DEBUG", -1); //No output require_once(dirname(__FILE__)."/../dependencies.php"); require_once(FILE_PATH."/src/functions.php"); require_once(FILE_PATH."/src/dependencies.php"); From eba33b0e00747ca646df7d3a7173918f5dda8fee Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 17:13:33 +0200 Subject: [PATCH 10/21] Again :'( --- src/PocketMinecraftServer.php | 4 ++-- src/tests/ServerSuiteTest.php | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 91db6ac0..e9934c94 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -26,7 +26,7 @@ class PocketMinecraftServer{ private function load(){ $this->version = new VersionString(); - if(!defined("DEBUG") or DEBUG >= 0){ + if(defined("DEBUG") and DEBUG >= 0){ @cli_set_process_title("PocketMine-MP ".MAJOR_VERSION); } if($this->version->isDev()){ @@ -89,7 +89,7 @@ class PocketMinecraftServer{ public function titleTick(){ $time = microtime(true); - if((!defined("DEBUG") or DEBUG >= 0) and ENABLE_ANSI === true){ + if(defined("DEBUG") and DEBUG >= 0 and ENABLE_ANSI === true){ echo "\x1b]0;PocketMine-MP ".MAJOR_VERSION." | Online ". count($this->clients)."/".$this->maxClients." | RAM ".round((memory_get_usage() / 1024) / 1024, 2)."MB | U ".round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." D ".round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2)." kB/s | TPS ".$this->getTPS()."\x07"; } $this->interface->bandwidth = array(0, 0, $time); diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 19e430a8..5d2b2cbf 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -5,7 +5,7 @@ private $server; public function testStart(){ define("NO_THREADS", true); - //define("DEBUG", -1); //No output + define("DEBUG", -1); //No output require_once(dirname(__FILE__)."/../dependencies.php"); require_once(FILE_PATH."/src/functions.php"); require_once(FILE_PATH."/src/dependencies.php"); @@ -24,11 +24,9 @@ $server->init(); } - public function hook(){ - $this->server = ServerAPI::request(); - + public function hook(){ //Everything done! - $this->server->close(); + ServerAPI::request()->close(); } } } From 3608ee1194d9853d1fb3e97cc5eda43455580483 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 17:17:34 +0200 Subject: [PATCH 11/21] Moved conditional class --- src/dependencies.php | 4 ++++ src/tests/ServerSuiteTest.php | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dependencies.php b/src/dependencies.php index 22c021a0..c8cde493 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -20,6 +20,10 @@ */ /***REM_START***/ +if(!class_exists("PHPUnit_Framework_TestCase", false)){ + class PHPUnit_Framework_TestCase{ + } +} require_once(dirname(__FILE__)."/config.php"); require_once(FILE_PATH."/src/functions.php"); /***REM_END***/ diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 5d2b2cbf..b0ecf450 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -1,8 +1,7 @@ close(); } } - } /***REM_END***/ \ No newline at end of file From b8594ab48f1f917235e045db8288ad18e4d0b0e5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 17:33:29 +0200 Subject: [PATCH 12/21] Firce exit(0) --- .travis.yml | 2 +- src/tests/ServerSuiteTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ef870b33..037df269 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_script: - pecl install channel://pecl.php.net/pthreads-0.0.44 script: - - phpunit --configuration phpunit.xml + - phpunit --process-isolation --configuration phpunit.xml notifications: email: false diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index b0ecf450..24771504 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -21,6 +21,7 @@ $server->load(); $this->assertTrue(is_integer($server->event("server.start", array($this, "hook")))); $server->init(); + exit(0); } public function hook(){ From 549ad5eff1b7053a7057ea05428a438b5e3e4b86 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 17:41:01 +0200 Subject: [PATCH 13/21] Async thread remove on NO_THREADS --- src/PocketMinecraftServer.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index e9934c94..f692cf58 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -66,7 +66,9 @@ class PocketMinecraftServer{ $this->reloadConfig(); $this->stop = false; $this->ticks = 0; - $this->asyncThread = new AsyncMultipleQueue(); + if(!defined("NO_THREADS")){ + $this->asyncThread = new AsyncMultipleQueue(); + } } function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){ @@ -188,7 +190,10 @@ class PocketMinecraftServer{ $this->stop = true; $this->trigger("server.close", $reason); $this->interface->close(); - @$this->asyncThread->stop = true; + + if(!defined("NO_THREADS")){ + @$this->asyncThread->stop = true; + } } } @@ -206,6 +211,9 @@ class PocketMinecraftServer{ } public function asyncOperation($type, array $data, callable $callable = null){ + if(defined("NO_THREADS")){ + return false; + } $d = ""; $type = (int) $type; switch($type){ @@ -229,6 +237,9 @@ class PocketMinecraftServer{ } public function asyncOperationChecker(){ + if(defined("NO_THREADS")){ + return false; + } if(isset($this->asyncThread->output{5})){ $offset = 0; $ID = Utils::readInt(substr($this->asyncThread->output, $offset, 4)); From 251859921db57cffb88d1c9755148845bd2ebea5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 17:50:39 +0200 Subject: [PATCH 14/21] $server global --- src/tests/ServerSuiteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 24771504..64d98f8c 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -17,11 +17,11 @@ $this->assertTrue(Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08") === "4684309878217770760", "Utils::readLong"); //PocketMine-MP server startup + global $server; $server = new ServerAPI(); $server->load(); $this->assertTrue(is_integer($server->event("server.start", array($this, "hook")))); $server->init(); - exit(0); } public function hook(){ From ad1930da88cf347d83e3b4d0d213da550444cc5a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 18:19:48 +0200 Subject: [PATCH 15/21] Custom unit test code. --- .travis.yml | 2 +- phpunit.xml | 7 ----- src/dependencies.php | 4 --- src/tests/ServerSuiteTest.php | 55 +++++++++++++++++++++++++---------- 4 files changed, 40 insertions(+), 28 deletions(-) delete mode 100644 phpunit.xml diff --git a/.travis.yml b/.travis.yml index 037df269..1c46d5ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ before_script: - pecl install channel://pecl.php.net/pthreads-0.0.44 script: - - phpunit --process-isolation --configuration phpunit.xml + - php src/tests/ServerSuiteTest.php notifications: email: false diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index cdfdb09c..00000000 --- a/phpunit.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - src/tests - - - \ No newline at end of file diff --git a/src/dependencies.php b/src/dependencies.php index c8cde493..22c021a0 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -20,10 +20,6 @@ */ /***REM_START***/ -if(!class_exists("PHPUnit_Framework_TestCase", false)){ - class PHPUnit_Framework_TestCase{ - } -} require_once(dirname(__FILE__)."/config.php"); require_once(FILE_PATH."/src/functions.php"); /***REM_END***/ diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 64d98f8c..cb472e87 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -1,30 +1,53 @@ assertTrue(Utils::readTriad("\x02\x01\x03") === 131331, "Utils::readTriad"); - $this->assertTrue(Utils::readInt("\xff\x02\x01\x03") === -16645885, "Utils::readInt"); - $this->assertTrue(abs(Utils::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, "Utils::readFloat"); - $this->assertTrue(abs(Utils::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, "Utils::readDouble"); - $this->assertTrue(Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08") === "4684309878217770760", "Utils::readLong"); + testCase("Utils::readTriad", Utils::readTriad("\x02\x01\x03"), 131331); + testCase("Utils::readInt", Utils::readInt("\xff\x02\x01\x03"), -16645885); + testCase("Utils::readFloat", abs(Utils::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, true); + testCase("Utils::readDouble", abs(Utils::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, true); + testCase("Utils::readTriad", Utils::readLong("\x41\x02\x03\x04\x05\x06\x07\x08"), "4684309878217770760"); //PocketMine-MP server startup global $server; $server = new ServerAPI(); $server->load(); - $this->assertTrue(is_integer($server->event("server.start", array($this, "hook")))); + testCase("event attached", is_integer($server->event("server.start", array($this, "hook"))), true); $server->init(); } - public function hook(){ + public function hook(){ + testCase("event fired", true, true); //Everything done! ServerAPI::request()->close(); } From 71fc3f2ef009181cd1461cd416acef686bdbd81c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 20:31:45 +0200 Subject: [PATCH 16/21] fix --- src/tests/ServerSuiteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index cb472e87..ec935783 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -7,7 +7,7 @@ console("[TEST] $name: \x1b[32mOk."); }else{ console("[TEST] $name: \x1b[31mError."); - console("Expected ".safe_var_dump($expected).", got ".$output); + console("Expected ".safe_var_dump($expected).", got ".safe_var_dump($output)); ++$testErrors; } } From d347137148853626822def0f090cd20e3087bf42 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 23:37:47 +0200 Subject: [PATCH 17/21] Removed obsolete Data.php --- src/Data.php | 256 ---------------------------------- src/functions.php | 26 ---- src/tests/ServerSuiteTest.php | 7 +- 3 files changed, 6 insertions(+), 283 deletions(-) delete mode 100644 src/Data.php diff --git a/src/Data.php b/src/Data.php deleted file mode 100644 index eb5486ac..00000000 --- a/src/Data.php +++ /dev/null @@ -1,256 +0,0 @@ - true, - 6 => true, - 30 => true, - 31 => true, - 32 => true, - 37 => true, - 38 => true, - 39 => true, - 40 => true, - 50 => true, - 51 => true, - 55 => true, - 59 => true, - 78 => true, - 105 => true, - ); - static $unbreakable = array( - 0 => true, - 7 => true, - 8 => true, - 9 => true, - 10 => true, - 11 => true, - ); - static $transparent = array( - 0 => true, - 6 => true, - 8 => true, - 9 => true, - 10 => true, - 11 => true, - 18 => true, - 20 => true, - 26 => true, - 30 => true, - 31 => true, - 32 => true, - 37 => true, - 38 => true, - 39 => true, - 40 => true, - 44 => true, - 46 => true, - 50 => true, - 51 => true, - 53 => true, - 59 => true, - 63 => true, - 64 => true, - 65 => true, - 67 => true, - 68 => true, - 71 => true, - 78 => true, - 79 => true, - 83 => true, - 85 => true, - 89 => true, - 96 => true, - 102 => true, - 105 => true, - 107 => true, - 108 => true, - 109 => true, - 114 => true, - 128 => true, - 156 => true, - ); - static $replaceable = array( - 0 => true, - 8 => true, - 9 => true, - 10 => true, - 11 => true, - 31 => true, - 51 => true, - 78 => true, - ); - static $activable = array( - 2 => true, - 3 => true, - 6 => true, - 26 => true, - 31 => true, - //46 => true, - 51 => true, - 54 => true, - 58 => true, - 59 => true, - 61 => true, - 62 => true, - 64 => true, - 71 => true, - 78 => true, - 96 => true, - 105 => true, - 107 => true, - 245 => true, - 247 => true, - ); - static $placeable = array( - 1 => true, - 2 => true, - 3 => true, - 4 => true, - 5 => true, - 6 => true, - //7 => true, - 8 => true, - 9 => true, - 10 => true, - 11 => true, - 12 => true, - 13 => true, - 14 => true, - 15 => true, - 16 => true, - 17 => true, - 18 => true, - 19 => true, - 20 => true, - 21 => true, - 22 => true, - 24 => true, - 355 => 26, - 30 => true, - 35 => true, - 37 => true, - 38 => true, - 39 => true, - 40 => true, - 41 => true, - 42 => true, - 43 => true, - 44 => true, - 45 => true, - 46 => true, - 47 => true, - 48 => true, - 49 => true, - 50 => true, - 53 => true, - 54 => true, - 56 => true, - 59 => true, - 57 => true, - 58 => true, - 295 => 59, - 61 => true, - 324 => 64, - 65 => true, - 67 => true, - 330 => 71, - 73 => true, - 79 => true, - 80 => true, - 81 => true, - 82 => true, - 83 => true, - 85 => true, - 86 => true, - 87 => true, - 88 => true, - 89 => true, - 91 => true, - 96 => true, - 98 => true, - 102 => true, - 103 => true, - 362 => 105, - 107 => true, - 108 => true, - 109 => true, - 112 => true, - 114 => true, - 128 => true, - 155 => true, - 156 => true, - 245 => true, - 246 => true, - 247 => true, - 323 => true, //Special case of signs - 338 => 83, - ); - static $blocks = array( - 0 => "Air", - 1 => "Stone", - 2 => "Grass", - 3 => "Dirt", - 4 => "Cobblestone", - 5 => "Wooden Planks", - 6 => "Sapling", - 7 => "Bedrock", - ); - - -} \ No newline at end of file diff --git a/src/functions.php b/src/functions.php index 6fd1c954..beb6a457 100644 --- a/src/functions.php +++ b/src/functions.php @@ -122,32 +122,6 @@ function hard_unset(&$var){ } } - -function parseNBTData($data){ - $x = array(); - if(isset($data["value"])){ - return parseNBTData($data["value"]); - } - foreach($data as $d){ - if(!isset($d["value"]) and is_array($d) and count($d) == 1){ - return parseNBTData(array_pop($d)); - }elseif(!isset($d["value"]) and is_array($d)){ - $x[] = parseNBTData($d); - }elseif(is_array($d["value"]) and isset($d["name"])){ - $x[$d["name"]] = parseNBTData($d["value"]); - }elseif(is_array($d["value"]) and $d["type"] == 10){ - return parseNBTData($d["value"]); - }elseif($d["name"] != ""){ - $x[$d["name"]] = $d["value"]; - } - } - if(count($x) == 0){ - $x = $data; - } - return $x; -} - - function arg($name, $default = false){ global $arguments, $argv; if(!isset($arguments)){ diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index ec935783..ef8144aa 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -18,6 +18,7 @@ require_once(FILE_PATH."/src/functions.php"); require_once(FILE_PATH."/src/dependencies.php"); console("\x1b[36m[TEST] Starting tests"); + testCase("dummy", dummy(), null); $t = new ServerSuiteTest; echo PHP_EOL; if($testErrors === 0){ @@ -48,8 +49,12 @@ public function hook(){ testCase("event fired", true, true); + $server = ServerAPI::request(); + testCase("defaultgamemode", $server->getGamemode(), "creative"); + + //Everything done! - ServerAPI::request()->close(); + $server->close(); } } /***REM_END***/ \ No newline at end of file From 31bf65ad5cb703f5d9a15b212db63367bc80cf44 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 28 Aug 2013 23:42:40 +0200 Subject: [PATCH 18/21] Fixed test + output --- src/tests/ServerSuiteTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index ef8144aa..1e1e53c6 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -7,7 +7,7 @@ console("[TEST] $name: \x1b[32mOk."); }else{ console("[TEST] $name: \x1b[31mError."); - console("Expected ".safe_var_dump($expected).", got ".safe_var_dump($output)); + console("Expected ".print_r($expected, true).", got ".print_r($output, true)); ++$testErrors; } } @@ -50,7 +50,7 @@ public function hook(){ testCase("event fired", true, true); $server = ServerAPI::request(); - testCase("defaultgamemode", $server->getGamemode(), "creative"); + testCase("defaultgamemode", $server->getGamemode(), "survival"); //Everything done! From dc5b8ecd304537e409848be30ce6b7a9dff01316 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 29 Aug 2013 09:21:52 +0200 Subject: [PATCH 19/21] Fixed low TPS --- src/PocketMinecraftServer.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index f692cf58..e73c176b 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -565,8 +565,12 @@ class PocketMinecraftServer{ $lastLoop = 0; }else{ ++$lastLoop; - if($lastLoop >= 16){ - usleep(5000); + if($lastLoop < 16){ + usleep(1); + }elseif($lastLoop >= 128){ + usleep(100); + }elseif($lastLoop >= 256){ + usleep(512); } } } From f609c40bdc9f04d4acac83b2806c52891ce38b4f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 29 Aug 2013 13:36:09 +0200 Subject: [PATCH 20/21] Added homepage info on start.cmd --- start.cmd | 1 + 1 file changed, 1 insertion(+) diff --git a/start.cmd b/start.cmd index 83d08496..47ec2390 100644 --- a/start.cmd +++ b/start.cmd @@ -6,6 +6,7 @@ cd /d %~dp0 FOR /F "tokens=*" %%i in ('php -r "echo 1;"') do SET PHPOUTPUT=%%i if not "%PHPOUTPUT%"=="1" ( echo [ERROR] Couldn't find PHP binary in PATH. +echo [INFO] Please use the Windows installer from the homepage ) else ( if exist php.cmd ( if exist bin\ansicon.exe ( From fe681cb7863e3b9fd6794385ce9cb8f7cb615f75 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 29 Aug 2013 18:35:57 +0200 Subject: [PATCH 21/21] Removed character range check for UTF-8 full support --- src/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Player.php b/src/Player.php index 174d55c3..85bd7cb5 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1631,7 +1631,7 @@ class Player{ } $this->craftingItems = array(); $this->toCraft = array(); - if(trim($data["message"]) != "" and strlen($data["message"]) <= 255 and preg_match('#[^\\x20-\\xff]#', $data["message"]) == 0){ + if(trim($data["message"]) != "" and strlen($data["message"]) <= 255){ $message = $data["message"]; if($message{0} === "/"){ //Command $this->server->api->console->run(substr($message, 1), $this);