Merge remote-tracking branch 'origin/0.7.4'

This commit is contained in:
Shoghi Cervantes 2013-08-29 19:47:25 +02:00
commit 08ed5dbfac
11 changed files with 85 additions and 360 deletions

View File

@ -7,7 +7,7 @@ before_script:
- pecl install channel://pecl.php.net/pthreads-0.0.44
script:
- phpunit src/tests/
- php src/tests/ServerSuiteTest.php
notifications:
email: false

View File

@ -1,31 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class MobAPI{
private $server;
function __construct(){
$this->server = ServerAPI::request();
}
public function init(){
}
}

View File

@ -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"))){

View File

@ -1,256 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
class BlockFace{
const BOTTOM = 0;
const TOP = 1;
const DOWN = 0;
const UP = 1;
const SOUTH = 3;
const EAST = 5;
const NORTH = 2;
const WEST = 4;
public static function setPosition(&$data, $face){
switch((int) $face){
case 0:
--$data["y"];
break;
case 1:
++$data["y"];
break;
case 2:
--$data["z"];
break;
case 3:
++$data["z"];
break;
case 4:
--$data["x"];
break;
case 5:
++$data["x"];
break;
default:
return false;
}
return true;
}
}
class Material{
static $flowable = array(
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",
);
}

View File

@ -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{
@ -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);

View File

@ -26,7 +26,9 @@ class PocketMinecraftServer{
private function load(){
$this->version = new VersionString();
@cli_set_process_title("PocketMine-MP ".MAJOR_VERSION);
if(defined("DEBUG") and DEBUG >= 0){
@cli_set_process_title("PocketMine-MP ".MAJOR_VERSION);
}
if($this->version->isDev()){
console("[INFO] \x1b[31;1mThis is a Development version");
}
@ -64,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"){
@ -87,7 +91,7 @@ class PocketMinecraftServer{
public function titleTick(){
$time = microtime(true);
if(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);
@ -186,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;
}
}
}
@ -204,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){
@ -227,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));
@ -552,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);
}
}
}

View File

@ -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)){

View File

@ -1,38 +1,60 @@
<?php
if(class_exists("PHPUnit_Framework_TestCase", false)){
class ServerSuiteTest extends PHPUnit_Framework_TestCase{
private $server;
public function hook(){
$this->assertTrue(true);
$server = ServerAPI::request();
//Everything done!
$server->close();
/***REM_START***/
$testErrors = 0;
function testCase($name, $output, $expected){
global $testErrors;
if($output === $expected){
console("[TEST] $name: \x1b[32mOk.");
}else{
console("[TEST] $name: \x1b[31mError.");
console("Expected ".print_r($expected, true).", got ".print_r($output, true));
++$testErrors;
}
}
public function testRead(){
if(!class_exists("PocketMinecraftServer", false)){
define("NO_THREADS", true);
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);
console("\x1b[36m[TEST] Starting tests");
testCase("dummy", dummy(), null);
$t = new ServerSuiteTest;
echo PHP_EOL;
if($testErrors === 0){
console("\x1b[32m[TEST] No errors. Test complete.");
exit(0);
}else{
console("\x1b[31m[TEST] Errors found.");
exit(1);
}
}
}
}
class ServerSuiteTest {
public function __construct(){
//binary things
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();
testCase("event attached", is_integer($server->event("server.start", array($this, "hook"))), true);
$server->init();
}
public function hook(){
testCase("event fired", true, true);
$server = ServerAPI::request();
testCase("defaultgamemode", $server->getGamemode(), "survival");
//Everything done!
$server->close();
}
}
/***REM_END***/

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpunit>
<testsuite name='PocketMine-MP'>
<directory suffix='.php'>./</directory>
</testsuite>
</phpunit>

View File

@ -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;
}

View File

@ -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 (