Fixed TABS

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-06 13:38:28 +01:00
parent b3b38605b5
commit aa1a39adfc
41 changed files with 549 additions and 549 deletions

View File

@ -37,14 +37,14 @@ class BlockAPI{
function __construct(PocketMinecraftServer $server){ function __construct(PocketMinecraftServer $server){
$this->server = $server; $this->server = $server;
} }
public function init(){ public function init(){
$this->server->addHandler("world.block.update", array($this, "updateBlockRemote"), 1); $this->server->addHandler("world.block.update", array($this, "updateBlockRemote"), 1);
$this->server->addHandler("player.block.break", array($this, "blockBreak"), 1); $this->server->addHandler("player.block.break", array($this, "blockBreak"), 1);
$this->server->addHandler("player.block.action", array($this, "blockAction"), 1); $this->server->addHandler("player.block.action", array($this, "blockAction"), 1);
$this->server->api->console->register("give", "Give items to a player", array($this, "commandHandler")); $this->server->api->console->register("give", "Give items to a player", array($this, "commandHandler"));
} }
public function commandHandler($cmd, $params){ public function commandHandler($cmd, $params){
switch($cmd){ switch($cmd){
case "give": case "give":
@ -74,11 +74,11 @@ class BlockAPI{
}else{ }else{
console("[INFO] Unknown player"); console("[INFO] Unknown player");
} }
break; break;
} }
} }
private function cancelAction($block){ private function cancelAction($block){
$this->server->api->dhandle("world.block.change", array( $this->server->api->dhandle("world.block.change", array(
"x" => $block[2][0], "x" => $block[2][0],
@ -90,7 +90,7 @@ class BlockAPI{
)); ));
return false; return false;
} }
public function blockBreak($data, $event){ public function blockBreak($data, $event){
if($event !== "player.block.break"){ if($event !== "player.block.break"){
return; return;
@ -189,7 +189,7 @@ class BlockAPI{
$this->server->trigger("player.block.break", $data); $this->server->trigger("player.block.break", $data);
return false; return false;
} }
public function drop($x, $y, $z, $block, $meta, $stack = 1){ public function drop($x, $y, $z, $block, $meta, $stack = 1){
if($block === 0 or $stack <= 0 or $this->server->gamemode === 1){ if($block === 0 or $stack <= 0 or $this->server->gamemode === 1){
return; return;
@ -213,7 +213,7 @@ class BlockAPI{
} }
} }
} }
public function blockAction($data, $event){ public function blockAction($data, $event){
if($event !== "player.block.action"){ if($event !== "player.block.action"){
return; return;
@ -225,9 +225,9 @@ class BlockAPI{
if($target[0] === 0){ //If no block exists if($target[0] === 0){ //If no block exists
$this->cancelAction($target); $this->cancelAction($target);
$block = $this->server->api->level->getBlockFace($target, $data["face"]); $block = $this->server->api->level->getBlockFace($target, $data["face"]);
return $this->cancelAction($block); return $this->cancelAction($block);
} }
$cancelPlace = false; $cancelPlace = false;
if(isset(Material::$activable[$target[0]])){ if(isset(Material::$activable[$target[0]])){
switch($target[0]){ switch($target[0]){
@ -252,7 +252,7 @@ class BlockAPI{
"type" => WINDOW_FURNACE, "type" => WINDOW_FURNACE,
"slots" => 3, "slots" => 3,
"title" => "Furnace", "title" => "Furnace",
)); ));
break; break;
case 6: case 6:
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
@ -273,9 +273,9 @@ class BlockAPI{
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
$data["block"] = $target[0]; $data["block"] = $target[0];
$data["meta"] = 0x07; $data["meta"] = 0x07;
$this->server->handle("player.block.place", $data); $this->server->handle("player.block.place", $data);
$cancelPlace = true; $cancelPlace = true;
} }
break; break;
case 64: //Door case 64: //Door
if(($target[1] & 0x08) === 0x08){ if(($target[1] & 0x08) === 0x08){
@ -320,13 +320,13 @@ class BlockAPI{
default: default:
$cancelPlace = true; $cancelPlace = true;
break; break;
} }
} }
if($cancelPlace === true){ if($cancelPlace === true){
return false; return false;
} }
$replace = false; $replace = false;
switch($target[0]){ switch($target[0]){
case 44: //Slabs case 44: //Slabs
@ -340,29 +340,29 @@ class BlockAPI{
} }
break; break;
} }
if($replace === false){ if($replace === false){
BlockFace::setPosition($data, $data["face"]); BlockFace::setPosition($data, $data["face"]);
} }
if($data["y"] >= 127){ if($data["y"] >= 127){
return false; return false;
} }
$block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]); $block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
if($replace === false and !isset(Material::$replaceable[$block[0]])){ if($replace === false and !isset(Material::$replaceable[$block[0]])){
return $this->cancelAction($block); return $this->cancelAction($block);
} }
if(isset(Material::$placeable[$data["block"]])){ if(isset(Material::$placeable[$data["block"]])){
$data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]]; $data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]];
}else{ }else{
return $this->cancelAction($block); return $this->cancelAction($block);
} }
$direction = $this->server->api->entity->get($data["eid"])->getDirection(); $direction = $this->server->api->entity->get($data["eid"])->getDirection();
switch($data["block"]){ switch($data["block"]){
case 6: case 6:
if($target[0] === 60){ if($target[0] === 60){
@ -391,7 +391,7 @@ class BlockAPI{
$block2 = $this->server->api->level->getBlock($data["x"] + 1, $data["y"], $data["z"]); $block2 = $this->server->api->level->getBlock($data["x"] + 1, $data["y"], $data["z"]);
$block3 = $this->server->api->level->getBlock($data["x"] - 1, $data["y"], $data["z"]); $block3 = $this->server->api->level->getBlock($data["x"] - 1, $data["y"], $data["z"]);
if($block0[0] === 9 or $block0[0] === 8 or $block1[0] === 9 or $block1[0] === 8 or $block2[0] === 9 or $block2[0] === 8 or $block3[0] === 9 or $block3[0] === 8){ if($block0[0] === 9 or $block0[0] === 8 or $block1[0] === 9 or $block1[0] === 8 or $block2[0] === 9 or $block2[0] === 8 or $block3[0] === 9 or $block3[0] === 8){
}else{ }else{
return false; return false;
} }
@ -527,11 +527,11 @@ class BlockAPI{
$this->server->handle("player.block.place", $data); $this->server->handle("player.block.place", $data);
return false; return false;
} }
public function blockScheduler($data){ public function blockScheduler($data){
$this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_SCHEDULED); $this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_SCHEDULED);
} }
public function updateBlockRemote($data, $event){ public function updateBlockRemote($data, $event){
if($event !== "world.block.update"){ if($event !== "world.block.update"){
return; return;
@ -570,14 +570,14 @@ class BlockAPI{
"type" => BLOCK_UPDATE_NORMAL, "type" => BLOCK_UPDATE_NORMAL,
)); ));
$this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 10, $level | $down, false); $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 10, $level | $down, false);
return true; return true;
}elseif(($source[1] & 0x08) === 0x08){ }elseif(($source[1] & 0x08) === 0x08){
$this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], $source[0], $source[1] & 0x07, false); $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], $source[0], $source[1] & 0x07, false);
return true; return true;
} }
return false; return false;
} }
public function flowWaterOn($source, $face){ public function flowWaterOn($source, $face){
$down = 0; $down = 0;
if($face === BlockFace::BOTTOM){ if($face === BlockFace::BOTTOM){
@ -609,14 +609,14 @@ class BlockAPI{
"type" => BLOCK_UPDATE_NORMAL, "type" => BLOCK_UPDATE_NORMAL,
)); ));
$this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 8, $level | $down, false); $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 8, $level | $down, false);
return true; return true;
}elseif(($source[1] & 0x08) === 0x08){ }elseif(($source[1] & 0x08) === 0x08){
$this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], $source[0], $source[1] & 0x07, false); $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], $source[0], $source[1] & 0x07, false);
return true; return true;
} }
return false; return false;
} }
public function updateBlock($x, $y, $z, $type = BLOCK_UPDATE_NORMAL){ public function updateBlock($x, $y, $z, $type = BLOCK_UPDATE_NORMAL){
$block = $this->server->api->level->getBlock($x, $y, $z); $block = $this->server->api->level->getBlock($x, $y, $z);
$changed = false; $changed = false;
@ -690,7 +690,7 @@ class BlockAPI{
"z" => $block[2][2], "z" => $block[2][2],
"type" => BLOCK_UPDATE_NORMAL, "type" => BLOCK_UPDATE_NORMAL,
)); ));
$this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false); $this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false);
}else{ }else{
$block[1] = ($block[1] & 0x08) | $level; $block[1] = ($block[1] & 0x08) | $level;
$this->server->schedule(10, array($this, "blockScheduler"), array( $this->server->schedule(10, array($this, "blockScheduler"), array(
@ -732,7 +732,7 @@ class BlockAPI{
$this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], $block[0], $block[1], false); $this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], $block[0], $block[1], false);
} }
} }
} }
break; break;
case 10: case 10:
case 11: case 11:
@ -802,7 +802,7 @@ class BlockAPI{
"z" => $block[2][2], "z" => $block[2][2],
"type" => BLOCK_UPDATE_NORMAL, "type" => BLOCK_UPDATE_NORMAL,
)); ));
$this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false); $this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false);
}else{ }else{
$block[1] = ($block[1] & 0x08) | $level; $block[1] = ($block[1] & 0x08) | $level;
$this->server->schedule(20, array($this, "blockScheduler"), array( $this->server->schedule(20, array($this, "blockScheduler"), array(
@ -845,7 +845,7 @@ class BlockAPI{
} }
} }
} }
break; break;
case 74: case 74:
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){ if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
@ -874,7 +874,7 @@ class BlockAPI{
$this->updateBlocksAround($x, $y, $z, $type); $this->updateBlocksAround($x, $y, $z, $type);
} }
} }
public function updateBlocksAround($x, $y, $z, $type){ public function updateBlocksAround($x, $y, $z, $type){
$this->updateBlock($x + 1, $y, $z, $type); $this->updateBlock($x + 1, $y, $z, $type);
$this->updateBlock($x, $y + 1, $z, $type); $this->updateBlock($x, $y + 1, $z, $type);

View File

@ -33,20 +33,20 @@ class ConsoleAPI{
$this->server = $server; $this->server = $server;
$this->last = microtime(true); $this->last = microtime(true);
} }
public function init(){ public function init(){
$this->event = $this->server->event("server.tick", array($this, "handle")); $this->event = $this->server->event("server.tick", array($this, "handle"));
$this->loop = new ConsoleLoop; $this->loop = new ConsoleLoop;
$this->loop->start(); $this->loop->start();
} }
function __destruct(){ function __destruct(){
$this->server->deleteEvent($this->event); $this->server->deleteEvent($this->event);
$this->loop->stop = true; $this->loop->stop = true;
$this->loop->notify(); $this->loop->notify();
$this->loop->join(); $this->loop->join();
} }
public function defaultCommands($cmd, $params){ public function defaultCommands($cmd, $params){
switch($cmd){ switch($cmd){
case "invisible": case "invisible":
@ -79,7 +79,7 @@ class ConsoleAPI{
break; break;
case "stop": case "stop":
$this->loop->stop = true; $this->loop->stop = true;
console("[INFO] Stopping the server..."); console("[INFO] Stopping the server...");
$this->server->close(); $this->server->close();
break; break;
/*case "restart": /*case "restart":
@ -93,7 +93,7 @@ class ConsoleAPI{
case "pardon": case "pardon":
case "remove": case "remove":
$ip = trim(implode($params)); $ip = trim(implode($params));
$new = array(); $new = array();
foreach(explode("\n", str_replace(array("\r","\t"), "", file_get_contents(FILE_PATH."banned-ips.txt"))) as $i){ foreach(explode("\n", str_replace(array("\r","\t"), "", file_get_contents(FILE_PATH."banned-ips.txt"))) as $i){
if($i == $ip){ if($i == $ip){
console("[INFO] IP \"$ip\" removed from ban list"); console("[INFO] IP \"$ip\" removed from ban list");
@ -154,7 +154,7 @@ class ConsoleAPI{
switch($p){ switch($p){
case "remove": case "remove":
$user = trim(implode(" ", $params)); $user = trim(implode(" ", $params));
$new = array(); $new = array();
foreach(explode("\n", str_replace(array("\r","\t"), "", file_get_contents(FILE_PATH."white-list.txt"))) as $u){ foreach(explode("\n", str_replace(array("\r","\t"), "", file_get_contents(FILE_PATH."white-list.txt"))) as $u){
if($u == $user){ if($u == $user){
console("[INFO] Player \"$user\" removed from white-list"); console("[INFO] Player \"$user\" removed from white-list");
@ -225,11 +225,11 @@ class ConsoleAPI{
break; break;
} }
} }
public function alias($alias, $cmd){ public function alias($alias, $cmd){
$this->cmds[strtolower(trim($alias))] = &$this->cmds[$cmd]; $this->cmds[strtolower(trim($alias))] = &$this->cmds[$cmd];
} }
public function register($cmd, $help, $callback){ public function register($cmd, $help, $callback){
if(!is_callable($callback)){ if(!is_callable($callback)){
return false; return false;
@ -238,7 +238,7 @@ class ConsoleAPI{
$this->cmds[$cmd] = $callback; $this->cmds[$cmd] = $callback;
$this->help[$cmd] = $help; $this->help[$cmd] = $help;
} }
public function handle($time){ public function handle($time){
if($this->loop->line !== false){ if($this->loop->line !== false){
$line = trim($this->loop->line); $line = trim($this->loop->line);

View File

@ -30,11 +30,11 @@ class EntityAPI{
function __construct(PocketMinecraftServer $server){ function __construct(PocketMinecraftServer $server){
$this->server = $server; $this->server = $server;
} }
public function init(){ public function init(){
$this->server->addHandler("player.death", array($this, "handle"), 1); $this->server->addHandler("player.death", array($this, "handle"), 1);
} }
public function handle($data, $event){ public function handle($data, $event){
switch($event){ switch($event){
case "player.death": case "player.death":
@ -58,7 +58,7 @@ class EntityAPI{
} }
$this->server->chat(false, $message); $this->server->chat(false, $message);
break; break;
} }
} }
public function get($eid){ public function get($eid){
@ -67,15 +67,15 @@ class EntityAPI{
} }
return false; return false;
} }
public function getAll(){ public function getAll(){
return $this->server->entities; return $this->server->entities;
} }
public function heal($eid, $heal = 1, $cause){ public function heal($eid, $heal = 1, $cause){
$this->harm($eid, -$heal, $cause); $this->harm($eid, -$heal, $cause);
} }
public function harm($eid, $attack = 1, $cause){ public function harm($eid, $attack = 1, $cause){
$e = $this->get($eid); $e = $this->get($eid);
if($e === false or $e->dead === true){ if($e === false or $e->dead === true){
@ -83,13 +83,13 @@ class EntityAPI{
} }
$e->setHealth($e->getHealth()-$attack, $cause); $e->setHealth($e->getHealth()-$attack, $cause);
} }
public function add($class, $type = 0, $data = array()){ public function add($class, $type = 0, $data = array()){
$eid = $this->server->eidCnt++; $eid = $this->server->eidCnt++;
$this->server->entities[$eid] = new Entity($this->server, $eid, $class, $type, $data); $this->server->entities[$eid] = new Entity($this->server, $eid, $class, $type, $data);
return $this->server->entities[$eid]; return $this->server->entities[$eid];
} }
public function spawnTo($eid, $player){ public function spawnTo($eid, $player){
$e = $this->get($eid); $e = $this->get($eid);
if($e === false){ if($e === false){
@ -97,7 +97,7 @@ class EntityAPI{
} }
$e->spawn($player); $e->spawn($player);
} }
public function spawnToAll($eid){ public function spawnToAll($eid){
$e = $this->get($eid); $e = $this->get($eid);
if($e === false){ if($e === false){
@ -109,17 +109,17 @@ class EntityAPI{
} }
} }
} }
public function spawnAll($player){ public function spawnAll($player){
foreach($this->getAll() as $e){ foreach($this->getAll() as $e){
$e->spawn($player); $e->spawn($player);
} }
} }
public function remove($eid){ public function remove($eid){
if(isset($this->server->entities[$eid])){ if(isset($this->server->entities[$eid])){
$this->server->entities[$eid]->close(); $this->server->entities[$eid]->close();
unset($this->server->entities[$eid]); unset($this->server->entities[$eid]);
} }
} }
} }

View File

@ -32,13 +32,13 @@ class LevelAPI{
$this->map = $this->server->map; $this->map = $this->server->map;
$this->heightMap = array_fill(0, 256, array()); $this->heightMap = array_fill(0, 256, array());
} }
public function init(){ public function init(){
$this->server->event("player.block.break", array($this, "handle")); $this->server->event("player.block.break", array($this, "handle"));
$this->server->event("player.block.place", array($this, "handle")); $this->server->event("player.block.place", array($this, "handle"));
$this->server->event("player.block.update", array($this, "handle")); $this->server->event("player.block.update", array($this, "handle"));
} }
public function handle($data, $event){ public function handle($data, $event){
switch($event){ switch($event){
case "player.block.place": case "player.block.place":
@ -49,7 +49,7 @@ class LevelAPI{
case "player.block.break": case "player.block.break":
$block = $this->getBlock($data["x"], $data["y"], $data["z"]); $block = $this->getBlock($data["x"], $data["y"], $data["z"]);
console("[DEBUG] EID ".$data["eid"]." broke ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2); console("[DEBUG] EID ".$data["eid"]." broke ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
if($block[0] === 0){ if($block[0] === 0){
break; break;
} }
@ -57,34 +57,34 @@ class LevelAPI{
break; break;
} }
} }
public function getSpawn(){ public function getSpawn(){
return $this->server->spawn; return $this->server->spawn;
} }
public function getChunk($X, $Z){ public function getChunk($X, $Z){
return $this->map->map[$X][$Z]; return $this->map->map[$X][$Z];
} }
public function getBlockFace($block, $face){ public function getBlockFace($block, $face){
$data = array("x" => $block[2][0], "y" => $block[2][1], "z" => $block[2][2]); $data = array("x" => $block[2][0], "y" => $block[2][1], "z" => $block[2][2]);
BlockFace::setPosition($data, $face); BlockFace::setPosition($data, $face);
return $this->getBlock($data["x"], $data["y"], $data["z"]); return $this->getBlock($data["x"], $data["y"], $data["z"]);
} }
public function getBlock($x, $y, $z){ public function getBlock($x, $y, $z){
$b = $this->map->getBlock($x, $y, $z); $b = $this->map->getBlock($x, $y, $z);
$b[2] = array($x, $y, $z); $b[2] = array($x, $y, $z);
return $b; return $b;
} }
public function getFloor($x, $z){ public function getFloor($x, $z){
if(!isset($this->heightMap[$z][$x])){ if(!isset($this->heightMap[$z][$x])){
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z); $this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
} }
return $this->heightMap[$z][$x]; return $this->heightMap[$z][$x];
} }
public function setBlock($x, $y, $z, $block, $meta = 0, $update = true){ public function setBlock($x, $y, $z, $block, $meta = 0, $update = true){
$this->map->setBlock($x, $y, $z, $block, $meta); $this->map->setBlock($x, $y, $z, $block, $meta);
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z); $this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
@ -101,7 +101,7 @@ class LevelAPI{
} }
} }
} }
public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){ public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){
$columnsPerPacket = max(1, (int) $columnsPerPacket); $columnsPerPacket = max(1, (int) $columnsPerPacket);
$c = $this->getChunk($X, $Z); $c = $this->getChunk($X, $Z);

View File

@ -30,7 +30,7 @@ class PlayerAPI{
function __construct(PocketMinecraftServer $server){ function __construct(PocketMinecraftServer $server){
$this->server = $server; $this->server = $server;
} }
public function init(){ public function init(){
$this->server->event("server.regeneration", array($this, "handle")); $this->server->event("server.regeneration", array($this, "handle"));
$this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler")); $this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler"));
@ -38,7 +38,7 @@ class PlayerAPI{
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler")); $this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler")); $this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
} }
public function handle($data, $event){ public function handle($data, $event){
switch($event){ switch($event){
case "server.regeneration": case "server.regeneration":
@ -53,7 +53,7 @@ class PlayerAPI{
break; break;
} }
} }
public function commandHandler($cmd, $params){ public function commandHandler($cmd, $params){
switch($cmd){ switch($cmd){
case "tp": case "tp":
@ -100,7 +100,7 @@ class PlayerAPI{
break; break;
} }
} }
public function teleport($name, $target){ public function teleport($name, $target){
$target = $this->get($target); $target = $this->get($target);
if($target !== false){ if($target !== false){
@ -108,7 +108,7 @@ class PlayerAPI{
} }
return false; return false;
} }
public function tppos($name, $x, $y, $z){ public function tppos($name, $x, $y, $z){
$player = $this->get($name); $player = $this->get($name);
if($player !== false){ if($player !== false){
@ -124,7 +124,7 @@ class PlayerAPI{
} }
return false; return false;
} }
public function get($name){ public function get($name){
$CID = $this->server->query("SELECT ip,port FROM players WHERE name = '".str_replace("'", "", $name)."';", true); $CID = $this->server->query("SELECT ip,port FROM players WHERE name = '".str_replace("'", "", $name)."';", true);
$CID = $this->server->clientID($CID["ip"], $CID["port"]); $CID = $this->server->clientID($CID["ip"], $CID["port"]);
@ -133,11 +133,11 @@ class PlayerAPI{
} }
return false; return false;
} }
public function getAll(){ public function getAll(){
return $this->server->clients; return $this->server->clients;
} }
public function getByEID($eid){ public function getByEID($eid){
$eid = (int) $eid; $eid = (int) $eid;
$CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true); $CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true);
@ -147,7 +147,7 @@ class PlayerAPI{
} }
return false; return false;
} }
public function getByClientID($clientID){ public function getByClientID($clientID){
$clientID = (int) $clientID; $clientID = (int) $clientID;
$CID = $this->server->query("SELECT ip,port FROM players WHERE clientID = '".$clientID."';", true); $CID = $this->server->query("SELECT ip,port FROM players WHERE clientID = '".$clientID."';", true);
@ -155,9 +155,9 @@ class PlayerAPI{
if(isset($this->server->clients[$CID])){ if(isset($this->server->clients[$CID])){
return $this->server->clients[$CID]; return $this->server->clients[$CID];
} }
return false; return false;
} }
public function online(){ public function online(){
$o = array(); $o = array();
foreach($this->server->clients as $p){ foreach($this->server->clients as $p){
@ -167,7 +167,7 @@ class PlayerAPI{
} }
return $o; return $o;
} }
public function add($CID){ public function add($CID){
if(isset($this->server->clients[$CID])){ if(isset($this->server->clients[$CID])){
$player = $this->server->clients[$CID]; $player = $this->server->clients[$CID];
@ -176,7 +176,7 @@ class PlayerAPI{
$this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".$player->username."');"); $this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".$player->username."');");
} }
} }
public function remove($CID){ public function remove($CID){
if(isset($this->server->clients[$CID])){ if(isset($this->server->clients[$CID])){
$player = $this->server->clients[$CID]; $player = $this->server->clients[$CID];
@ -189,7 +189,7 @@ class PlayerAPI{
unset($this->server->clients[$player->CID]); unset($this->server->clients[$player->CID]);
} }
} }
public function getOffline($name){ public function getOffline($name){
if(!file_exists(FILE_PATH."players/".$name.".dat")){ if(!file_exists(FILE_PATH."players/".$name.".dat")){
console("[NOTICE] Player data not found for \"".$name."\", creating new profile"); console("[NOTICE] Player data not found for \"".$name."\", creating new profile");
@ -210,9 +210,9 @@ class PlayerAPI{
$this->server->handle("api.player.offline.get", $data); $this->server->handle("api.player.offline.get", $data);
return $data; return $data;
} }
public function saveOffline($name, $data){ public function saveOffline($name, $data){
$this->server->handle("api.player.offline.save", $data); $this->server->handle("api.player.offline.save", $data);
file_put_contents(FILE_PATH."players/".str_replace("/", "", $name).".dat", serialize($data)); file_put_contents(FILE_PATH."players/".str_replace("/", "", $name).".dat", serialize($data));
} }
} }

View File

@ -32,7 +32,7 @@ class PluginAPI extends stdClass{
$this->plugins = array(); $this->plugins = array();
require_once("classes/Spyc.class.php"); //YAML parser require_once("classes/Spyc.class.php"); //YAML parser
} }
public function getList(){ public function getList(){
$list = array(); $list = array();
foreach($this->plugins as $p){ foreach($this->plugins as $p){
@ -40,7 +40,7 @@ class PluginAPI extends stdClass{
} }
return $list; return $list;
} }
public function getInfo($className){ public function getInfo($className){
if(!isset($this->plugins[$className])){ if(!isset($this->plugins[$className])){
return false; return false;
@ -48,7 +48,7 @@ class PluginAPI extends stdClass{
$plugin = $this->plugins[$className]; $plugin = $this->plugins[$className];
return array($plugin[1], get_class_methods($plugin[0])); return array($plugin[1], get_class_methods($plugin[0]));
} }
public function load($file){ public function load($file){
$content = file_get_contents($file); $content = file_get_contents($file);
$info = strstr($content, "*/", true); $info = strstr($content, "*/", true);
@ -95,12 +95,12 @@ class PluginAPI extends stdClass{
$object->__destruct(); $object->__destruct();
} }
$object = null; $object = null;
unset($object); unset($object);
}else{ }else{
$this->plugins[$className] = array($object, $info); $this->plugins[$className] = array($object, $info);
} }
} }
public function get(Plugin $plugin){ public function get(Plugin $plugin){
foreach($this->plugins as &$p){ foreach($this->plugins as &$p){
if($p[0] === $plugin){ if($p[0] === $plugin){
@ -109,7 +109,7 @@ class PluginAPI extends stdClass{
} }
return false; return false;
} }
public function createConfig(Plugin $plugin, $default = array()){ public function createConfig(Plugin $plugin, $default = array()){
$p = $this->get($plugin); $p = $this->get($plugin);
if($p === false){ if($p === false){
@ -127,7 +127,7 @@ class PluginAPI extends stdClass{
} }
return $path; return $path;
} }
private function fillDefaults($default, &$yaml){ private function fillDefaults($default, &$yaml){
foreach($default as $k => $v){ foreach($default as $k => $v){
if(is_array($v)){ if(is_array($v)){
@ -140,19 +140,19 @@ class PluginAPI extends stdClass{
} }
} }
} }
public function readYAML($file){ public function readYAML($file){
return Spyc::YAMLLoad(file_get_contents($file)); return Spyc::YAMLLoad(file_get_contents($file));
} }
public function writeYAML($file, $data){ public function writeYAML($file, $data){
return file_put_contents($file, Spyc::YAMLDump($data)); return file_put_contents($file, Spyc::YAMLDump($data));
} }
public function init(){ public function init(){
$this->server->event("server.start", array($this, "loadAll")); $this->server->event("server.start", array($this, "loadAll"));
} }
public function loadAll(){ public function loadAll(){
console("[INFO] Loading Plugins..."); console("[INFO] Loading Plugins...");
$dir = dir(FILE_PATH."plugins/"); $dir = dir(FILE_PATH."plugins/");

View File

@ -69,7 +69,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
die(); die();
} }
} }
if(!file_exists(FILE_PATH."white-list.txt")){ if(!file_exists(FILE_PATH."white-list.txt")){
console("[NOTICE] No white-list.txt found, creating blank file"); console("[NOTICE] No white-list.txt found, creating blank file");
file_put_contents(FILE_PATH."white-list.txt", ""); file_put_contents(FILE_PATH."white-list.txt", "");
@ -84,7 +84,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
console("[NOTICE] No server.properties found, using default settings"); console("[NOTICE] No server.properties found, using default settings");
copy(FILE_PATH."src/common/default.properties", FILE_PATH."server.properties"); copy(FILE_PATH."src/common/default.properties", FILE_PATH."server.properties");
} }
console("[DEBUG] Loading server.properties...", true, true, 2); console("[DEBUG] Loading server.properties...", true, true, 2);
$this->parseProperties(); $this->parseProperties();
define("DEBUG", $this->config["debug"]); define("DEBUG", $this->config["debug"]);
@ -98,7 +98,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$channel = "dev"; $channel = "dev";
} }
$this->setProperty("update-channel", $channel); $this->setProperty("update-channel", $channel);
if($channel === "dev"){ if($channel === "dev"){
$info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/PocketMine-MP"), true); $info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/PocketMine-MP"), true);
if($info === false or !isset($info["updated_at"])){ if($info === false or !isset($info["updated_at"])){
@ -131,7 +131,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$newest = array($i, $update); $newest = array($i, $update);
} }
} }
if($newest[0] !== -1){ if($newest[0] !== -1){
$target = $info[$newest[0]]; $target = $info[$newest[0]];
console("[NOTICE] A new STABLE version of PocketMine-MP has been released"); console("[NOTICE] A new STABLE version of PocketMine-MP has been released");
@ -144,7 +144,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
console("[INFO] This is the latest STABLE version"); console("[INFO] This is the latest STABLE version");
} }
} }
} }
} }
if(file_exists(FILE_PATH."worlds/level.dat")){ if(file_exists(FILE_PATH."worlds/level.dat")){
@ -174,7 +174,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
} }
$this->loadProperties(); $this->loadProperties();
$this->server->loadMap(); $this->server->loadMap();
//Autoload all default APIs //Autoload all default APIs
console("[INFO] Loading default APIs"); console("[INFO] Loading default APIs");
$dir = dir(FILE_PATH."src/API/"); $dir = dir(FILE_PATH."src/API/");
@ -192,10 +192,10 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$ob->init(); $ob->init();
} }
} }
$this->server->loadEntities(); $this->server->loadEntities();
} }
public function __destruct(){ public function __destruct(){
foreach($this->apiList as $ob){ foreach($this->apiList as $ob){
if(is_callable($ob, "__destruct")){ if(is_callable($ob, "__destruct")){
@ -204,8 +204,8 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
} }
} }
} }
private function loadProperties(){ private function loadProperties(){
if(isset($this->config["memory-limit"])){ if(isset($this->config["memory-limit"])){
@ini_set("memory_limit", $this->config["memory-limit"]); @ini_set("memory_limit", $this->config["memory-limit"]);
@ -228,7 +228,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$this->server->reloadConfig(); $this->server->reloadConfig();
} }
} }
private function writeProperties(){ private function writeProperties(){
if(is_object($this->server)){ if(is_object($this->server)){
$this->config["server-id"] = $this->server->serverID; $this->config["server-id"] = $this->server->serverID;
@ -242,7 +242,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
} }
file_put_contents(FILE_PATH."server.properties", $prop); file_put_contents(FILE_PATH."server.properties", $prop);
} }
private function parseProperties(){ private function parseProperties(){
$prop = file_get_contents(FILE_PATH."server.properties"); $prop = file_get_contents(FILE_PATH."server.properties");
$prop = explode("\n", str_replace("\r", "", $prop)); $prop = explode("\n", str_replace("\r", "", $prop));
@ -291,7 +291,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$this->config[$n] = $v; $this->config[$n] = $v;
} }
} }
public function start(){ public function start(){
$this->server->init(); $this->server->init();
unregister_tick_function(array($this->server, "tick")); unregister_tick_function(array($this->server, "tick"));
@ -299,7 +299,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
unset($this->server); unset($this->server);
return $this->restart; return $this->restart;
} }
/*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/
public function addHandler($e, $c, $p = 5){ public function addHandler($e, $c, $p = 5){
@ -309,31 +309,31 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
public function dhandle($e, $d){ public function dhandle($e, $d){
return $this->server->handle($e, $d); return $this->server->handle($e, $d);
} }
public function handle($e, &$d){ public function handle($e, &$d){
return $this->server->handle($e, $d); return $this->server->handle($e, $d);
} }
public function action($t, $c, $r = true){ public function action($t, $c, $r = true){
return $this->server->action($t, $c, $r); return $this->server->action($t, $c, $r);
} }
public function schedule($t, $c, $d, $r = false, $e = "server.schedule"){ public function schedule($t, $c, $d, $r = false, $e = "server.schedule"){
return $this->server->schedule($t, $c, $d, $r, $e); return $this->server->schedule($t, $c, $d, $r, $e);
} }
public function event($e, $d){ public function event($e, $d){
return $this->server->event($e, $d); return $this->server->event($e, $d);
} }
public function trigger($e, $d){ public function trigger($e, $d){
return $this->server->trigger($e, $d); return $this->server->trigger($e, $d);
} }
public function deleteEvent($id){ public function deleteEvent($id){
return $this->server->deleteEvent($id); return $this->server->deleteEvent($id);
} }
public function importMap($dir, $remove = false){ public function importMap($dir, $remove = false){
if(file_exists($dir."level.dat")){ if(file_exists($dir."level.dat")){
$nbt = new NBT(); $nbt = new NBT();
@ -341,7 +341,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
console("[DEBUG] Importing map \"".$level["LevelName"]."\" gamemode ".$level["GameType"]." with seed ".$level["RandomSeed"], true, true, 2); console("[DEBUG] Importing map \"".$level["LevelName"]."\" gamemode ".$level["GameType"]." with seed ".$level["RandomSeed"], true, true, 2);
unset($level["Player"]); unset($level["Player"]);
$lvName = $level["LevelName"]."/"; $lvName = $level["LevelName"]."/";
@mkdir(FILE_PATH."worlds/".$lvName, 0777); @mkdir(FILE_PATH."worlds/".$lvName, 0777);
file_put_contents(FILE_PATH."worlds/".$lvName."level.dat", serialize($level)); file_put_contents(FILE_PATH."worlds/".$lvName."level.dat", serialize($level));
$entities = parseNBTData($nbt->loadFile($dir."entities.dat")); $entities = parseNBTData($nbt->loadFile($dir."entities.dat"));
file_put_contents(FILE_PATH."worlds/".$lvName."entities.dat", serialize($entities["Entities"])); file_put_contents(FILE_PATH."worlds/".$lvName."entities.dat", serialize($entities["Entities"]));
@ -350,7 +350,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
} }
file_put_contents(FILE_PATH."worlds/".$lvName."tileEntities.dat", serialize($entities["TileEntities"])); file_put_contents(FILE_PATH."worlds/".$lvName."tileEntities.dat", serialize($entities["TileEntities"]));
console("[DEBUG] Imported ".count($entities["Entities"])." Entities and ".count($entities["TileEntities"])." TileEntities", true, true, 2); console("[DEBUG] Imported ".count($entities["Entities"])." Entities and ".count($entities["TileEntities"])." TileEntities", true, true, 2);
if($remove === true){ if($remove === true){
rename($dir."chunks.dat", FILE_PATH."worlds/".$lvName."chunks.dat"); rename($dir."chunks.dat", FILE_PATH."worlds/".$lvName."chunks.dat");
unlink($dir."level.dat"); unlink($dir."level.dat");
@ -369,29 +369,29 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
$this->writeProperties(); $this->writeProperties();
} }
console("[INFO] Map \"".$level["LevelName"]."\" importing done!"); console("[INFO] Map \"".$level["LevelName"]."\" importing done!");
unset($level, $entities, $nbt); unset($level, $entities, $nbt);
return true; return true;
} }
return false; return false;
} }
public function getProperty($name){ public function getProperty($name){
if(isset($this->config[$name])){ if(isset($this->config[$name])){
return $this->config[$name]; return $this->config[$name];
} }
return false; return false;
} }
public function setProperty($name, $value){ public function setProperty($name, $value){
$this->config[$name] = $value; $this->config[$name] = $value;
$this->writeProperties(); $this->writeProperties();
$this->loadProperties(); $this->loadProperties();
} }
public function getList(){ public function getList(){
return $this->apiList; return $this->apiList;
} }
public function loadAPI($name, $class, $dir = false){ public function loadAPI($name, $class, $dir = false){
if($dir === false){ if($dir === false){
$dir = FILE_PATH."src/API/"; $dir = FILE_PATH."src/API/";

View File

@ -36,11 +36,11 @@ class TimeAPI{
function __construct(PocketMinecraftServer $server){ function __construct(PocketMinecraftServer $server){
$this->server = $server; $this->server = $server;
} }
public function init(){ public function init(){
$this->server->api->console->register("time", "Manages server time", array($this, "commandHandler")); $this->server->api->console->register("time", "Manages server time", array($this, "commandHandler"));
} }
public function commandHandler($cmd, $params){ public function commandHandler($cmd, $params){
switch($cmd){ switch($cmd){
case "time": case "time":
@ -74,7 +74,7 @@ class TimeAPI{
break; break;
} }
} }
public function night(){ public function night(){
$this->set("night"); $this->set("night");
} }
@ -87,20 +87,20 @@ class TimeAPI{
public function sunset(){ public function sunset(){
$this->set("sunset"); $this->set("sunset");
} }
public function get($raw = false){ public function get($raw = false){
return $raw === true ? $this->server->time:abs($this->server->time) % 19200; return $raw === true ? $this->server->time:abs($this->server->time) % 19200;
} }
public function add($time){ public function add($time){
$this->server->time += (int) $time; $this->server->time += (int) $time;
} }
public function getDate($time = false){ public function getDate($time = false){
$time = $time === false ? $this->get():$time; $time = $time === false ? $this->get():$time;
return str_pad(strval((floor($time /800) + 6) % 24), 2, "0", STR_PAD_LEFT).":".str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT); return str_pad(strval((floor($time /800) + 6) % 24), 2, "0", STR_PAD_LEFT).":".str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
} }
public function getPhase($time = false){ public function getPhase($time = false){
$time = $time === false ? $this->get():$time; $time = $time === false ? $this->get():$time;
if($time < $this->phase["sunset"]){ if($time < $this->phase["sunset"]){
@ -114,7 +114,7 @@ class TimeAPI{
} }
return $time; return $time;
} }
public function set($time){ public function set($time){
if(is_string($time) and isset($this->phases[$time])){ if(is_string($time) and isset($this->phases[$time])){
$this->server->time = $this->phases[$time]; $this->server->time = $this->phases[$time];
@ -122,6 +122,6 @@ class TimeAPI{
$this->server->time = (int) $time; $this->server->time = (int) $time;
} }
} }
} }

View File

@ -60,7 +60,7 @@ class Async extends Thread {
/** /**
* Do whatever, result stored in $this->result, don't try to join twice * Do whatever, result stored in $this->result, don't try to join twice
**/ **/
public function __toString(){ public function __toString(){
if(!$this->joined) { if(!$this->joined) {
$this->joined = true; $this->joined = true;
$this->join(); $this->join();

View File

@ -9,7 +9,7 @@
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the * {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the
* {@link MATH_BIGINTEGER_MODE_INTERNAL MATH_BIGINTEGER_MODE_INTERNAL} mode) * {@link MATH_BIGINTEGER_MODE_INTERNAL MATH_BIGINTEGER_MODE_INTERNAL} mode)
* *
* Math_BigInteger uses base-2**26 to perform operations such as multiplication and division and * Math_BigInteger uses base-2**26 to perform operations such as multiplication and division and
@ -53,10 +53,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -234,7 +234,7 @@ class Math_BigInteger {
/** /**
* Mode independant value used for serialization. * Mode independant value used for serialization.
* *
* If the bcmath or gmp extensions are installed $this->value will be a non-serializable resource, hence the need for * If the bcmath or gmp extensions are installed $this->value will be a non-serializable resource, hence the need for
* a variable that'll be serializable regardless of whether or not extensions are being used. Unlike $this->value, * a variable that'll be serializable regardless of whether or not extensions are being used. Unlike $this->value,
* however, $this->hex is only calculated when $this->__sleep() is called. * however, $this->hex is only calculated when $this->__sleep() is called.
* *
@ -750,7 +750,7 @@ class Math_BigInteger {
$vars[] = 'precision'; $vars[] = 'precision';
} }
return $vars; return $vars;
} }
/** /**
@ -2237,7 +2237,7 @@ class Math_BigInteger {
/** /**
* Montgomery Multiply * Montgomery Multiply
* *
* Interleaves the montgomery reduction and long multiplication algorithms together as described in * Interleaves the montgomery reduction and long multiplication algorithms together as described in
* {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=13 HAC 14.36} * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=13 HAC 14.36}
* *
* @see _prepMontgomery() * @see _prepMontgomery()
@ -2317,7 +2317,7 @@ class Math_BigInteger {
* {@link http://groups.google.com/group/sci.crypt/msg/7a137205c1be7d85} * {@link http://groups.google.com/group/sci.crypt/msg/7a137205c1be7d85}
* *
* As for why we do all the bitmasking... strange things can happen when converting from floats to ints. For * As for why we do all the bitmasking... strange things can happen when converting from floats to ints. For
* instance, on some computers, var_dump((int) -4294967297) yields int(-1) and on others, it yields * instance, on some computers, var_dump((int) -4294967297) yields int(-1) and on others, it yields
* int(-2147483648). To avoid problems stemming from this, we use bitmasks to guarantee that ints aren't * int(-2147483648). To avoid problems stemming from this, we use bitmasks to guarantee that ints aren't
* auto-converted to floats. The outermost bitmask is present because without it, there's no guarantee that * auto-converted to floats. The outermost bitmask is present because without it, there's no guarantee that
* the "residue" returned would be the so-called "common residue". We use fmod, in the last step, because the * the "residue" returned would be the so-called "common residue". We use fmod, in the last step, because the
@ -3217,7 +3217,7 @@ class Math_BigInteger {
* @return Boolean * @return Boolean
* @access public * @access public
* @internal Uses the * @internal Uses the
* {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See * {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See
* {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=8 HAC 4.24}. * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=8 HAC 4.24}.
*/ */
function isPrime($t = false) function isPrime($t = false)
@ -3266,16 +3266,16 @@ class Math_BigInteger {
if (!isset($primes)) { if (!isset($primes)) {
$primes = array( $primes = array(
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227,
229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419,
421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617,
619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829,
839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947,
953, 967, 971, 977, 983, 991, 997 953, 967, 971, 977, 983, 991, 997
); );

View File

@ -30,11 +30,11 @@ class ChunkParser{
var $sectorLength = 4096; //16 * 16 * 16 var $sectorLength = 4096; //16 * 16 * 16
var $chunkLength = 86016; //21 * $sectorLength var $chunkLength = 86016; //21 * $sectorLength
var $map; var $map;
function __construct(){ function __construct(){
$map = array(); $map = array();
} }
private function loadLocationTable(){ private function loadLocationTable(){
$this->location = array(); $this->location = array();
console("[DEBUG] Loading Chunk Location table...", true, true, 2); console("[DEBUG] Loading Chunk Location table...", true, true, 2);
@ -57,7 +57,7 @@ class ChunkParser{
++$chunkCnt; ++$chunkCnt;
} }
} }
public function loadFile($file){ public function loadFile($file){
if(ZLIB_EXTENSION === true and file_exists($file.".gz")){ if(ZLIB_EXTENSION === true and file_exists($file.".gz")){
$this->raw = gzinflate(file_get_contents($file.".gz")); $this->raw = gzinflate(file_get_contents($file.".gz"));
@ -69,40 +69,40 @@ class ChunkParser{
file_put_contents($file, $this->raw); file_put_contents($file, $this->raw);
}elseif(!file_exists($file)){ }elseif(!file_exists($file)){
return false; return false;
}else{ }else{
$this->raw = file_get_contents($file); $this->raw = file_get_contents($file);
} }
$this->file = $file; $this->file = $file;
$this->chunkLength = $this->sectorLength * ord($this->raw{0}); $this->chunkLength = $this->sectorLength * ord($this->raw{0});
return true; return true;
} }
public function loadRaw($raw, $file){ public function loadRaw($raw, $file){
$this->file = $file; $this->file = $file;
$this->raw = $raw; $this->raw = $raw;
$this->chunkLength = $this->sectorLength * ord($this->raw{0}); $this->chunkLength = $this->sectorLength * ord($this->raw{0});
return true; return true;
} }
private function getOffsetPosition($X, $Z){ private function getOffsetPosition($X, $Z){
$data = substr($this->raw, ($X << 2) + ($Z << 7), 4); //$X * 4 + $Z * 128 $data = substr($this->raw, ($X << 2) + ($Z << 7), 4); //$X * 4 + $Z * 128
return array(ord($data{0}), ord($data{1}), ord($data{2}), ord($data{3})); return array(ord($data{0}), ord($data{1}), ord($data{2}), ord($data{3}));
} }
private function getOffset($X, $Z, $sectors = 21){ private function getOffset($X, $Z, $sectors = 21){
return 0x1000 + (($X * $sectors) << 12) + (($Z * $sectors) << 16); return 0x1000 + (($X * $sectors) << 12) + (($Z * $sectors) << 16);
} }
private function getOffsetLocation($X, $Z){ private function getOffsetLocation($X, $Z){
return $X << 2 + $Z << 7; return $X << 2 + $Z << 7;
} }
public function getChunk($X, $Z){ public function getChunk($X, $Z){
$X = (int) $X; $X = (int) $X;
$Z = (int) $Z; $Z = (int) $Z;
return substr($this->raw, $this->getOffset($X, $Z), $this->chunkLength); return substr($this->raw, $this->getOffset($X, $Z), $this->chunkLength);
} }
public function writeChunk($X, $Z){ public function writeChunk($X, $Z){
$X = (int) $X; $X = (int) $X;
$Z = (int) $Z; $Z = (int) $Z;
@ -117,7 +117,7 @@ class ChunkParser{
} }
return Utils::writeLInt(strlen($chunk)).$chunk; return Utils::writeLInt(strlen($chunk)).$chunk;
} }
public function parseChunk($X, $Z){ public function parseChunk($X, $Z){
$X = (int) $X; $X = (int) $X;
$Z = (int) $Z; $Z = (int) $Z;
@ -139,7 +139,7 @@ class ChunkParser{
} }
return $chunk; return $chunk;
} }
public function loadMap(){ public function loadMap(){
if($this->raw == ""){ if($this->raw == ""){
return false; return false;
@ -155,10 +155,10 @@ class ChunkParser{
$this->raw = b""; $this->raw = b"";
console("[DEBUG] Chunks loaded!", true, true, 2); console("[DEBUG] Chunks loaded!", true, true, 2);
} }
public function saveMap($final = false){ public function saveMap($final = false){
console("[DEBUG] Saving chunks...", true, true, 2); console("[DEBUG] Saving chunks...", true, true, 2);
$fp = fopen($this->file, "r+b"); $fp = fopen($this->file, "r+b");
flock($fp, LOCK_EX); flock($fp, LOCK_EX);
foreach($this->map as $x => $d){ foreach($this->map as $x => $d){
@ -179,7 +179,7 @@ class ChunkParser{
} }
} }
} }
public function getFloor($x, $z){ public function getFloor($x, $z){
$X = $x >> 4; $X = $x >> 4;
$Z = $z >> 4; $Z = $z >> 4;
@ -193,7 +193,7 @@ class ChunkParser{
} }
return $y; return $y;
} }
public function getBlock($x, $y, $z){ public function getBlock($x, $y, $z){
$x = (int) $x; $x = (int) $x;
$y = (int) $y; $y = (int) $y;
@ -212,12 +212,12 @@ class ChunkParser{
} }
return array($block, $meta); return array($block, $meta);
} }
public function getChunkColumn($X, $Z, $x, $z, $type = 0){ public function getChunkColumn($X, $Z, $x, $z, $type = 0){
$index = $z + ($x << 4); $index = $z + ($x << 4);
return $this->map[$X][$Z][$type][$index]; return $this->map[$X][$Z][$type][$index];
} }
public function setBlock($x, $y, $z, $block, $meta = 0){ public function setBlock($x, $y, $z, $block, $meta = 0){
$x = (int) $x; $x = (int) $x;
$y = (int) $y; $y = (int) $y;

View File

@ -42,7 +42,7 @@ class CustomPacketHandler{
} }
return $data; return $data;
} }
public function __construct($pid, $raw = "", $data = array(), $create = false){ public function __construct($pid, $raw = "", $data = array(), $create = false){
$this->raw = $raw; $this->raw = $raw;
$this->data = $data; $this->data = $data;
@ -54,7 +54,7 @@ class CustomPacketHandler{
$this->data["payload"] = Utils::readLong($this->get(8)); $this->data["payload"] = Utils::readLong($this->get(8));
}else{ }else{
$this->raw .= Utils::writeLong($this->data["payload"]); $this->raw .= Utils::writeLong($this->data["payload"]);
} }
break; break;
case 0x03: case 0x03:
if($this->c === false){ if($this->c === false){
@ -63,10 +63,10 @@ class CustomPacketHandler{
}else{ }else{
$this->raw .= Utils::writeLong($this->data["unknown1"]); $this->raw .= Utils::writeLong($this->data["unknown1"]);
$this->raw .= Utils::writeLong($this->data["unknown2"]); $this->raw .= Utils::writeLong($this->data["unknown2"]);
} }
break; break;
case MC_CLIENT_CONNECT: case MC_CLIENT_CONNECT:
if($this->c === false){ if($this->c === false){
$this->data["clientID"] = Utils::readLong($this->get(8)); $this->data["clientID"] = Utils::readLong($this->get(8));
$this->data["session"] = Utils::readLong($this->get(8)); $this->data["session"] = Utils::readLong($this->get(8));
$this->data["unknown2"] = $this->get(1); $this->data["unknown2"] = $this->get(1);
@ -105,7 +105,7 @@ class CustomPacketHandler{
$this->raw .= "\x00\x00"; $this->raw .= "\x00\x00";
$this->raw .= Utils::writeLong($this->data["session"]); $this->raw .= Utils::writeLong($this->data["session"]);
$this->raw .= Utils::writeLong($this->data["session2"]); $this->raw .= Utils::writeLong($this->data["session2"]);
} }
break; break;
case MC_CLIENT_HANDSHAKE: case MC_CLIENT_HANDSHAKE:
if($this->c === false){ if($this->c === false){
@ -137,7 +137,7 @@ class CustomPacketHandler{
//null //null
break; break;
case MC_LOGIN: case MC_LOGIN:
if($this->c === false){ if($this->c === false){
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
$this->data["maxX"] = Utils::readInt($this->get(4)); $this->data["maxX"] = Utils::readInt($this->get(4));
$this->data["maxY"] = Utils::readInt($this->get(4)); $this->data["maxY"] = Utils::readInt($this->get(4));
@ -147,35 +147,35 @@ class CustomPacketHandler{
} }
break; break;
case MC_LOGIN_STATUS: case MC_LOGIN_STATUS:
if($this->c === false){ if($this->c === false){
$this->data["status"] = Utils::readInt($this->get(4)); $this->data["status"] = Utils::readInt($this->get(4));
}else{ }else{
$this->raw .= Utils::writeInt($this->data["status"]); $this->raw .= Utils::writeInt($this->data["status"]);
} }
break; break;
case MC_READY: case MC_READY:
if($this->c === false){ if($this->c === false){
$this->data["status"] = ord($this->get(1)); $this->data["status"] = ord($this->get(1));
}else{ }else{
$this->raw .= chr($this->data["status"]); $this->raw .= chr($this->data["status"]);
} }
break; break;
case MC_CHAT: case MC_CHAT:
if($this->c === false){ if($this->c === false){
$this->data["message"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["message"] = $this->get(Utils::readShort($this->get(2), false));
}else{ }else{
$this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"]; $this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"];
} }
break; break;
case MC_SET_TIME: case MC_SET_TIME:
if($this->c === false){ if($this->c === false){
$this->data["time"] = Utils::readInt($this->get(4)); $this->data["time"] = Utils::readInt($this->get(4));
}else{ }else{
$this->raw .= Utils::writeInt($this->data["time"]); $this->raw .= Utils::writeInt($this->data["time"]);
} }
break; break;
case MC_START_GAME: case MC_START_GAME:
if($this->c === false){ if($this->c === false){
$this->data["seed"] = Utils::readInt($this->get(4)); $this->data["seed"] = Utils::readInt($this->get(4));
$this->data["unknown1"] = Utils::readInt($this->get(4)); $this->data["unknown1"] = Utils::readInt($this->get(4));
$this->data["gamemode"] = Utils::readInt($this->get(4)); $this->data["gamemode"] = Utils::readInt($this->get(4));
@ -191,9 +191,9 @@ class CustomPacketHandler{
$this->raw .= Utils::writeFloat($this->data["x"]); $this->raw .= Utils::writeFloat($this->data["x"]);
$this->raw .= Utils::writeFloat($this->data["y"]); $this->raw .= Utils::writeFloat($this->data["y"]);
$this->raw .= Utils::writeFloat($this->data["z"]); $this->raw .= Utils::writeFloat($this->data["z"]);
} }
break; break;
case MC_ADD_MOB: case MC_ADD_MOB:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
$this->data["type"] = Utils::readInt($this->get(4)); $this->data["type"] = Utils::readInt($this->get(4));
@ -214,7 +214,7 @@ class CustomPacketHandler{
)); ));
} }
break; break;
case MC_ADD_PLAYER: case MC_ADD_PLAYER:
if($this->c === false){ if($this->c === false){
$this->data["clientID"] = Utils::readLong($this->get(8)); $this->data["clientID"] = Utils::readLong($this->get(8));
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
@ -298,7 +298,7 @@ class CustomPacketHandler{
} }
break; break;
case MC_MOVE_ENTITY: case MC_MOVE_ENTITY:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
$this->data["x"] = Utils::readFloat($this->get(4)); $this->data["x"] = Utils::readFloat($this->get(4));
$this->data["y"] = Utils::readFloat($this->get(4)); $this->data["y"] = Utils::readFloat($this->get(4));
@ -311,7 +311,7 @@ class CustomPacketHandler{
} }
break; break;
case MC_MOVE_ENTITY_POSROT: case MC_MOVE_ENTITY_POSROT:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
$this->data["x"] = Utils::readFloat($this->get(4)); $this->data["x"] = Utils::readFloat($this->get(4));
$this->data["y"] = Utils::readFloat($this->get(4)); $this->data["y"] = Utils::readFloat($this->get(4));
@ -328,7 +328,7 @@ class CustomPacketHandler{
} }
break; break;
case MC_MOVE_PLAYER: case MC_MOVE_PLAYER:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
$this->data["x"] = Utils::readFloat($this->get(4)); $this->data["x"] = Utils::readFloat($this->get(4));
$this->data["y"] = Utils::readFloat($this->get(4)); $this->data["y"] = Utils::readFloat($this->get(4));
@ -345,7 +345,7 @@ class CustomPacketHandler{
} }
break; break;
case MC_PLACE_BLOCK: case MC_PLACE_BLOCK:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
$this->data["x"] = Utils::readInt($this->get(4)); $this->data["x"] = Utils::readInt($this->get(4));
$this->data["z"] = Utils::readInt($this->get(4)); $this->data["z"] = Utils::readInt($this->get(4));
@ -361,10 +361,10 @@ class CustomPacketHandler{
$this->raw .= chr($this->data["block"]); $this->raw .= chr($this->data["block"]);
$this->raw .= chr($this->data["meta"]); $this->raw .= chr($this->data["meta"]);
$this->raw .= chr($this->data["face"]); $this->raw .= chr($this->data["face"]);
} }
break; break;
case MC_REMOVE_BLOCK: case MC_REMOVE_BLOCK:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
$this->data["x"] = Utils::readInt($this->get(4)); $this->data["x"] = Utils::readInt($this->get(4));
$this->data["z"] = Utils::readInt($this->get(4)); $this->data["z"] = Utils::readInt($this->get(4));
@ -374,7 +374,7 @@ class CustomPacketHandler{
$this->raw .= Utils::writeInt($this->data["x"]); $this->raw .= Utils::writeInt($this->data["x"]);
$this->raw .= Utils::writeInt($this->data["z"]); $this->raw .= Utils::writeInt($this->data["z"]);
$this->raw .= chr($this->data["y"]); $this->raw .= chr($this->data["y"]);
} }
break; break;
case MC_UPDATE_BLOCK: case MC_UPDATE_BLOCK:
if($this->c === false){ if($this->c === false){
@ -389,10 +389,10 @@ class CustomPacketHandler{
$this->raw .= chr($this->data["y"]); $this->raw .= chr($this->data["y"]);
$this->raw .= chr($this->data["block"]); $this->raw .= chr($this->data["block"]);
$this->raw .= chr($this->data["meta"]); $this->raw .= chr($this->data["meta"]);
} }
break; break;
case MC_REQUEST_CHUNK: case MC_REQUEST_CHUNK:
if($this->c === false){ if($this->c === false){
$this->data["x"] = Utils::readInt($this->get(4)); $this->data["x"] = Utils::readInt($this->get(4));
$this->data["z"] = Utils::readInt($this->get(4)); $this->data["z"] = Utils::readInt($this->get(4));
}else{ }else{
@ -401,7 +401,7 @@ class CustomPacketHandler{
} }
break; break;
case MC_CHUNK_DATA: case MC_CHUNK_DATA:
if($this->c === false){ if($this->c === false){
$this->data["x"] = Utils::readInt($this->get(4)); $this->data["x"] = Utils::readInt($this->get(4));
$this->data["z"] = Utils::readInt($this->get(4)); $this->data["z"] = Utils::readInt($this->get(4));
$this->data["data"] = $this->get(true); $this->data["data"] = $this->get(true);
@ -412,7 +412,7 @@ class CustomPacketHandler{
} }
break; break;
case MC_PLAYER_EQUIPMENT: case MC_PLAYER_EQUIPMENT:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
$this->data["block"] = Utils::readShort($this->get(2), false); $this->data["block"] = Utils::readShort($this->get(2), false);
$this->data["meta"] = Utils::readShort($this->get(2), false); $this->data["meta"] = Utils::readShort($this->get(2), false);
@ -420,10 +420,10 @@ class CustomPacketHandler{
$this->raw .= Utils::writeInt($this->data["eid"]); $this->raw .= Utils::writeInt($this->data["eid"]);
$this->raw .= Utils::writeShort($this->data["block"]); $this->raw .= Utils::writeShort($this->data["block"]);
$this->raw .= Utils::writeShort($this->data["meta"]); $this->raw .= Utils::writeShort($this->data["meta"]);
} }
break; break;
case MC_INTERACT: case MC_INTERACT:
if($this->c === false){ if($this->c === false){
$this->data["action"] = Utils::readByte($this->get(1)); $this->data["action"] = Utils::readByte($this->get(1));
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
$this->data["target"] = Utils::readInt($this->get(4)); $this->data["target"] = Utils::readInt($this->get(4));
@ -431,10 +431,10 @@ class CustomPacketHandler{
$this->raw .= Utils::writeByte($this->data["action"]); $this->raw .= Utils::writeByte($this->data["action"]);
$this->raw .= Utils::writeInt($this->data["eid"]); $this->raw .= Utils::writeInt($this->data["eid"]);
$this->raw .= Utils::writeInt($this->data["target"]); $this->raw .= Utils::writeInt($this->data["target"]);
} }
break; break;
case MC_USE_ITEM: case MC_USE_ITEM:
if($this->c === false){ if($this->c === false){
$this->data["x"] = Utils::readInt($this->get(4)); $this->data["x"] = Utils::readInt($this->get(4));
$this->data["y"] = Utils::readInt($this->get(4)); $this->data["y"] = Utils::readInt($this->get(4));
$this->data["z"] = Utils::readInt($this->get(4)); $this->data["z"] = Utils::readInt($this->get(4));
@ -449,33 +449,33 @@ class CustomPacketHandler{
/*$this->raw .= Utils::writeByte($this->data["action"]); /*$this->raw .= Utils::writeByte($this->data["action"]);
$this->raw .= Utils::writeInt($this->data["eid"]); $this->raw .= Utils::writeInt($this->data["eid"]);
$this->raw .= Utils::writeInt($this->data["target"]);*/ $this->raw .= Utils::writeInt($this->data["target"]);*/
} }
break; break;
case MC_SET_ENTITY_DATA: case MC_SET_ENTITY_DATA:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
}else{ }else{
$this->raw .= Utils::writeInt($this->data["eid"]); $this->raw .= Utils::writeInt($this->data["eid"]);
$this->raw .= Utils::writeMetadata(array( $this->raw .= Utils::writeMetadata(array(
)); ));
} }
break; break;
case MC_SET_HEALTH: case MC_SET_HEALTH:
if($this->c === false){ if($this->c === false){
$this->data["health"] = Utils::readByte($this->get(1)); $this->data["health"] = Utils::readByte($this->get(1));
}else{ }else{
$this->raw .= Utils::writeByte($this->data["health"]); $this->raw .= Utils::writeByte($this->data["health"]);
} }
break; break;
case MC_ANIMATE: case MC_ANIMATE:
if($this->c === false){ if($this->c === false){
$this->data["action"] = Utils::readByte($this->get(1)); $this->data["action"] = Utils::readByte($this->get(1));
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));
}else{ }else{
$this->raw .= Utils::writeByte($this->data["action"]); $this->raw .= Utils::writeByte($this->data["action"]);
$this->raw .= Utils::writeInt($this->data["eid"]); $this->raw .= Utils::writeInt($this->data["eid"]);
} }
break; break;
case MC_RESPAWN: case MC_RESPAWN:
if($this->c === false){ if($this->c === false){
@ -516,14 +516,14 @@ class CustomPacketHandler{
$this->raw .= chr($this->data["type"]); $this->raw .= chr($this->data["type"]);
$this->raw .= Utils::writeShort($this->data["slots"]); $this->raw .= Utils::writeShort($this->data["slots"]);
$this->raw .= Utils::writeShort(strlen($this->data["title"])).$this->data["title"]; $this->raw .= Utils::writeShort(strlen($this->data["title"])).$this->data["title"];
} }
break; break;
case MC_CONTAINER_CLOSE: case MC_CONTAINER_CLOSE:
if($this->c === false){ if($this->c === false){
$this->data["windowid"] = ord($this->get(1)); $this->data["windowid"] = ord($this->get(1));
}else{ }else{
$this->raw .= chr($this->data["windowid"]); $this->raw .= chr($this->data["windowid"]);
} }
break; break;
case MC_CONTAINER_SET_SLOT: case MC_CONTAINER_SET_SLOT:
if($this->c === false){ if($this->c === false){
@ -538,17 +538,17 @@ class CustomPacketHandler{
$this->raw .= Utils::writeShort($this->data["block"]); $this->raw .= Utils::writeShort($this->data["block"]);
$this->raw .= chr($this->data["stack"]); $this->raw .= chr($this->data["stack"]);
$this->raw .= Utils::writeShort($this->data["meta"]); $this->raw .= Utils::writeShort($this->data["meta"]);
} }
break; break;
case MC_CLIENT_MESSAGE: case MC_CLIENT_MESSAGE:
if($this->c === false){ if($this->c === false){
$this->data["message"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["message"] = $this->get(Utils::readShort($this->get(2), false));
}else{ }else{
$this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"]; $this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"];
} }
break; break;
case MC_SIGN_UPDATE: case MC_SIGN_UPDATE:
if($this->c === false){ if($this->c === false){
$this->data["x"] = Utils::readShort($this->get(2)); $this->data["x"] = Utils::readShort($this->get(2));
$this->data["y"] = ord($this->get(1)); $this->data["y"] = ord($this->get(1));
$this->data["z"] = Utils::readShort($this->get(2)); $this->data["z"] = Utils::readShort($this->get(2));
@ -565,7 +565,7 @@ class CustomPacketHandler{
} }
break; break;
case MC_ADVENTURE_SETTINGS: case MC_ADVENTURE_SETTINGS:
if($this->c === false){ if($this->c === false){
$this->data["x"] = Utils::readShort($this->get(2)); $this->data["x"] = Utils::readShort($this->get(2));
$this->data["y"] = ord($this->get(1)); $this->data["y"] = ord($this->get(1));
$this->data["z"] = Utils::readShort($this->get(2)); $this->data["z"] = Utils::readShort($this->get(2));
@ -575,10 +575,10 @@ class CustomPacketHandler{
}else{ }else{
$this->raw .= $this->data["unknown1"]; $this->raw .= $this->data["unknown1"];
$this->raw .= $this->data["unknown2"]; $this->raw .= $this->data["unknown2"];
} }
break; break;
default: default:
if($this->c === false){ if($this->c === false){
console("[DEBUG] Received unknown Data Packet ID 0x".dechex($pid), true, true, 2); console("[DEBUG] Received unknown Data Packet ID 0x".dechex($pid), true, true, 2);
}else{ }else{
console("[DEBUG] Sent unknown Data Packet ID 0x".dechex($pid), true, true, 2); console("[DEBUG] Sent unknown Data Packet ID 0x".dechex($pid), true, true, 2);

View File

@ -120,7 +120,7 @@ class Material{
102 => true, 102 => true,
105 => true, 105 => true,
107 => true, 107 => true,
108 => true, 108 => true,
); );
static $replaceable = array( static $replaceable = array(
0 => true, 0 => true,
@ -130,7 +130,7 @@ class Material{
11 => true, 11 => true,
31 => true, 31 => true,
51 => true, 51 => true,
78 => true, 78 => true,
); );
static $activable = array( static $activable = array(
2 => true, 2 => true,
@ -234,7 +234,7 @@ class Material{
4 => "Cobblestone", 4 => "Cobblestone",
5 => "Wooden Planks", 5 => "Wooden Planks",
6 => "Sapling", 6 => "Sapling",
7 => "Bedrock", 7 => "Bedrock",
); );

View File

@ -74,7 +74,7 @@ class Entity extends stdClass{
break; break;
} }
} }
public function update(){ public function update(){
if($this->class === ENTITY_ITEM and $this->closed === false){ if($this->class === ENTITY_ITEM and $this->closed === false){
$this->server->api->dhandle("entity.move", $this); $this->server->api->dhandle("entity.move", $this);
@ -86,12 +86,12 @@ class Entity extends stdClass{
"meta" => $this->meta, "meta" => $this->meta,
"target" => $this->eid "target" => $this->eid
)) !== false){ )) !== false){
$this->close(); $this->close();
} }
} }
} }
} }
public function getDirection(){ public function getDirection(){
$rotation = ($this->yaw - 90) % 360; $rotation = ($this->yaw - 90) % 360;
if ($rotation < 0) { if ($rotation < 0) {
@ -111,7 +111,7 @@ class Entity extends stdClass{
return null; return null;
} }
} }
public function spawn($player){ public function spawn($player){
if(!is_object($player)){ if(!is_object($player)){
$player = $this->server->api->player->get($player); $player = $this->server->api->player->get($player);
@ -145,7 +145,7 @@ class Entity extends stdClass{
"meta" => $this->meta, "meta" => $this->meta,
"stack" => $this->stack, "stack" => $this->stack,
)); ));
break; break;
case ENTITY_MOB: case ENTITY_MOB:
$player->dataPacket(MC_ADD_MOB, array( $player->dataPacket(MC_ADD_MOB, array(
"type" => $this->type, "type" => $this->type,
@ -160,7 +160,7 @@ class Entity extends stdClass{
break; break;
} }
} }
public function close(){ public function close(){
if($this->closed === false){ if($this->closed === false){
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";"); $this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
@ -169,24 +169,24 @@ class Entity extends stdClass{
$this->__destruct(); $this->__destruct();
} }
} }
public function __destruct(){ public function __destruct(){
$this->close(); $this->close();
} }
public function getEID(){ public function getEID(){
return $this->eid; return $this->eid;
} }
public function getName(){ public function getName(){
return $this->name; return $this->name;
} }
public function setName($name){ public function setName($name){
$this->name = $name; $this->name = $name;
$this->server->query("UPDATE entities SET name = '".str_replace("'", "", $this->name)."' WHERE EID = ".$this->eid.";"); $this->server->query("UPDATE entities SET name = '".str_replace("'", "", $this->name)."' WHERE EID = ".$this->eid.";");
} }
public function look($pos2){ public function look($pos2){
$pos = $this->getPosition(); $pos = $this->getPosition();
$angle = Utils::angle3D($pos2, $pos); $angle = Utils::angle3D($pos2, $pos);
@ -194,14 +194,14 @@ class Entity extends stdClass{
$this->pitch = $angle["pitch"]; $this->pitch = $angle["pitch"];
$this->server->query("UPDATE entities SET pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";"); $this->server->query("UPDATE entities SET pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
} }
public function setCoords($x, $y, $z){ public function setCoords($x, $y, $z){
$this->x = $x; $this->x = $x;
$this->y = $y; $this->y = $y;
$this->z = $z; $this->z = $z;
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z." WHERE EID = ".$this->eid.";"); $this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z." WHERE EID = ".$this->eid.";");
} }
public function move($x, $y, $z, $yaw = 0, $pitch = 0){ public function move($x, $y, $z, $yaw = 0, $pitch = 0){
$this->x += $x; $this->x += $x;
$this->y += $y; $this->y += $y;
@ -212,22 +212,22 @@ class Entity extends stdClass{
$this->pitch %= 90; $this->pitch %= 90;
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";"); $this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
} }
public function setPosition($x, $y, $z, $yaw, $pitch){ public function setPosition($x, $y, $z, $yaw, $pitch){
$this->x = $x; $this->x = $x;
$this->y = $y; $this->y = $y;
$this->z = $z; $this->z = $z;
$this->yaw = $yaw; $this->yaw = $yaw;
$this->pitch = $pitch; $this->pitch = $pitch;
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";"); $this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
return true; return true;
} }
public function getPosition($round = false){ public function getPosition($round = false){
return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position); return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position);
} }
public function setHealth($health, $cause = ""){ public function setHealth($health, $cause = ""){
$this->health = (int) $health; $this->health = (int) $health;
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";"); $this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
$this->server->api->dhandle("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause)); $this->server->api->dhandle("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause));
@ -245,7 +245,7 @@ class Entity extends stdClass{
$this->dead = false; $this->dead = false;
} }
} }
public function getHealth(){ public function getHealth(){
return $this->health; return $this->health;
} }

View File

@ -33,15 +33,15 @@ class WorldGenerator{
$this->genName = $genName; $this->genName = $genName;
$this->gen = new $genName($this->seed); $this->gen = new $genName($this->seed);
} }
public function getSpawn(){ public function getSpawn(){
return $this->gen->getSpawn(); return $this->gen->getSpawn();
} }
public function set($name, $value){ public function set($name, $value){
$this->gen->set($name, $value); $this->gen->set($name, $value);
} }
public function init(){ public function init(){
$this->raw = "\x15\x01\x00\x00\x15\x16\x00\x00\x15\x2b\x00\x00\x15\x40\x00\x00". //Location Header $this->raw = "\x15\x01\x00\x00\x15\x16\x00\x00\x15\x2b\x00\x00\x15\x40\x00\x00". //Location Header
"\x15\x55\x00\x00\x15\x6a\x00\x00\x15\x7f\x00\x00\x15\x94\x00\x00". "\x15\x55\x00\x00\x15\x6a\x00\x00\x15\x7f\x00\x00\x15\x94\x00\x00".
@ -301,18 +301,18 @@ class WorldGenerator{
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$this->gen->init(); $this->gen->init();
} }
public function generate(){ public function generate(){
for($Z = 0; $Z < 16; ++$Z){ for($Z = 0; $Z < 16; ++$Z){
for($X = 0; $X < 16; ++$X){ for($X = 0; $X < 16; ++$X){
$chunk = str_pad($this->getChunk($X, $Z), 86012, "\x00", STR_PAD_RIGHT); $chunk = str_pad($this->getChunk($X, $Z), 86012, "\x00", STR_PAD_RIGHT);
$this->raw .= Utils::writeLInt(strlen($chunk)) . $chunk; $this->raw .= Utils::writeLInt(strlen($chunk)) . $chunk;
} }
console("[DEBUG] Generating level ".ceil(($Z + 1)/0.16)."%", true, true, 2); console("[DEBUG] Generating level ".ceil(($Z + 1)/0.16)."%", true, true, 2);
} }
return true; return true;
} }
private function getChunk($X, $Z){ private function getChunk($X, $Z){
$chunk = b""; $chunk = b"";
$columns = array(); $columns = array();
@ -333,7 +333,7 @@ class WorldGenerator{
unset($columns); unset($columns);
return $chunk; return $chunk;
} }
public function save($dir, $name){ public function save($dir, $name){
@mkdir($dir, 0777, true); @mkdir($dir, 0777, true);
file_put_contents($dir."chunks.dat", $this->raw); file_put_contents($dir."chunks.dat", $this->raw);

View File

@ -28,26 +28,26 @@ the Free Software Foundation, either version 3 of the License, or
class Java_String{ class Java_String{
private $value = "", $count = 0, $hash = 0; private $value = "", $count = 0, $hash = 0;
public function __construct($string = false){ public function __construct($string = false){
if($string !== false){ if($string !== false){
$this->value = (string) $string; $this->value = (string) $string;
$this->count = strlen($this->value); $this->count = strlen($this->value);
} }
} }
public function __toString(){ public function __toString(){
return $this->value; return $this->value;
} }
public function lenght(){ public function lenght(){
return $this->count; return $this->count;
} }
public function isEmpty(){ public function isEmpty(){
return $this->count === 0; return $this->count === 0;
} }
public function charAt($index){ public function charAt($index){
$index = (int) $index; $index = (int) $index;
if($index < 0 or $index >= $this->count){ if($index < 0 or $index >= $this->count){
@ -56,7 +56,7 @@ class Java_String{
} }
return $this->value{$index}; return $this->value{$index};
} }
public function hashCode(){ public function hashCode(){
$h = $this->hash; $h = $this->hash;
if($h === 0 and $this->count > 0){ if($h === 0 and $this->count > 0){
@ -68,13 +68,13 @@ class Java_String{
$this->hash = $h; $this->hash = $h;
} }
return $h; return $h;
} }
} }
class Java_Random{ class Java_Random{
private $haveNextNextGaussian, $nextNextGaussian, $seed, $n1, $n2, $n3, $zero; private $haveNextNextGaussian, $nextNextGaussian, $seed, $n1, $n2, $n3, $zero;
public function __construct($seed = false){ public function __construct($seed = false){
$this->n1 = new Math_BigInteger(0x5DEECE66D); $this->n1 = new Math_BigInteger(0x5DEECE66D);
$this->n2 = new Math_BigInteger(1); $this->n2 = new Math_BigInteger(1);
@ -86,19 +86,19 @@ class Java_Random{
} }
$this->setSeed($seed); $this->setSeed($seed);
} }
public function setSeed($seed){ public function setSeed($seed){
$seed = new Math_BigInteger($seed); $seed = new Math_BigInteger($seed);
$this->seed = $seed->bitwise_xor($this->n1)->bitwise_and($this->n2); $this->seed = $seed->bitwise_xor($this->n1)->bitwise_and($this->n2);
$this->haveNextNextGaussian = false; $this->haveNextNextGaussian = false;
} }
protected function next($bits){ protected function next($bits){
$bits = (int) $bits; $bits = (int) $bits;
$this->seed = $this->seed->multiply($this->n1)->add($this->n3)->bitwise_and($this->n2); $this->seed = $this->seed->multiply($this->n1)->add($this->n3)->bitwise_and($this->n2);
return $this->_tripleRightShift($this->seed, (48 - $bits)); return $this->_tripleRightShift($this->seed, (48 - $bits));
} }
private function _tripleRightShift($number, $places){ private function _tripleRightShift($number, $places){
if($number->compare($this->zero) >= 0){ if($number->compare($this->zero) >= 0){
return $number->bitwise_rightShift($places); return $number->bitwise_rightShift($places);
@ -106,7 +106,7 @@ class Java_Random{
$n1 = new Math_BigInteger(2); $n1 = new Math_BigInteger(2);
return $number->bitwise_rightShift($places)->add($n1->bitwise_leftShift(~$places)); return $number->bitwise_rightShift($places)->add($n1->bitwise_leftShift(~$places));
} }
public function nextBytes($bytes){ public function nextBytes($bytes){
$bytes = (int) $bytes; $bytes = (int) $bytes;
$b = b""; $b = b"";

View File

@ -41,18 +41,18 @@ class MinecraftInterface{
$this->client = (bool) $client; $this->client = (bool) $client;
$this->start = microtime(true); $this->start = microtime(true);
} }
public function close(){ public function close(){
return $this->socket->close(); return $this->socket->close();
} }
protected function getStruct($pid){ protected function getStruct($pid){
if(isset($this->pstruct[$pid])){ if(isset($this->pstruct[$pid])){
return $this->pstruct[$pid]; return $this->pstruct[$pid];
} }
return false; return false;
} }
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){ protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
if(LOG === true and DEBUG >= 3){ if(LOG === true and DEBUG >= 3){
$p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".(isset($data["id"]) ? "MC Packet ".$this->dataName[$pid]:$this->name[$pid])." (0x".Utils::strTohex(chr($pid)).") [length ".strlen($raw)."]".PHP_EOL; $p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".(isset($data["id"]) ? "MC Packet ".$this->dataName[$pid]:$this->name[$pid])." (0x".Utils::strTohex(chr($pid)).") [length ".strlen($raw)."]".PHP_EOL;
@ -65,9 +65,9 @@ class MinecraftInterface{
$p .= PHP_EOL; $p .= PHP_EOL;
logg($p, "packets", false); logg($p, "packets", false);
} }
} }
public function readPacket(){ public function readPacket(){
$p = $this->popPacket(); $p = $this->popPacket();
if($p !== false){ if($p !== false){
@ -90,13 +90,13 @@ class MinecraftInterface{
logg($p, "packets", true, 2); logg($p, "packets", true, 2);
return false; return false;
} }
$packet = new Packet($pid, $struct, $data[0]); $packet = new Packet($pid, $struct, $data[0]);
$packet->parse(); $packet->parse();
$this->data[] = array($pid, $packet->data, $data[0], $data[1], $data[2]); $this->data[] = array($pid, $packet->data, $data[0], $data[1], $data[2]);
return $this->popPacket(); return $this->popPacket();
} }
public function popPacket(){ public function popPacket(){
if(count($this->data) > 0){ if(count($this->data) > 0){
$p = array_shift($this->data); $p = array_shift($this->data);
@ -112,7 +112,7 @@ class MinecraftInterface{
} }
return false; return false;
} }
public function writePacket($pid, $data = array(), $raw = false, $dest = false, $port = false){ public function writePacket($pid, $data = array(), $raw = false, $dest = false, $port = false){
$struct = $this->getStruct($pid); $struct = $this->getStruct($pid);
if($raw === false){ if($raw === false){
@ -124,10 +124,10 @@ class MinecraftInterface{
}else{ }else{
$write = $this->socket->write($data, $dest, $port); $write = $this->socket->write($data, $dest, $port);
$this->writeDump($pid, $data, false, "client", $dest, $port); $this->writeDump($pid, $data, false, "client", $dest, $port);
} }
return true; return true;
} }
} }
?> ?>

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Class for reading in NBT-format files. * Class for reading in NBT-format files.
* *
* @author Justin Martin <frozenfire@thefrozenfire.com> * @author Justin Martin <frozenfire@thefrozenfire.com>
* @version 1.0 * @version 1.0
* MODIFIED BY @shoghicp * MODIFIED BY @shoghicp
@ -12,7 +12,7 @@
class NBT { class NBT {
public $root = array(); public $root = array();
const TAG_END = 0; const TAG_END = 0;
const TAG_BYTE = 1; const TAG_BYTE = 1;
const TAG_SHORT = 2; const TAG_SHORT = 2;
@ -24,7 +24,7 @@ class NBT {
const TAG_STRING = 8; const TAG_STRING = 8;
const TAG_LIST = 9; const TAG_LIST = 9;
const TAG_COMPOUND = 10; const TAG_COMPOUND = 10;
public function loadFile($filename) { public function loadFile($filename) {
if(is_file($filename)) { if(is_file($filename)) {
$fp = fopen($filename, "rb"); $fp = fopen($filename, "rb");
@ -44,7 +44,7 @@ class NBT {
$this->traverseTag($fp, $this->root); $this->traverseTag($fp, $this->root);
return end($this->root); return end($this->root);
} }
public function traverseTag($fp, &$tree) { public function traverseTag($fp, &$tree) {
if(feof($fp)) { if(feof($fp)) {
return false; return false;
@ -59,7 +59,7 @@ class NBT {
return true; return true;
} }
} }
public function readType($fp, $tagType) { public function readType($fp, $tagType) {
switch($tagType) { switch($tagType) {
case self::TAG_BYTE: // Signed byte (8 bit) case self::TAG_BYTE: // Signed byte (8 bit)

View File

@ -33,19 +33,19 @@ class NormalGenerator{
"seed" => (int) $seed, "seed" => (int) $seed,
); );
} }
public function set($name, $value){ public function set($name, $value){
$this->config[$name] = $value; $this->config[$name] = $value;
} }
public function init(){ public function init(){
$this->spawn = array(128, 128, 128); $this->spawn = array(128, 128, 128);
} }
public function getSpawn(){ public function getSpawn(){
return $this->spawn; return $this->spawn;
} }
public function getColumn($x, $z){ public function getColumn($x, $z){
$x = (int) $x; $x = (int) $x;
$z = (int) $z; $z = (int) $z;

View File

@ -30,7 +30,7 @@ class Packet{
private $struct, $sock; private $struct, $sock;
protected $pid, $packet; protected $pid, $packet;
public $data, $raw; public $data, $raw;
function __construct($pid, $struct, $data = ""){ function __construct($pid, $struct, $data = ""){
$this->pid = $pid; $this->pid = $pid;
$this->offset = 1; $this->offset = 1;
@ -42,7 +42,7 @@ class Packet{
$this->struct = $struct; $this->struct = $struct;
$this->sock = $sock; $this->sock = $sock;
} }
public function create($raw = false){ public function create($raw = false){
foreach($this->struct as $field => $type){ foreach($this->struct as $field => $type){
if(!isset($this->data[$field])){ if(!isset($this->data[$field])){
@ -83,7 +83,7 @@ class Packet{
$reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true); $reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true);
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3)); $this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
$this->addRaw(chr($this->data[$field]["id"])); $this->addRaw(chr($this->data[$field]["id"]));
$this->addRaw($reply->raw); $this->addRaw($reply->raw);
break; break;
} }
break; break;
@ -136,10 +136,10 @@ class Packet{
default: default:
$this->addRaw(Utils::writeByte($this->data[$field])); $this->addRaw(Utils::writeByte($this->data[$field]));
break; break;
} }
} }
} }
private function get($len = true){ private function get($len = true){
if($len === true){ if($len === true){
$data = substr($this->raw, $this->offset); $data = substr($this->raw, $this->offset);
@ -150,12 +150,12 @@ class Packet{
$this->offset += $len; $this->offset += $len;
return $data; return $data;
} }
protected function addRaw($str){ protected function addRaw($str){
$this->raw .= $str; $this->raw .= $str;
return $str; return $str;
} }
public function parse(){ public function parse(){
$continue = true; $continue = true;
foreach($this->struct as $field => $type){ foreach($this->struct as $field => $type){
@ -205,7 +205,7 @@ class Packet{
break; break;
case "byte": case "byte":
$this->data[] = Utils::readByte($this->get(1)); $this->data[] = Utils::readByte($this->get(1));
break; break;
case "ubyte": case "ubyte":
$this->data[] = ord($this->get(1)); $this->data[] = ord($this->get(1));
break; break;
@ -231,8 +231,8 @@ class Packet{
} }
} }
} }
} }

View File

@ -52,7 +52,7 @@ class Player{
$this->auth = false; $this->auth = false;
$this->counter = array(0, 0, 0); $this->counter = array(0, 0, 0);
} }
public function onTick($time, $event){ public function onTick($time, $event){
if($event !== "server.tick"){ if($event !== "server.tick"){
return; return;
@ -80,7 +80,7 @@ class Player{
} }
} }
} }
public function save(){ public function save(){
if(is_object($this->entity)){ if(is_object($this->entity)){
$this->data["spawn"] = array( $this->data["spawn"] = array(
@ -90,7 +90,7 @@ class Player{
); );
} }
} }
public function close($reason = "", $msg = true){ public function close($reason = "", $msg = true){
$reason = $reason == "" ? "server stop":$reason; $reason = $reason == "" ? "server stop":$reason;
$this->save(); $this->save();
@ -110,14 +110,14 @@ class Player{
console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason); console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason);
$this->server->api->player->remove($this->CID); $this->server->api->player->remove($this->CID);
} }
public function eventHandler($data, $event){ public function eventHandler($data, $event){
switch($event){ switch($event){
case "player.item.pick": case "player.item.pick":
if($data["eid"] === $this->eid){ if($data["eid"] === $this->eid){
$data["eid"] = 0; $data["eid"] = 0;
} }
$this->dataPacket(MC_TAKE_ITEM_ENTITY, $data); $this->dataPacket(MC_TAKE_ITEM_ENTITY, $data);
break; break;
case "player.equipment.change": case "player.equipment.change":
if($data["eid"] === $this->eid){ if($data["eid"] === $this->eid){
@ -170,7 +170,7 @@ class Player{
break; break;
} }
} }
public function handle($pid, $data){ public function handle($pid, $data){
if($this->connected === true){ if($this->connected === true){
$this->timeout = microtime(true) + 25; $this->timeout = microtime(true) + 25;
@ -210,7 +210,7 @@ class Player{
$data[3], $data[3],
0, 0,
)); ));
break; break;
case 0x80: case 0x80:
case 0x81: case 0x81:
case 0x82: case 0x82:
@ -240,12 +240,12 @@ class Player{
$this->send(0xc0, array(1, true, $data[0])); $this->send(0xc0, array(1, true, $data[0]));
} }
switch($data["id"]){ switch($data["id"]){
case MC_KEEP_ALIVE: case MC_KEEP_ALIVE:
break; break;
case 0x03: case 0x03:
break; break;
case MC_DISCONNECT: case MC_DISCONNECT:
$this->connected = false; $this->connected = false;
@ -259,13 +259,13 @@ class Player{
)); ));
break; break;
case MC_CLIENT_HANDSHAKE: case MC_CLIENT_HANDSHAKE:
break; break;
case MC_LOGIN: case MC_LOGIN:
$this->username = str_replace(array("\x00", "/", " ", "\r", "\n"), array("", "-", "_", "", ""), $data["username"]); $this->username = str_replace(array("\x00", "/", " ", "\r", "\n"), array("", "-", "_", "", ""), $data["username"]);
if($this->username == ""){ if($this->username == ""){
$this->close("bad username", false); $this->close("bad username", false);
break; break;
} }
$o = $this->server->api->player->getOffline($this->username); $o = $this->server->api->player->getOffline($this->username);
if($this->server->whitelist !== false and (!in_array($this->username, $this->server->whitelist)/* or ($o["lastID"] != 0 and $o["lastID"] != $this->clientID)*/)){ if($this->server->whitelist !== false and (!in_array($this->username, $this->server->whitelist)/* or ($o["lastID"] != 0 and $o["lastID"] != $this->clientID)*/)){
@ -298,7 +298,7 @@ class Player{
"eid" => 0, "eid" => 0,
)); ));
break; break;
case MC_READY: case MC_READY:
switch($data["status"]){ switch($data["status"]){
case 1: case 1:
if($this->spawned !== false){ if($this->spawned !== false){
@ -321,7 +321,7 @@ class Player{
$this->evid[] = $this->server->event("player.item.pick", array($this, "eventHandler")); $this->evid[] = $this->server->event("player.item.pick", array($this, "eventHandler"));
$this->evid[] = $this->server->event("world.block.change", array($this, "eventHandler")); $this->evid[] = $this->server->event("world.block.change", array($this, "eventHandler"));
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2); console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
$this->eventHandler($this->server->motd, "server.chat"); $this->eventHandler($this->server->motd, "server.chat");
if($this->MTU <= 548){ if($this->MTU <= 548){
$this->eventHandler("Your connection is bad, you may experience lag and slow map loading.", "server.chat"); $this->eventHandler("Your connection is bad, you may experience lag and slow map loading.", "server.chat");
@ -337,7 +337,7 @@ class Player{
$this->server->api->dhandle("entity.move", $this->entity); $this->server->api->dhandle("entity.move", $this->entity);
} }
break; break;
case MC_PLAYER_EQUIPMENT: case MC_PLAYER_EQUIPMENT:
$data["eid"] = $this->eid; $data["eid"] = $this->eid;
if($this->server->handle("player.equipment.change", $data) !== false){ if($this->server->handle("player.equipment.change", $data) !== false){
$this->equipment[0] = $data["block"]; $this->equipment[0] = $data["block"];
@ -353,7 +353,7 @@ class Player{
$this->dataPacket(MC_CHUNK_DATA, array( $this->dataPacket(MC_CHUNK_DATA, array(
"x" => '.$data["x"].', "x" => '.$data["x"].',
"z" => '.$data["z"].', "z" => '.$data["z"].',
"data" => $d, "data" => $d,
), true); ), true);
} }
'); ');
@ -376,7 +376,7 @@ class Player{
case MC_INTERACT: case MC_INTERACT:
if(isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){ if(isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2); console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2);
if($this->server->gamemode !== 1 and $this->server->difficulty > 0){ if($this->server->gamemode !== 1 and $this->server->difficulty > 0){
$this->server->api->entity->harm($data["target"], $this->server->difficulty, $this->eid); $this->server->api->entity->harm($data["target"], $this->server->difficulty, $this->eid);
} }
} }
@ -405,17 +405,17 @@ class Player{
} }
} }
} }
public function send($pid, $data = array(), $raw = false){ public function send($pid, $data = array(), $raw = false){
if($this->connected === true){ if($this->connected === true){
$this->server->send($pid, $data, $raw, $this->ip, $this->port); $this->server->send($pid, $data, $raw, $this->ip, $this->port);
} }
} }
public function actionQueue($code){ public function actionQueue($code){
$this->queue[] = array(1, $code); $this->queue[] = array(1, $code);
} }
public function dataPacket($id, $data = array(), $queue = false, $count = false){ public function dataPacket($id, $data = array(), $queue = false, $count = false){
if($queue === true){ if($queue === true){
$this->queue[] = array(0, $id, $data, $count); $this->queue[] = array(0, $id, $data, $count);

View File

@ -71,7 +71,7 @@ class PocketMinecraftServer extends stdClass{
$this->timePerSecond = 10; $this->timePerSecond = 10;
$this->tickMeasure = array_fill(0, 40, 0); $this->tickMeasure = array_fill(0, 40, 0);
$this->setType("normal"); $this->setType("normal");
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false); $this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false);
$this->reloadConfig(); $this->reloadConfig();
console("[INFO] Server Name: ".$this->name); console("[INFO] Server Name: ".$this->name);
console("[INFO] Server GUID: ".$this->serverID); console("[INFO] Server GUID: ".$this->serverID);
@ -79,17 +79,17 @@ class PocketMinecraftServer extends stdClass{
console("[INFO] Max Clients: ".$this->maxClients); console("[INFO] Max Clients: ".$this->maxClients);
$this->stop = false; $this->stop = false;
} }
public function getTPS(){ public function getTPS(){
$v = array_values($this->tickMeasure); $v = array_values($this->tickMeasure);
$tps = 40 / ($v[39] - $v[0]); $tps = 40 / ($v[39] - $v[0]);
return round($tps, 4); return round($tps, 4);
} }
public function loadEvents(){ public function loadEvents(){
$this->event("server.chat", array($this, "eventHandler")); $this->event("server.chat", array($this, "eventHandler"));
$this->event("player.new", array($this, "eventHandler")); $this->event("player.new", array($this, "eventHandler"));
$this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->api->dhandle("server.time.change", $this->time);'); $this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->api->dhandle("server.time.change", $this->time);');
$this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}'); $this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}');
$this->action(1000000 * 60, '$this->reloadConfig();'); $this->action(1000000 * 60, '$this->reloadConfig();');
@ -103,7 +103,7 @@ class PocketMinecraftServer extends stdClass{
public function startDatabase(){ public function startDatabase(){
$this->preparedSQL = new stdClass(); $this->preparedSQL = new stdClass();
$this->database = new SQLite3(":memory:"); $this->database = new SQLite3(":memory:");
//$this->query("PRAGMA journal_mode = OFF;"); //$this->query("PRAGMA journal_mode = OFF;");
//$this->query("PRAGMA encoding = \"UTF-8\";"); //$this->query("PRAGMA encoding = \"UTF-8\";");
//$this->query("PRAGMA secure_delete = OFF;"); //$this->query("PRAGMA secure_delete = OFF;");
$this->query("CREATE TABLE players (clientID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE);"); $this->query("CREATE TABLE players (clientID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE);");
@ -118,7 +118,7 @@ class PocketMinecraftServer extends stdClass{
$this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);"); $this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);");
$this->preparedSQL->updateActions = $this->database->prepare("UPDATE actions SET last = :time WHERE last <= (:time - interval);"); $this->preparedSQL->updateActions = $this->database->prepare("UPDATE actions SET last = :time WHERE last <= (:time - interval);");
} }
public function query($sql, $fetch = false){ public function query($sql, $fetch = false){
console("[INTERNAL] [SQL] ".$sql, true, true, 3); console("[INTERNAL] [SQL] ".$sql, true, true, 3);
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0); $result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0);
@ -127,14 +127,14 @@ class PocketMinecraftServer extends stdClass{
} }
return $result; return $result;
} }
public function reloadConfig(){ public function reloadConfig(){
if($this->whitelist === true or is_array($this->whitelist)){ if($this->whitelist === true or is_array($this->whitelist)){
$this->whitelist = explode("\n", str_replace(array("\t","\r"), "", file_get_contents(FILE_PATH."white-list.txt"))); $this->whitelist = explode("\n", str_replace(array("\t","\r"), "", file_get_contents(FILE_PATH."white-list.txt")));
} }
$this->bannedIPs = explode("\n", str_replace(array(" ","\t","\r"), "", file_get_contents(FILE_PATH."banned-ips.txt"))); $this->bannedIPs = explode("\n", str_replace(array(" ","\t","\r"), "", file_get_contents(FILE_PATH."banned-ips.txt")));
} }
public function debugInfo($console = false){ public function debugInfo($console = false){
$info = array(); $info = array();
$info["tps"] = $this->getTPS(); $info["tps"] = $this->getTPS();
@ -152,7 +152,7 @@ class PocketMinecraftServer extends stdClass{
} }
return $info; return $info;
} }
public function close($reason = "stop"){ public function close($reason = "stop"){
if($this->stop !== true){ if($this->stop !== true){
$this->chat(false, "Stopping server..."); $this->chat(false, "Stopping server...");
@ -162,7 +162,7 @@ class PocketMinecraftServer extends stdClass{
$this->interface->close(); $this->interface->close();
} }
} }
public function chat($owner, $text, $target = true){ public function chat($owner, $text, $target = true){
$message = ""; $message = "";
if($owner !== false){ if($owner !== false){
@ -171,7 +171,7 @@ class PocketMinecraftServer extends stdClass{
$message .= $text; $message .= $text;
$this->handle("server.chat", $message); $this->handle("server.chat", $message);
} }
public function setType($type = "normal"){ public function setType($type = "normal"){
switch($type){ switch($type){
case "normal": case "normal":
@ -181,9 +181,9 @@ class PocketMinecraftServer extends stdClass{
$this->serverType = "MCCPP;MINECON;"; $this->serverType = "MCCPP;MINECON;";
break; break;
} }
} }
public function addHandler($event, $callable, $priority = 5){ public function addHandler($event, $callable, $priority = 5){
if(!is_callable($callable)){ if(!is_callable($callable)){
return false; return false;
@ -194,14 +194,14 @@ class PocketMinecraftServer extends stdClass{
console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$this->handCnt.")", true, true, 3); console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$this->handCnt.")", true, true, 3);
return $this->handCnt++; return $this->handCnt++;
} }
public function handle($event, &$data){ public function handle($event, &$data){
$this->preparedSQL->selectHandlers->reset(); $this->preparedSQL->selectHandlers->reset();
$this->preparedSQL->selectHandlers->clear(); $this->preparedSQL->selectHandlers->clear();
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT); $this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
$handlers = $this->preparedSQL->selectHandlers->execute(); $handlers = $this->preparedSQL->selectHandlers->execute();
$result = true; $result = true;
if($handlers !== false and $handlers !== true){ if($handlers !== false and $handlers !== true){
while(false !== ($hn = $handlers->fetchArray(SQLITE3_ASSOC)) and $result !== false){ while(false !== ($hn = $handlers->fetchArray(SQLITE3_ASSOC)) and $result !== false){
$handler = $this->handlers[(int) $hn["ID"]]; $handler = $this->handlers[(int) $hn["ID"]];
if(is_array($handler)){ if(is_array($handler)){
@ -210,7 +210,7 @@ class PocketMinecraftServer extends stdClass{
}else{ }else{
$result = $handler($data, $event); $result = $handler($data, $event);
} }
} }
} }
$handlers->finalize(); $handlers->finalize();
if($result !== false){ if($result !== false){
@ -218,7 +218,7 @@ class PocketMinecraftServer extends stdClass{
} }
return $result; return $result;
} }
public function eventHandler($data, $event){ public function eventHandler($data, $event){
switch($event){ switch($event){
case "player.new": case "player.new":
@ -229,14 +229,14 @@ class PocketMinecraftServer extends stdClass{
break; break;
} }
} }
public function loadMap(){ public function loadMap(){
if($this->mapName !== false and trim($this->mapName) !== ""){ if($this->mapName !== false and trim($this->mapName) !== ""){
$this->level = unserialize(file_get_contents($this->mapDir."level.dat")); $this->level = unserialize(file_get_contents($this->mapDir."level.dat"));
console("[INFO] Map: ".$this->level["LevelName"]); console("[INFO] Map: ".$this->level["LevelName"]);
$this->time = (int) $this->level["Time"]; $this->time = (int) $this->level["Time"];
$this->seed = (int) $this->level["RandomSeed"]; $this->seed = (int) $this->level["RandomSeed"];
if(isset($this->level["SpawnX"])){ if(isset($this->level["SpawnX"])){
$this->spawn = array("x" => $this->level["SpawnX"], "y" => $this->level["SpawnY"], "z" => $this->level["SpawnZ"]); $this->spawn = array("x" => $this->level["SpawnX"], "y" => $this->level["SpawnY"], "z" => $this->level["SpawnZ"]);
}else{ }else{
$this->level["SpawnX"] = $this->spawn["x"]; $this->level["SpawnX"] = $this->spawn["x"];
@ -264,7 +264,7 @@ class PocketMinecraftServer extends stdClass{
console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative")); console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative"));
} }
} }
public function loadEntities(){ public function loadEntities(){
if($this->map !== false){ if($this->map !== false){
console("[INFO] Loading entities..."); console("[INFO] Loading entities...");
@ -288,26 +288,26 @@ class PocketMinecraftServer extends stdClass{
$e = $this->api->entity->add(ENTITY_MOB, $entity["id"]); $e = $this->api->entity->add(ENTITY_MOB, $entity["id"]);
$e->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]); $e->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]); $e->setHealth($entity["Health"]);
} }
} }
} }
console("[DEBUG] Loaded ".count($this->entities)." Entities", true, true, 2); console("[DEBUG] Loaded ".count($this->entities)." Entities", true, true, 2);
$this->action(1000000 * 60 * 15, '$this->chat(false, "Forcing save...");$this->save();$this->chat(false, "Done");'); $this->action(1000000 * 60 * 15, '$this->chat(false, "Forcing save...");$this->save();$this->chat(false, "Done");');
} }
} }
public function save($final = false){ public function save($final = false){
if($this->mapName !== false){ if($this->mapName !== false){
file_put_contents($this->mapDir."level.dat", serialize($this->level)); file_put_contents($this->mapDir."level.dat", serialize($this->level));
$this->map->saveMap($final); $this->map->saveMap($final);
console("[INFO] Saving entities..."); console("[INFO] Saving entities...");
foreach($this->entities as $entity){ foreach($this->entities as $entity){
} }
} }
} }
public function init(){ public function init(){
if($this->mapName !== false and $this->map === false){ if($this->mapName !== false and $this->map === false){
$this->loadMap(); $this->loadMap();
@ -322,21 +322,21 @@ class PocketMinecraftServer extends stdClass{
console("[INFO] Server started!"); console("[INFO] Server started!");
$this->process(); $this->process();
} }
public function tick(){ public function tick(){
$time = microtime(true); $time = microtime(true);
if($this->lastTick <= ($time - 0.05)){ if($this->lastTick <= ($time - 0.05)){
array_shift($this->tickMeasure); array_shift($this->tickMeasure);
$this->tickMeasure[] = $this->lastTick = $time; $this->tickMeasure[] = $this->lastTick = $time;
$this->tickerFunction($time); $this->tickerFunction($time);
$this->trigger("server.tick", $time); $this->trigger("server.tick", $time);
} }
} }
public function clientID($ip, $port){ public function clientID($ip, $port){
return md5($ip . $port, true); return md5($ip . $port, true);
} }
public function packetHandler($packet){ public function packetHandler($packet){
$data =& $packet["data"]; $data =& $packet["data"];
$CID = $this->clientID($packet["ip"], $packet["port"]); $CID = $this->clientID($packet["ip"], $packet["port"]);
@ -351,7 +351,7 @@ class PocketMinecraftServer extends stdClass{
$this->serverID, $this->serverID,
MAGIC, MAGIC,
$this->serverType, $this->serverType,
), false, $packet["ip"], $packet["port"]); ), false, $packet["ip"], $packet["port"]);
break; break;
} }
if(in_array($packet["ip"], $this->bannedIPs)){ if(in_array($packet["ip"], $this->bannedIPs)){
@ -441,11 +441,11 @@ class PocketMinecraftServer extends stdClass{
} }
} }
} }
public function send($pid, $data = array(), $raw = false, $dest = false, $port = false){ public function send($pid, $data = array(), $raw = false, $dest = false, $port = false){
$this->interface->writePacket($pid, $data, $raw, $dest, $port); $this->interface->writePacket($pid, $data, $raw, $dest, $port);
} }
public function process(){ public function process(){
while($this->stop === false){ while($this->stop === false){
$packet = @$this->interface->readPacket(); $packet = @$this->interface->readPacket();
@ -453,10 +453,10 @@ class PocketMinecraftServer extends stdClass{
$this->packetHandler($packet); $this->packetHandler($packet);
}else{ }else{
usleep(1); usleep(1);
} }
} }
} }
public function trigger($event, $data = ""){ public function trigger($event, $data = ""){
$this->preparedSQL->selectEvents->reset(); $this->preparedSQL->selectEvents->reset();
$this->preparedSQL->selectEvents->clear(); $this->preparedSQL->selectEvents->clear();
@ -486,7 +486,7 @@ class PocketMinecraftServer extends stdClass{
} }
return false; return false;
} }
public function schedule($ticks, $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){ public function schedule($ticks, $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){
if(!is_callable($callback)){ if(!is_callable($callback)){
return false; return false;
@ -499,7 +499,7 @@ class PocketMinecraftServer extends stdClass{
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.'if(!is_callable($schedule[0])){unset($this->schedule['.$this->scheduleCnt.']);return;} call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat); $this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.'if(!is_callable($schedule[0])){unset($this->schedule['.$this->scheduleCnt.']);return;} call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat);
return $this->scheduleCnt++; return $this->scheduleCnt++;
} }
public function action($microseconds, $code, $repeat = true){ public function action($microseconds, $code, $repeat = true){
$this->query("INSERT INTO actions (interval, last, code, repeat) VALUES(".($microseconds / 1000000).", ".microtime(true).", '".base64_encode($code)."', ".($repeat === true ? 1:0).");"); $this->query("INSERT INTO actions (interval, last, code, repeat) VALUES(".($microseconds / 1000000).", ".microtime(true).", '".base64_encode($code)."', ".($repeat === true ? 1:0).");");
console("[INTERNAL] Attached to action ".$microseconds, true, true, 3); console("[INTERNAL] Attached to action ".$microseconds, true, true, 3);
@ -511,7 +511,7 @@ class PocketMinecraftServer extends stdClass{
$this->preparedSQL->selectActions->clear(); $this->preparedSQL->selectActions->clear();
$this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT); $this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT);
$actions = $this->preparedSQL->selectActions->execute(); $actions = $this->preparedSQL->selectActions->execute();
if($actions === false or $actions === true){ if($actions === false or $actions === true){
return; return;
} }
@ -526,8 +526,8 @@ class PocketMinecraftServer extends stdClass{
$this->preparedSQL->updateActions->clear(); $this->preparedSQL->updateActions->clear();
$this->preparedSQL->updateActions->bindValue(":time", $time, SQLITE3_FLOAT); $this->preparedSQL->updateActions->bindValue(":time", $time, SQLITE3_FLOAT);
$this->preparedSQL->updateActions->execute(); $this->preparedSQL->updateActions->execute();
} }
public function event($event, $func){ public function event($event, $func){
if(!is_callable($func)){ if(!is_callable($func)){
return false; return false;
@ -537,11 +537,11 @@ class PocketMinecraftServer extends stdClass{
console("[INTERNAL] Attached ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)." to event ".$event." (ID ".$this->evCnt.")", true, true, 3); console("[INTERNAL] Attached ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)." to event ".$event." (ID ".$this->evCnt.")", true, true, 3);
return $this->evCnt++; return $this->evCnt++;
} }
public function deleteEvent($id){ public function deleteEvent($id){
$id = (int) $id; $id = (int) $id;
unset($this->events[$id]); unset($this->events[$id]);
$this->query("DELETE FROM events WHERE ID = ".$id.";"); $this->query("DELETE FROM events WHERE ID = ".$id.";");
} }
} }

View File

@ -42,7 +42,7 @@ class SerializedPacketHandler{
} }
return $data; return $data;
} }
public function __construct($pid, $raw = "", $data = array(), $create = false){ public function __construct($pid, $raw = "", $data = array(), $create = false){
$this->raw = $raw; $this->raw = $raw;
$this->data = $data; $this->data = $data;
@ -54,12 +54,12 @@ class SerializedPacketHandler{
case 0x00: case 0x00:
if($this->c === false){ if($this->c === false){
$this->data["packets"] = array(); $this->data["packets"] = array();
$i = 0; $i = 0;
while($this->offset < strlen($this->raw)){ while($this->offset < strlen($this->raw)){
if($i > 0){ if($i > 0){
$pid = ord($this->get(1)); $pid = ord($this->get(1));
} }
$len = ceil(Utils::readShort($this->get(2), false) / 8); //Utils::readShort($this->get(2), false) >> 3; $len = ceil(Utils::readShort($this->get(2), false) / 8); //Utils::readShort($this->get(2), false) >> 3;
if($pid !== 0x00){ if($pid !== 0x00){
$c = Utils::readTriad(strrev($this->get(3))); $c = Utils::readTriad(strrev($this->get(3)));

View File

@ -88,7 +88,7 @@ class Spyc {
/** /**
* Setting this to true will force YAMLDump to enclose any string value in * Setting this to true will force YAMLDump to enclose any string value in
* quotes. False by default. * quotes. False by default.
* *
* @var bool * @var bool
*/ */
public $setting_dump_force_quotes = false; public $setting_dump_force_quotes = false;
@ -168,7 +168,7 @@ class Spyc {
/** /**
* Load a string of YAML into a PHP array statically * Load a string of YAML into a PHP array statically
* *
* The load method, when supplied with a YAML string, will do its best * The load method, when supplied with a YAML string, will do its best
* to convert YAML in a string into a PHP array. Pretty simple. * to convert YAML in a string into a PHP array. Pretty simple.
* *
* Note: use this function if you don't want files from the file system * Note: use this function if you don't want files from the file system
@ -257,7 +257,7 @@ class Spyc {
// Start at the base of the array and move through it. // Start at the base of the array and move through it.
if ($array) { if ($array) {
$array = (array)$array; $array = (array)$array;
$previous_key = -1; $previous_key = -1;
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if (!isset($first_key)) $first_key = $key; if (!isset($first_key)) $first_key = $key;
@ -346,7 +346,7 @@ class Spyc {
if (is_bool($value)) { if (is_bool($value)) {
$value = ($value) ? "true" : "false"; $value = ($value) ? "true" : "false";
} }
if ($value === null) $value = 'null'; if ($value === null) $value = 'null';
if ($value === "'" . self::REMPTY . "'") $value = null; if ($value === "'" . self::REMPTY . "'") $value = null;
@ -438,7 +438,7 @@ class Spyc {
$cnt = count($Source); $cnt = count($Source);
for ($i = 0; $i < $cnt; $i++) { for ($i = 0; $i < $cnt; $i++) {
$line = $Source[$i]; $line = $Source[$i];
$this->indent = strlen($line) - strlen(ltrim($line)); $this->indent = strlen($line) - strlen(ltrim($line));
$tempPath = $this->getParentPathByIndent($this->indent); $tempPath = $this->getParentPathByIndent($this->indent);
$line = self::stripIndent($line, $this->indent); $line = self::stripIndent($line, $this->indent);
@ -530,9 +530,9 @@ class Spyc {
return $this->returnArrayElement($line); return $this->returnArrayElement($line);
if ($this->isPlainArray($line)) if ($this->isPlainArray($line))
return $this->returnPlainArray($line); return $this->returnPlainArray($line);
return $this->returnKeyValuePair($line); return $this->returnKeyValuePair($line);
} }
@ -558,7 +558,7 @@ class Spyc {
if ($is_quoted) if ($is_quoted)
return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\'\'' => '\'', '\\\'' => '\'')); return strtr(substr ($value, 1, -1), array ('\\"' => '"', '\'\'' => '\'', '\\\'' => '\''));
if (strpos($value, ' #') !== false && !$is_quoted) if (strpos($value, ' #') !== false && !$is_quoted)
$value = preg_replace('/\s+#(.+)$/','',$value); $value = preg_replace('/\s+#(.+)$/','',$value);
@ -585,7 +585,7 @@ class Spyc {
$value = $this->_toType($value); $value = $this->_toType($value);
return array($key => $value); return array($key => $value);
} }
if ($first_character == '{' && $last_character == '}') { if ($first_character == '{' && $last_character == '}') {
$innerValue = trim(substr ($value, 1, -1)); $innerValue = trim(substr ($value, 1, -1));
if ($innerValue === '') return array(); if ($innerValue === '') return array();
@ -632,7 +632,7 @@ class Spyc {
$value = (float)$value; $value = (float)$value;
return $value; return $value;
} }
return $value; return $value;
} }
@ -735,7 +735,7 @@ class Spyc {
if ($finished) break; if ($finished) break;
$i++; $i++;
if ($i > 10) if ($i > 10)
break; // Prevent infinite loops. break; // Prevent infinite loops.
} }
@ -763,7 +763,7 @@ class Spyc {
private function addArrayInline ($array, $indent) { private function addArrayInline ($array, $indent) {
$CommonGroupPath = $this->path; $CommonGroupPath = $this->path;
if (empty ($array)) return false; if (empty ($array)) return false;
foreach ($array as $k => $_) { foreach ($array as $k => $_) {
$this->addArray(array($k => $_), $indent); $this->addArray(array($k => $_), $indent);
$this->path = $CommonGroupPath; $this->path = $CommonGroupPath;
@ -777,7 +777,7 @@ class Spyc {
if (count ($incoming_data) > 1) if (count ($incoming_data) > 1)
return $this->addArrayInline ($incoming_data, $incoming_indent); return $this->addArrayInline ($incoming_data, $incoming_indent);
$key = key ($incoming_data); $key = key ($incoming_data);
$value = isset($incoming_data[$key]) ? $incoming_data[$key] : null; $value = isset($incoming_data[$key]) ? $incoming_data[$key] : null;
if ($key === '__!YAMLZero') $key = '0'; if ($key === '__!YAMLZero') $key = '0';
@ -793,7 +793,7 @@ class Spyc {
} }
$history = array(); $history = array();
// Unfolding inner array tree. // Unfolding inner array tree.
$history[] = $_arr = $this->result; $history[] = $_arr = $this->result;
@ -940,7 +940,7 @@ class Spyc {
if ($line[0] != '-') return false; if ($line[0] != '-') return false;
if (strlen ($line) > 3) if (strlen ($line) > 3)
if (substr($line,0,3) == '---') return false; if (substr($line,0,3) == '---') return false;
return true; return true;
} }
@ -985,14 +985,14 @@ class Spyc {
private function startsMappedValue ($line) { private function startsMappedValue ($line) {
return (substr ($line, -1, 1) == ':'); return (substr ($line, -1, 1) == ':');
} }
private function isPlainArray ($line) { private function isPlainArray ($line) {
return ($line[0] == '[' && substr ($line, -1, 1) == ']'); return ($line[0] == '[' && substr ($line, -1, 1) == ']');
} }
private function returnPlainArray ($line) { private function returnPlainArray ($line) {
return $this->_toType($line); return $this->_toType($line);
} }
private function returnKeyValuePair ($line) { private function returnKeyValuePair ($line) {
$array = array(); $array = array();
@ -1032,7 +1032,7 @@ class Spyc {
} }
private function nodeContainsGroup ($line) { private function nodeContainsGroup ($line) {
$symbolsForReference = 'A-z0-9_\-'; $symbolsForReference = 'A-z0-9_\-';
if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-) if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-)
if ($line[0] == '&' && preg_match('/^(&['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1]; if ($line[0] == '&' && preg_match('/^(&['.$symbolsForReference.']+)/', $line, $matches)) return $matches[1];

View File

@ -38,14 +38,14 @@ class SuperflatGenerator{
); );
$this->parsePreset(); $this->parsePreset();
} }
public function set($name, $value){ public function set($name, $value){
$this->config[$name] = $value; $this->config[$name] = $value;
if($name === "preset"){ if($name === "preset"){
$this->parsePreset(); $this->parsePreset();
} }
} }
private function parsePreset(){ private function parsePreset(){
$this->structure = array( $this->structure = array(
0 => "", 0 => "",
@ -53,7 +53,7 @@ class SuperflatGenerator{
2 => str_repeat("\x00", 64), 2 => str_repeat("\x00", 64),
3 => str_repeat("\x00", 64), 3 => str_repeat("\x00", 64),
); );
$preset = explode(";", trim($this->config["preset"])); $preset = explode(";", trim($this->config["preset"]));
foreach($preset as $i => $data){ foreach($preset as $i => $data){
$num = 1; $num = 1;
if(preg_match('#([a-zA-Z\-_]*)\((.*)\)#', $data, $matches) > 0){ //Property if(preg_match('#([a-zA-Z\-_]*)\((.*)\)#', $data, $matches) > 0){ //Property
@ -78,15 +78,15 @@ class SuperflatGenerator{
$this->structure[2] = substr($this->structure[2], 0, 64); $this->structure[2] = substr($this->structure[2], 0, 64);
$this->structure[3] = substr($this->structure[3], 0, 64); $this->structure[3] = substr($this->structure[3], 0, 64);
} }
public function init(){ public function init(){
$this->spawn = array(128, strlen($this->structure[0]), 128); $this->spawn = array(128, strlen($this->structure[0]), 128);
} }
public function getSpawn(){ public function getSpawn(){
return $this->spawn; return $this->spawn;
} }
public function getColumn($x, $z){ public function getColumn($x, $z){
$x = (int) $x; $x = (int) $x;
$z = (int) $z; $z = (int) $z;

View File

@ -28,7 +28,7 @@ the Free Software Foundation, either version 3 of the License, or
class TileEntity extends stdClass{ class TileEntity extends stdClass{
private $server; private $server;
function __construct(PocketMinecraftServer $server){ function __construct(PocketMinecraftServer $server){
} }
} }

View File

@ -42,7 +42,7 @@ class UDPSocket{
$this->unblock(); $this->unblock();
}else{ }else{
$this->sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $this->sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($this->sock, SOL_SOCKET, SO_BROADCAST, 1); socket_set_option($this->sock, SOL_SOCKET, SO_BROADCAST, 1);
if($listen !== true){ if($listen !== true){
$this->connected = true; $this->connected = true;
$this->buffer = array(); $this->buffer = array();
@ -57,7 +57,7 @@ class UDPSocket{
} }
} }
} }
function listenSocket(){ function listenSocket(){
$sock = @socket_accept($this->sock); $sock = @socket_accept($this->sock);
if($sock !== false){ if($sock !== false){
@ -67,7 +67,7 @@ class UDPSocket{
} }
return false; return false;
} }
public function close($error = 125){ public function close($error = 125){
$this->connected = false; $this->connected = false;
if($error === false){ if($error === false){
@ -77,7 +77,7 @@ class UDPSocket{
} }
return @socket_close($this->sock); return @socket_close($this->sock);
} }
public function block(){ public function block(){
socket_set_block($this->sock); socket_set_block($this->sock);
} }
@ -85,18 +85,18 @@ class UDPSocket{
public function unblock(){ public function unblock(){
socket_set_nonblock($this->sock); socket_set_nonblock($this->sock);
} }
public function read(){ public function read(){
$source = false; $source = false;
$port = 1; $port = 1;
$len = @socket_recvfrom($this->sock, $buf, 65536, 0, $source, $port); $len = @socket_recvfrom($this->sock, $buf, 65536, 0, $source, $port);
return array($buf, $source, $port, $len); return array($buf, $source, $port, $len);
} }
public function write($data, $dest = false, $port = false){ public function write($data, $dest = false, $port = false){
return @socket_sendto($this->sock, $data, strlen($data), 0, ($dest === false ? $this->server:$dest), ($port === false ? $this->port:$port)); return @socket_sendto($this->sock, $data, strlen($data), 0, ($dest === false ? $this->server:$dest), ($port === false ? $this->port:$port));
} }
} }
?> ?>

View File

@ -36,7 +36,7 @@ define("LITTLE_ENDIAN", 0x01);
define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN)); define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN));
abstract class Utils{ abstract class Utils{
public static function getOS(){ public static function getOS(){
$uname = strtoupper(php_uname("s")); $uname = strtoupper(php_uname("s"));
if(strpos($uname, "WIN") !== false){ if(strpos($uname, "WIN") !== false){
@ -47,22 +47,22 @@ abstract class Utils{
return "linux"; return "linux";
} }
} }
public static function hexdump($bin){ public static function hexdump($bin){
$output = ""; $output = "";
$bin = str_split($bin, 16); $bin = str_split($bin, 16);
foreach($bin as $counter => $line){ foreach($bin as $counter => $line){
$hex = chunk_split(chunk_split(str_pad(bin2hex($line), 32, " ", STR_PAD_RIGHT), 2, " "), 24, " "); $hex = chunk_split(chunk_split(str_pad(bin2hex($line), 32, " ", STR_PAD_RIGHT), 2, " "), 24, " ");
$ascii = preg_replace('#([^\x20-\x7E])#', ".", $line); $ascii = preg_replace('#([^\x20-\x7E])#', ".", $line);
$output .= str_pad(dechex($counter << 4), 4, "0", STR_PAD_LEFT). " " . $hex . " " . $ascii . PHP_EOL; $output .= str_pad(dechex($counter << 4), 4, "0", STR_PAD_LEFT). " " . $hex . " " . $ascii . PHP_EOL;
} }
return $output; return $output;
} }
public static function printable($str){ public static function printable($str){
return preg_replace('#([^\x20-\x7E])#', '.', $str); return preg_replace('#([^\x20-\x7E])#', '.', $str);
} }
public static function readTriad($str){ public static function readTriad($str){
list(,$unpacked) = unpack("N", "\x00".$str); list(,$unpacked) = unpack("N", "\x00".$str);
return (int) $unpacked; return (int) $unpacked;
@ -103,18 +103,18 @@ abstract class Utils{
$m .= Utils::writeLInt($data["value"][$i]); $m .= Utils::writeLInt($data["value"][$i]);
} }
break; break;
} }
} }
$m .= "\x7f"; $m .= "\x7f";
return $m; return $m;
} }
public static function readMetadata($value, $types = false){ public static function readMetadata($value, $types = false){
$offset = 0; $offset = 0;
$m = array(); $m = array();
$b = ord($value{$offset}); $b = ord($value{$offset});
++$offset; ++$offset;
while($b !== 127){ while($b !== 127){
$bottom = $b & 0x1F; $bottom = $b & 0x1F;
$type = $b >> 5; $type = $b >> 5;
@ -157,7 +157,7 @@ abstract class Utils{
$offset += 4; $offset += 4;
} }
break; break;
} }
if($types === true){ if($types === true){
$m[$bottom] = array($r, $type); $m[$bottom] = array($r, $type);
@ -167,9 +167,9 @@ abstract class Utils{
$b = ord($value{$offset}); $b = ord($value{$offset});
++$offset; ++$offset;
} }
return $m; return $m;
} }
public static function readDataArray($str, $len = 10, &$offset = null){ public static function readDataArray($str, $len = 10, &$offset = null){
$data = array(); $data = array();
$offset = 0; $offset = 0;
@ -181,7 +181,7 @@ abstract class Utils{
} }
return $data; return $data;
} }
public static function writeDataArray($data){ public static function writeDataArray($data){
$raw = ""; $raw = "";
foreach($data as $v){ foreach($data as $v){
@ -190,7 +190,7 @@ abstract class Utils{
} }
return $raw; return $raw;
} }
public static function getRandomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0){ public static function getRandomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0){
$output = b""; $output = b"";
$length = abs((int) $length); $length = abs((int) $length);
@ -227,7 +227,7 @@ abstract class Utils{
(string) disk_total_space("."), (string) disk_total_space("."),
uniqid(microtime(),true), uniqid(microtime(),true),
); );
shuffle($weakEntropy); shuffle($weakEntropy);
$value = hash("sha256", implode($weakEntropy), true); $value = hash("sha256", implode($weakEntropy), true);
foreach($weakEntropy as $k => $c){ //mixing entropy values with XOR and hash randomness extractor foreach($weakEntropy as $k => $c){ //mixing entropy values with XOR and hash randomness extractor
@ -237,7 +237,7 @@ abstract class Utils{
$value ^= hash("sha256", $c . microtime() . $k, true); $value ^= hash("sha256", $c . microtime() . $k, true);
} }
unset($weakEntropy); unset($weakEntropy);
if($secure === true){ if($secure === true){
$strongEntropy = array( $strongEntropy = array(
is_array($startEntropy) ? $startEntropy[($rounds + $drop) % count($startEntropy)]:$startEntropy, //Get a random index of the startEntropy, or just read it is_array($startEntropy) ? $startEntropy[($rounds + $drop) % count($startEntropy)]:$startEntropy, //Get a random index of the startEntropy, or just read it
@ -275,15 +275,15 @@ abstract class Utils{
} }
return $raw === false ? bin2hex($output):$output; return $raw === false ? bin2hex($output):$output;
} }
public static function round($number){ public static function round($number){
return round($number, 0, PHP_ROUND_HALF_DOWN); return round($number, 0, PHP_ROUND_HALF_DOWN);
} }
public static function distance($pos1, $pos2){ public static function distance($pos1, $pos2){
return sqrt(pow($pos1["x"] - $pos2["x"], 2) + pow($pos1["y"] - $pos2["y"], 2) + pow($pos1["z"] - $pos2["z"], 2)); return sqrt(pow($pos1["x"] - $pos2["x"], 2) + pow($pos1["y"] - $pos2["y"], 2) + pow($pos1["z"] - $pos2["z"], 2));
} }
public static function angle3D($pos1, $pos2){ public static function angle3D($pos1, $pos2){
$X = $pos1["x"] - $pos2["x"]; $X = $pos1["x"] - $pos2["x"];
$Z = $pos1["z"] - $pos2["z"]; $Z = $pos1["z"] - $pos2["z"];
@ -293,17 +293,17 @@ abstract class Utils{
$vAngle = rad2deg(-atan2($Y, $dXZ)); $vAngle = rad2deg(-atan2($Y, $dXZ));
return array("yaw" => $hAngle, "pitch" => $vAngle); return array("yaw" => $hAngle, "pitch" => $vAngle);
} }
public static function sha1($input){ public static function sha1($input){
$number = new Math_BigInteger(sha1($input, true), -256); $number = new Math_BigInteger(sha1($input, true), -256);
$zero = new Math_BigInteger(0); $zero = new Math_BigInteger(0);
return ($zero->compare($number) <= 0 ? "":"-") . ltrim($number->toHex(), "0"); return ($zero->compare($number) <= 0 ? "":"-") . ltrim($number->toHex(), "0");
} }
public static function microtime(){ public static function microtime(){
return microtime(true); return microtime(true);
} }
public static function curl_get($page){ public static function curl_get($page){
$ch = curl_init($page); $ch = curl_init($page);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Minecraft PHP Client 2")); curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Minecraft PHP Client 2"));
@ -317,7 +317,7 @@ abstract class Utils{
curl_close($ch); curl_close($ch);
return $ret; return $ret;
} }
public static function curl_post($page, $args, $timeout = 10){ public static function curl_post($page, $args, $timeout = 10){
$ch = curl_init($page); $ch = curl_init($page);
curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POST, 1);
@ -331,26 +331,26 @@ abstract class Utils{
curl_close($ch); curl_close($ch);
return $ret; return $ret;
} }
public static function strToHex($str){ public static function strToHex($str){
return bin2hex($str); return bin2hex($str);
} }
public static function hexToStr($hex){ public static function hexToStr($hex){
if(HEX2BIN === true){ if(HEX2BIN === true){
return hex2bin($hex); return hex2bin($hex);
} }
return pack("H*" , $hex); return pack("H*" , $hex);
} }
public static function readBool($b){ public static function readBool($b){
return Utils::readByte($b, false) === 0 ? false:true; return Utils::readByte($b, false) === 0 ? false:true;
} }
public static function writeBool($b){ public static function writeBool($b){
return Utils::writeByte($b === true ? 1:0); return Utils::writeByte($b === true ? 1:0);
} }
public static function readByte($c, $signed = true){ public static function readByte($c, $signed = true){
$b = ord($c{0}); $b = ord($c{0});
if($signed === true and ($b & 0x80) === 0x80){ //calculate Two's complement if($signed === true and ($b & 0x80) === 0x80){ //calculate Two's complement
@ -358,7 +358,7 @@ abstract class Utils{
} }
return $b; return $b;
} }
public static function writeByte($c){ public static function writeByte($c){
if($c > 0xff){ if($c > 0xff){
return false; return false;
@ -376,14 +376,14 @@ abstract class Utils{
} }
return $unpacked; return $unpacked;
} }
public static function writeShort($value){ public static function writeShort($value){
if($value < 0){ if($value < 0){
$value += 0x10000; $value += 0x10000;
} }
return pack("n", $value); return pack("n", $value);
} }
public static function readLShort($str, $signed = true){ public static function readLShort($str, $signed = true){
list(,$unpacked) = unpack("v", $str); list(,$unpacked) = unpack("v", $str);
if($unpacked > 0x7fff and $signed === true){ if($unpacked > 0x7fff and $signed === true){
@ -391,10 +391,10 @@ abstract class Utils{
} }
return $unpacked; return $unpacked;
} }
public static function writeLShort($value){ public static function writeLShort($value){
if($value < 0){ if($value < 0){
$value += 0x10000; $value += 0x10000;
} }
return pack("v", $value); return pack("v", $value);
} }
@ -406,14 +406,14 @@ abstract class Utils{
} }
return (int) $unpacked; return (int) $unpacked;
} }
public static function writeInt($value){ public static function writeInt($value){
if($value < 0){ if($value < 0){
$value += 0x100000000; $value += 0x100000000;
} }
return pack("N", $value); return pack("N", $value);
} }
public static function readLInt($str){ public static function readLInt($str){
list(,$unpacked) = unpack("V", $str); list(,$unpacked) = unpack("V", $str);
if($unpacked >= 2147483648){ if($unpacked >= 2147483648){
@ -421,50 +421,50 @@ abstract class Utils{
} }
return (int) $unpacked; return (int) $unpacked;
} }
public static function writeLInt($value){ public static function writeLInt($value){
if($value < 0){ if($value < 0){
$value += 0x100000000; $value += 0x100000000;
} }
return pack("V", $value); return pack("V", $value);
} }
public static function readFloat($str){ public static function readFloat($str){
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", $str):unpack("f", strrev($str)); list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", $str):unpack("f", strrev($str));
return $value; return $value;
} }
public static function writeFloat($value){ public static function writeFloat($value){
return ENDIANNESS === BIG_ENDIAN ? pack("f", $value):strrev(pack("f", $value)); return ENDIANNESS === BIG_ENDIAN ? pack("f", $value):strrev(pack("f", $value));
} }
public static function readLFloat($str){ public static function readLFloat($str){
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", strrev($str)):unpack("f", $str); list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", strrev($str)):unpack("f", $str);
return $value; return $value;
} }
public static function writeLFloat($value){ public static function writeLFloat($value){
return ENDIANNESS === BIG_ENDIAN ? strrev(pack("f", $value)):pack("f", $value); return ENDIANNESS === BIG_ENDIAN ? strrev(pack("f", $value)):pack("f", $value);
} }
public static function printFloat($value){ public static function printFloat($value){
return preg_replace("/(\.\d+?)0+$/", "$1", sprintf("%F", $value)); return preg_replace("/(\.\d+?)0+$/", "$1", sprintf("%F", $value));
} }
public static function readDouble($str){ public static function readDouble($str){
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", $str):unpack("d", strrev($str)); list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", $str):unpack("d", strrev($str));
return $value; return $value;
} }
public static function writeDouble($value){ public static function writeDouble($value){
return ENDIANNESS === BIG_ENDIAN ? pack("d", $value):strrev(pack("d", $value)); return ENDIANNESS === BIG_ENDIAN ? pack("d", $value):strrev(pack("d", $value));
} }
public static function readLDouble($str){ public static function readLDouble($str){
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", strrev($str)):unpack("d", $str); list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", strrev($str)):unpack("d", $str);
return $value; return $value;
} }
public static function writeLDouble($value){ public static function writeLDouble($value){
return ENDIANNESS === BIG_ENDIAN ? strrev(pack("d", $value)):pack("d", $value); return ENDIANNESS === BIG_ENDIAN ? strrev(pack("d", $value)):pack("d", $value);
} }
@ -473,20 +473,20 @@ abstract class Utils{
$long = new Math_BigInteger($str, -256); $long = new Math_BigInteger($str, -256);
return $long->toString(); return $long->toString();
} }
public static function writeLong($value){ public static function writeLong($value){
$long = new Math_BigInteger($value, -10); $long = new Math_BigInteger($value, -10);
return str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT); return str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT);
} }
public static function readLLong($str){ public static function readLLong($str){
$long = new Math_BigInteger(strrev($str), -256); $long = new Math_BigInteger(strrev($str), -256);
return $long->toString(); return $long->toString();
} }
public static function writeLLong($value){ public static function writeLLong($value){
$long = new Math_BigInteger($value, -10); $long = new Math_BigInteger($value, -10);
return strrev(str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT)); return strrev(str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT));
} }
} }

View File

@ -32,7 +32,7 @@ define("WINDOW_FURNACE", 2);
class Window{ class Window{
private $server; private $server;
public function __construct(PocketMinecraftServer $server){ public function __construct(PocketMinecraftServer $server){
} }
} }

View File

@ -112,7 +112,7 @@ function arg($name, $default){
if(!isset($arguments)){ if(!isset($arguments)){
$arguments = arguments($argv); $arguments = arguments($argv);
} }
if(isset($arguments["commands"][$name])){ if(isset($arguments["commands"][$name])){
return $arguments["commands"][$name]; return $arguments["commands"][$name];
}else{ }else{
@ -171,7 +171,7 @@ function console($message, $EOL = true, $log = true, $level = 1){
$message = date("H:i:s"). " ". $message; $message = date("H:i:s"). " ". $message;
if($log === true and (!defined("LOG") or LOG === true)){ if($log === true and (!defined("LOG") or LOG === true)){
logg($message, "console", false, $level); logg($message, "console", false, $level);
} }
echo $message; echo $message;
} }
} }

View File

@ -30,7 +30,7 @@ class Sapling{
const SPRUCE = 1; const SPRUCE = 1;
const BIRCH = 2; const BIRCH = 2;
const BURN_TIME = 5; const BURN_TIME = 5;
public static function growTree(LevelAPI $level, $block, $type){ public static function growTree(LevelAPI $level, $block, $type){
$type = $type & 0x03; $type = $type & 0x03;
TreeObject::growTree($level, $block, $type); TreeObject::growTree($level, $block, $type);

View File

@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
class Vector2{ class Vector2{
public $x, $y; public $x, $y;
public function __construct($x = 0, $y = 0){ public function __construct($x = 0, $y = 0){
if(($x instanceof Vector2) === true){ if(($x instanceof Vector2) === true){
$this->__construct($x->x, $x->y); $this->__construct($x->x, $x->y);
@ -36,23 +36,23 @@ class Vector2{
$this->y = $y; $this->y = $y;
} }
} }
public function getX(){ public function getX(){
return $this->x; return $this->x;
} }
public function getY(){ public function getY(){
return $this->y; return $this->y;
} }
public function getFloorX(){ public function getFloorX(){
return (int) $this->x; return (int) $this->x;
} }
public function getFloorY(){ public function getFloorY(){
return (int) $this->y; return (int) $this->y;
} }
public function add($x = 0, $y = 0){ public function add($x = 0, $y = 0){
if(($x instanceof Vector2) === true){ if(($x instanceof Vector2) === true){
return $this->add($x->x, $x->y); return $this->add($x->x, $x->y);
@ -62,7 +62,7 @@ class Vector2{
return new Vector3($this->x + $x, $this->y + $y); return new Vector3($this->x + $x, $this->y + $y);
} }
} }
public function subtract($x = 0, $y = 0){ public function subtract($x = 0, $y = 0){
if(($x instanceof Vector2) === true){ if(($x instanceof Vector2) === true){
return $this->add(-$x->x, -$x->y); return $this->add(-$x->x, -$x->y);
@ -70,23 +70,23 @@ class Vector2{
return $this->add(-$x, -$y); return $this->add(-$x, -$y);
} }
} }
public function ceil(){ public function ceil(){
return new Vector2((int) ($this->x + 1), (int) ($this->y + 1)); return new Vector2((int) ($this->x + 1), (int) ($this->y + 1));
} }
public function floor(){ public function floor(){
return new Vector2((int) $this->x, (int) $this->y); return new Vector2((int) $this->x, (int) $this->y);
} }
public function round(){ public function round(){
return new Vector2(round($this->x), round($this->y)); return new Vector2(round($this->x), round($this->y));
} }
public function abs(){ public function abs(){
return new Vector2(abs($this->x), abs($this->y)); return new Vector2(abs($this->x), abs($this->y));
} }
public function distance($x = 0, $y = 0){ public function distance($x = 0, $y = 0){
if(($x instanceof Vector2) === true){ if(($x instanceof Vector2) === true){
return sqrt($this->distanceSquared($x->x, $x->y)); return sqrt($this->distanceSquared($x->x, $x->y));
@ -94,7 +94,7 @@ class Vector2{
return sqrt($this->distanceSquared($x, $y)); return sqrt($this->distanceSquared($x, $y));
} }
} }
public function distanceSquared($x = 0, $y = 0){ public function distanceSquared($x = 0, $y = 0){
if(($x instanceof Vector2) === true){ if(($x instanceof Vector2) === true){
return $this->distanceSquared($x->x, $x->y); return $this->distanceSquared($x->x, $x->y);
@ -102,9 +102,9 @@ class Vector2{
return pow($this->x - $x, 2) + pow($this->y - $y, 2); return pow($this->x - $x, 2) + pow($this->y - $y, 2);
} }
} }
public function __toString(){ public function __toString(){
return "Vector2(x=".$this->x.",y=".$this->y.")"; return "Vector2(x=".$this->x.",y=".$this->y.")";
} }
} }

View File

@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
class Vector3{ class Vector3{
public $x, $y, $z; public $x, $y, $z;
public function __construct($x = 0, $y = 0, $z = 0){ public function __construct($x = 0, $y = 0, $z = 0){
if(($x instanceof Vector3) === true){ if(($x instanceof Vector3) === true){
$this->__construct($x->x, $x->y, $x->z); $this->__construct($x->x, $x->y, $x->z);
@ -37,51 +37,51 @@ class Vector3{
$this->z = $z; $this->z = $z;
} }
} }
public function getX(){ public function getX(){
return $this->x; return $this->x;
} }
public function getY(){ public function getY(){
return $this->y; return $this->y;
} }
public function getZ(){ public function getZ(){
return $this->z; return $this->z;
} }
public function getFloorX(){ public function getFloorX(){
return (int) $this->x; return (int) $this->x;
} }
public function getFloorY(){ public function getFloorY(){
return (int) $this->y; return (int) $this->y;
} }
public function getFloorZ(){ public function getFloorZ(){
return (int) $this->z; return (int) $this->z;
} }
public function getRight(){ public function getRight(){
return $this->getX(); return $this->getX();
} }
public function getUp(){ public function getUp(){
return $this->getY(); return $this->getY();
} }
public function getForward(){ public function getForward(){
return $this->getZ(); return $this->getZ();
} }
public function getSouth(){ public function getSouth(){
return $this->getX(); return $this->getX();
} }
public function getWest(){ public function getWest(){
return $this->getZ(); return $this->getZ();
} }
public function add($x = 0, $y = 0, $z = 0){ public function add($x = 0, $y = 0, $z = 0){
if(($x instanceof Vector3) === true){ if(($x instanceof Vector3) === true){
return $this->add($x->x, $x->y, $x->z); return $this->add($x->x, $x->y, $x->z);
@ -92,7 +92,7 @@ class Vector3{
return new Vector3($this->x + $x, $this->y + $y, $this->z + $z); return new Vector3($this->x + $x, $this->y + $y, $this->z + $z);
} }
} }
public function subtract($x = 0, $y = 0, $z = 0){ public function subtract($x = 0, $y = 0, $z = 0){
if(($x instanceof Vector3) === true){ if(($x instanceof Vector3) === true){
return $this->add(-$x->x, -$x->y, -$x->z); return $this->add(-$x->x, -$x->y, -$x->z);
@ -100,23 +100,23 @@ class Vector3{
return $this->add(-$x, -$y, -$z); return $this->add(-$x, -$y, -$z);
} }
} }
public function ceil(){ public function ceil(){
return new Vector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1)); return new Vector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
} }
public function floor(){ public function floor(){
return new Vector3((int) $this->x, (int) $this->y, (int) $this->z); return new Vector3((int) $this->x, (int) $this->y, (int) $this->z);
} }
public function round(){ public function round(){
return new Vector3(round($this->x), round($this->y), round($this->z)); return new Vector3(round($this->x), round($this->y), round($this->z));
} }
public function abs(){ public function abs(){
return new Vector3(abs($this->x), abs($this->y), abs($this->z)); return new Vector3(abs($this->x), abs($this->y), abs($this->z));
} }
public function distance($x = 0, $y = 0, $z = 0){ public function distance($x = 0, $y = 0, $z = 0){
if(($x instanceof Vector3) === true){ if(($x instanceof Vector3) === true){
return sqrt($this->distanceSquared($x->x, $x->y, $x->z)); return sqrt($this->distanceSquared($x->x, $x->y, $x->z));
@ -124,7 +124,7 @@ class Vector3{
return sqrt($this->distanceSquared($x, $y, $z)); return sqrt($this->distanceSquared($x, $y, $z));
} }
} }
public function distanceSquared($x = 0, $y = 0, $z = 0){ public function distanceSquared($x = 0, $y = 0, $z = 0){
if(($x instanceof Vector3) === true){ if(($x instanceof Vector3) === true){
return $this->distanceSquared($x->x, $x->y, $x->z); return $this->distanceSquared($x->x, $x->y, $x->z);
@ -132,9 +132,9 @@ class Vector3{
return pow($this->x - $x, 2) + pow($this->y - $y, 2) + pow($this->z - $z, 2); return pow($this->x - $x, 2) + pow($this->y - $y, 2) + pow($this->z - $z, 2);
} }
} }
public function __toString(){ public function __toString(){
return "Vector3(x=".$this->x.",y=".$this->y.",z=".$this->z.")"; return "Vector3(x=".$this->x.",y=".$this->y.",z=".$this->z.")";
} }
} }

View File

@ -47,11 +47,11 @@ class VersionString{
$this->minor = (int) $version[4]; //0-31 $this->minor = (int) $version[4]; //0-31
} }
} }
public function getNumber(){ public function getNumber(){
return (int) (VersionString::$stageOrder[$this->stage] << 13) + ($this->generation << 9) + ($this->major << 5) + $this->minor; return (int) (VersionString::$stageOrder[$this->stage] << 13) + ($this->generation << 9) + ($this->major << 5) + $this->minor;
} }
public function getStage(){ public function getStage(){
return $this->stage; return $this->stage;
} }
@ -59,23 +59,23 @@ class VersionString{
public function getGeneration(){ public function getGeneration(){
return $this->generation; return $this->generation;
} }
public function getMajor(){ public function getMajor(){
return $this->major; return $this->major;
} }
public function getMinor(){ public function getMinor(){
return $this->minor; return $this->minor;
} }
public function getRelease(){ public function getRelease(){
return $this->generation . "." . $this->major . "." . $this->minor; return $this->generation . "." . $this->major . "." . $this->minor;
} }
public function __toString(){ public function __toString(){
return ucfirst($this->stage) . "_" . $this->generation . "." . $this->major . "." . $this->minor; return ucfirst($this->stage) . "_" . $this->generation . "." . $this->major . "." . $this->minor;
} }
public function compare($target, $diff = false){ public function compare($target, $diff = false){
if(($target instanceof VersionString) === false){ if(($target instanceof VersionString) === false){
$target = new VersionString($target); $target = new VersionString($target);
@ -91,6 +91,6 @@ class VersionString{
return 1; //Target is newer return 1; //Target is newer
}else{ }else{
return 0; //Same version return 0; //Same version
} }
} }
} }

View File

@ -35,20 +35,20 @@ class BigTreeObject extends TreeObject{
private $leafDistanceLimit = 5; private $leafDistanceLimit = 5;
private $widthScale = 1; private $widthScale = 1;
private $branchSlope = 0.381; private $branchSlope = 0.381;
private $totalHeight = 6; private $totalHeight = 6;
private $leavesHeight = 3; private $leavesHeight = 3;
protected $radiusIncrease = 0; protected $radiusIncrease = 0;
private $addLeavesVines = false; private $addLeavesVines = false;
private $addLogVines = false; private $addLogVines = false;
private $addCocoaPlants = false; private $addCocoaPlants = false;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){ public function canPlaceObject(LevelAPI $level, $x, $y, $z){
return false; return false;
} }
public function placeObject(LevelAPI $level, $x, $y, $z, $type){ public function placeObject(LevelAPI $level, $x, $y, $z, $type){
$this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier); $this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier);
$leaves = $this->getLeafGroupPoints($level, $x, $y, $z); $leaves = $this->getLeafGroupPoints($level, $x, $y, $z);
foreach($leaves as $leafGroup){ foreach($leaves as $leafGroup){
@ -64,7 +64,7 @@ class BigTreeObject extends TreeObject{
trunk.next().setMaterial(VanillaMaterials.LOG, logMetadata); trunk.next().setMaterial(VanillaMaterials.LOG, logMetadata);
} }
generateBranches(w, x, y, z, leaves); generateBranches(w, x, y, z, leaves);
$level->setBlock($x, $y - 1, $z, 3, 0); $level->setBlock($x, $y - 1, $z, 3, 0);
$this->totalHeight += mt_rand(-1, 3); $this->totalHeight += mt_rand(-1, 3);
$this->leavesHeight += mt_rand(0, 1); $this->leavesHeight += mt_rand(0, 1);

View File

@ -33,7 +33,7 @@ class PineTreeObject extends TreeObject{
private $totalHeight = 8; private $totalHeight = 8;
private $leavesSizeY = -1; private $leavesSizeY = -1;
private $leavesAbsoluteMaxRadius = -1; private $leavesAbsoluteMaxRadius = -1;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){ public function canPlaceObject(LevelAPI $level, $x, $y, $z){
$this->findRandomLeavesSize(); $this->findRandomLeavesSize();
$checkRadius = 0; $checkRadius = 0;
@ -52,13 +52,13 @@ class PineTreeObject extends TreeObject{
} }
return true; return true;
} }
private function findRandomLeavesSize(){ private function findRandomLeavesSize(){
$this->totalHeight += mt_rand(-1, 2); $this->totalHeight += mt_rand(-1, 2);
$this->leavesSizeY = 1 + mt_rand(0,2); $this->leavesSizeY = 1 + mt_rand(0,2);
$this->leavesAbsoluteMaxRadius = 2 + mt_rand(0, 2); $this->leavesAbsoluteMaxRadius = 2 + mt_rand(0, 2);
} }
public function placeObject(LevelAPI $level, $x, $y, $z){ public function placeObject(LevelAPI $level, $x, $y, $z){
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) { if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) {
$this->findRandomLeavesSize(); $this->findRandomLeavesSize();
@ -90,7 +90,7 @@ class PineTreeObject extends TreeObject{
$trunkHeightReducer = mt_rand(0,3); $trunkHeightReducer = mt_rand(0,3);
for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){ for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type); $level->setBlock($x, $y + $yy, $z, 17, $this->type);
} }
} }

View File

@ -35,8 +35,8 @@ class SmallTreeObject extends TreeObject{
protected $radiusIncrease = 0; protected $radiusIncrease = 0;
private $addLeavesVines = false; private $addLeavesVines = false;
private $addLogVines = false; private $addLogVines = false;
private $addCocoaPlants = false; private $addCocoaPlants = false;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){ public function canPlaceObject(LevelAPI $level, $x, $y, $z){
$radiusToCheck = $this->radiusIncrease; $radiusToCheck = $this->radiusIncrease;
for ($yy = 0; $yy < $this->totalHeight + 2; ++$yy) { for ($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
@ -54,7 +54,7 @@ class SmallTreeObject extends TreeObject{
} }
return true; return true;
} }
public function placeObject(LevelAPI $level, $x, $y, $z){ public function placeObject(LevelAPI $level, $x, $y, $z){
$level->setBlock($x, $y - 1, $z, 3, 0); $level->setBlock($x, $y - 1, $z, 3, 0);
$this->totalHeight += mt_rand(-1, 3); $this->totalHeight += mt_rand(-1, 3);
@ -72,7 +72,7 @@ class SmallTreeObject extends TreeObject{
} }
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){ for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type); $level->setBlock($x, $y + $yy, $z, 17, $this->type);
} }
} }

View File

@ -33,7 +33,7 @@ class SpruceTreeObject extends TreeObject{
private $totalHeight = 8; private $totalHeight = 8;
private $leavesBottomY = -1; private $leavesBottomY = -1;
private $leavesMaxRadius = -1; private $leavesMaxRadius = -1;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){ public function canPlaceObject(LevelAPI $level, $x, $y, $z){
$this->findRandomLeavesSize(); $this->findRandomLeavesSize();
$checkRadius = 0; $checkRadius = 0;
@ -52,13 +52,13 @@ class SpruceTreeObject extends TreeObject{
} }
return true; return true;
} }
private function findRandomLeavesSize(){ private function findRandomLeavesSize(){
$this->totalHeight += mt_rand(-1, 2); $this->totalHeight += mt_rand(-1, 2);
$this->leavesBottomY = (int) ($this->totalHeight - mt_rand(1,2) - 3); $this->leavesBottomY = (int) ($this->totalHeight - mt_rand(1,2) - 3);
$this->leavesMaxRadius = 1 + mt_rand(0, 1); $this->leavesMaxRadius = 1 + mt_rand(0, 1);
} }
public function placeObject(LevelAPI $level, $x, $y, $z){ public function placeObject(LevelAPI $level, $x, $y, $z){
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) { if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
$this->findRandomLeavesSize(); $this->findRandomLeavesSize();
@ -81,7 +81,7 @@ class SpruceTreeObject extends TreeObject{
} }
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){ for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type); $level->setBlock($x, $y + $yy, $z, 17, $this->type);
} }
} }

View File

@ -31,7 +31,7 @@ class TreeObject{
0 => true, 0 => true,
6 => true, 6 => true,
17 => true, 17 => true,
18 => true, 18 => true,
); );
public static function growTree(LevelAPI $level, $block, $type){ public static function growTree(LevelAPI $level, $block, $type){
switch($type){ switch($type){

View File

@ -30,20 +30,20 @@ $pstruct = array(
"long", //Ping ID "long", //Ping ID
"magic", "magic",
), ),
0x05 => array( 0x05 => array(
"magic", "magic",
"byte", //Protocol Version "byte", //Protocol Version
"special1", //MTU Size Null Lenght "special1", //MTU Size Null Lenght
), ),
0x06 => array( 0x06 => array(
"magic", "magic",
"long", //Server GUID "long", //Server GUID
"byte", //Server Security "byte", //Server Security
"short", //MTU Size "short", //MTU Size
), ),
0x07 => array( 0x07 => array(
"magic", "magic",
5, //Security Cookie (idk why it's sent here) 5, //Security Cookie (idk why it's sent here)
@ -51,7 +51,7 @@ $pstruct = array(
"short", //MTU Size "short", //MTU Size
"long", //Client GUID "long", //Client GUID
), ),
0x08 => array( 0x08 => array(
"magic", "magic",
"long", //Server GUID "long", //Server GUID
@ -59,20 +59,20 @@ $pstruct = array(
"short", //MTU Size "short", //MTU Size
"byte", //Security "byte", //Security
), ),
0x1a => array( 0x1a => array(
"byte", //Server Version "byte", //Server Version
"magic", "magic",
"long", //Server GUID "long", //Server GUID
), ),
0x1c => array( 0x1c => array(
"long", //Ping ID "long", //Ping ID
"long", //Server GUID "long", //Server GUID
"magic", "magic",
"string", //Data "string", //Data
), ),
0x1d => array( 0x1d => array(
"long", //Ping ID "long", //Ping ID
"long", //Server GUID "long", //Server GUID
@ -85,50 +85,50 @@ $pstruct = array(
"ubyte", "ubyte",
"customData", "customData",
), ),
0x81 => array( 0x81 => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x82 => array( 0x82 => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x83 => array( 0x83 => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x84 => array( 0x84 => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x85 => array( 0x85 => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x86 => array( 0x86 => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x87 => array( 0x87 => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x88 => array( 0x88 => array(
"itriad", "itriad",
"ubyte", "ubyte",
@ -140,52 +140,52 @@ $pstruct = array(
"ubyte", "ubyte",
"customData", "customData",
), ),
0x8a => array( 0x8a => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x8b => array( 0x8b => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x8c => array( 0x8c => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x8d => array( 0x8d => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x8e => array( 0x8e => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0x8f => array( 0x8f => array(
"itriad", "itriad",
"ubyte", "ubyte",
"customData", "customData",
), ),
0xa0 => array( 0xa0 => array(
"short", "short",
"bool", "bool",
"itriad", "itriad",
"special1", "special1",
), ),
0xc0 => array( 0xc0 => array(
"short", "short",
"bool", "bool",

View File

@ -27,44 +27,44 @@ the Free Software Foundation, either version 3 of the License, or
$dataName = array( $dataName = array(
MC_KEEP_ALIVE => "KeepAlive", MC_KEEP_ALIVE => "KeepAlive",
MC_CLIENT_CONNECT => "ClientConnect", MC_CLIENT_CONNECT => "ClientConnect",
MC_SERVER_HANDSHAKE => "ServerHandshake", MC_SERVER_HANDSHAKE => "ServerHandshake",
MC_CLIENT_HANDSHAKE => "ClientHandshake", MC_CLIENT_HANDSHAKE => "ClientHandshake",
MC_DISCONNECT => "Disconnect", MC_DISCONNECT => "Disconnect",
0x18 => "Unknown", 0x18 => "Unknown",
MC_LOGIN => "Login", MC_LOGIN => "Login",
MC_LOGIN_STATUS => "LoginStatus", MC_LOGIN_STATUS => "LoginStatus",
MC_READY => "Ready", MC_READY => "Ready",
MC_CHAT => "Chat", MC_CHAT => "Chat",
MC_SET_TIME => "SetTime", MC_SET_TIME => "SetTime",
MC_START_GAME => "StartGame", MC_START_GAME => "StartGame",
MC_ADD_MOB => "AddMob", MC_ADD_MOB => "AddMob",
MC_ADD_PLAYER => "AddPlayer", MC_ADD_PLAYER => "AddPlayer",
MC_ADD_ENTITY => "AddEntity", MC_ADD_ENTITY => "AddEntity",
MC_REMOVE_ENTITY => "RemoveEntity", MC_REMOVE_ENTITY => "RemoveEntity",
MC_ADD_ITEM_ENTITY => "AddItemEntity", MC_ADD_ITEM_ENTITY => "AddItemEntity",
MC_TAKE_ITEM_ENTITY => "TakeItemEntity", MC_TAKE_ITEM_ENTITY => "TakeItemEntity",
MC_MOVE_ENTITY => "MoveEntity", MC_MOVE_ENTITY => "MoveEntity",
MC_MOVE_ENTITY_POSROT => "MoveEntity_PosRot", MC_MOVE_ENTITY_POSROT => "MoveEntity_PosRot",
MC_MOVE_PLAYER => "MovePlayer", MC_MOVE_PLAYER => "MovePlayer",
MC_PLACE_BLOCK => "PlaceBlock", MC_PLACE_BLOCK => "PlaceBlock",
MC_REMOVE_BLOCK => "RemoveBlock", MC_REMOVE_BLOCK => "RemoveBlock",
MC_UPDATE_BLOCK => "UpdateBlock", MC_UPDATE_BLOCK => "UpdateBlock",
MC_REQUEST_CHUNK => "RequestChunk", MC_REQUEST_CHUNK => "RequestChunk",
MC_CHUNK_DATA => "ChunkData", MC_CHUNK_DATA => "ChunkData",
MC_PLAYER_EQUIPMENT => "PlayerEquipment", MC_PLAYER_EQUIPMENT => "PlayerEquipment",
MC_INTERACT => "Interact", MC_INTERACT => "Interact",
MC_USE_ITEM => "UseItem", MC_USE_ITEM => "UseItem",
MC_PLAYER_ACTION => "PlayerAction", MC_PLAYER_ACTION => "PlayerAction",
@ -74,12 +74,12 @@ $dataName = array(
MC_SET_SPAWN_POSITION => "SetSpawnPosition", MC_SET_SPAWN_POSITION => "SetSpawnPosition",
MC_ANIMATE => "Animate", MC_ANIMATE => "Animate",
MC_RESPAWN => "Respawn", MC_RESPAWN => "Respawn",
MC_DROP_ITEM => "DropItem", MC_DROP_ITEM => "DropItem",
MC_CONTAINER_OPEN => "ContainerOpen", MC_CONTAINER_OPEN => "ContainerOpen",
MC_CONTAINER_CLOSE => "ContainerClose", MC_CONTAINER_CLOSE => "ContainerClose",
MC_CONTAINER_SET_SLOT => "ContainerSetSlot", MC_CONTAINER_SET_SLOT => "ContainerSetSlot",
MC_CLIENT_MESSAGE => "ClientMessage", MC_CLIENT_MESSAGE => "ClientMessage",
MC_SIGN_UPDATE => "SignUpdate", MC_SIGN_UPDATE => "SignUpdate",
MC_ADVENTURE_SETTINGS => "AdventureSettings", MC_ADVENTURE_SETTINGS => "AdventureSettings",