diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 7dcd2a81..0c5d6f3e 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -362,10 +362,8 @@ class BanAPI{ return true; }elseif($this->bannedIPs->exists($ip, true)){ return true; - } - else - { - return false; + }else{ + return false; } } @@ -380,10 +378,8 @@ class BanAPI{ return true; }elseif($this->banned->exists($username, true)){ return true; - } - else - { - return false; + }else{ + return false; } } diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 9f566a63..972752b3 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -170,8 +170,8 @@ class BlockAPI{ array(CARPET, 8), //Tools - array(RAIL, 0), - array(POWERED_RAIL, 0), + array(RAILS, 0), + array(POWERED_RAILS, 0), array(TORCH, 0), array(BUCKET, 0), array(BUCKET, 8), @@ -194,7 +194,7 @@ class BlockAPI{ array(SPAWN_EGG, MOB_SKELETON), array(SPAWN_EGG, MOB_SPIDER), array(SPAWN_EGG, MOB_PIGMAN), - + //Seeds array(SUGARCANE, 0), array(WHEAT, 0), @@ -322,13 +322,13 @@ class BlockAPI{ } private function cancelAction(Block $block, Player $player, $send = true){ - $player->dataPacket(MC_UPDATE_BLOCK, array( - "x" => $block->x, - "y" => $block->y, - "z" => $block->z, - "block" => $block->getID(), - "meta" => $block->getMetadata() - )); + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $player->dataPacket($pk); if($send === true){ $player->sendInventorySlot($player->slot); } @@ -341,11 +341,15 @@ class BlockAPI{ $item = $player->getSlot($player->slot); if($this->server->api->dhandle("player.block.touch", array("type" => "break", "player" => $player, "target" => $target, "item" => $item)) === false){ - return $this->cancelAction($target, $player, false); + if($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){ + return $this->cancelAction($target, $player, false); + } } if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - $player->getLag() / 1000) + $target->getBreakTime($item, $player) - 0.2) >= microtime(true)){ - return $this->cancelAction($target, $player, false); + if($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){ + return $this->cancelAction($target, $player, false); + } } $player->lastBreak = microtime(true); @@ -380,12 +384,16 @@ class BlockAPI{ $item = $player->getSlot($player->slot); if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists or not allowed in CREATIVE - $this->cancelAction($target, $player); - return $this->cancelAction($block, $player); + if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ + $this->cancelAction($target, $player); + return $this->cancelAction($block, $player); + } } if($this->server->api->dhandle("player.block.touch", array("type" => "place", "player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false){ - return $this->cancelAction($block, $player); + if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ + return $this->cancelAction($block, $player); + } } $this->blockUpdate($target, BLOCK_UPDATE_TOUCH); @@ -396,7 +404,9 @@ class BlockAPI{ } if(($player->gamemode & 0x02) === 0x02){ //Adventure mode!! - return $this->cancelAction($block, $player, false); + if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ + return $this->cancelAction($block, $player, false); + } } if($block->y > 127 or $block->y < 0){ @@ -454,363 +464,6 @@ class BlockAPI{ return false; } - /* - - public function flowLavaOn($source, $face){ - $down = 0; - if($face === BlockFace::BOTTOM){ - $level = 0; - $down = 1; - }else{ - $level = ($source[1] & 0x07) + 2; - if($level > 0x07){ - return false; - } - } - $spread = $this->server->api->level->getBlockFace($source, $face); - if(($source[0] === 10 or $source[0] === 11) and $spread[0] === 10){ - if($level < ($spread[1] & 0x07)){ - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $spread[2][0], - "y" => $spread[2][1], - "z" => $spread[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], $spread[0], $level | $down, false); - return true; - } - }elseif($spread[0] === 9 or $spread[0] === 8){ - if($source[0] === 11){ - $this->server->api->level->setBlock($source[2][0], $source[2][1], $source[2][2], 49, 0); - }elseif($face === 0){ - $this->server->api->level->setBlock($source[2][0], $source[2][1], $source[2][2], 1, 0); - }else{ - $this->server->api->level->setBlock($source[2][0], $source[2][1], $source[2][2], 4, 0); - } - return true; - }elseif(isset(Material::$flowable[$spread[0]])){ - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $spread[2][0], - "y" => $spread[2][1], - "z" => $spread[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 10, $level | $down, false); - return true; - }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); - return true; - } - return false; - } - - public function flowWaterOn($source, $face, &$spread = null){ - $down = 0; - if($face === BlockFace::BOTTOM){ - $level = 0; - $down = 1; - }else{ - $level = ($source[1] & 0x07) + 1; - if($level > 0x07){ - return false; - } - } - $spread = $this->server->api->level->getBlockFace($source, $face); - if(($source[0] === 8 or $source[0] === 9) and $spread[0] === 8){ - if($level < ($spread[1] & 0x07)){ - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $spread[2][0], - "y" => $spread[2][1], - "z" => $spread[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], $spread[0], $level | $down, false); - return true; - } - }elseif($spread[0] === 11){ - $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 49, 0, true); - return true; - }elseif($spread[0] === 10){ - if($face === 0 or ($spread[1] & 0x08) === 0){ - $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 4, 0, true); - return true; - } - }elseif(isset(Material::$flowable[$spread[0]])){ - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $spread[2][0], - "y" => $spread[2][1], - "z" => $spread[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->api->level->setBlock($spread[2][0], $spread[2][1], $spread[2][2], 8, $level | $down, false); - return true; - }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); - return true; - } - return false; - } - - public function updateBlock($x, $y, $z, $type = BLOCK_UPDATE_NORMAL){ - $block = $this->server->api->level->getBlock($x, $y, $z); - $changed = false; - - switch($block[0]){ - case 8: - case 9: - $faces = array(); - if(!$this->flowWaterOn($block, 0, $floor) or $block[0] === 9){ - $this->flowWaterOn($block, 2, $faces[0]); - $this->flowWaterOn($block, 3, $faces[1]); - $this->flowWaterOn($block, 4, $faces[2]); - $this->flowWaterOn($block, 5, $faces[3]); - } - if($block[0] === 8){ - //Source creation - if(!isset(Material::$flowable[$floor[0]])){ - $sources = 0; - foreach($faces as $i => $b){ - if($b[0] === 9){ - ++$sources; - } - } - if($sources >= 2){ - $this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 9, 0, false); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - break; - } - } - - $drained = true; - $level = $block[1] & 0x07; - $up = $this->server->api->level->getBlockFace($block, BlockFace::UP); - if($up[0] === 8 or $up[0] === 9){ - $drained = false; - }else{ - $b = $this->server->api->level->getBlockFace($block, BlockFace::NORTH); - if($b[0] === 9 or ($b[0] === 8 and ($b[1] & 0x08) === 0 and ($b[1] & 0x07) < $level)){ - $drained = false; - }else{ - $b = $this->server->api->level->getBlockFace($block, BlockFace::SOUTH); - if($b[0] === 9 or ($b[0] === 8 and ($b[1] & 0x08) === 0 and ($b[1] & 0x07) < $level)){ - $drained = false; - }else{ - $b = $this->server->api->level->getBlockFace($block, BlockFace::EAST); - if($b[0] === 9 or ($b[0] === 8 and ($b[1] & 0x08) === 0 and ($b[1] & 0x07) < $level)){ - $drained = false; - }else{ - $b = $this->server->api->level->getBlockFace($block, BlockFace::WEST); - if($b[0] === 9 or ($b[0] === 8 and ($b[1] & 0x08) === 0 and ($b[1] & 0x07) < $level)){ - $drained = false; - } - } - } - } - } - if($drained === true){ - ++$level; - if($level > 0x07){ - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0] + 1, - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0] - 1, - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2] + 1, - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2] - 1, - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1] - 1, - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false); - }else{ - $block[1] = ($block[1] & 0x08) | $level; - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0] + 1, - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0] - 1, - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2] + 1, - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2] - 1, - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1] - 1, - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(10, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], $block[0], $block[1], false); - } - } - } - break; - case 10: - case 11: - if(!$this->flowLavaOn($block, 0) or $block[0] === 11){ - $this->flowLavaOn($block, 2); - $this->flowLavaOn($block, 3); - $this->flowLavaOn($block, 4); - $this->flowLavaOn($block, 5); - } - if($block[0] === 10){ - $drained = true; - $level = $block[1] & 0x07; - $up = $this->server->api->level->getBlockFace($block, BlockFace::UP); - if($up[0] === 10 or $up[0] === 11){ - $drained = false; - }else{ - $b = $this->server->api->level->getBlockFace($block, BlockFace::NORTH); - if($b[0] === 11 or ($b[0] === 10 and ($b[1] & 0x08) === 0 and ($b[1] & 0x07) < $level)){ - $drained = false; - }else{ - $b = $this->server->api->level->getBlockFace($block, BlockFace::SOUTH); - if($b[0] === 11 or ($b[0] === 10 and ($b[1] & 0x08) === 0 and ($b[1] & 0x07) < $level)){ - $drained = false; - }else{ - $b = $this->server->api->level->getBlockFace($block, BlockFace::EAST); - if($b[0] === 11 or ($b[0] === 10 and ($b[1] & 0x08) === 0 and ($b[1] & 0x07) < $level)){ - $drained = false; - }else{ - $b = $this->server->api->level->getBlockFace($block, BlockFace::WEST); - if($b[0] === 11 or ($b[0] === 10 and ($b[1] & 0x08) === 0 and ($b[1] & 0x07) < $level)){ - $drained = false; - } - } - } - } - } - if($drained === true){ - ++$level; - if($level > 0x07){ - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0] + 1, - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0] - 1, - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2] + 1, - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2] - 1, - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1] - 1, - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], 0, 0, false); - }else{ - $block[1] = ($block[1] & 0x08) | $level; - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0] + 1, - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0] - 1, - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2] + 1, - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2] - 1, - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1] - 1, - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->schedule(20, array($this, "blockScheduler"), array( - "x" => $block[2][0], - "y" => $block[2][1], - "z" => $block[2][2], - "type" => BLOCK_UPDATE_NORMAL, - )); - $this->server->api->level->setBlock($block[2][0], $block[2][1], $block[2][2], $block[0], $block[1], false); - } - } - } - - break; - } - if($type === BLOCK_TYPE_SCHEDULED){ - $type = BLOCK_UPDATE_WEAK; - } - if($changed === true){ - $this->updateBlocksAround($x, $y, $z, $type); - } - }*/ - public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){ if($delay !== false){ $this->scheduleBlockUpdate($pos->getSide(0), $delay, $type); diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index c7b6786d..0ac1583e 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -47,6 +47,9 @@ class ConsoleAPI{ if(!defined("NO_THREADS")){ $this->loop->stop(); $this->loop->notify(); + //@fclose($this->loop->fp); + usleep(50000); + $this->loop->kill(); //$this->loop->join(); } } @@ -204,22 +207,16 @@ class ConsoleAPI{ break; case "a": case "all": - if($issuer instanceof Player) - { - if($this->server->api->ban->isOp($issuer->username)) - { + if($issuer instanceof Player){ + if($this->server->api->ban->isOp($issuer->username)){ $output = ""; foreach($this->server->api->player->getAll() as $p){ $output .= $this->run($cmd . " ". substr_replace($params, $p->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias); } - } - else - { + }else{ $issuer->sendChat("You don't have permissions to use this command.\n"); } - } - else - { + }else{ $output = ""; foreach($this->server->api->player->getAll() as $p){ $output .= $this->run($cmd . " ". substr_replace($params, $p->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias); @@ -294,7 +291,7 @@ class ConsoleLoop extends Thread{ public $stop; public $base; public $ev; - public $fp; + public $fp; public function __construct(){ $this->line = false; $this->stop = false; @@ -319,7 +316,7 @@ class ConsoleLoop extends Thread{ public function run(){ if(!extension_loaded("readline")){ - $this->fp = fopen( "php://stdin", "r" ); + $this->fp = fopen("php://stdin", "r"); } while($this->stop === false){ @@ -328,7 +325,7 @@ class ConsoleLoop extends Thread{ $this->line = false; } - if(!$this->haveReadline){ + if(!extension_loaded("readline")){ @fclose($fp); } exit(0); diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 31ca6b75..9023000d 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -142,7 +142,6 @@ class EntityAPI{ //"speedZ" => mt_rand(-3, 3) / 8, "item" => $item, ); - if($this->server->api->handle("item.drop", $data) !== false){ for($count = $item->count; $count > 0; ){ $item->count = min($item->getMaxStackSize(), $count); @@ -170,18 +169,18 @@ class EntityAPI{ $entity->closed = true; $this->server->query("DELETE FROM entities WHERE EID = ".$eid.";"); if($entity->class === ENTITY_PLAYER){ - $this->server->api->player->broadcastPacket($this->server->api->player->getAll(), MC_REMOVE_PLAYER, array( - "clientID" => 0, - "eid" => $entity->eid, - )); + $pk = new RemovePlayerPacket; + $pk->eid = $entity->eid; + $pk->clientID = 0; + $this->server->api->player->broadcastPacket($this->server->api->player->getAll(), $pk); }else{ - $this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), MC_REMOVE_ENTITY, array( - "eid" => $entity->eid, - )); + $pk = new RemoveEntityPacket; + $pk->eid = $entity->eid; + $this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), $pk); } $this->server->api->dhandle("entity.remove", $entity); $entity = null; unset($entity); } } -} \ No newline at end of file +} diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 7b05c640..722d6ddd 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -241,8 +241,7 @@ class LevelAPI{ } } - public function getAll() - { + public function getAll(){ return $this->levels; } diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 214ae475..2a3a2bb1 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -32,7 +32,7 @@ class PlayerAPI{ $this->server->api->console->register("kill", "", array($this, "commandHandler")); $this->server->api->console->register("gamemode", " [player]", array($this, "commandHandler")); $this->server->api->console->register("tp", "[target player] OR /tp [target player] ", array($this, "commandHandler")); - $this->server->api->console->register("setspawn", "[player] [x] [y] [z]", array($this, "commandHandler")); + $this->server->api->console->register("spawnpoint", "[player] [x] [y] [z]", array($this, "commandHandler")); $this->server->api->console->register("spawn", "", array($this, "commandHandler")); $this->server->api->console->register("ping", "", array($this, "commandHandler")); $this->server->api->console->alias("lag", "ping"); @@ -118,7 +118,7 @@ class PlayerAPI{ public function commandHandler($cmd, $params, $issuer, $alias){ $output = ""; switch($cmd){ - case "setspawn": + case "spawnpoint": if(!($issuer instanceof Player)){ $output .= "Please run this command in-game.\n"; break; @@ -324,7 +324,7 @@ class PlayerAPI{ } } } - + if($multiple === false){ if(count($players) > 0){ return array_shift($players); @@ -353,11 +353,9 @@ class PlayerAPI{ return $this->server->clients; } - public function broadcastPacket(array $players, $id, $data = array()){ - $data = new CustomPacketHandler($id, "", $data, true); - $packet = array("raw" => chr($id).$data->raw); + public function broadcastPacket(array $players, RakNetDataPacket $packet){ foreach($players as $p){ - $p->dataPacket(false, $packet); + $p->dataPacket(clone $packet); } } @@ -404,14 +402,14 @@ class PlayerAPI{ if($p !== $player and ($p->entity instanceof Entity)){ $p->entity->spawn($player); if($p->level !== $player->level){ - $player->dataPacket(MC_MOVE_ENTITY_POSROT, array( - "eid" => $p->entity->eid, - "x" => -256, - "y" => 128, - "z" => -256, - "yaw" => 0, - "pitch" => 0, - )); + $pk = new MoveEntityPacket_PosRot; + $pk->eid = $p->entity->eid; + $pk->x = -256; + $pk->y = 128; + $pk->z = -256; + $pk->yaw = 0; + $pk->pitch = 0; + $player->dataPacket($pk); } } } @@ -422,14 +420,14 @@ class PlayerAPI{ if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){ $player->entity->spawn($p); if($p->level !== $player->level){ - $p->dataPacket(MC_MOVE_ENTITY_POSROT, array( - "eid" => $player->entity->eid, - "x" => -256, - "y" => 128, - "z" => -256, - "yaw" => 0, - "pitch" => 0, - )); + $pk = new MoveEntityPacket_PosRot; + $pk->eid = $player->entity->eid; + $pk->x = -256; + $pk->y = 128; + $pk->z = -256; + $pk->yaw = 0; + $pk->pitch = 0; + $p->dataPacket($pk); } } } @@ -471,7 +469,7 @@ class PlayerAPI{ "z" => $this->server->spawn->z, ), "inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, array(AIR, 0, 0)), - "hotbar" => array(0, -1, -1, -1, -1, -1, -1, -1, -1), + "hotbar" => array(0, -1, -1, -1, -1, -1, -1, -1, -1), "armor" => array_fill(0, 4, array(AIR, 0)), "gamemode" => $this->server->gamemode, "health" => 20, @@ -499,4 +497,4 @@ class PlayerAPI{ $this->server->handle("player.offline.save", $data); $data->save(); } -} \ No newline at end of file +} diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 4b9fe73c..64c068ff 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -55,6 +55,13 @@ class PluginAPI extends stdClass{ return $output; } + public function __destruct(){ + foreach($this->plugins as $p){ + $p[0]->__destruct(); + } + unset($plugins); + } + public function getList(){ $list = array(); foreach($this->plugins as $p){ @@ -206,11 +213,11 @@ class PluginAPI extends stdClass{ } public function readYAML($file){ - return Spyc::YAMLLoad(file_get_contents($file)); + return yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file))); } public function writeYAML($file, $data){ - return file_put_contents($file, Spyc::YAMLDump($data)); + return file_put_contents($file, yaml_emit($data, YAML_UTF8_ENCODING)); } public function init(){ diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 288e1677..473442e2 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -28,7 +28,8 @@ class ServerAPI{ private $apiList = array(); private $asyncCnt = 0; private $rcon; - private $query; + + public $query; //TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs. @@ -97,6 +98,14 @@ class ServerAPI{ @mkdir(DATA_PATH."players/", 0755); @mkdir(DATA_PATH."worlds/", 0755); @mkdir(DATA_PATH."plugins/", 0755); + + //Init all the events + foreach(get_declared_classes() as $class){ + if(is_subclass_of($class, "BaseEvent") and property_exists($class, "handlers") and property_exists($class, "handlerPriority")){ + $class::unregisterAll(); + } + } + $version = new VersionString(); console("[INFO] Starting Minecraft PE server version ".FORMAT_AQUA.CURRENT_MINECRAFT_VERSION); @@ -134,27 +143,25 @@ class ServerAPI{ )); $this->parseProperties(); + + //Load advanced properties define("DEBUG", $this->getProperty("debug", 1)); define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); - if($this->getProperty("port") !== false){ - $this->setProperty("server-port", $this->getProperty("port")); - $this->config->remove("port"); - $this->config->remove("invisible"); + define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s + if(ADVANCED_CACHE == true){ + console("[INFO] Advanced cache enabled"); } + + if($this->getProperty("upnp-forwarding") == true){ + console("[INFO] [UPnP] Trying to port forward..."); + UPnP_PortForward($this->getProperty("server-port")); + } + $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"); $this->server->api = $this; self::$serverRequest = $this->server; console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.")", true, true, 0); console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0); - - if(ADVANCED_CACHE == true){ - console("[INFO] Advanced cache enabled"); - } - - if($this->getProperty("upnp-forwarding") === true){ - console("[INFO] [UPnP] Trying to port forward..."); - UPnP_PortForward($this->getProperty("server-port")); - } if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){ console("[INFO] Checking for new server version"); @@ -257,7 +264,7 @@ class ServerAPI{ "php_version" => PHP_VERSION, "version" => MAJOR_VERSION, "mc_version" => CURRENT_MINECRAFT_VERSION, - "protocol" => CURRENT_PROTOCOL, + "protocol" => ProtocolInfo::CURRENT_PROTOCOL, "online" => count($this->server->clients), "max" => $this->server->maxClients, "plugins" => $plist, @@ -349,7 +356,7 @@ class ServerAPI{ } if($this->getProperty("enable-query") === true){ - $this->query = new Query(); + $this->query = new QueryHandler(); } CraftingRecipes::init(); $this->server->init(); @@ -445,9 +452,11 @@ class ServerAPI{ return ($this->config->exists($name) ? $this->config->get($name):$default); } - public function setProperty($name, $value){ + public function setProperty($name, $value, $save = true){ $this->config->set($name, $value); - $this->writeProperties(); + if($save == true){ + $this->writeProperties(); + } $this->loadProperties(); } diff --git a/src/BaseEvent.php b/src/BaseEvent.php new file mode 100644 index 00000000..38b81c85 --- /dev/null +++ b/src/BaseEvent.php @@ -0,0 +1,135 @@ +eventName !== null ? get_class($this) : $this->eventName; + } + + final public function setPrioritySlot($slot){ + $this->prioritySlot = (int) $slot; + } + + final public function getPrioritySlot(){ + return (int) $this->prioritySlot; + } + + + public function isAllowed(){ + return ($this->status & 0x7FFFFFFF) === BaseEvent::ALLOW; + } + + public function setAllowed($forceAllow = false){ + $this->status = BaseEvent::ALLOW | ($forceAllow === true ? BaseEvent::FORCE : 0); + } + + public function isCancelled(){ + return ($this->status & 0x7FFFFFFF) === BaseEvent::DENY; + } + + public function setCancelled($forceCancel = false){ + if($this instanceof CancellableEvent){ + $this->status = BaseEvent::DENY | ($forceCancel === true ? BaseEvent::FORCE : 0); + } + return false; + } + + public function isNormal(){ + return $this->status === BaseEvent::NORMAL; + } + + public function setNormal(){ + $this->status = BaseEvent::NORMAL; + } + + public function isForced(){ + return ($this->status & BaseEvent::FORCE) > 0; + } + + public static function getHandlerList(){ + return static::$handlers; + } + + public static function getPriorityList(){ + return static::$handlerPriority; + } + + public static function unregisterAll(){ + static::$handlers = array(); + static::$handlerPriority = array(); + } + + public static function register(callable $handler, $priority = EventPriority::NORMAL){ + if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){ + return false; + } + $identifier = Utils::getCallableIdentifier($handler); + if(isset(static::$handlers[$identifier])){ //Already registered + return false; + }else{ + static::$handlers[$identifier] = $handler; + if(!isset(static::$handlerPriority[(int) $priority])){ + static::$handlerPriority[(int) $priority] = array(); + } + static::$handlerPriority[(int) $priority][$identifier] = $handler; + return true; + } + } + + public static function unregister(callable $handler, $priority = EventPriority::NORMAL){ + $identifier = Utils::getCallableIdentifier($handler); + if(isset(static::$handlers[$identifier])){ + if(isset(static::$handlerPriority[(int) $priority][$identifier])){ + unset(static::$handlerPriority[(int) $priority][$identifier]); + }else{ + for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){ + unset(static::$handlerPriority[$priority][$identifier]); + if(count(static::$handlerPriority[$priority]) === 0){ + unset(static::$handlerPriority[$priority]); + } + } + } + unset(static::$handlers[$identifier]); + return true; + }else{ + return false; + } + } + +} \ No newline at end of file diff --git a/src/Player.php b/src/Player.php index 3e354afc..fa5eac0c 100644 --- a/src/Player.php +++ b/src/Player.php @@ -27,7 +27,8 @@ class Player{ private $resendQueue = array(); private $ackQueue = array(); private $receiveCount = -1; - private $buffer = ""; + private $buffer; + private $bufferLen = 0; private $nextBuffer = 0; private $evid = array(); private $lastMovement = 0; @@ -79,7 +80,7 @@ class Player{ public $lastCraft = 0; private $chunkCount = array(); private $received = array(); - public $realmsData = array(); + public $loginData = array(); /** @var \Level */ public $level; @@ -114,9 +115,11 @@ class Player{ $this->slot = 0; $this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1); $this->packetStats = array(0,0); + $this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0); + $this->buffer->data = array(); $this->server->schedule(2, array($this, "handlePacketQueues"), array(), true); $this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true); - $this->evid[] = $this->server->event("server.close", array($this, "close")); + $this->evid[] = $this->server->event("server.close", array($this, "close")); console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2); } @@ -134,11 +137,11 @@ class Player{ $level = $pos->level; } $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level); - $this->dataPacket(MC_SET_SPAWN_POSITION, array( - "x" => (int) $this->spawnPosition->x, - "y" => (int) $this->spawnPosition->y, - "z" => (int) $this->spawnPosition->z, - )); + $pk = new SetSpawnPositionPacket; + $pk->x = (int) $this->spawnPosition->x; + $pk->y = (int) $this->spawnPosition->y; + $pk->z = (int) $this->spawnPosition->z; + $this->dataPacket($pk); } public function orderChunks(){ @@ -214,11 +217,11 @@ class Player{ $Yndex |= 1 << $iY; } } - $cnt = $this->dataPacket(MC_CHUNK_DATA, array( - "x" => $X, - "z" => $Z, - "data" => $this->level->getOrderedChunk($X, $Z, $Yndex), - )); + $pk = new ChunkDataPacket; + $pk->chunkX = $X; + $pk->chunkZ = $Z; + $pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex); + $cnt = $this->dataPacket($pk); if($cnt === false){ return false; } @@ -288,9 +291,10 @@ class Player{ $reason = $reason == "" ? "server stop":$reason; $this->sendChat("You have been kicked. Reason: ".$reason."\n"); $this->sendBuffer(); - $this->directDataPacket(MC_DISCONNECT); + $this->directDataPacket(new DisconnectPacket); $this->connected = false; $this->level->freeAllChunks($this); + $this->spawned = false; $this->loggedIn = false; $this->buffer = null; unset($this->buffer); @@ -298,12 +302,10 @@ class Player{ $this->receiveQueue = array(); $this->resendQueue = array(); $this->ackQueue = array(); - $this->server->interface->stopChunked($this->CID); $this->server->api->player->remove($this->CID); if($msg === true and $this->username != "" and $this->spawned !== false){ $this->server->api->chat->broadcast($this->username." left the game"); } - $this->spawned = false; console("[INFO] ".FORMAT_AQUA.$this->username.FORMAT_RESET."[/".$this->ip.":".$this->port."] logged out due to ".$reason); $this->windows = array(); $this->armor = array(); @@ -492,23 +494,19 @@ class Player{ return; $s = (int) $s; if(!isset($this->inventory[$s])){ - $this->dataPacket(MC_CONTAINER_SET_SLOT, array( - "windowid" => 0, - "slot" => (int) $s, - "block" => AIR, - "stack" => 0, - "meta" => 0, - )); + $pk = new ContainerSetSlotPacket; + $pk->windowid = 0; + $pk->slot = (int) $s; + $pk->item = BlockAPI::getItem(AIR, 0, 0); + $this->dataPacket($pk); } $slot = $this->inventory[$s]; - $this->dataPacket(MC_CONTAINER_SET_SLOT, array( - "windowid" => 0, - "slot" => (int) $s, - "block" => $slot->getID(), - "stack" => $slot->count, - "meta" => $slot->getMetadata(), - )); + $pk = new ContainerSetSlotPacket; + $pk->windowid = 0; + $pk->slot = (int) $s; + $pk->item = $slot; + $this->dataPacket($pk); return true; } @@ -553,16 +551,17 @@ class Player{ if($data->class === TILE_FURNACE){ foreach($this->windows as $id => $w){ if($w === $data){ - $this->dataPacket(MC_CONTAINER_SET_DATA, array( - "windowid" => $id, - "property" => 0, //Smelting - "value" => floor($data->data["CookTime"]), - )); - $this->dataPacket(MC_CONTAINER_SET_DATA, array( - "windowid" => $id, - "property" => 1, //Fire icon - "value" => $data->data["BurnTicks"], - )); + $pk = new ContainerSetDataPacket; + $pk->windowid = $id; + $pk->property = 0; //Smelting + $pk->value = floor($data->data["CookTime"]); + $this->dataPacket($pk); + + $pk = new ContainerSetDataPacket; + $pk->windowid = $id; + $pk->property = 1; //Fire icon + $pk->value = $data->data["BurnTicks"]; + $this->dataPacket($pk); } } } @@ -572,13 +571,11 @@ class Player{ if($data["tile"]->level === $this->level){ foreach($this->windows as $id => $w){ if($w === $data["tile"]){ - $this->dataPacket(MC_CONTAINER_SET_SLOT, array( - "windowid" => $id, - "slot" => $data["slot"] + (isset($data["offset"]) ? $data["offset"]:0), - "block" => $data["slotdata"]->getID(), - "stack" => $data["slotdata"]->count, - "meta" => $data["slotdata"]->getMetadata(), - )); + $pk = new ContainerSetSlotPacket; + $pk->windowid = $id; + $pk->slot = $data["slot"] + (isset($data["offset"]) ? $data["offset"]:0); + $pk->item = $data["slotdata"]; + $this->dataPacket($pk); } } } @@ -589,13 +586,19 @@ class Player{ $this->sendArmor($this); break; } - $this->dataPacket(MC_PLAYER_ARMOR_EQUIPMENT, $data); + $pk = new PlayerArmorEquipmentPacket; + $pk->eid = $data["eid"]; + $pk->slots = $data["slots"]; + $this->dataPacket($pk); } break; case "player.pickup": if($data["eid"] === $this->eid){ $data["eid"] = 0; - $this->dataPacket(MC_TAKE_ITEM_ENTITY, $data); + $pk = new TakeItemEntityPacket; + $pk->eid = 0; + $pk->target = $data["entity"]->eid; + $this->dataPacket($pk); if(($this->gamemode & 0x01) === 0x00){ $this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack, false); } @@ -606,12 +609,12 @@ class Player{ case DIAMOND: AchievementAPI::grantAchievement($this, "diamond"); break; - case LEATHER: - AchievementAPI::grantAchievement($this, "leather"); - break; } }elseif($data["entity"]->level === $this->level){ - $this->dataPacket(MC_TAKE_ITEM_ENTITY, $data); + $pk = new TakeItemEntityPacket; + $pk->eid = $data["eid"]; + $pk->target = $data["entity"]->eid; + $this->dataPacket($pk); } break; case "player.equipment.change": @@ -619,28 +622,34 @@ class Player{ break; } $data["slot"] = 0; - $this->dataPacket(MC_PLAYER_EQUIPMENT, $data); + + $pk = new PlayerEquipmentPacket; + $pk->eid = $data["eid"]; + $pk->item = $data["item"]->getID(); + $pk->meta = $data["item"]->getMetadata(); + $pk->slot = $data["slot"]; + $this->dataPacket($pk); break; case "entity.motion": if($data->eid === $this->eid or $data->level !== $this->level){ break; } - $this->dataPacket(MC_SET_ENTITY_MOTION, array( - "eid" => $data->eid, - "speedX" => (int) ($data->speedX * 400), - "speedY" => (int) ($data->speedY * 400), - "speedZ" => (int) ($data->speedZ * 400), - )); + $pk = new SetEntityMotionPacket; + $pk->eid = $data->eid; + $pk->speedX = $data->speedX; + $pk->speedY = $data->speedY; + $pk->speedZ = $data->speedZ; + $this->dataPacket($pk); break; case "entity.animate": if($data["eid"] === $this->eid or $data["entity"]->level !== $this->level){ break; } - $this->dataPacket(MC_ANIMATE, array( - "eid" => $data["eid"], - "action" => $data["action"], //1 swing arm, - )); + $pk = new AnimatePacket; + $pk->eid = $data["eid"]; + $pk->action = $data["action"]; //1 swing arm, + $this->dataPacket($pk); break; case "entity.metadata": if($data->eid === $this->eid){ @@ -649,10 +658,10 @@ class Player{ $eid = $data->eid; } if($data->level === $this->level){ - $this->dataPacket(MC_SET_ENTITY_DATA, array( - "eid" => $eid, - "metadata" => $data->getMetadata(), - )); + $pk = new SetEntityDataPacket; + $pk->eid = $eid; + $pk->metadata = $data->getMetadata(); + $this->dataPacket($pk); } break; case "entity.event": @@ -662,10 +671,10 @@ class Player{ $eid = $data["entity"]->eid; } if($data["entity"]->level === $this->level){ - $this->dataPacket(MC_ENTITY_EVENT, array( - "eid" => $eid, - "event" => $data["event"], - )); + $pk = new EntityEventPacket; + $pk->eid = $eid; + $pk->event = $data["event"]; + $this->dataPacket($pk); } break; case "server.chat": @@ -709,11 +718,11 @@ class Player{ } } - if($m !== ""){ - $this->dataPacket(MC_CHAT, array( - "player" => ($author instanceof Player) ? $author->username:$author, - "message" => TextFormat::clean($m), //Colors not implemented :( - )); + if($m !== ""){ + $pk = new MessagePacket; + $pk->source = ($author instanceof Player) ? $author->username:$author; + $pk->message = TextFormat::clean($m); //Colors not implemented :( + $this->dataPacket($pk); } } } @@ -756,16 +765,16 @@ class Player{ */ $flags = 0; if(($this->gamemode & 0x02) === 0x02){ - $flags |= 0x01; //Not allow placing/breaking blocks, adventure mode + $flags |= 0x01; //Do not allow placing/breaking blocks, adventure mode } if($nametags !== false){ $flags |= 0x20; //Show Nametags } - - $this->dataPacket(MC_ADVENTURE_SETTINGS, array( - "flags" => $flags, - )); + + $pk = new AdventureSettingsPacket; + $pk->flags = $flags; + $this->dataPacket($pk); } /** @@ -905,26 +914,27 @@ class Player{ foreach($this->server->api->entity->getAll($this->level) as $e){ if($e !== $this->entity){ if($e->player instanceof Player){ - $e->player->dataPacket(MC_MOVE_ENTITY_POSROT, array( - "eid" => $this->entity->eid, - "x" => -256, - "y" => 128, - "z" => -256, - "yaw" => 0, - "pitch" => 0, - )); - $this->dataPacket(MC_MOVE_ENTITY_POSROT, array( - "eid" => $e->eid, - "x" => -256, - "y" => 128, - "z" => -256, - "yaw" => 0, - "pitch" => 0, - )); + $pk = new MoveEntityPacket_PosRot; + $pk->eid = $this->entity->eid; + $pk->x = -256; + $pk->y = 128; + $pk->z = -256; + $pk->yaw = 0; + $pk->pitch = 0; + $e->player->dataPacket($pk); + + $pk = new MoveEntityPacket_PosRot; + $pk->eid = $e->eid; + $pk->x = -256; + $pk->y = 128; + $pk->z = -256; + $pk->yaw = 0; + $pk->pitch = 0; + $this->dataPacket($pk); }else{ - $this->dataPacket(MC_REMOVE_ENTITY, array( - "eid" => $e->eid, - )); + $pk = new RemoveEntityPacket; + $pk->eid = $e->eid; + $this->dataPacket($pk); } } } @@ -935,34 +945,37 @@ class Player{ $this->chunksLoaded = array(); $this->server->api->entity->spawnToAll($this->entity); $this->server->api->entity->spawnAll($this); - $this->dataPacket(MC_SET_TIME, array( - "time" => $this->level->getTime(), - )); + + $pk = new SetTimePacket; + $pk->time = $this->level->getTime(); + $this->dataPacket($pk); $terrain = true; foreach($this->server->api->player->getAll($this->level) as $player){ if($player !== $this and $player->entity instanceof Entity){ - $this->dataPacket(MC_MOVE_ENTITY_POSROT, array( - "eid" => $player->entity->eid, - "x" => $player->entity->x, - "y" => $player->entity->y, - "z" => $player->entity->z, - "yaw" => $player->entity->yaw, - "pitch" => $player->entity->pitch, - )); - $player->dataPacket(MC_PLAYER_EQUIPMENT, array( - "eid" => $this->eid, - "block" => $this->getSlot($this->slot)->getID(), - "meta" => $this->getSlot($this->slot)->getMetadata(), - "slot" => 0, - )); + $pk = new MoveEntityPacket_PosRot; + $pk->eid = $player->entity->eid; + $pk->x = $player->entity->x; + $pk->y = $player->entity->y; + $pk->z = $player->entity->z; + $pk->yaw = $player->entity->yaw; + $pk->pitch = $player->entity->pitch; + $this->dataPacket($pk); + + $pk = new PlayerEquipmentPacket; + $pk->eid = $this->eid; + $pk->item = $this->getSlot($this->slot)->getID(); + $pk->meta = $this->getSlot($this->slot)->getMetadata(); + $pk->slot = 0; + $player->dataPacket($pk); $this->sendArmor($player); - $this->dataPacket(MC_PLAYER_EQUIPMENT, array( - "eid" => $player->eid, - "block" => $player->getSlot($player->slot)->getID(), - "meta" => $player->getSlot($player->slot)->getMetadata(), - "slot" => 0, - )); + + $pk = new PlayerEquipmentPacket; + $pk->eid = $player->eid; + $pk->item = $player->getSlot($player->slot)->getID(); + $pk->meta = $player->getSlot($player->slot)->getMetadata(); + $pk->slot = 0; + $this->dataPacket($pk); $player->sendArmor($this); } } @@ -984,15 +997,16 @@ class Player{ $this->forceMovement = $pos; } } - $this->dataPacket(MC_MOVE_PLAYER, array( - "eid" => 0, - "x" => $pos->x, - "y" => $pos->y, - "z" => $pos->z, - "bodyYaw" => $yaw, - "pitch" => $pitch, - "yaw" => $yaw, - )); + + $pk = new MovePlayerPacket; + $pk->eid = 0; + $pk->x = $pos->x; + $pk->y = $pos->y; + $pk->z = $pos->z; + $pk->bodyYaw = $yaw; + $pk->pitch = $pitch; + $pk->yaw = $yaw; + $this->dataPacket($pk); } public function getGamemode(){ @@ -1109,14 +1123,15 @@ class Player{ $safeCount = (int) (($this->MTU - 1) / 4); $packetCnt = (int) ($ackCnt / $safeCount + 1); for($p = 0; $p < $packetCnt; ++$p){ - $acks = array(); + $pk = new RakNetPacket(RakNetInfo::ACK); + $pk->packets = array(); for($c = 0; $c < $safeCount; ++$c){ if(($k = array_pop($this->ackQueue)) === null){ break; } - $acks[] = $k; + $pk->packets[] = $k; } - $this->send(0xc0, array($acks)); + $this->send($pk); } $this->ackQueue = array(); } @@ -1126,38 +1141,41 @@ class Player{ foreach($this->receiveQueue as $count => $packets){ unset($this->receiveQueue[$count]); foreach($packets as $p){ - if(isset($p["counter"])){ - if($p["counter"] > $this->receiveCount){ - $this->receiveCount = $p["counter"]; - }elseif($p["counter"] !== 0){ - if(isset($this->received[$p["counter"]])){ - continue; - } - switch($p["id"]){ - case 0x01: - case MC_PONG: - case MC_PING: - case MC_MOVE_PLAYER: - case MC_REQUEST_CHUNK: - case MC_ANIMATE: - case MC_SET_HEALTH: + if($p instanceof RakNetDataPacket and $p->hasSplit === false){ + if(isset($p->messageIndex) and $p->messageIndex !== false){ + if($p->messageIndex > $this->receiveCount){ + $this->receiveCount = $p->messageIndex; + }elseif($p->messageIndex !== 0){ + if(isset($this->received[$p->messageIndex])){ continue; + } + switch($p->pid()){ + case 0x01: + case ProtocolInfo::PING_PACKET: + case ProtocolInfo::PONG_PACKET: + case ProtocolInfo::MOVE_PLAYER_PACKET: + case ProtocolInfo::REQUEST_CHUNK_PACKET: + case ProtocolInfo::ANIMATE_PACKET: + case ProtocolInfo::SET_HEALTH_PACKET: + continue; + } } + $this->received[$p->messageIndex] = true; } - $this->received[$p["counter"]] = true; + $p->decode(); + $this->handleDataPacket($p); } - $this->handleDataPacket($p["id"], $p); } } } - if($this->nextBuffer <= $time and strlen($this->buffer) > 0){ + if($this->nextBuffer <= $time and $this->bufferLen > 0){ $this->sendBuffer(); } $limit = $time - 5; //max lag foreach($this->recoveryQueue as $count => $data){ - if($data["sendtime"] > $limit){ + if($data->sendtime > $limit){ break; } unset($this->recoveryQueue[$count]); @@ -1168,8 +1186,9 @@ class Player{ foreach($this->resendQueue as $count => $data){ unset($this->resendQueue[$count]); $this->packetStats[1]++; - $this->lag[] = microtime(true) - $data["sendtime"]; - $cnt = $this->directDataPacket($data["id"], $data, $data["pid"]); + $this->lag[] = microtime(true) - $data->sendtime; + $data->sendtime = microtime(true); + $cnt = $this->send($data); if(isset($this->chunkCount[$count])){ unset($this->chunkCount[$count]); $this->chunkCount[$cnt[0]] = true; @@ -1178,25 +1197,25 @@ class Player{ } } - public function handlePacket($pid, $data){ + public function handlePacket(RakNetPacket $packet){ if($this->connected === true){ $this->timeout = microtime(true) + 20; - switch($pid){ - case 0xa0: //NACK - foreach($data[0] as $count){ + switch($packet->pid()){ + case RakNetInfo::NACK: + foreach($packet->packets as $count){ if(isset($this->recoveryQueue[$count])){ $this->resendQueue[$count] =& $this->recoveryQueue[$count]; - $this->lag[] = microtime(true) - $this->recoveryQueue[$count]["sendtime"]; + $this->lag[] = microtime(true) - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); } ++$this->packetStats[1]; } break; - case 0xc0: //ACK - foreach($data[0] as $count){ + case RakNetInfo::ACK: + foreach($packet->packets as $count){ if(isset($this->recoveryQueue[$count])){ - $this->lag[] = microtime(true) - $this->recoveryQueue[$count]["sendtime"]; + $this->lag[] = microtime(true) - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); unset($this->resendQueue[$count]); } @@ -1204,91 +1223,97 @@ class Player{ } break; - case 0x80: //Data Packet - case 0x81: - case 0x82: - case 0x83: - case 0x84: - case 0x85: - case 0x86: - case 0x87: - case 0x88: - case 0x89: - case 0x8a: - case 0x8b: - case 0x8c: - case 0x8d: - case 0x8e: - case 0x8f: - $this->ackQueue[] = $data[0]; - $this->receiveQueue[$data[0]] = array(); - foreach($data["packets"] as $packet){ - $this->receiveQueue[$data[0]][] = $packet[1]; + case RakNetInfo::DATA_PACKET_0: + case RakNetInfo::DATA_PACKET_1: + case RakNetInfo::DATA_PACKET_2: + case RakNetInfo::DATA_PACKET_3: + case RakNetInfo::DATA_PACKET_4: + case RakNetInfo::DATA_PACKET_5: + case RakNetInfo::DATA_PACKET_6: + case RakNetInfo::DATA_PACKET_7: + case RakNetInfo::DATA_PACKET_8: + case RakNetInfo::DATA_PACKET_9: + case RakNetInfo::DATA_PACKET_A: + case RakNetInfo::DATA_PACKET_B: + case RakNetInfo::DATA_PACKET_C: + case RakNetInfo::DATA_PACKET_D: + case RakNetInfo::DATA_PACKET_E: + case RakNetInfo::DATA_PACKET_F: + $this->ackQueue[] = $packet->seqNumber; + $this->receiveQueue[$packet->seqNumber] = array(); + foreach($packet->data as $pk){ + $this->receiveQueue[$packet->seqNumber][] = $pk; } break; } } } - public function handleDataPacket($pid, $data){ - switch($pid){ + public function handleDataPacket(RakNetDataPacket $packet){ + if($this->connected === false){ + return; + } + + if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){ + return; + } + + switch($packet->pid()){ case 0x01: break; - case MC_PONG: + case ProtocolInfo::PONG_PACKET: break; - case MC_PING: - $t = abs(microtime(true) * 1000); - $this->dataPacket(MC_PONG, array( - "ptime" => $data["time"], - "time" => $t, - )); - $this->sendBuffer(); + case ProtocolInfo::PING_PACKET: + $pk = new PongPacket; + $pk->ptime = $packet->time; + $pk->time = abs(microtime(true) * 1000); + $this->directDataPacket($pk); break; - case MC_DISCONNECT: + case ProtocolInfo::DISCONNECT_PACKET: $this->close("client disconnect"); break; - case MC_CLIENT_CONNECT: + case ProtocolInfo::CLIENT_CONNECT_PACKET: if($this->loggedIn === true){ break; } - $this->dataPacket(MC_SERVER_HANDSHAKE, array( - "port" => $this->port, - "session" => $data["session"], - "session2" => Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9"), - )); + $pk = new ServerHandshakePacket; + $pk->port = $this->port; + $pk->session = $packet->session; + $pk->session2 = Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9"); + $this->dataPacket($pk); break; - case MC_CLIENT_HANDSHAKE: + case ProtocolInfo::CLIENT_HANDSHAKE_PACKET: if($this->loggedIn === true){ break; } break; - case MC_LOGIN: + case ProtocolInfo::LOGIN_PACKET: if($this->loggedIn === true){ break; } - $this->username = TextFormat::clean($data["username"]); + $this->username = $packet->username; $this->iusername = strtolower($this->username); - $this->realmsData = array("clientId" => $data["clientId"], "realms_data" => $data["realms_data"]); + $this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData); if(count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){ $this->close("server is full!", false); return; } - if($data["protocol1"] !== CURRENT_PROTOCOL){ - if($data["protocol1"] < CURRENT_PROTOCOL){ - $this->directDataPacket(MC_LOGIN_STATUS, array( - "status" => 1, - )); + if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ + if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ + $pk = new LoginStatusPacket; + $pk->status = 1; + $this->directDataPacket($pk); }else{ - $this->directDataPacket(MC_LOGIN_STATUS, array( - "status" => 2, - )); + $pk = new LoginStatusPacket; + $pk->status = 2; + $this->directDataPacket($pk); } - $this->close("Incorrect protocol #".$data["protocol1"], false); - break; + $this->close("Incorrect protocol #".$packet->protocol1, false); + return; } - if(preg_match('#[^a-zA-Z0-9_]#', $data["username"]) > 0 or $data["username"] === "" or strtolower($data["username"]) === "rcon" or strtolower($data["username"]) === "console" or strtolower($data["username"]) === "server"){ + if(preg_match('#[^a-zA-Z0-9_]#', $packet->username) > 0 or $packet->username === ""){ $this->close("Bad username", false); - break; + return; } if($this->server->api->handle("player.connect", $this) === false){ $this->close("Unknown reason", false); @@ -1308,12 +1333,11 @@ class Player{ if($u !== false){ $u->close("logged in from another location"); } - if(!isset($this->CID) or $this->CID == null){ console("[DEBUG] Player ".$this->username." does not have a CID", true, true, 2); $this->CID = Utils::readLong(Utils::getRandomBytes(8, false)); } - + $this->server->api->player->add($this->CID); if($this->server->api->handle("player.join", $this) === false){ $this->close("join cancelled", false); @@ -1361,21 +1385,24 @@ class Player{ $this->server->api->player->saveOffline($this->data); - $this->dataPacket(MC_LOGIN_STATUS, array( - "status" => 0, - )); - $this->dataPacket(MC_START_GAME, array( - "seed" => $this->level->getSeed(), - "x" => round($this->data->get("position")["x"], 4), - "y" => $this->data->get("position")["y"] + 1, - "z" => round($this->data->get("position")["z"], 4), - "generator" => 0, - "gamemode" => ($this->gamemode & 0x01), - "eid" => 0, - )); + + $pk = new LoginStatusPacket; + $pk->status = 0; + $this->dataPacket($pk); + + $pk = new StartGamePacket; + $pk->seed = $this->level->getSeed(); + $pk->x = $this->data->get("position")["x"]; + $pk->y = $this->data->get("position")["y"]; + $pk->z = $this->data->get("position")["z"]; + $pk->generator = 0; + $pk->gamemode = $this->gamemode & 0x01; + $pk->eid = 0; + $this->dataPacket($pk); + if(($this->gamemode & 0x01) === 0x01){ $this->slot = 0; - $this->hotbar = array(); + $this->hotbar = array(); }elseif($this->data->exists("hotbar")){ $this->hotbar = $this->data->get("hotbar"); $this->slot = $this->hotbar[0]; @@ -1391,11 +1418,12 @@ class Player{ $this->entity->z = $this->data->get("position")["z"]; if(($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false){ $this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level); - $this->dataPacket(MC_SET_SPAWN_POSITION, array( - "x" => (int) $this->spawnPosition->x, - "y" => (int) $this->spawnPosition->y, - "z" => (int) $this->spawnPosition->z, - )); + + $pk = new SetSpawnPositionPacket; + $pk->x = (int) $this->spawnPosition->x; + $pk->y = (int) $this->spawnPosition->y; + $pk->z = (int) $this->spawnPosition->z; + $this->dataPacket($pk); } $this->entity->check = false; $this->entity->setName($this->username); @@ -1412,13 +1440,13 @@ class Player{ $this->evid[] = $this->server->event("tile.update", array($this, "eventHandler")); $this->lastMeasure = microtime(true); $this->server->schedule(50, array($this, "measureLag"), array(), true); - console("[INFO] ".FORMAT_AQUA.$this->username.FORMAT_RESET."[/".$this->ip.":".$this->port."] logged in with entity id ".$this->eid." at (".$this->entity->level->getName().", ".round($this->entity->x, 4).", ".round($this->entity->y, 4).", ".round($this->entity->z, 4).")"); + console("[INFO] ".FORMAT_AQUA.$this->username.FORMAT_RESET."[/".$this->ip.":".$this->port."] logged in with entity id ".$this->eid." at (".$this->entity->level->getName().", ".round($this->entity->x, 2).", ".round($this->entity->y, 2).", ".round($this->entity->z, 2).")"); break; - case MC_READY: + case ProtocolInfo::READY_PACKET: if($this->loggedIn === false){ break; } - switch($data["status"]){ + switch($packet->status){ case 1: //Spawn!! if($this->spawned !== false){ break; @@ -1439,9 +1467,11 @@ class Player{ $this->sendSettings(); $this->server->schedule(50, array($this, "orderChunks"), array(), true); $this->blocked = false; - $this->dataPacket(MC_SET_TIME, array( - "time" => $this->level->getTime(), - )); + + $pk = new SetTimePacket; + $pk->time = $this->level->getTime(); + $this->dataPacket($pk); + $pos = new Position($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"], $this->level); $pos = $this->level->getSafeSpawn($pos); $this->teleport($pos); @@ -1454,7 +1484,7 @@ class Player{ break; } break; - case MC_ROTATE_HEAD: + case ProtocolInfo::ROTATE_HEAD_PACKET: if($this->spawned === false){ break; } @@ -1464,17 +1494,17 @@ class Player{ $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); } }else{ - $this->entity->setPosition($this->entity, $data["yaw"], $data["pitch"]); + $this->entity->setPosition($this->entity, $packet->yaw, $this->entity->pitch); } } break; - case MC_MOVE_PLAYER: + case ProtocolInfo::MOVE_PLAYER_PACKET: if($this->spawned === false){ break; } - if(($this->entity instanceof Entity) and $data["counter"] > $this->lastMovement){ - $this->lastMovement = $data["counter"]; - $newPos = new Vector3($data["x"], $data["y"], $data["z"]); + if(($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement){ + $this->lastMovement = $packet->messageIndex; + $newPos = new Vector3($packet->x, $packet->y, $packet->z); if($this->forceMovement instanceof Vector3){ if($this->forceMovement->distance($newPos) <= 0.7){ $this->forceMovement = false; @@ -1491,19 +1521,21 @@ class Player{ console("[WARNING] ".$this->username." moved too quickly!"); } }else{ - $this->entity->setPosition($newPos, $data["yaw"], $data["pitch"]); + $this->entity->setPosition($newPos, $packet->yaw, $packet->pitch); } } break; - case MC_PLAYER_EQUIPMENT: + case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: if($this->spawned === false){ break; } - - $data["eid"] = $this->eid; + $packet->eid = $this->eid; + + $data = array(); + $data["eid"] = $packet->eid; $data["player"] = $this; - if($data["slot"] === 0x28 or $data["slot"] === 0){ //0 for 0.8.0 compatibility + if($packet->slot === 0x28 or $packet->slot === 0){ //0 for 0.8.0 compatibility $data["slot"] = -1; $data["item"] = BlockAPI::getItem(AIR, 0, 0); if($this->server->handle("player.equipment.change", $data) !== false){ @@ -1511,34 +1543,35 @@ class Player{ } break; }else{ - $data["slot"] -= 9; + $packet->slot -= 9; } if(($this->gamemode & 0x01) === SURVIVAL){ - $data["item"] = $this->getSlot($data["slot"]); + $data["item"] = $this->getSlot($packet->slot); if(!($data["item"] instanceof Item)){ break; } }elseif(($this->gamemode & 0x01) === CREATIVE){ - $data["slot"] = false; + $packet->slot = false; foreach(BlockAPI::$creative as $i => $d){ - if($d[0] === $data["block"] and $d[1] === $data["meta"]){ - $data["slot"] = $i; + if($d[0] === $packet->item and $d[1] === $packet->meta){ + $packet->slot = $i; } } - if($data["slot"] !== false){ - $data["item"] = $this->getSlot($data["slot"]); + if($packet->slot !== false){ + $data["item"] = $this->getSlot($packet->slot); }else{ break; } }else{ break;//????? } - $data["block"] = $data["item"]->getID(); - $data["meta"] = $data["item"]->getMetadata(); + + $data["slot"] = $packet->slot; + if($this->server->handle("player.equipment.change", $data) !== false){ - $this->slot = $data["slot"]; + $this->slot = $packet->slot; if(($this->gamemode & 0x01) === SURVIVAL){ if(!in_array($this->slot, $this->hotbar)){ array_pop($this->hotbar); @@ -1546,7 +1579,7 @@ class Player{ } } }else{ - //$this->sendInventorySlot($data["slot"]); + //$this->sendInventorySlot($packet->slot); $this->sendInventory(); } if($this->entity->inAction === true){ @@ -1554,78 +1587,103 @@ class Player{ $this->entity->updateMetadata(); } break; - case MC_REQUEST_CHUNK: + case ProtocolInfo::REQUEST_CHUNK_PACKET: break; - case MC_USE_ITEM: + case ProtocolInfo::USE_ITEM_PACKET: if(!($this->entity instanceof Entity)){ break; } - if(($this->spawned === false or $this->blocked === true) and $data["face"] >= 0 and $data["face"] <= 5){ - $target = $this->level->getBlock(new Vector3($data["x"], $data["y"], $data["z"])); - $block = $target->getSide($data["face"]); - $this->dataPacket(MC_UPDATE_BLOCK, array( - "x" => $target->x, - "y" => $target->y, - "z" => $target->z, - "block" => $target->getID(), - "meta" => $target->getMetadata() - )); - $this->dataPacket(MC_UPDATE_BLOCK, array( - "x" => $block->x, - "y" => $block->y, - "z" => $block->z, - "block" => $block->getID(), - "meta" => $block->getMetadata() - )); + + $blockVector = new Vector3($packet->x, $packet->y, $packet->z); + + if(($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5){ + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->dataPacket($pk); break; } $this->craftingItems = array(); $this->toCraft = array(); - $data["eid"] = $this->eid; + $packet->eid = $this->eid; + $data = array(); + $data["eid"] = $packet->eid; $data["player"] = $this; - if($data["face"] >= 0 and $data["face"] <= 5){ //Use Block, place + $data["face"] = $packet->face; + $data["x"] = $packet->x; + $data["y"] = $packet->y; + $data["z"] = $packet->z; + $data["item"] = $packet->item; + $data["meta"] = $packet->meta; + $data["fx"] = $packet->fx; + $data["fy"] = $packet->fy; + $data["fz"] = $packet->fz; + $data["posX"] = $packet->posX; + $data["posY"] = $packet->posY; + $data["posZ"] = $packet->posZ; + + if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place if($this->entity->inAction === true){ $this->entity->inAction = false; $this->entity->updateMetadata(); } - if($this->blocked === true or Utils::distance($this->entity->position, $data) > 10){ - }elseif($this->getSlot($this->slot)->getID() !== $data["block"] or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $data["meta"])){ + + if($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 10)){ + + }elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){ $this->sendInventorySlot($this->slot); }else{ - $this->server->api->block->playerBlockAction($this, new Vector3($data["x"], $data["y"], $data["z"]), $data["face"], $data["fx"], $data["fy"], $data["fz"]); + $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz); break; } - $target = $this->level->getBlock(new Vector3($data["x"], $data["y"], $data["z"])); - $block = $target->getSide($data["face"]); - $this->dataPacket(MC_UPDATE_BLOCK, array( - "x" => $target->x, - "y" => $target->y, - "z" => $target->z, - "block" => $target->getID(), - "meta" => $target->getMetadata() - )); - $this->dataPacket(MC_UPDATE_BLOCK, array( - "x" => $block->x, - "y" => $block->y, - "z" => $block->z, - "block" => $block->getID(), - "meta" => $block->getMetadata() - )); + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->dataPacket($pk); break; - }elseif($data["face"] === 0xFF and $this->server->handle("player.action", $data) !== false){ + }elseif($packet->face === 0xff and $this->server->handle("player.action", $data) !== false){ $this->entity->inAction = true; $this->startAction = microtime(true); $this->entity->updateMetadata(); } break; - case MC_PLAYER_ACTION: + case ProtocolInfo::PLAYER_ACTION_PACKET: if($this->spawned === false or $this->blocked === true){ break; } + $packet->eid = $this->eid; $this->craftingItems = array(); $this->toCraft = array(); - switch($data["action"]){ + switch($packet->action){ case 5: //Shot arrow if($this->entity->inAction === true){ if($this->getSlot($this->slot)->getID() === BOW){ @@ -1652,18 +1710,15 @@ class Player{ $overturn = false; if(0 <= $rotation and $rotation < 90){ - } - elseif(90 <= $rotation and $rotation < 180){ + }elseif(90 <= $rotation and $rotation < 180){ $rotation -= 90; $X = (-1); $overturn = true; - } - elseif(180 <= $rotation and $rotation < 270){ + }elseif(180 <= $rotation and $rotation < 270){ $rotation -= 180; $X = (-1); $Z = (-1); - } - elseif(270 <= $rotation and $rotation < 360){ + }elseif(270 <= $rotation and $rotation < 360){ $rotation -= 270; $Z = (-1); $overturn = true; @@ -1696,33 +1751,34 @@ class Player{ $this->stopSleep(); } break; - case MC_REMOVE_BLOCK: - if($this->spawned === false or $this->blocked === true or $this->entity->distance(new Vector3($data["x"], $data["y"], $data["z"])) > 8){ - $target = $this->level->getBlock(new Vector3($data["x"], $data["y"], $data["z"])); - $this->dataPacket(MC_UPDATE_BLOCK, array( - "x" => $target->x, - "y" => $target->y, - "z" => $target->z, - "block" => $target->getID(), - "meta" => $target->getMetadata() - )); + case ProtocolInfo::REMOVE_BLOCK_PACKET: + $blockVector = new Vector3($packet->x, $packet->y, $packet->z); + if($this->spawned === false or $this->blocked === true or $this->entity->distance($blockVector) > 8){ + $target = $this->level->getBlock($blockVector); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); break; } $this->craftingItems = array(); $this->toCraft = array(); - $this->server->api->block->playerBlockBreak($this, new Vector3($data["x"], $data["y"], $data["z"])); + $this->server->api->block->playerBlockBreak($this, $blockVector); break; - case MC_PLAYER_ARMOR_EQUIPMENT: + case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: if($this->spawned === false or $this->blocked === true){ break; } $this->craftingItems = array(); $this->toCraft = array(); - $data["eid"] = $this->eid; - $data["player"] = $this; + $packet->eid = $this->eid; for($i = 0; $i < 4; ++$i){ - $s = $data["slot$i"]; + $s = $packet->slots[$i]; if($s === 0 or $s === 255){ $s = BlockAPI::getItem(AIR, 0, 0); }else{ @@ -1732,7 +1788,7 @@ class Player{ if($slot->getID() !== AIR and $s->getID() === AIR){ $this->addItem($slot->getID(), $slot->getMetadata(), 1, false); $this->armor[$i] = BlockAPI::getItem(AIR, 0, 0); - $data["slot$i"] = 255; + $packet->slots[$i] = 255; }elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false){ $this->armor[$i] = $this->getSlot($sl); $this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0), false); @@ -1741,7 +1797,7 @@ class Player{ $this->armor[$i] = $this->getSlot($sl); $this->setSlot($sl, $item, false); }else{ - $data["slot$i"] = 255; + $packet->slots[$i] = 255; } } @@ -1751,13 +1807,18 @@ class Player{ $this->entity->updateMetadata(); } break; - case MC_INTERACT: + case ProtocolInfo::INTERACT_PACKET: if($this->spawned === false){ break; } + $packet->eid = $this->eid; + $data = array(); + $data["target"] = $packet->target; + $data["eid"] = $packet->eid; + $data["action"] = $packet->action; $this->craftingItems = array(); $this->toCraft = array(); - $target = $this->server->api->entity->get($data["target"]); + $target = $this->server->api->entity->get($packet->target); if($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){ $data["targetentity"] = $target; $data["entity"] = $this->entity; @@ -1835,13 +1896,14 @@ class Player{ } break; - case MC_ANIMATE: + case ProtocolInfo::ANIMATE_PACKET: if($this->spawned === false){ break; } - $this->server->api->dhandle("entity.animate", array("eid" => $this->eid, "entity" => $this->entity, "action" => $data["action"])); + $packet->eid = $this->eid; + $this->server->api->dhandle("entity.animate", array("eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action)); break; - case MC_RESPAWN: + case ProtocolInfo::RESPAWN_PACKET: if($this->spawned === false){ break; } @@ -1856,27 +1918,27 @@ class Player{ $this->entity->air = 300; $this->entity->setHealth(20, "respawn", true); $this->entity->updateMetadata(); - } else { + }else{ break; } $this->sendInventory(); $this->blocked = false; $this->server->handle("player.respawn", $this); break; - case MC_SET_HEALTH: //Not used + case ProtocolInfo::SET_HEALTH_PACKET: //Not used break; - case MC_ENTITY_EVENT: + case ProtocolInfo::ENTITY_EVENT_PACKET: if($this->spawned === false or $this->blocked === true){ break; } $this->craftingItems = array(); $this->toCraft = array(); - $data["eid"] = $this->eid; + $packet->eid = $this->eid; if($this->entity->inAction === true){ $this->entity->inAction = false; $this->entity->updateMetadata(); } - switch($data["event"]){ + switch($packet->event){ case 9: //Eating $items = array( APPLE => 4, @@ -1901,10 +1963,12 @@ class Player{ ); $slot = $this->getSlot($this->slot); if($this->entity->getHealth() < 20 and isset($items[$slot->getID()])){ - $this->dataPacket(MC_ENTITY_EVENT, array( - "eid" => 0, - "event" => 9, - )); + + $pk = new EntityEventPacket; + $pk->eid = 0; + $pk->event = 9; + $this->dataPacket($pk); + $this->entity->heal($items[$slot->getID()], "eating"); --$slot->count; if($slot->count <= 0){ @@ -1917,15 +1981,20 @@ class Player{ break; } break; - case MC_DROP_ITEM: + case ProtocolInfo::DROP_ITEM_PACKET: if($this->spawned === false or $this->blocked === true){ break; } + $packet->eid = $this->eid; + $packet->item = $this->getSlot($this->slot); $this->craftingItems = array(); $this->toCraft = array(); - $data["item"] = $this->getSlot($this->slot); + $data["eid"] = $packet->eid; + $data["unknown"] = $packet->unknown; + $data["item"] = $packet->item; + $data["player"] = $this; if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){ - $this->server->api->entity->drop(new Position($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5, $this->level), $data["item"]); + $this->server->api->entity->drop(new Position($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5, $this->level), $packet->item); $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); } if($this->entity->inAction === true){ @@ -1933,16 +2002,15 @@ class Player{ $this->entity->updateMetadata(); } break; - case MC_CHAT: + case ProtocolInfo::MESSAGE_PACKET: if($this->spawned === false){ break; } $this->craftingItems = array(); $this->toCraft = array(); - if(trim($data["message"]) != "" and strlen($data["message"]) <= 255){ - $message = $data["message"]; + if(trim($packet->message) != "" and strlen($packet->message) <= 255){ + $message = $packet->message; if($message{0} === "/"){ //Command - console("[INFO] " . FORMAT_AQUA . $data["player"] . FORMAT_RESET . " issued a command: " . FORMAT_AQUA . $message); $this->server->api->console->run(substr($message, 1), $this); }else{ $data = array("player" => $this, "message" => $message); @@ -1956,40 +2024,40 @@ class Player{ } } break; - case MC_CONTAINER_CLOSE: + case ProtocolInfo::CONTAINER_CLOSE_PACKET: if($this->spawned === false){ break; } $this->craftingItems = array(); $this->toCraft = array(); - if(isset($this->windows[$data["windowid"]])){ - if(is_array($this->windows[$data["windowid"]])){ - foreach($this->windows[$data["windowid"]] as $ob){ - $this->server->api->player->broadcastPacket($this->level->players, MC_TILE_EVENT, array( - "x" => $ob->x, - "y" => $ob->y, - "z" => $ob->z, - "case1" => 1, - "case2" => 0, - )); + if(isset($this->windows[$packet->windowid])){ + if(is_array($this->windows[$packet->windowid])){ + foreach($this->windows[$packet->windowid] as $ob){ + $pk = new TileEventPacket; + $pk->x = $ob->x; + $pk->y = $ob->y; + $pk->z = $ob->z; + $pk->case1 = 1; + $pk->case2 = 0; + $this->server->api->player->broadcastPacket($this->level->players, $pk); } - }elseif($this->windows[$data["windowid"]]->class === TILE_CHEST){ - $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), MC_TILE_EVENT, array( - "x" => $this->windows[$data["windowid"]]->x, - "y" => $this->windows[$data["windowid"]]->y, - "z" => $this->windows[$data["windowid"]]->z, - "case1" => 1, - "case2" => 0, - )); + }elseif($this->windows[$packet->windowid]->class === TILE_CHEST){ + $pk = new TileEventPacket; + $pk->x = $this->windows[$packet->windowid]->x; + $pk->y = $this->windows[$packet->windowid]->y; + $pk->z = $this->windows[$packet->windowid]->z; + $pk->case1 = 1; + $pk->case2 = 0; + $this->server->api->player->broadcastPacket($this->level->players, $pk); } } - unset($this->windows[$data["windowid"]]); + unset($this->windows[$packet->windowid]); - $this->dataPacket(MC_CONTAINER_CLOSE, array( - "windowid" => $data["windowid"], - )); + $pk = new ContainerClosePacket; + $pk->windowid = $packet->windowid; + $this->dataPacket($pk); break; - case MC_CONTAINER_SET_SLOT: + case ProtocolInfo::CONTAINER_SET_SLOT_PACKET: if($this->spawned === false or $this->blocked === true){ break; } @@ -2003,28 +2071,28 @@ class Player{ $this->craftingItems = array(); } - if($data["windowid"] === 0){ + if($packet->windowid === 0){ $craft = false; - $slot = $this->getSlot($data["slot"]); - if($slot->count >= $data["stack"] and (($slot->getID() === $data["block"] and $slot->getMetadata() === $data["meta"]) or ($data["block"] === AIR and $data["stack"] === 0)) and !isset($this->craftingItems[$data["slot"]])){ //Crafting recipe - $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count - $data["stack"]); - $this->craftingItems[$data["slot"]] = $use; + $slot = $this->getSlot($packet->slot); + if($slot->count >= $packet->item->count and (($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()) or ($packet->item->getID() === AIR and $packet->item->count === 0)) and !isset($this->craftingItems[$packet->slot])){ //Crafting recipe + $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count - $packet->item->count); + $this->craftingItems[$packet->slot] = $use; $craft = true; - }elseif($slot->count <= $data["stack"] and ($slot->getID() === AIR or ($slot->getID() === $data["block"] and $slot->getMetadata() === $data["meta"]))){ //Crafting final - $craftItem = BlockAPI::getItem($data["block"], $data["meta"], $data["stack"] - $slot->count); + }elseif($slot->count <= $packet->item->count and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))){ //Crafting final + $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count - $slot->count); if(count($this->toCraft) === 0){ $this->toCraft[-1] = 0; } - $this->toCraft[$data["slot"]] = $craftItem; + $this->toCraft[$packet->slot] = $craftItem; $craft = true; - }elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->count > 0 and $slot->getID() > AIR and ($slot->getID() !== $data["block"] or $slot->getMetadata() !== $data["meta"])){ //Crafting final - $craftItem = BlockAPI::getItem($data["block"], $data["meta"], $data["stack"]); + }elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->count > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())){ //Crafting final + $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); if(count($this->toCraft) === 0){ $this->toCraft[-1] = 0; } $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count); - $this->craftingItems[$data["slot"]] = $use; - $this->toCraft[$data["slot"]] = $craftItem; + $this->craftingItems[$packet->slot] = $use; + $this->toCraft[$packet->slot] = $craftItem; $craft = true; } @@ -2045,48 +2113,45 @@ class Player{ $this->toCraft = array(); $this->craftingItems = array(); } - if(!isset($this->windows[$data["windowid"]])){ + if(!isset($this->windows[$packet->windowid])){ break; } - if(is_array($this->windows[$data["windowid"]])){ - $tiles = $this->windows[$data["windowid"]]; - if($data["slot"] >= 0 and $data["slot"] < CHEST_SLOTS){ + if(is_array($this->windows[$packet->windowid])){ + $tiles = $this->windows[$packet->windowid]; + if($packet->slot >= 0 and $packet->slot < CHEST_SLOTS){ $tile = $tiles[0]; - $slotn = $data["slot"]; + $slotn = $packet->slot; $offset = 0; - }elseif($data["slot"] >= CHEST_SLOTS and $data["slot"] <= (CHEST_SLOTS << 1)){ + }elseif($packet->slot >= CHEST_SLOTS and $packet->slot <= (CHEST_SLOTS << 1)){ $tile = $tiles[1]; - $slotn = $data["slot"] - CHEST_SLOTS; + $slotn = $packet->slot - CHEST_SLOTS; $offset = CHEST_SLOTS; }else{ break; } - $item = BlockAPI::getItem($data["block"], $data["meta"], $data["stack"]); + $item = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); $slot = $tile->getSlot($slotn); if($this->server->api->dhandle("player.container.slot", array( "tile" => $tile, - "slot" => $data["slot"], + "slot" => $packet->slot, "offset" => $offset, "slotdata" => $slot, "itemdata" => $item, "player" => $this, )) === false){ - $this->dataPacket(MC_CONTAINER_SET_SLOT, array( - "windowid" => $data["windowid"], - "slot" => $data["slot"], - "block" => $slot->getID(), - "stack" => $slot->count, - "meta" => $slot->getMetadata(), - )); + $pk = new ContainerSetSlotPacket; + $pk->windowid = $packet->windowid; + $pk->slot = $packet->slot; + $pk->item = $slot; + $this->dataPacket($pk); break; } if($item->getID() !== AIR and $slot->getID() == $item->getID()){ if($slot->count < $item->count){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ - $this->sendInventory(); break; } }elseif($slot->count > $item->count){ @@ -2094,38 +2159,35 @@ class Player{ } }else{ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){ - $this->sendInventory(); break; } $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); } $tile->setSlot($slotn, $item, true, $offset); }else{ - $tile = $this->windows[$data["windowid"]]; - if(($tile->class !== TILE_CHEST and $tile->class !== TILE_FURNACE) or $data["slot"] < 0 or ($tile->class === TILE_CHEST and $data["slot"] >= CHEST_SLOTS) or ($tile->class === TILE_FURNACE and $data["slot"] >= FURNACE_SLOTS)){ + $tile = $this->windows[$packet->windowid]; + if(($tile->class !== TILE_CHEST and $tile->class !== TILE_FURNACE) or $packet->slot < 0 or ($tile->class === TILE_CHEST and $packet->slot >= CHEST_SLOTS) or ($tile->class === TILE_FURNACE and $packet->slot >= FURNACE_SLOTS)){ break; } - $item = BlockAPI::getItem($data["block"], $data["meta"], $data["stack"]); + $item = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); - $slot = $tile->getSlot($data["slot"]); + $slot = $tile->getSlot($packet->slot); if($this->server->api->dhandle("player.container.slot", array( "tile" => $tile, - "slot" => $data["slot"], + "slot" => $packet->slot, "slotdata" => $slot, "itemdata" => $item, "player" => $this, )) === false){ - $this->dataPacket(MC_CONTAINER_SET_SLOT, array( - "windowid" => $data["windowid"], - "slot" => $data["slot"], - "block" => $slot->getID(), - "stack" => $slot->count, - "meta" => $slot->getMetadata(), - )); + $pk = new ContainerSetSlotPacket; + $pk->windowid = $packet->windowid; + $pk->slot = $packet->slot; + $pk->item = $slot; + $this->dataPacket($pk); break; } - if($tile->class === TILE_FURNACE and $data["slot"] == 2){ + if($tile->class === TILE_FURNACE and $packet->slot == 2){ switch($slot->getID()){ case IRON_INGOT: AchievementAPI::grantAchievement($this, "acquireIron"); @@ -2136,7 +2198,6 @@ class Player{ if($item->getID() !== AIR and $slot->getID() == $item->getID()){ if($slot->count < $item->count){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ - $this->sendInventory(); break; } }elseif($slot->count > $item->count){ @@ -2144,32 +2205,31 @@ class Player{ } }else{ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){ - $this->sendInventory(); break; } $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); } - $tile->setSlot($data["slot"], $item); + $tile->setSlot($packet->slot, $item); } break; - case MC_SEND_INVENTORY: //TODO, Mojang, enable this ´^_^` + case ProtocolInfo::SEND_INVENTORY_PACKET: //TODO, Mojang, enable this ´^_^` if($this->spawned === false){ break; } break; - case MC_ENTITY_DATA: + case ProtocolInfo::ENTITY_DATA_PACKET: if($this->spawned === false or $this->blocked === true){ break; } $this->craftingItems = array(); $this->toCraft = array(); - $t = $this->server->api->tile->get(new Position($data["x"], $data["y"], $data["z"], $this->level)); + $t = $this->server->api->tile->get(new Position($packet->x, $packet->y, $packet->z, $this->level)); if(($t instanceof Tile) and $t->class === TILE_SIGN){ if($t->data["creator"] !== $this->username){ $t->spawn($this); }else{ $nbt = new NBT(); - $nbt->load($data["namedtag"]); + $nbt->load($packet->namedtag); $d = array_shift($nbt->tree); if($d["id"] !== TILE_SIGN){ $t->spawn($this); @@ -2180,7 +2240,7 @@ class Player{ } break; default: - console("[DEBUG] Unhandled 0x".dechex($pid)." Data Packet for Client ID ".$this->clientID.": ".print_r($data, true), true, true, 2); + console("[DEBUG] Unhandled 0x".dechex($packet->pid())." data packet for ".$this->username." (".$this->clientID."): ".print_r($packet, true), true, true, 2); break; } } @@ -2191,27 +2251,28 @@ class Player{ public function sendArmor($player = false){ $data = array( "player" => $this, - "eid" => $this->eid + "eid" => $this->eid, + "slots" => array() ); - $armor = array(); for($i = 0; $i < 4; ++$i){ if(isset($this->armor[$i]) and ($this->armor[$i] instanceof Item) and $this->armor[$i]->getID() > AIR){ - $data["slot$i"] = $this->armor[$i]->getID() !== AIR ? $this->armor[$i]->getID() - 256:0; + $data["slots"][$i] = $this->armor[$i]->getID() !== AIR ? $this->armor[$i]->getID() - 256:0; }else{ $this->armor[$i] = BlockAPI::getItem(AIR, 0, 0); - $data["slot$i"] = 255; + $data["slots"][$i] = 255; } - $armor[] = $this->armor[$i]; } if($player instanceof Player){ if($player === $this){ - $this->dataPacket(MC_CONTAINER_SET_CONTENT, array( - "windowid" => 0x78, - "count" => 4, - "slots" => $armor, - )); + $pk = new ContainerSetContentPacket; + $pk->windowid = 0x78; //Armor window id + $pk->slots = $this->armor; + $this->dataPacket($pk); }else{ - $player->dataPacket(MC_PLAYER_ARMOR_EQUIPMENT, $data); + $pk = new PlayerArmorEquipmentPacket; + $pk->eid = $this->eid; + $pk->slots = $data["slots"]; + $player->dataPacket($pk); } }else{ $this->server->api->dhandle("player.armor", $data); @@ -2226,74 +2287,89 @@ class Player{ foreach($this->hotbar as $slot){ $hotbar[] = $slot <= -1 ? -1 : $slot + 9; } - - $this->dataPacket(MC_CONTAINER_SET_CONTENT, array( - "windowid" => 0, - "count" => count($this->inventory), - "slots" => $this->inventory, - "hotbar" => $hotbar, - )); + + $pk = new ContainerSetContentPacket; + $pk->windowid = 0; + $pk->slots = $this->inventory; + $pk->hotbar = $hotbar; + $this->dataPacket($pk); } - public function send($pid, $data = array(), $raw = false){ + public function send(RakNetPacket $packet){ if($this->connected === true){ - $this->bandwidthRaw += $this->server->send($pid, $data, $raw, $this->ip, $this->port); + $packet->ip = $this->ip; + $packet->port = $this->port; + $this->bandwidthRaw += $this->server->send($packet); } } public function sendBuffer(){ - if(strlen($this->buffer) > 0){ - $this->directDataPacket(false, array("raw" => $this->buffer), 0x40); + if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket){ + $this->buffer->seqNumber = $this->counter[0]++; + $this->send($this->buffer); } - $this->buffer = ""; + $this->bufferLen = 0; + $this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0); + $this->buffer->data = array(); $this->nextBuffer = microtime(true) + 0.1; } - public function directBigRawPacket($id, $buffer){ + private function directBigRawPacket(RakNetDataPacket $packet){ if($this->connected === false){ return false; - } - $data = array( - "id" => false, - "pid" => 0x50, - "sendtime" => microtime(true), - "raw" => "", - ); + } + + $sendtime = microtime(true); + $size = $this->MTU - 34; - $buffer = str_split(($id === false ? "":chr($id)).$buffer, $size); - $h = Utils::writeInt(count($buffer)).Utils::writeShort($this->bigCnt); + $buffer = str_split($packet->buffer, $size); + $bigCnt = $this->bigCnt; $this->bigCnt = ($this->bigCnt + 1) % 0x10000; $cnts = array(); + $bufCount = count($buffer); foreach($buffer as $i => $buf){ - $data["raw"] = Utils::writeShort(strlen($buf) << 3).strrev(Utils::writeTriad($this->counter[3]++)).$h.Utils::writeInt($i).$buf; $cnts[] = $count = $this->counter[0]++; - $this->recoveryQueue[$count] = $data; - $this->send(0x80, array( - $count, - 0x50, //0b01010000 - $data, - )); + + $pk = new UnknownPacket; + $pk->packetID = $packet->pid(); + $pk->reliability = 2; + $pk->hasSplit = true; + $pk->splitCount = $bufCount; + $pk->splitID = $bigCnt; + $pk->splitIndex = $i; + $pk->buffer = $buf; + $pk->messageIndex = $this->counter[3]++; + + $rk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); + $rk->data[] = $pk; + $rk->seqNumber = $count; + $rk->sendtime = $sendtime; + $this->recoveryQueue[$count] = $rk; + $this->send($rk); } return $cnts; } - public function directDataPacket($id, $data = array(), $pid = 0x00, $recover = true){ + public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $recover = true){ if($this->connected === false){ return false; } - $data["id"] = $id; - $data["pid"] = $pid; - $data["sendtime"] = microtime(true); - $count = $this->counter[0]++; - if($recover !== false){ - $this->recoveryQueue[$count] = $data; + + if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ + return array(); } - $this->send(0x80, array( - $count, - $pid, - $data, - )); - return array($count); + + $packet->encode(); + $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); + $pk->data[] = $packet; + $pk->seqNumber = $this->counter[0]++; + $pk->sendtime = microtime(true); + if($recover !== false){ + $this->recoveryQueue[$pk->seqNumber] = $pk; + } + + $this->send($pk); + return array($pk->seqNumber); } /** @@ -2302,24 +2378,30 @@ class Player{ * * @return array|bool */ - public function dataPacket($id, $data = array()){ - $data["id"] = $id; - if($id === false){ - $raw = $data["raw"]; - }else{ - $data = new CustomPacketHandler($id, "", $data, true); - $raw = chr($id).$data->raw; - } - $len = strlen($raw); - $MTU = $this->MTU - 24; - if($len > $MTU){ - return $this->directBigRawPacket(false, $raw); + public function dataPacket(RakNetDataPacket $packet){ + if($this->connected === false){ + return false; } - if((strlen($this->buffer) + $len) >= $MTU){ + if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ + return; + } + + $packet->encode(); + $len = strlen($packet->buffer) + 1; + $MTU = $this->MTU - 24; + if($len > $MTU){ + return $this->directBigRawPacket($packet); + } + + if(($this->bufferLen + $len) >= $MTU){ $this->sendBuffer(); } - $this->buffer .= ($this->buffer === "" ? "":"\x40").Utils::writeShort($len << 3).strrev(Utils::writeTriad($this->counter[3]++)).$raw; + + $packet->messageIndex = $this->counter[3]++; + $packet->reliability = 2; + $this->buffer->data[] = $packet; + $this->bufferLen += 6 + $len; return array(); } diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 304c4dd6..3c1e47e7 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -414,6 +414,7 @@ class PocketMinecraftServer{ if(stripos($er["file"], "plugin") !== false){ $dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n"; } + $dump .= "Code: \r\n"; $file = @file($er["file"], FILE_IGNORE_NEW_LINES); for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){ @@ -421,7 +422,7 @@ class PocketMinecraftServer{ } $dump .= "\r\n\r\n"; $version = new VersionString(); - $dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".CURRENT_PROTOCOL."; API ".CURRENT_API_VERSION."]\r\n"; + $dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".ProtocolInfo::CURRENT_PROTOCOL."; API ".CURRENT_API_VERSION."]\r\n"; $dump .= "Git commit: ".GIT_COMMIT."\r\n"; $dump .= "Source SHA1 sum: ".SOURCE_SHA1SUM."\r\n"; $dump .= "uname -a: ".php_uname("a")."\r\n"; @@ -444,11 +445,12 @@ class PocketMinecraftServer{ } $dump .= "\r\n\r\n"; } + $extensions = array(); foreach(get_loaded_extensions() as $ext){ $extensions[$ext] = phpversion($ext); } - + $dump .= "Loaded Modules: ".var_export($extensions, true)."\r\n"; $this->checkMemory(); $dump .= "Memory Usage Tracking: \r\n".chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9)))."\r\n"; @@ -474,29 +476,30 @@ class PocketMinecraftServer{ } public static function clientID($ip, $port){ - //faster than string indexes in PHP return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM); + //return $ip . ":" . $port; } - public function packetHandler($packet){ - $data =& $packet["data"]; - $CID = PocketMinecraftServer::clientID($packet["ip"], $packet["port"]); + public function packetHandler(Packet $packet){ + $data =& $packet; + $CID = PocketMinecraftServer::clientID($packet->ip, $packet->port); if(isset($this->clients[$CID])){ - $this->clients[$CID]->handlePacket($packet["pid"], $data); + $this->clients[$CID]->handlePacket($packet); }else{ - if($this->handle("server.noauthpacket", $packet) === false){ + if($this->handle("server.noauthpacket.".$packet->pid(), $packet) === false){ return; } - switch($packet["pid"]){ - case 0x01: - case 0x02: + switch($packet->pid()){ + case RakNetInfo::UNCONNECTED_PING: + case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS: if($this->invisible === true){ - $this->send(0x1c, array( - $data[0], - $this->serverID, - RAKNET_MAGIC, - $this->serverType, - ), false, $packet["ip"], $packet["port"]); + $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG); + $pk->pingID = $packet->pingID; + $pk->serverID = $this->serverID; + $pk->serverType = $this->serverType; + $pk->ip = $packet->ip; + $pk->port = $packet->port; + $this->send($pk); break; } if(!isset($this->custom["times_".$CID])){ @@ -508,64 +511,59 @@ class PocketMinecraftServer{ } $txt = substr($this->description, $this->custom["times_".$CID], $ln); $txt .= substr($this->description, 0, $ln - strlen($txt)); - $this->send(0x1c, array( - $data[0], - $this->serverID, - RAKNET_MAGIC, - $this->serverType. $this->name . " [".count($this->clients)."/".$this->maxClients."] ".$txt, - ), false, $packet["ip"], $packet["port"]); + $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG); + $pk->pingID = $packet->pingID; + $pk->serverID = $this->serverID; + $pk->serverType = $this->serverType . $this->name . " [".count($this->clients)."/".$this->maxClients."] ".$txt; + $pk->ip = $packet->ip; + $pk->port = $packet->port; + $this->send($pk); $this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description); break; - case 0x05: - $version = $data[1]; - $size = strlen($data[2]); - if($version !== CURRENT_STRUCTURE){ - console("[DEBUG] Incorrect structure #$version from ".$packet["ip"].":".$packet["port"], true, true, 2); - $this->send(0x1a, array( - CURRENT_STRUCTURE, - RAKNET_MAGIC, - $this->serverID, - ), false, $packet["ip"], $packet["port"]); + case RakNetInfo::OPEN_CONNECTION_REQUEST_1: + if($packet->structure !== RakNetInfo::STRUCTURE){ + console("[DEBUG] Incorrect structure #".$packet->structure." from ".$packet->ip.":".$packet->port, true, true, 2); + $pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION); + $pk->serverID = $this->serverID; + $pk->ip = $packet->ip; + $pk->port = $packet->port; + $this->send($pk); }else{ - $this->send(0x06, array( - RAKNET_MAGIC, - $this->serverID, - 0, - strlen($packet["raw"]), - ), false, $packet["ip"], $packet["port"]); + $pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1); + $pk->serverID = $this->serverID; + $pk->mtuSize = strlen($packet->buffer); + $pk->ip = $packet->ip; + $pk->port = $packet->port; + $this->send($pk); } break; - case 0x07: + case RakNetInfo::OPEN_CONNECTION_REQUEST_2: if($this->invisible === true){ break; } - $port = $data[2]; - $MTU = $data[3]; - $clientID = $data[4]; - if(count($this->clients) < $this->maxClients){ - $this->clients[$CID] = new Player($clientID, $packet["ip"], $packet["port"], $MTU); //New Session! - $this->send(0x08, array( - RAKNET_MAGIC, - $this->serverID, - $this->port, - $data[3], - 0, - ), false, $packet["ip"], $packet["port"]); - } + + $this->clients[$CID] = new Player($packet->clientID, $packet->ip, $packet->port, $packet->mtuSize); //New Session! + $pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_2); + $pk->serverID = $this->serverID; + $pk->port = $this->port; + $pk->mtuSize = $packet->mtuSize; + $pk->ip = $packet->ip; + $pk->port = $packet->port; + $this->send($pk); break; } } } - public function send($pid, $data = array(), $raw = false, $dest = false, $port = false){ - return $this->interface->writePacket($pid, $data, $raw, $dest, $port); + public function send(Packet $packet){ + return $this->interface->writePacket($packet); } public function process(){ $lastLoop = 0; while($this->stop === false){ $packet = $this->interface->readPacket(); - if($packet !== false){ + if($packet instanceof Packet){ $this->packetHandler($packet); $lastLoop = 0; }elseif($this->tick() > 0){ diff --git a/src/build/compile.sh b/src/build/compile.sh index e7741053..885898db 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -1,13 +1,15 @@ #!/bin/bash -COMPILER_VERSION="0.14" +COMPILER_VERSION="0.16" -PHP_VERSION="5.5.8" +PHP_VERSION="5.5.9" ZEND_VM="GOTO" LIBEDIT_VERSION="0.3" ZLIB_VERSION="1.2.8" -PTHREADS_VERSION="0.0.45" -CURL_VERSION="curl-7_34_0" +PTHREADS_VERSION="0.1.0" +PHPYAML_VERSION="1.1.1" +YAML_VERSION="0.1.4" +CURL_VERSION="curl-7_35_0" echo "[PocketMine] PHP installer and compiler for Linux & Mac" DIR="$(pwd)" @@ -19,11 +21,27 @@ type autoconf >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \ type automake >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"automake\""; read -p "Press [Enter] to continue..."; exit 1; } type libtool >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"libtool\""; read -p "Press [Enter] to continue..."; exit 1; } type m4 >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"m4\""; read -p "Press [Enter] to continue..."; exit 1; } -type wget >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"wget\""; read -p "Press [Enter] to continue..."; exit 1; } +type wget >> "$DIR/install.log" 2>&1 || type curl >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"wget\" or \"curl\""; read -p "Press [Enter] to continue..."; exit 1; } +type getconf >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"getconf\""; read -p "Press [Enter] to continue..."; exit 1; } + +#Needed to use aliases +shopt -s expand_aliases +type wget >> "$DIR/install.log" 2>&1 +if [ $? -eq 0 ]; then + alias download_file="wget --no-check-certificate -q -O -" +else + type curl >> "$DIR/install.log" 2>&1 + if [ $? -eq 0 ]; then + alias download_file="curl --insecure --silent --location" + else + echo "error, curl or wget not found" + fi +fi export CC="gcc" COMPILE_FOR_ANDROID=no RANLIB=ranlib +HAVE_MYSQLI="--with-mysqli=mysqlnd" if [ "$1" == "rpi" ]; then [ -z "$march" ] && march=armv6zk; [ -z "$mtune" ] && mtune=arm1176jzf-s; @@ -34,24 +52,31 @@ elif [ "$1" == "mac" ]; then [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-fomit-frame-pointer"; echo "[INFO] Compiling for Intel MacOS" +elif [ "$1" == "ios" ]; then + [ -z "$march" ] && march=armv6; + [ -z "$mtune" ] && mtune=cortex-a8; + echo "[INFO] Compiling for iOS ARMv6" elif [ "$1" == "crosscompile" ]; then + HAVE_MYSQLI="--without-mysqli" if [ "$2" == "android" ] || [ "$2" == "android-armv6" ]; then COMPILE_FOR_ANDROID=yes [ -z "$march" ] && march=armv6; - [ -z "$mtune" ] && mtune=generic; - TOOLCHAIN_PREFIX="arm-none-linux-gnueabi" + [ -z "$mtune" ] && mtune=arm1136jf-s; + TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" - [ -z "$CFLAGS" ] && CFLAGS="-uclibc"; + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" + CFLAGS="-uclibc --static $CFLAGS"; + LDFLAGS="--static" echo "[INFO] Cross-compiling for Android ARMv6" elif [ "$2" == "android-armv7" ]; then COMPILE_FOR_ANDROID=yes - [ -z "$march" ] && march=armv7a; - [ -z "$mtune" ] && mtune=generic-armv7-a; - TOOLCHAIN_PREFIX="arm-none-linux-gnueabi" + [ -z "$march" ] && march=armv7-a; + [ -z "$mtune" ] && mtune=cortex-a8; + TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" - [ -z "$CFLAGS" ] && CFLAGS="-uclibc"; + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" + CFLAGS="-uclibc --static $CFLAGS"; + LDFLAGS="--static" echo "[INFO] Cross-compiling for Android ARMv7" elif [ "$2" == "rpi" ]; then TOOLCHAIN_PREFIX="arm-linux-gnueabihf" @@ -72,50 +97,74 @@ elif [ "$1" == "crosscompile" ]; then #zlib doesn't use the correct ranlib RANLIB=$TOOLCHAIN_PREFIX-ranlib echo "[INFO] Cross-compiling for Intel MacOS" + elif [ "$2" == "ios" ] || [ "$2" == "ios-armv6" ]; then + [ -z "$march" ] && march=armv6; + [ -z "$mtune" ] && mtune=generic-armv6; + CONFIGURE_FLAGS="--target=arm-apple-darwin10" + elif [ "$2" == "ios-armv7" ]; then + [ -z "$march" ] && march=armv7-a; + [ -z "$mtune" ] && mtune=generic-armv7-a; + CONFIGURE_FLAGS="--target=arm-apple-darwin10" else - echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac] to cross-compile" + echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile" exit 1 fi -else - echo "[INFO] Compiling for current machine" - if [ $(uname -m) == "x86_64" ]; then - CFLAGS="-mx32 $CFLAGS" +elif [ -z "$CFLAGS" ]; then + if [ `getconf LONG_BIT` = "64" ]; then + echo "[INFO] Compiling for current machine using 64-bit" + CFLAGS="-m64 $CFLAGS" + else + echo "[INFO] Compiling for current machine using 32-bit" + CFLAGS="-m32 $CFLAGS" fi fi +cat > test.c <<'CTEST' +#include +main(){ + printf("Hello world\n"); +} +CTEST + + type $CC >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"$CC\""; read -p "Press [Enter] to continue..."; exit 1; } [ -z "$THREADS" ] && THREADS=1; [ -z "$march" ] && march=native; [ -z "$mtune" ] && mtune=native; [ -z "$CFLAGS" ] && CFLAGS=""; +[ -z "$LDFLAGS" ] && LDFLAGS=""; [ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS=""; -$CC -O3 -march=$march -mtune=$mtune -fno-gcse $CFLAGS -Q --help=target >> "$DIR/install.log" 2>&1 -if [ $? -ne 0 ]; then - $CC -O3 -fno-gcse $CFLAGS -Q --help=target >> "$DIR/install.log" 2>&1 - if [ $? -ne 0 ]; then - export CFLAGS="-O3 -fno-gcse " - else - export CFLAGS="-O3 -fno-gcse $CFLAGS" + +if [ "$mtune" != "none" ]; then + $CC -march=$march -mtune=$mtune $CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 + if [ $? -eq 0 ]; then + CFLAGS="-march=$march -mtune=$mtune -fno-gcse $CFLAGS" fi else - export CFLAGS="-O3 -march=$march -mtune=$mtune -fno-gcse $CFLAGS" + $CC -march=$march $CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 + if [ $? -eq 0 ]; then + CFLAGS="-march=$march -fno-gcse $CFLAGS" + fi fi +rm test >> "$DIR/install.log" 2>&1 +rm test.c >> "$DIR/install.log" 2>&1 + +export CFLAGS="-O2 $CFLAGS" +export LDFLAGS="$LDFLAGS" rm -r -f install_data/ >> "$DIR/install.log" 2>&1 -rm -r -f php5/ >> "$DIR/install.log" 2>&1 rm -r -f bin/ >> "$DIR/install.log" 2>&1 mkdir -m 0777 install_data >> "$DIR/install.log" 2>&1 -mkdir -m 0777 php5 >> "$DIR/install.log" 2>&1 mkdir -m 0777 bin >> "$DIR/install.log" 2>&1 cd install_data set -e #PHP 5 echo -n "[PHP] downloading $PHP_VERSION..." -wget http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror -q -O - | tar -zx >> "$DIR/install.log" 2>&1 +download_file "http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror" | tar -zx >> "$DIR/install.log" 2>&1 mv php-$PHP_VERSION php echo " done!" @@ -124,7 +173,7 @@ if [ 1 ] || [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ]; then else #libedit echo -n "[libedit] downloading $LIBEDIT_VERSION..." - wget http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz -q -O - | tar -zx >> "$DIR/install.log" 2>&1 + download_file "http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 echo -n " checking..." cd libedit ./configure --prefix="$DIR/install_data/php/ext/libedit" --enable-static >> "$DIR/install.log" 2>&1 @@ -145,7 +194,7 @@ fi #zlib echo -n "[zlib] downloading $ZLIB_VERSION..." -wget http://zlib.net/zlib-$ZLIB_VERSION.tar.gz -q -O - | tar -zx >> "$DIR/install.log" 2>&1 +download_file "http://zlib.net/zlib-$ZLIB_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 mv zlib-$ZLIB_VERSION zlib echo -n " checking..." cd zlib @@ -161,16 +210,19 @@ rm -r -f ./zlib echo " done!" if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then - HAVE_CURL="shared,/usr/local" + HAVE_CURL="shared,/usr" else #curl echo -n "[cURL] downloading $CURL_VERSION..." - wget https://github.com/bagder/curl/archive/$CURL_VERSION.tar.gz --no-check-certificate -q -O - | tar -zx >> "$DIR/install.log" 2>&1 + download_file "https://github.com/bagder/curl/archive/$CURL_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 mv curl-$CURL_VERSION curl echo -n " checking..." cd curl - ./buildconf >> "$DIR/install.log" 2>&1 - ./configure --enable-ipv6 \ + if [ ! -f ./configure ]; then + ./buildconf --force >> "$DIR/install.log" 2>&1 + fi + ./configure --disable-dependency-tracking \ + --enable-ipv6 \ --enable-optimize \ --enable-http \ --enable-ftp \ @@ -183,8 +235,13 @@ else --disable-smtp \ --disable-telnet \ --disable-tftp \ + --disable-ldap \ + --disable-ldaps \ + --without-libidn \ + --enable-threaded-resolver \ --prefix="$DIR/install_data/php/ext/curl" \ --disable-shared \ + --enable-static \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 @@ -199,10 +256,35 @@ fi #pthreads echo -n "[PHP pthreads] downloading $PTHREADS_VERSION..." -wget http://pecl.php.net/get/pthreads-$PTHREADS_VERSION.tgz --no-check-certificate -q -O - | tar -zx >> "$DIR/install.log" 2>&1 +download_file "http://pecl.php.net/get/pthreads-$PTHREADS_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1 mv pthreads-$PTHREADS_VERSION "$DIR/install_data/php/ext/pthreads" echo " done!" +#PHP YAML +echo -n "[PHP YAML] downloading $PHPYAML_VERSION..." +download_file "http://pecl.php.net/get/yaml-$PHPYAML_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1 +mv yaml-$PHPYAML_VERSION "$DIR/install_data/php/ext/yaml" +echo " done!" + +#YAML +echo -n "[YAML] downloading $YAML_VERSION..." +download_file "http://pyyaml.org/download/libyaml/yaml-$YAML_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 +mv yaml-$YAML_VERSION yaml +echo -n " checking..." +cd yaml +RANLIB=$RANLIB ./configure \ +--prefix="$DIR/install_data/php/ext/yaml" \ +--enable-static \ +--disable-shared \ +$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 +echo -n " compiling..." +make -j $THREADS >> "$DIR/install.log" 2>&1 +echo -n " installing..." +make install >> "$DIR/install.log" 2>&1 +echo -n " cleaning..." +cd .. +rm -r -f ./yaml +echo " done!" echo -n "[PHP]" set +e @@ -230,11 +312,12 @@ if [ "$1" == "crosscompile" ]; then CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" fi -./configure $OPTIMIZATION--prefix="$DIR/php5" \ ---exec-prefix="$DIR/php5" \ +./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ +--exec-prefix="$DIR/bin/php5" \ --with-curl="$HAVE_CURL" \ --with-zlib="$DIR/install_data/php/ext/zlib" \ --with-zlib-dir="$DIR/install_data/php/ext/zlib" \ +--with-yaml="$DIR/install_data/php/ext/yaml" \ $HAVE_LIBEDIT \ --disable-libxml \ --disable-xml \ @@ -259,6 +342,7 @@ $HAVE_LIBEDIT \ --enable-pthreads \ --enable-maintainer-zts \ --enable-zend-signals \ +$HAVE_MYSQLI \ --enable-embedded-mysqli \ --enable-bcmath \ --enable-cli \ @@ -272,12 +356,33 @@ fi make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." make install >> "$DIR/install.log" 2>&1 +echo " generating php.ini..." + +TIMEZONE=$(date +%Z) +touch "$DIR/bin/php5/lib/php.ini" +if [ "$1" != "crosscompile" ]; then + OPCACHE_PATH=$(find "$DIR/bin/php5" -name opcache.so) + echo "zend_extension=\"$OPCACHE_PATH\"" >> "$DIR/bin/php5/lib/php.ini" + echo "opcache.enable=1" >> "$DIR/bin/php5/lib/php.ini" + echo "opcache.enable_cli=1" >> "$DIR/bin/php5/lib/php.ini" + echo "opcache.save_comments=0" >> "$DIR/bin/php5/lib/php.ini" + echo "opcache.fast_shutdown=1" >> "$DIR/bin/php5/lib/php.ini" + echo "opcache.max_accelerated_files=4096" >> "$DIR/bin/php5/lib/php.ini" + echo "opcache.interned_strings_buffer=8" >> "$DIR/bin/php5/lib/php.ini" + echo "opcache.memory_consumption=128" >> "$DIR/bin/php5/lib/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "$DIR/bin/php5/lib/php.ini" +fi +if [ "$HAVE_CURL" == "shared,/usr" ]; then + echo "extension=curl.so" >> "$DIR/bin/php5/lib/php.ini" +fi +echo "date.timezone=$TIMEZONE" >> "$DIR/bin/php5/lib/php.ini" +echo "short_open_tag=0" >> "$DIR/bin/php5/lib/php.ini" +echo "asp_tags=0" >> "$DIR/bin/php5/lib/php.ini" + echo " done!" cd "$DIR" echo -n "[INFO] Cleaning up..." rm -r -f install_data/ >> "$DIR/install.log" 2>&1 -mv php5/bin/php bin/php -rm -r -f php5/ >> "$DIR/install.log" 2>&1 date >> "$DIR/install.log" 2>&1 echo " done!" echo "[PocketMine] You should start the server now using \"./start.sh.\"" diff --git a/src/build/installer.sh b/src/build/installer.sh new file mode 100644 index 00000000..4cba6bcd --- /dev/null +++ b/src/build/installer.sh @@ -0,0 +1,141 @@ +#!/bin/bash +PMMP_VERSION="" +MAC_BUILD="PHP_5.5.9_x86_MacOS" +RPI_BUILD="PHP_5.5.9_ARM_Raspbian_hard" +AND_BUILD="PHP_5.5.9_ARMv7_Android" +IOS_BUILD="PHP_5.5.9_ARMv6_iOS" +update=off + +#Needed to use aliases +shopt -s expand_aliases +type wget > /dev/null 2>&1 +if [ $? -eq 0 ]; then + alias download_file="wget --no-check-certificate -q -O -" +else + type curl >> /dev/null 2>&1 + if [ $? -eq 0 ]; then + alias download_file="curl --insecure --silent --location" + else + echo "error, curl or wget not found" + fi +fi + + +while getopts "udv:" opt; do + case $opt in + u) + update=on + ;; + d) + PMMP_VERSION="master" + ;; + v) + PMMP_VERSION="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + esac +done + +if [ "$PMMP_VERSION" == "" ]; then + PMMP_VERSION=$(download_file "https://api.github.com/repos/PocketMine/PocketMine-MP/tags" | grep '"name": "[A-Za-z0-9_\.]*",' | head -1 | sed -r 's/[ ]*"name": "([A-Za-z0-9_\.]*)",[ ]*/\1/') + if [ "$PMMP_VERSION" == "" ]; then + echo "[ERROR] Couldn't get the latest PocketMine-MP version" + exit 1 + fi +fi + +echo "[INFO] PocketMine-MP $PMMP_VERSION downloader & installer for Linux & Mac" + +echo "[0/3] Cleaning..." +rm -r -f src/ +rm -f PocketMine-MP.php +rm -f README.md +rm -f CONTRIBUTING.md +rm -f LICENSE +rm -f start.sh +rm -f start.bat +echo "[1/3] Downloading PocketMine-MP $PMMP_VERSION..." +set -e +download_file "https://github.com/PocketMine/PocketMine-MP/archive/$PMMP_VERSION.tar.gz" | tar -zx > /dev/null +mv -f PocketMine-MP-$PMMP_VERSION/* ./ +rm -f -r PocketMine-MP-$PMMP_VERSION/ +rm -f ./start.cmd +chmod +x ./start.sh +chmod +x ./src/build/compile.sh +if [ $update == on ]; then + echo "[3/3] Skipping PHP recompilation due to user request" +else + echo -n "[3/3] Obtaining PHP:" + echo " detecting if build is available..." + if [ "$(uname -s)" == "Darwin" ]; then + set +e + UNAME_M=$(uname -m) + IS_IOS=$(expr match $UNAME_M 'iP[a-zA-Z0-9,]*') + set -e + if [ $IS_IOS -gt 0 ]; then + rm -r -f bin/ >> /dev/null 2>&1 + echo -n "[3/3] iOS PHP build available, downloading $IOS_BUILD.tar.gz..." + download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 + chmod +x ./bin/php5/bin/* + echo -n " regenerating php.ini..." + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" + else + rm -r -f bin/ >> /dev/null 2>&1 + echo -n "[3/3] Mac OSX PHP build available, downloading $MAC_BUILD.tar.gz..." + download_file "http://sourceforge.net/projects/pocketmine/files/builds/$MAC_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 + chmod +x ./bin/php5/bin/* + echo -n " regenerating php.ini..." + OPCACHE_PATH=$(find "./bin/php5" -name opcache.so) + echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/lib/php.ini" + echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" + echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" + echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" + echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" + echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" + echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" + echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" + fi + else + set +e + grep -q BCM2708 /proc/cpuinfo > /dev/null 2>&1 + if [ $? -eq 0 ]; then + set -e + rm -r -f bin/ >> /dev/null 2>&1 + echo -n "[3/3] Raspberry Pi PHP build available, downloading $RPI_BUILD.tar.gz..." + download_file "http://sourceforge.net/projects/pocketmine/files/builds/$RPI_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 + chmod +x ./bin/php5/bin/* + echo -n " regenerating php.ini..." + OPCACHE_PATH=$(find "./bin/php5" -name opcache.so) + echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/lib/php.ini" + echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" + echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" + echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" + echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" + echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" + echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" + echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" + else + set -e + echo "[3/3] no build found, compiling PHP" + exec ./src/build/compile.sh + fi + fi +fi +echo "[INFO] Everything done! Run ./start.sh to start PocketMine-MP" +exit 0 diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh new file mode 100644 index 00000000..00615861 --- /dev/null +++ b/src/build/jenkins.sh @@ -0,0 +1,182 @@ +#!/bin/bash -x +export PATH=/opt/arm-2013.05/bin:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/opt/arm-unknown-linux-uclibcgnueabi/bin:$PATH +export THREADS=2 + +#Needed to use aliases +shopt -s expand_aliases +type wget > /dev/null 2>&1 +if [ $? -eq 0 ]; then + alias download_file="wget --no-check-certificate -q -O -" +else + type curl >> /dev/null 2>&1 + if [ $? -eq 0 ]; then + alias download_file="curl --insecure --silent --location" + else + echo "error, curl or wget not found" + fi +fi + +rm -rf $WORKSPACE/compile.sh +download_file "https://github.com/PocketMine/PocketMine-MP/raw/master/src/build/compile.sh" > $WORKSPACE/compile.sh +chmod +x $WORKSPACE/compile.sh +SCRIPT="$WORKSPACE/compile.sh" +ARCHIVE=$WORKSPACE/archive +COMPILEDIR=$WORKSPACE/compile +rm -rf $ARCHIVE $COMPILEDIR +mkdir -p $ARCHIVE +mkdir -p $COMPILEDIR + +if [ "$COMPILE_LINUX_32BIT" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit + cd $COMPILEDIR/linux/32bit + + CFLAGS=-m32 march=i686 mtune=generic $SCRIPT + + cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ + if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$COMPILE_LINUX_64BIT" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit + cd $COMPILEDIR/linux/64bit + + $SCRIPT + + cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ + if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$COMPILE_MAC" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/mac + cd $COMPILEDIR/mac + + curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null + cd libtool-2.4.2 + ./configure --prefix="$COMPILEDIR/mac/libtool" > /dev/null + make > /dev/null + make install + cd ../ + rm -rf libtool-2.4.2 + export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" + export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" + $SCRIPT mac curl + + cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/ + if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$COMPILE_RPI" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi + cd $COMPILEDIR/rpi + + $SCRIPT rpi + + cp -r $COMPILEDIR/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/rpi/ + if [ ! -f $COMPILEDIR/rpi/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_ANDROID_ARMV6" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6 + cd $COMPILEDIR/crosscompile/android-armv6 + + $SCRIPT crosscompile android-armv6 + + cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv6/ + if [ ! -f $COMPILEDIR/crosscompile/android-armv6/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_ANDROID_ARMV7" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7 + cd $COMPILEDIR/crosscompile/android-armv7 + + $SCRIPT crosscompile android-armv7 + + cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv7/ + if [ ! -f $COMPILEDIR/crosscompile/android-armv7/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_IOS_ARMV6" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6 + cd $COMPILEDIR/crosscompile/ios-armv6 + curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null + cd libtool-2.4.2 + ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv6/libtool" > /dev/null + make > /dev/null + make install + cd ../ + rm -rf libtool-2.4.2 + export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool" + export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize" + PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv6 + + cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/ + if [ ! -f $COMPILEDIR/crosscompile/ios-armv6/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_IOS_ARMV7" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7 + cd $COMPILEDIR/crosscompile/ios-armv7 + curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null + cd libtool-2.4.2 + ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv7/libtool" > /dev/null + make > /dev/null + make install + cd ../ + rm -rf libtool-2.4.2 + export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool" + export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize" + PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv7 + + cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/ + if [ ! -f $COMPILEDIR/crosscompile/ios-armv7/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_RPI" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi + cd $COMPILEDIR/crosscompile/rpi + + $SCRIPT crosscompile rpi + + cp -r $COMPILEDIR/crosscompile/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/rpi/ + if [ ! -f $COMPILEDIR/crosscompile/rpi/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_MAC" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac + cd $COMPILEDIR/crosscompile/mac + + $SCRIPT crosscompile mac curl + + cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/ + if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then + exit 1 + fi +fi diff --git a/src/config.php b/src/config.php index 3f8cde81..83b3f24a 100644 --- a/src/config.php +++ b/src/config.php @@ -38,16 +38,15 @@ if(ini_get("date.timezone") == ""){ //No Timezone set $offset = round((intval(trim($t[0])) - time()) / 60) * 60; } -$daylight = (int) date("I"); - -$d = timezone_name_from_abbr("", $offset, $daylight); - ini_set("date.timezone", $d); + $daylight = (int) date("I"); + $d = timezone_name_from_abbr("", $offset, $daylight); + @ini_set("date.timezone", $d); date_default_timezone_set($d); }else{ $d = @date_default_timezone_get(); if(strpos($d, "/") === false){ $d = timezone_name_from_abbr($d); - ini_set("date.timezone", $d); + @ini_set("date.timezone", $d); date_default_timezone_set($d); } } @@ -71,7 +70,7 @@ define("START_TIME", microtime(true)); define("MAJOR_VERSION", "Alpha_1.3.11"); define("CODENAME", "懐かしさ (Nostalgia)"); //i'm not very creative - kotyaralih define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha"); -define("CURRENT_API_VERSION", 11); +define("CURRENT_API_VERSION", 12); define("CURRENT_PHP_VERSION", "5.5"); $gitsha1 = false; if(file_exists(FILE_PATH.".git/refs/heads/master")){ //Found Git information! diff --git a/src/dependencies.php b/src/dependencies.php index 562b9271..0da2459f 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -54,6 +54,15 @@ if(!extension_loaded("sockets") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") if(!extension_loaded("pthreads") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "pthreads." . PHP_SHLIB_SUFFIX) === false){ console("[ERROR] Unable to find the pthreads extension.", true, true, 0); ++$errors; +}else{ + $pthreads_version = phpversion("pthreads"); + if(substr_count($pthreads_version, ".") < 2){ + $pthreads_version = "0.$pthreads_version"; + } + if(version_compare($pthreads_version, "0.1.0") < 0){ + console("[ERROR] pthreads >= 0.1.0 is required, while you have $pthreads_version.", true, true, 0); + ++$errors; + } } if(!extension_loaded("curl") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "curl." . PHP_SHLIB_SUFFIX) === false){ @@ -66,6 +75,11 @@ if(!extension_loaded("sqlite3") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") ++$errors; } +if(!extension_loaded("yaml") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "yaml." . PHP_SHLIB_SUFFIX) === false){ + console("[ERROR] Unable to find the YAML extension.", true, true, 0); + ++$errors; +} + if(!extension_loaded("zlib") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "zlib." . PHP_SHLIB_SUFFIX) === false){ console("[ERROR] Unable to find the Zlib extension.", true, true, 0); ++$errors; @@ -94,4 +108,10 @@ foreach($inc as $s){ $sha1sum ^= sha1_file($s, true); } /***REM_END***/ -define("SOURCE_SHA1SUM", bin2hex($sha1sum)); \ No newline at end of file +define("SOURCE_SHA1SUM", bin2hex($sha1sum)); + +/***REM_START***/ +if(!file_exists(DATA_PATH."server.properties") and arg("no-wizard", false) != true){ + $installer = new Installer(); +} +/***REM_END***/ \ No newline at end of file diff --git a/src/event/CancellableEvent.php b/src/event/CancellableEvent.php new file mode 100644 index 00000000..11b64cb2 --- /dev/null +++ b/src/event/CancellableEvent.php @@ -0,0 +1,28 @@ + $handlerList){ + if(count($handlerList) > 0){ + $event->setPrioritySlot($priority); + foreach($handlerList as $handler){ + call_user_func($handler, $event); + } + if($event->isForced()){ + if($event instanceof CancellableEvent and $event->isCancelled()){ + return BaseEvent::DENY; + }else{ + return BaseEvent::ALLOW; + } + } + } + } + + if($event instanceof CancellableEvent and $event->isCancelled()){ + return BaseEvent::DENY; + }elseif($event->isAllowed()){ + return BaseEvent::ALLOW; + }else{ + return BaseEvent::NORMAL; + } + + } + +} \ No newline at end of file diff --git a/src/event/EventPriority.php b/src/event/EventPriority.php new file mode 100644 index 00000000..f42e8d73 --- /dev/null +++ b/src/event/EventPriority.php @@ -0,0 +1,52 @@ +packet = $packet; + $this->player = $player; + } + + public function getPacket(){ + return $this->packet; + } + + public function getPlayer(){ + return $this->player; + } +} \ No newline at end of file diff --git a/src/event/server/DataPacketSendEvent.php b/src/event/server/DataPacketSendEvent.php new file mode 100644 index 00000000..5e55a29b --- /dev/null +++ b/src/event/server/DataPacketSendEvent.php @@ -0,0 +1,41 @@ +packet = $packet; + $this->player = $player; + } + + public function getPacket(){ + return $this->packet; + } + + public function getPlayer(){ + return $this->player; + } +} \ No newline at end of file diff --git a/src/event/server/PacketReceiveEvent.php b/src/event/server/PacketReceiveEvent.php new file mode 100644 index 00000000..cb26cbf0 --- /dev/null +++ b/src/event/server/PacketReceiveEvent.php @@ -0,0 +1,36 @@ +packet = $packet; + } + + public function getPacket(){ + return $this->packet; + } +} \ No newline at end of file diff --git a/src/event/server/PacketSendEvent.php b/src/event/server/PacketSendEvent.php new file mode 100644 index 00000000..becb15e4 --- /dev/null +++ b/src/event/server/PacketSendEvent.php @@ -0,0 +1,36 @@ +packet = $packet; + } + + public function getPacket(){ + return $this->packet; + } +} \ No newline at end of file diff --git a/src/installer/Installer.php b/src/installer/Installer.php new file mode 100644 index 00000000..e7dd1070 --- /dev/null +++ b/src/installer/Installer.php @@ -0,0 +1,287 @@ + $native){ + echo " $native => $short\n"; + } + do{ + echo "[?] Language (en): "; + $lang = strtolower($this->getInput("en")); + if(!isset(InstallerLang::$languages[$lang])){ + echo "[!] Couldn't find the language\n"; + $lang = false; + } + }while($lang == false); + $this->lang = new InstallerLang($lang); + echo "[*] ".$this->lang->language_has_been_selected."\n"; + echo "[?] ".$this->lang->skip_installer." (y/N): "; + if(strtolower($this->getInput()) === "y"){ + return; + } + echo "\n"; + $this->welcome(); + $this->generateBaseConfig(); + $this->generateUserFiles(); + + $this->networkFunctions(); + + $this->endWizard(); + } + + private function welcome(){ + echo $this->lang->welcome_to_pocketmine."\n"; + echo <<lang->accept_license." (y/N): "; + if(strtolower($this->getInput("n")) != "y"){ + echo "[!] ".$this->lang->you_have_to_accept_the_license."\n"; + sleep(5); + exit(0); + } + echo "[*] ".$this->lang->setting_up_server_now."\n"; + echo "[*] ".$this->lang->default_values_info."\n"; + echo "[*] ".$this->lang->server_properties."\n"; + + } + + private function generateBaseConfig(){ + $config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES); + echo "[?] ".$this->lang->name_your_server." (".self::DEFAULT_NAME."): "; + $config->set("server-name", $this->getInput(self::DEFAULT_NAME)); + echo "[*] ".$this->lang->port_warning."\n"; + do{ + echo "[?] ".$this->lang->server_port." (".self::DEFAULT_PORT."): "; + $port = (int) $this->getInput(self::DEFAULT_PORT); + if($port <= 0 or $port > 65535){ + echo "[!] ".$this->lang->invalid_port."\n"; + } + }while($port <= 0 or $port > 65535); + $config->set("server-port", $port); + echo "[*] ".$this->lang->ram_warning."\n"; + echo "[?] ".$this->lang->server_ram." (".self::DEFAULT_MEMORY."): "; + $config->set("memory-limit", ((int) $this->getInput(self::DEFAULT_MEMORY))."M"); + echo "[*] ".$this->lang->gamemode_info."\n"; + do{ + echo "[?] ".$this->lang->default_gamemode.": (".self::DEFAULT_GAMEMODE."): "; + $gamemode = (int) $this->getInput(self::DEFAULT_GAMEMODE); + }while($gamemode < 0 or $gamemode > 3); + $config->set("gamemode", $gamemode); + echo "[?] ".$this->lang->max_players." (".self::DEFAULT_PLAYERS."): "; + $config->set("max-players", (int) $this->getInput(self::DEFAULT_PLAYERS)); + echo "[*] ".$this->lang->spawn_protection_info."\n"; + echo "[?] ".$this->lang->spawn_protection." (Y/n): "; + if(strtolower($this->getInput("y")) == "n"){ + $config->set("spawn-protection", -1); + }else{ + $config->set("spawn-protection", 16); + } + $config->save(); + } + + private function generateUserFiles(){ + echo "[*] ".$this->lang->op_info."\n"; + echo "[?] ".$this->lang->op_who.": "; + $op = strtolower($this->getInput("")); + if($op === ""){ + echo "[!] ".$this->lang->op_warning."\n"; + }else{ + $ops = new Config(DATA_PATH."ops.txt", CONFIG_LIST); + $ops->set($op, true); + $ops->save(); + } + echo "[*] ".$this->lang->whitelist_info."\n"; + echo "[?] ".$this->lang->whitelist_enable." (y/N): "; + $config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES); + if(strtolower($this->getInput("n")) === "y"){ + echo "[!] ".$this->lang->whitelist_warning."\n"; + $config->set("white-list", true); + }else{ + $config->set("white-list", false); + } + $config->save(); + } + + private function networkFunctions(){ + $config = new Config(DATA_PATH . "server.properties", CONFIG_PROPERTIES); + echo "[!] ".$this->lang->query_warning1."\n"; + echo "[!] ".$this->lang->query_warning2."\n"; + echo "[?] ".$this->lang->query_disable." (y/N): "; + if(strtolower($this->getInput("n")) === "y"){ + $config->set("enable-query", false); + }else{ + $config->set("enable-query", true); + } + + echo "[*] ".$this->lang->rcon_info."\n"; + echo "[?] ".$this->lang->rcon_enable." (y/N): "; + if(strtolower($this->getInput("n")) === "y"){ + $config->set("enable-rcon", true); + $password = substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10); + $config->set("rcon.password", $password); + echo "[*] ".$this->lang->rcon_password.": ".$password."\n"; + }else{ + $config->set("enable-rcon", false); + } + + echo "[*] ".$this->lang->usage_info."\n"; + echo "[?] ".$this->lang->usage_disable." (y/N): "; + if(strtolower($this->getInput("n")) === "y"){ + $config->set("send-usage", false); + }else{ + $config->set("send-usage", true); + } + $config->save(); + + + echo "[*] ".$this->lang->ip_get."\n"; + + $externalIP = Utils::getIP(); + $internalIP = gethostbyname(trim(`hostname`)); + + echo "[!] ".$this->lang->get("ip_warning", array("{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"), array($externalIP, $internalIP))."\n"; + echo "[!] ".$this->lang->ip_confirm; + $this->getInput(); + } + + private function endWizard(){ + echo "[*] ".$this->lang->you_have_finished."\n"; + echo "[*] ".$this->lang->pocketmine_plugins."\n"; + echo "[*] ".$this->lang->pocketmine_will_start."\n\n\n"; + sleep(4); + } + + private function getInput($default = ""){ + $input = trim(fgets(STDIN)); + return $input === "" ? $default:$input; + } + + + } + + class InstallerLang{ + public static $languages = array( + "en" => "English", + "es" => "Español", + "zh" => "中文", + "ru" => "Pyccĸий", + "ja" => "日本語", + "de" => "Deutsch", + //"vi" => "Tiếng Việt", + "ko" => "한국어", + "fr" => "Français", + "it" => "Italiano", + //"lv" => "Latviešu", + "nl" => "Nederlands", + //"pt" => "Português", + "sv" => "Svenska", + "fi" => "Suomi", + "tr" => "Türkçe", + //"et" => "Eesti", + ); + private $texts = array(); + private $lang; + private $langfile; + public function __construct($lang = ""){ + if(file_exists(FILE_PATH."src/lang/Installer/".$lang.".ini")){ + $this->lang = $lang; + $this->langfile = FILE_PATH."src/lang/Installer/".$lang.".ini"; + }else{ + $l = glob(FILE_PATH."src/lang/Installer/".$lang."_*.ini"); + if(count($l) > 0){ + $files = array(); + foreach($l as $file){ + $files[$file] = filesize($file); + } + arsort($files); + reset($files); + $l = key($files); + $l = substr($l, strrpos($l, "/") + 1, -4); + $this->lang = isset(self::$languages[$l]) ? $l:$lang; + $this->langfile = FILE_PATH."src/lang/Installer/".$l.".ini"; + }else{ + $this->lang = "en"; + $this->langfile = FILE_PATH."src/lang/Installer/en.ini"; + } + } + + $this->loadLang(FILE_PATH."src/lang/Installer/en.ini", "en"); + if($this->lang !== "en"){ + $this->loadLang($this->langfile, $this->lang); + } + + } + + public function getLang(){ + return ($this->lang); + } + + public function loadLang($langfile, $lang = "en"){ + $this->texts[$lang] = array(); + $texts = explode("\n", str_replace(array("\r", "\/\/"), array("", "//"), file_get_contents($langfile))); + foreach($texts as $line){ + $line = trim($line); + if($line === ""){ + continue; + } + $line = explode("=", $line); + $this->texts[$lang][array_shift($line)] = str_replace(array("\\n", "\\N",), "\n", implode("=", $line)); + } + } + + public function get($name, $search = array(), $replace = array()){ + if(!isset($this->texts[$this->lang][$name])){ + if($this->lang !== "en" and isset($this->texts["en"][$name])){ + return $this->texts["en"][$name]; + }else{ + return $name; + } + }elseif(count($search) > 0){ + return str_replace($search, $replace, $this->texts[$this->lang][$name]); + }else{ + return $this->texts[$this->lang][$name]; + } + } + + public function __get($name){ + return $this->get($name); + } + + } +/***REM_END***/ diff --git a/src/lang/Installer/af_ZA.ini b/src/lang/Installer/af_ZA.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/af_ZA.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/ar_SA.ini b/src/lang/Installer/ar_SA.ini new file mode 100644 index 00000000..b643a596 --- /dev/null +++ b/src/lang/Installer/ar_SA.ini @@ -0,0 +1,21 @@ +language_has_been_selected=وقد تم اختيار اللغة الإنجليزية بشكل صحيح. +skip_installer=هل تريد تخطي معالج الإعداد؟ + +welcome_to_pocketmine=مرحبا بكم في PocketMine-MP! \ nBefore بدء إعداد ملقم جديد لديك لقبول الترخيص. \ مرخص nPocketMine-MP تحت رخصة LGPL، \ n التي يمكنك أن تقرأ فتح ملف الترخيص على هذا folder.Do كنت ترغب في تخطي المعالج انشاء؟ +accept_license=هل تقبل رخصة؟ +you_have_to_accept_the_license=عليك أن تقبل رخصة LGPL إلى الاستمرار في استخدام PocketMine-MP + +setting_up_server_now=أنت ذاهب لإعداد الخادم الخاص بك الآن. +default_values_info=إذا كنت لا تريد تغيير القيمة الافتراضية، فقط اضغط على Enter. +server_properties=يمكنك تحريرها في وقت لاحق على الملف server.properties. + +name_your_server=إعطاء اسم على الخادم الخاص بك +port_warning=لا تقم بتغيير قيمة المنفذ الافتراضي إذا كان هذا هو الخادم الخاص بك أولا. +server_port=منفذ خادم +invalid_port=منفذ خادم غير صالحة +ram_warning=ذاكرة الوصول العشوائي هو الحد الأقصى لمقدار الذاكرة سوف تستخدم PocketMine-MP. ينصح قيمة 128-256 ميغا بايت +server_ram=RAM الخادم في ميغا بايت +gamemode_info=الاختيار بين العمل الإبداعي (1) أو البقاء على قيد الحياة (0) + + + diff --git a/src/lang/Installer/cs_CZ.ini b/src/lang/Installer/cs_CZ.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/cs_CZ.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/de_DE.ini b/src/lang/Installer/de_DE.ini new file mode 100644 index 00000000..ebe7f9d8 --- /dev/null +++ b/src/lang/Installer/de_DE.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Englisch haben Sie richtig ausgewählt. +skip_installer=Möchten Sie den Setup-Assistenten überspringen? + +welcome_to_pocketmine=Willkommen auf PocketMine-MP!\nBevor Sie die Einrichtung Ihres neuen Server starten, müssen Sie die Lizenz akzeptieren. \nPocketMine-MP ist unter der LGPL-Lizenz, \ndamit Sie die LIZENZ in diesem Ordner lesen oder öffnen können. +accept_license=Akzeptieren Sie die Lizenz? +you_have_to_accept_the_license=Sie müssen die LGPL Lizenz akzeptieren, um weiterhin PocketMine-MP zu nutzen + +setting_up_server_now=Sie werden jetzt Ihren Server einrichten. +default_values_info=Wenn Sie nicht den Standardwert ändern möchten, drücken Sie einfach Enter. +server_properties=Sie können sie später in der server.properties Datei bearbeiten. + +name_your_server=Geben Sie einen Namen für Ihren Server ein +port_warning=Ändern Sie den Standard-Port-Wert nicht, wenn dies Ihr erster Server ist. +server_port=Server-Port +invalid_port=Ungültiger Server-Port +ram_warning=Der RAM ist die maximale Speichermenge die PocketMine-MP verwenden kann. Ein Wert zwischen 128 bis 256 MB wird empfohlen +server_ram=Server RAM in MB +gamemode_info=Wählen Sie zwischen Kreativ (1) oder Überleben (0) +default_gamemode=Standard Spielmodus +max_players=Max. Online-Spieler +spawn_protection_info=Der Spawn-Schutz verbietet Platzierung/Zerstörung der Blöcke in der Einstiegszone, was aber nicht für OPs gilt +spawn_protection=Aktiviere Spawn-Schutz? + +op_info=Ein OP ist der Admin Spieler des Servers. OPs können mehr Befehle ausführen als normale Spieler +op_who=OP Spieler Name (z.B. dein Spiel-Name) +op_warning=Sie werden in der Lage sein einen OP Benutzer später mit /op hinzuzufügen +whitelist_info=Nur die Spieler auf der white-list können zu ihrem Spiel verbinden. +whitelist_enable=Möchten Sie die white-list aktivieren? +whitelist_warning=Sie müssen die Spieler zur white-list hinzufügen + +query_warning1=Query ist ein Protokoll das von verschiedenen Tools verwendet wird, um Informationen von Ihrem Server und eingeloggten Spieler zu nehmen. +query_warning2=Wenn Sie es deaktivieren, werden Sie nicht in der Lage sein, Server-Listen zu verwenden. +query_disable=Wollen Sie Query deaktivieren? +rcon_info=RCON ist ein Protokoll für eine Remote-Verbindung mit der Server-Konsole, mit der Benutzung eines Passworts. +rcon_enable=Wollen Sie RCON aktivieren? +rcon_password=RCON Passwort (Sie können es später ändern) +usage_info=Die anonymen Nutzungsdaten ermöglichen es uns, globale Statistiken für PocketMine-MP und seine Plugins zu berechnen. Sie können sie auf stats.pocketmine.net ansehen +usage_disable=Wollen Sie die anonyme Nutzung deaktivieren? +ip_get=Bekomme deine externe IP und interne IP +ip_warning=Ihre externe IP ist {{EXTERNAL_IP}}. Evtl. musst Du einen port-forward auf deine interne IP {{INTERNAL_IP}} machen +ip_confirm=Achten Sie darauf, wenn Sie den Port forwarden müssen und Sie es überspringen, dass keine externen Spieler beitreten können. [Drücke Enter] + +you_have_finished=Sie haben den Setup-Assistenten korrekt beendet +pocketmine_will_start=PocketMine-MP wird nun gestartet. Tippe /help um die Liste der verfügbaren Befehle anzuzeigen. +pocketmine_plugins=Überprüfen Sie das Plugin Repository um neue Features, Minispiele, oder einen erweiterten Schutz für Ihren Server hinzuzufügen diff --git a/src/lang/Installer/el_GR.ini b/src/lang/Installer/el_GR.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/el_GR.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/en.ini b/src/lang/Installer/en.ini new file mode 100644 index 00000000..c1fb634f --- /dev/null +++ b/src/lang/Installer/en.ini @@ -0,0 +1,45 @@ +language_has_been_selected=English has been correctly selected. +skip_installer=Do you want to skip the set-up wizard? + +welcome_to_pocketmine=Welcome to PocketMine-MP!\nBefore starting setting up your new server you have to accept the license.\nPocketMine-MP is licensed under the LGPL License,\nthat you can read opening the LICENSE file on this folder. +accept_license=Do you accept the License? +you_have_to_accept_the_license=You have to accept the LGPL license to continue using PocketMine-MP + +setting_up_server_now=You are going to set up your server now. +default_values_info=If you don't want to change the default value, just press Enter. +server_properties=You can edit them later on the server.properties file. + +name_your_server=Give a name to your server +port_warning=Do not change the default port value if this is your first server. +server_port=Server port +invalid_port=Invalid server port +ram_warning=The RAM is the maximum amount of memory PocketMine-MP will use. A value of 128-256 MB is recommended +server_ram=Server RAM in MB +gamemode_info=Choose between Creative (1) or Survival (0) +default_gamemode=Default Game mode +max_players=Max. online players +spawn_protection_info=The spawn protection disallows placing/breaking blocks in the spawn zone except for OPs +spawn_protection=Enable spawn protection? + +op_info=An OP is the player admin of the server. OPs can run more commands than normal players +op_who=OP player name (example, your game name) +op_warning=You will be able to add an OP user later using /op +whitelist_info=The white-list only allows players in it to join. +whitelist_enable=Do you want to enable the white-list? +whitelist_warning=You will have to add the players to the white-list + +query_warning1=Query is a protocol used by diferent tools to get information of your server and players logged in. +query_warning2=If you disable it, you won't be able to use server lists. +query_disable=Do you want to disable Query? +rcon_info=RCON is a protocol to remote connect with the server console using a password. +rcon_enable=Do you want to enable RCON? +rcon_password=RCON password (you can change it later) +usage_info=The anonymous usage data allows us to calculate global statistics for PocketMine-MP and its plugins. You can view them on stats.pocketmine.net +usage_disable=Do you want to disable the anonymous usage? +ip_get=Getting your external IP and internal IP +ip_warning=Your external IP is {{EXTERNAL_IP}}. You may have to port-forward to your internal IP {{INTERNAL_IP}} +ip_confirm=Be sure to check it, if you have to forward and you skip that, no external players will be able to join. [Press Enter] + +you_have_finished=You have finished the set-up wizard correctly +pocketmine_will_start=PocketMine-MP will now start. Type /help to view the list of available commands. +pocketmine_plugins=Check the Plugin Repository to add new features, minigames, or advanced protection to your server \ No newline at end of file diff --git a/src/lang/Installer/en_AU.ini b/src/lang/Installer/en_AU.ini new file mode 100644 index 00000000..86899b95 --- /dev/null +++ b/src/lang/Installer/en_AU.ini @@ -0,0 +1,45 @@ +language_has_been_selected=English has been correctly selected. +skip_installer=Do you want to skip the set-up wizard? + +welcome_to_pocketmine=Welcome to PocketMine-MP!\nBefore starting setting up your new server you have to accept the license.\nPocketMine-MP is licensed under the LGPL License,\nthat you can read opening the LICENSE file on this folder. +accept_license=Do you accept the License? +you_have_to_accept_the_license=You have to accept the LGPL license to continue using PocketMine-MP + +setting_up_server_now=You are going to set up your server now. +default_values_info=If you don't want to change the default value, just press Enter. +server_properties=You can edit them later on the server.properties file. + +name_your_server=Give a name to your server +port_warning=Do not change the default port value if this is your first server. +server_port=Server port +invalid_port=Invalid server port +ram_warning=The RAM is the maximum amount of memory PocketMine-MP will use. A value of 128-256 MB is recommended +server_ram=Server RAM in MB +gamemode_info=Choose between Creative (1) or Survival (0) +default_gamemode=Default Game mode +max_players=Max. online players +spawn_protection_info=The spawn protection disallows placing/breaking blocks in the spawn zone except for OPs +spawn_protection=Enable spawn protection? + +op_info=An OP is the player admin of the server. OPs can run more commands than normal players +op_who=OP player name (example, your game name) +op_warning=You will be able to add an OP user later using /op +whitelist_info=The white-list only allows players in it to join. +whitelist_enable=Do you want to enable the white-list? +whitelist_warning=You will have to add the players to the white-list + +query_warning1=Query is a protocol used by diferent tools to get information of your server and players logged in. +query_warning2=If you disable it, you won't be able to use server lists. +query_disable=Do you want to disable Query? +rcon_info=RCON is a protocol to remote connect with the server console using a password. +rcon_enable=Do you want to enable RCON? +rcon_password=RCON password (you can change it later) +usage_info=The anonymous usage data allows us to calculate global statistics for PocketMine-MP and its plugins. You can view them on stats.pocketmine.net +usage_disable=Do you want to disable the anonymous usage? +ip_get=Getting your external IP and internal IP +ip_warning=Your external IP is {{EXTERNAL_IP}}. You may have to port-forward to your internal IP {{INTERNAL_IP}} +ip_confirm=Be sure to check it, if you have to forward and you skip that, no external players will be able to join. [Press Enter] + +you_have_finished=You have finished the set-up wizard correctly +pocketmine_will_start=PocketMine-MP will now start. Type /help to view the list of available commands. +pocketmine_plugins=Check the Plugin Repository to add new features, minigames, or advanced protection to your server diff --git a/src/lang/Installer/en_CA.ini b/src/lang/Installer/en_CA.ini new file mode 100644 index 00000000..86899b95 --- /dev/null +++ b/src/lang/Installer/en_CA.ini @@ -0,0 +1,45 @@ +language_has_been_selected=English has been correctly selected. +skip_installer=Do you want to skip the set-up wizard? + +welcome_to_pocketmine=Welcome to PocketMine-MP!\nBefore starting setting up your new server you have to accept the license.\nPocketMine-MP is licensed under the LGPL License,\nthat you can read opening the LICENSE file on this folder. +accept_license=Do you accept the License? +you_have_to_accept_the_license=You have to accept the LGPL license to continue using PocketMine-MP + +setting_up_server_now=You are going to set up your server now. +default_values_info=If you don't want to change the default value, just press Enter. +server_properties=You can edit them later on the server.properties file. + +name_your_server=Give a name to your server +port_warning=Do not change the default port value if this is your first server. +server_port=Server port +invalid_port=Invalid server port +ram_warning=The RAM is the maximum amount of memory PocketMine-MP will use. A value of 128-256 MB is recommended +server_ram=Server RAM in MB +gamemode_info=Choose between Creative (1) or Survival (0) +default_gamemode=Default Game mode +max_players=Max. online players +spawn_protection_info=The spawn protection disallows placing/breaking blocks in the spawn zone except for OPs +spawn_protection=Enable spawn protection? + +op_info=An OP is the player admin of the server. OPs can run more commands than normal players +op_who=OP player name (example, your game name) +op_warning=You will be able to add an OP user later using /op +whitelist_info=The white-list only allows players in it to join. +whitelist_enable=Do you want to enable the white-list? +whitelist_warning=You will have to add the players to the white-list + +query_warning1=Query is a protocol used by diferent tools to get information of your server and players logged in. +query_warning2=If you disable it, you won't be able to use server lists. +query_disable=Do you want to disable Query? +rcon_info=RCON is a protocol to remote connect with the server console using a password. +rcon_enable=Do you want to enable RCON? +rcon_password=RCON password (you can change it later) +usage_info=The anonymous usage data allows us to calculate global statistics for PocketMine-MP and its plugins. You can view them on stats.pocketmine.net +usage_disable=Do you want to disable the anonymous usage? +ip_get=Getting your external IP and internal IP +ip_warning=Your external IP is {{EXTERNAL_IP}}. You may have to port-forward to your internal IP {{INTERNAL_IP}} +ip_confirm=Be sure to check it, if you have to forward and you skip that, no external players will be able to join. [Press Enter] + +you_have_finished=You have finished the set-up wizard correctly +pocketmine_will_start=PocketMine-MP will now start. Type /help to view the list of available commands. +pocketmine_plugins=Check the Plugin Repository to add new features, minigames, or advanced protection to your server diff --git a/src/lang/Installer/en_GB.ini b/src/lang/Installer/en_GB.ini new file mode 100644 index 00000000..86899b95 --- /dev/null +++ b/src/lang/Installer/en_GB.ini @@ -0,0 +1,45 @@ +language_has_been_selected=English has been correctly selected. +skip_installer=Do you want to skip the set-up wizard? + +welcome_to_pocketmine=Welcome to PocketMine-MP!\nBefore starting setting up your new server you have to accept the license.\nPocketMine-MP is licensed under the LGPL License,\nthat you can read opening the LICENSE file on this folder. +accept_license=Do you accept the License? +you_have_to_accept_the_license=You have to accept the LGPL license to continue using PocketMine-MP + +setting_up_server_now=You are going to set up your server now. +default_values_info=If you don't want to change the default value, just press Enter. +server_properties=You can edit them later on the server.properties file. + +name_your_server=Give a name to your server +port_warning=Do not change the default port value if this is your first server. +server_port=Server port +invalid_port=Invalid server port +ram_warning=The RAM is the maximum amount of memory PocketMine-MP will use. A value of 128-256 MB is recommended +server_ram=Server RAM in MB +gamemode_info=Choose between Creative (1) or Survival (0) +default_gamemode=Default Game mode +max_players=Max. online players +spawn_protection_info=The spawn protection disallows placing/breaking blocks in the spawn zone except for OPs +spawn_protection=Enable spawn protection? + +op_info=An OP is the player admin of the server. OPs can run more commands than normal players +op_who=OP player name (example, your game name) +op_warning=You will be able to add an OP user later using /op +whitelist_info=The white-list only allows players in it to join. +whitelist_enable=Do you want to enable the white-list? +whitelist_warning=You will have to add the players to the white-list + +query_warning1=Query is a protocol used by diferent tools to get information of your server and players logged in. +query_warning2=If you disable it, you won't be able to use server lists. +query_disable=Do you want to disable Query? +rcon_info=RCON is a protocol to remote connect with the server console using a password. +rcon_enable=Do you want to enable RCON? +rcon_password=RCON password (you can change it later) +usage_info=The anonymous usage data allows us to calculate global statistics for PocketMine-MP and its plugins. You can view them on stats.pocketmine.net +usage_disable=Do you want to disable the anonymous usage? +ip_get=Getting your external IP and internal IP +ip_warning=Your external IP is {{EXTERNAL_IP}}. You may have to port-forward to your internal IP {{INTERNAL_IP}} +ip_confirm=Be sure to check it, if you have to forward and you skip that, no external players will be able to join. [Press Enter] + +you_have_finished=You have finished the set-up wizard correctly +pocketmine_will_start=PocketMine-MP will now start. Type /help to view the list of available commands. +pocketmine_plugins=Check the Plugin Repository to add new features, minigames, or advanced protection to your server diff --git a/src/lang/Installer/en_PT.ini b/src/lang/Installer/en_PT.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/en_PT.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/en_US.ini b/src/lang/Installer/en_US.ini new file mode 100644 index 00000000..86899b95 --- /dev/null +++ b/src/lang/Installer/en_US.ini @@ -0,0 +1,45 @@ +language_has_been_selected=English has been correctly selected. +skip_installer=Do you want to skip the set-up wizard? + +welcome_to_pocketmine=Welcome to PocketMine-MP!\nBefore starting setting up your new server you have to accept the license.\nPocketMine-MP is licensed under the LGPL License,\nthat you can read opening the LICENSE file on this folder. +accept_license=Do you accept the License? +you_have_to_accept_the_license=You have to accept the LGPL license to continue using PocketMine-MP + +setting_up_server_now=You are going to set up your server now. +default_values_info=If you don't want to change the default value, just press Enter. +server_properties=You can edit them later on the server.properties file. + +name_your_server=Give a name to your server +port_warning=Do not change the default port value if this is your first server. +server_port=Server port +invalid_port=Invalid server port +ram_warning=The RAM is the maximum amount of memory PocketMine-MP will use. A value of 128-256 MB is recommended +server_ram=Server RAM in MB +gamemode_info=Choose between Creative (1) or Survival (0) +default_gamemode=Default Game mode +max_players=Max. online players +spawn_protection_info=The spawn protection disallows placing/breaking blocks in the spawn zone except for OPs +spawn_protection=Enable spawn protection? + +op_info=An OP is the player admin of the server. OPs can run more commands than normal players +op_who=OP player name (example, your game name) +op_warning=You will be able to add an OP user later using /op +whitelist_info=The white-list only allows players in it to join. +whitelist_enable=Do you want to enable the white-list? +whitelist_warning=You will have to add the players to the white-list + +query_warning1=Query is a protocol used by diferent tools to get information of your server and players logged in. +query_warning2=If you disable it, you won't be able to use server lists. +query_disable=Do you want to disable Query? +rcon_info=RCON is a protocol to remote connect with the server console using a password. +rcon_enable=Do you want to enable RCON? +rcon_password=RCON password (you can change it later) +usage_info=The anonymous usage data allows us to calculate global statistics for PocketMine-MP and its plugins. You can view them on stats.pocketmine.net +usage_disable=Do you want to disable the anonymous usage? +ip_get=Getting your external IP and internal IP +ip_warning=Your external IP is {{EXTERNAL_IP}}. You may have to port-forward to your internal IP {{INTERNAL_IP}} +ip_confirm=Be sure to check it, if you have to forward and you skip that, no external players will be able to join. [Press Enter] + +you_have_finished=You have finished the set-up wizard correctly +pocketmine_will_start=PocketMine-MP will now start. Type /help to view the list of available commands. +pocketmine_plugins=Check the Plugin Repository to add new features, minigames, or advanced protection to your server diff --git a/src/lang/Installer/es_AR.ini b/src/lang/Installer/es_AR.ini new file mode 100644 index 00000000..0d3d9ba5 --- /dev/null +++ b/src/lang/Installer/es_AR.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Español sido seleccionado correctamente. +skip_installer=Quieres saltarte el asistente de configuración? + +welcome_to_pocketmine=Bienvenido a PocketMine-MP!\nAntes de comenzar a configurar tu nuevo servidor, tienes que aceptar la licencia.\nPocketMine-MP está licenciado con la licencia LGPL,\nque puedes leer abriendo el archivo LICENSE en esta carpeta. +accept_license=¿Aceptas la Licencia? +you_have_to_accept_the_license=Tienes que aceptar la licencia LGPL antes de continuar usando PocketMine-MP + +setting_up_server_now=La configuración del servidor va a comenzar. +default_values_info=Si no quieres cambiar el valor por defecto, pulsa Enter. +server_properties=Puedes editar todo despues en el fichero server.properties. + +name_your_server=Nombre del servidor +port_warning=No cambies el puerto por defecto si este es tu primer servidor. +server_port=Puerto del servidor +invalid_port=Puerto inválido +ram_warning=La RAM esla máxima memoria que PocketMine-MP usará. Es recomendado usar un valor de 128-256 MB +server_ram=RAM del servidor en MB +gamemode_info=Elige entre Creativo (1) o Supervivencia (0) +default_gamemode=Modo de juego por defecto +max_players=Límite de jugadores +spawn_protection_info=La protección del inicio bloquea poner/romper bloques en la zona de inicio, excepto los OPs +spawn_protection=¿Activar protección de inicio? + +op_info=Un OP es el jugador administrador del servidor. Los OPs pueden usar más comandos que los jugadores normales +op_who=Jugador OP (por ejemplo, tu nombre de jugador) +op_warning=Podrás añadir mas OPs después usando /op +whitelist_info=La lista blanca permite entrar únicamente a los jugadores en ella. +whitelist_enable=¿Quieres activar la lista blanca? +whitelist_warning=Tendrás que añadir los jugadores a la lista blanca + +query_warning1=Query es un protocolo usado por diferentes herramientas para conseguir informacion de tu servidor y los jugadores conectados. +query_warning2=Si lo desactivas, no podrás usar listas de servidores. +query_disable=¿Quieres desactivar Query? +rcon_info=RCON es un protocolo que permite conectarte a la consola del servidor usando una contraseña. +rcon_enable=¿Queres activar RCON? +rcon_password=Contraseña RCON (puedes cambiarla después) +usage_info=Los datos de uso anónimos nos permiten calcular estadísticas globales para PocketMine-MP y sus plugins. Puedes verlas en stats.pocketmine.net +usage_disable=¿Quieres desactivar las datos de uso anónimos? +ip_get=Obteniendo tu IP externa e IP interna +ip_warning=Tu IP externa es {{EXTERNAL_IP}}. Quizás debas redireccionar el puerto a tu IP interna {{INTERNAL_IP}} +ip_confirm=Asegúrate de comprobarlo, ya que si debes hacerlo y lo saltas, ningún jugador externo podra entrar. [Pulsa Enter] + +you_have_finished=Has completado el asistente de configuración correctamente +pocketmine_will_start=PocketMine-MP se iniciará ahora. Escribe /help para ver la lista de los comandos disponibles. +pocketmine_plugins=Ves al Repositorio de Plugins para añadir nuevas funcionalidades, minijuegos o protección avanzada a tu servidor diff --git a/src/lang/Installer/es_ES.ini b/src/lang/Installer/es_ES.ini new file mode 100644 index 00000000..0d3d9ba5 --- /dev/null +++ b/src/lang/Installer/es_ES.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Español sido seleccionado correctamente. +skip_installer=Quieres saltarte el asistente de configuración? + +welcome_to_pocketmine=Bienvenido a PocketMine-MP!\nAntes de comenzar a configurar tu nuevo servidor, tienes que aceptar la licencia.\nPocketMine-MP está licenciado con la licencia LGPL,\nque puedes leer abriendo el archivo LICENSE en esta carpeta. +accept_license=¿Aceptas la Licencia? +you_have_to_accept_the_license=Tienes que aceptar la licencia LGPL antes de continuar usando PocketMine-MP + +setting_up_server_now=La configuración del servidor va a comenzar. +default_values_info=Si no quieres cambiar el valor por defecto, pulsa Enter. +server_properties=Puedes editar todo despues en el fichero server.properties. + +name_your_server=Nombre del servidor +port_warning=No cambies el puerto por defecto si este es tu primer servidor. +server_port=Puerto del servidor +invalid_port=Puerto inválido +ram_warning=La RAM esla máxima memoria que PocketMine-MP usará. Es recomendado usar un valor de 128-256 MB +server_ram=RAM del servidor en MB +gamemode_info=Elige entre Creativo (1) o Supervivencia (0) +default_gamemode=Modo de juego por defecto +max_players=Límite de jugadores +spawn_protection_info=La protección del inicio bloquea poner/romper bloques en la zona de inicio, excepto los OPs +spawn_protection=¿Activar protección de inicio? + +op_info=Un OP es el jugador administrador del servidor. Los OPs pueden usar más comandos que los jugadores normales +op_who=Jugador OP (por ejemplo, tu nombre de jugador) +op_warning=Podrás añadir mas OPs después usando /op +whitelist_info=La lista blanca permite entrar únicamente a los jugadores en ella. +whitelist_enable=¿Quieres activar la lista blanca? +whitelist_warning=Tendrás que añadir los jugadores a la lista blanca + +query_warning1=Query es un protocolo usado por diferentes herramientas para conseguir informacion de tu servidor y los jugadores conectados. +query_warning2=Si lo desactivas, no podrás usar listas de servidores. +query_disable=¿Quieres desactivar Query? +rcon_info=RCON es un protocolo que permite conectarte a la consola del servidor usando una contraseña. +rcon_enable=¿Queres activar RCON? +rcon_password=Contraseña RCON (puedes cambiarla después) +usage_info=Los datos de uso anónimos nos permiten calcular estadísticas globales para PocketMine-MP y sus plugins. Puedes verlas en stats.pocketmine.net +usage_disable=¿Quieres desactivar las datos de uso anónimos? +ip_get=Obteniendo tu IP externa e IP interna +ip_warning=Tu IP externa es {{EXTERNAL_IP}}. Quizás debas redireccionar el puerto a tu IP interna {{INTERNAL_IP}} +ip_confirm=Asegúrate de comprobarlo, ya que si debes hacerlo y lo saltas, ningún jugador externo podra entrar. [Pulsa Enter] + +you_have_finished=Has completado el asistente de configuración correctamente +pocketmine_will_start=PocketMine-MP se iniciará ahora. Escribe /help para ver la lista de los comandos disponibles. +pocketmine_plugins=Ves al Repositorio de Plugins para añadir nuevas funcionalidades, minijuegos o protección avanzada a tu servidor diff --git a/src/lang/Installer/es_MX.ini b/src/lang/Installer/es_MX.ini new file mode 100644 index 00000000..92bd6d42 --- /dev/null +++ b/src/lang/Installer/es_MX.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Español seleccionado. +skip_installer=Deseas omitir el asistente de configuración? + +welcome_to_pocketmine=¡Bienvenido a PocketMine-MP!\nAntes de empezar a configurar tu nuevo servidor necesitas aceptar la licensia.\nLa licensia de PocketMine-MP esta bajo la licensia LGPL,\n que puedes leer abriendo el archivo "License" en esta carpeta. +accept_license=Aceptas la licensia? +you_have_to_accept_the_license=Debes aceptar la licensia de LPGL para continuar utilizando PocketMine-MP + +setting_up_server_now=Empezemos con la configuración. +default_values_info=Si no quieres cambiar los valores predeterminados pulsa Enter. +server_properties=Puedes editarlos despues editando el archivo "server.properties". + +name_your_server=Escribe el nombre de tu servidor +port_warning=No cambies el puerto predeterminado si este es tu primer servidor. +server_port=Puerto del servidor +invalid_port=Puerto invalido +ram_warning=La RAM es la máxima memoria que PocketMine-MP usará. Se recomienda utilizar un mínimo de 128 MB +server_ram=RAM del servidor en MB +gamemode_info=Escoge entre Creativo (1) o Survival (0) +default_gamemode=Modo de juego predeterminado +max_players=Límite de jugadores +spawn_protection_info=La protección del inicio impide poner/romper bloques en la zona de aparición, a excepción de los OPs +spawn_protection=Activar la protección del spawn? + +op_info=Un OP es el administrador del servidor. Los OPs pueden ejecutar más comandos que los usuarios normales +op_who=OP nombre del jugador (Por ejemplo: Tu nombre de Minecraft) +op_warning=Podrás añadir más usuarios a la lista de OPs después, utilizando el comando /op +whitelist_info=La lista blanca (white-list) permite hacer una lista de invitados, solo los usuarios en la lista podrán entrar a tu servidor. +whitelist_enable=¿Deseas activar la lista blanca? +whitelist_warning=Tendrás que añadir usuarios a la lista blanca + +query_warning1=Query es un protocolo usado por diferentes herramientas para conseguir informacion de tu servidor y los jugadores conectados. +query_warning2=Si lo desactivas, no podrás registrar tu servidor en una lista de servidores. +query_disable=¿Quieres desactivar Query? +rcon_info=RCON es un protocolo que te permite conectarte a la consola de tu servidor usando una contraseña. +rcon_enable=¿Queres activar RCON? +rcon_password=Contraseña para RCON (puedes cambiarla después) +usage_info=Los datos de uso anónimos nos permiten calcular estadísticas globales para PocketMine-MP y sus plugins. Puedes verlas en stats.pocketmine.net +usage_disable=¿Quieres desactivar las datos de uso anónimos? +ip_get=Obteniendo tu IP externa e IP interna +ip_warning=Tu IP externa es {{EXTERNAL_IP}}. Quizás debas redireccionar el puerto a tu IP interna: {{INTERNAL_IP}} +ip_confirm=Asegúrate de que este bien, ya que si debes hacerlo y lo saltas, ningún jugador podrá entrar si esta fuera de tu red WIFI. [Pulsa Enter] + +you_have_finished=Has completado el asistente de configuración correctamente +pocketmine_will_start=PocketMine-MP se iniciará ahora. Escribe /help para ver la lista de los comandos disponibles. +pocketmine_plugins=Ve al Repositorio de Plugins para añadir nuevas funciones, minijuegos o protección avanzada a tu servidor diff --git a/src/lang/Installer/et_EE.ini b/src/lang/Installer/et_EE.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/et_EE.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/fi_FI.ini b/src/lang/Installer/fi_FI.ini new file mode 100644 index 00000000..bdfa7ab6 --- /dev/null +++ b/src/lang/Installer/fi_FI.ini @@ -0,0 +1,7 @@ + + + +default_gamemode=Normaali Peli Tila + + + diff --git a/src/lang/Installer/fr_FR.ini b/src/lang/Installer/fr_FR.ini new file mode 100644 index 00000000..035e5be6 --- /dev/null +++ b/src/lang/Installer/fr_FR.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Français a été correctement sélectionné. +skip_installer=Voulez-vous passer l'assistant d'installation? + +welcome_to_pocketmine=Bienvenue sur PocketMine-MP!\nAvant de commencer à paramétrer votre nouveau serveur, vous devez accepter la license d'utilisation.\nPocketMine-MP est sous licence LGPL,\nvous pouvez la lire en ouvrant le fichier LICENSE dans ce dossier. +accept_license=Acceptez-vous la Licence? +you_have_to_accept_the_license=Vous devez accepter la licence LGPL pour continuer à utiliser PocketMine-MP + +setting_up_server_now=Vous êtes maintenant prêt à paramétrer votre serveur. +default_values_info=Si vous ne voulez pas changer la valeur par défaut, pressez juste Enter. +server_properties=Vous pouvez éditer cela plus tard dans le fichier server.properties. + +name_your_server=Donnez un nom à votre serveur +port_warning=Ne changez pas la valeur par défaut du port si c'est votre premier serveur. +server_port=Port du serveur +invalid_port=Port du serveur invalide +ram_warning=La RAM est au maximum de sa capacité par rapport à la mémoire utilisée par PocketMine-MP. Une valeur de 128-256 MB est recommandée +server_ram=RAM du serveur en MB +gamemode_info=Choisir entre Créatif (1) ou Survie (1) +default_gamemode=Mode de jeu par défaut +max_players=Joueurs max. en ligne +spawn_protection_info=La protection de spawn désactive le placement/cassement de blocs dans la zone de spawn excepté pour les OPs +spawn_protection=Activer la protection de spawn? + +op_info=Un OP est un administrateur du serveur. Les OPs peuvent exécuter plus de commandes que les joueurs normaux +op_who=Nom de joueur OP (exemple, votre nom de jeu) +op_warning=Vous serez en mesure d'ajouter un OP plus tard en utilisant /op +whitelist_info=La white-list autorise seulement les joueurs présents sur celle-ci. +whitelist_enable=Voulez-vous activer la white-list? +whitelist_warning=Vous devrez ajouter les joueurs à la white-list + +query_warning1=Query est un protocole utilisé par différents outils pour avoir des informations sur votre serveur et les joueurs connectés. +query_warning2=Si vous le désactivez, vous ne pourrez pas utiliser les listes du serveur. +query_disable=Voulez-vous désactiver Query? +rcon_info=RCON est un protocole pour se connecter à distance à la console du serveur par un mot de passe. +rcon_enable=Voulez-vous activer RCON? +rcon_password=Mot de passe RCON (vous pouvez le changer plus tard) +usage_info=Les données d'utilisation anonyme vous permettent de calculer les statistiques globales de PocketMine-MP et ses plugins. Vous pouvez les voir sur stats.pocketmine.net +usage_disable=Voulez-vous désactiver l'utilisation anonyme? +ip_get=Obtention de votre IP externe et IP interne +ip_warning=Votre IP externe est {{EXTERNAL_IP}}. Vous pourriez avoir à transmettre au port votre IP interne {{INTERNAL_IP}} +ip_confirm=Vérifiez-le bien, si vous avancez et sautez cette étape, les joueurs extérieurs ne pourront pas rejoindre votre serveur. [Tapez Enter] + +you_have_finished=Vous avez correctement terminé l'assistant d'installation +pocketmine_will_start=PocketMine-MP démarre. Tapez /help pour voir la liste des commandes disponibles. +pocketmine_plugins=Vérification du répertoire de plugin pour ajouter des nouvelles caractéristiques, mini-jeux, ou une protection avancée de votre serveur diff --git a/src/lang/Installer/ga_IE.ini b/src/lang/Installer/ga_IE.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/ga_IE.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/he_IL.ini b/src/lang/Installer/he_IL.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/he_IL.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/id_ID.ini b/src/lang/Installer/id_ID.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/id_ID.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/it_IT.ini b/src/lang/Installer/it_IT.ini new file mode 100644 index 00000000..d66b9f79 --- /dev/null +++ b/src/lang/Installer/it_IT.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Italiano selezionato correttamente. +skip_installer=Vuoi evitare il programma di installazione? + +welcome_to_pocketmine=Benvenuto in PocketMine-MP!\nPrima di iniziare a impostare il tuo nuovo server devi accettare la licenza.\nPocketMine-MP è distribuito sotto licenza LGPL,\nche potrai leggere aprendo il file LICNESE in questa cartella. +accept_license=Accetti i termini della licenza? +you_have_to_accept_the_license=Devi accettare i termini della licenza LGPL per continuare ad usare PocketMine-MP + +setting_up_server_now=Stai per iniziare ad impostare il tuo server. +default_values_info=Se non vuoi cambiare i valori proposti, premi Invio. +server_properties=Potrai modificarli in seguito nel file server.properties. + +name_your_server=Dai un nome al tuo server +port_warning=Non cambiare la porta predefinita se questo è il tuo primo server. +server_port=Porta del server +invalid_port=Porta del server non valida +ram_warning=La RAM è la massima quantità di memoria che PocketMine-MP potrà usare. Un valore di 128-256 MB è raccomandata +server_ram=RAM del server in MB +gamemode_info=Scegli tra Creative (1) o Survival (0) +default_gamemode=Modalità di gioco predefinita +max_players=Players massimi +spawn_protection_info=La protezione dello spawn non permette di piazzare/rompere blocchi nella zona di spawn, ad eccezione degli Operatori +spawn_protection=Abilitare la protezione dello spawn? + +op_info=Un Operatore (OP) è un player amministratore del server. Gli operatori possono usare più comandi dei players normali +op_who=Nome del player OP (ad esempio, il tuo nome in gioco) +op_warning=Sarà possibile aggiungere un player OP più tardi con /op +whitelist_info=La white-list permette solo ad i players in lista di entrare. +whitelist_enable=Vuoi abilitare la white-list? +whitelist_warning=Dovrai aggiungere i players in white-list + +query_warning1=Query è un protocollo usato da differenti programmi per ottenere informazioni dal tuo server e dai player che ci entrano. +query_warning2=Se lo disabiliti, non sarai in grado di usare le liste server. +query_disable=Vuoi disabilitare Query? +rcon_info=RCON è un protocollo per connessioni remote con la console del server grazie all'utilizzo di una password. +rcon_enable=Vuoi abilitare RCON? +rcon_password=Password RCON (potrai cambiarla più tardi) +usage_info=L'invio anonimo dei dati di utilizzo ci aiuta a calcolare statistiche generali per PocketMine-MP ed i suoi plugins. Puoi vederle su stats.pocketmine.net +usage_disable=Vuoi disabilitare l'invio anonimo dei dati di utilizzo? +ip_get=Ottengo il tuo indirizzo IP interno ed esterno +ip_warning=Il tuo indirizzo IP è {{EXTERNAL_IP}}. Potresti dover redirigere le porte al tuo IP interno: {{INTERNAL_IP}} +ip_confirm=Sii sicuro di farlo, se devi redirigere le porte e non lo fai, nessun player esterno sarà in grado di entrare. [Premi Invio] + +you_have_finished=Hai completato l'installazione con successo +pocketmine_will_start=Ora PocketMine-MP si avvierà. Digita /help per visualizzare la lista dei comandi disponibili. +pocketmine_plugins=Controlla il Repository dei Plugins per aggiungere nuove funzionalità, minigiochi, o protezioni avanzate al tuo server diff --git a/src/lang/Installer/ja_JP.ini b/src/lang/Installer/ja_JP.ini new file mode 100644 index 00000000..c49e2733 --- /dev/null +++ b/src/lang/Installer/ja_JP.ini @@ -0,0 +1,45 @@ +language_has_been_selected=日本語に設定されました +skip_installer=セットアップウィザードをスキップしますか? + +welcome_to_pocketmine=PocketMine-MPをインストールして頂きありがとうございます!サーバのセットアップを開始するにはライセンスに同意する必要があります。PocketMine-MPはLGPLライセンスに基づいて認可されており、これについてはこのフォルダ内のLICENSEファイルから確認することができます。 +accept_license=ライセンスに同意しますか? +you_have_to_accept_the_license=PocketMine-MPを使用するにはLGPLライセンスに同意する必要があります + +setting_up_server_now=サーバのセットアップを開始します +default_values_info=設定を変更しない場合は、Enterキーを押してください。 +server_properties=それらの設定は後からでもserver.propertiesファイルから変更できます + +name_your_server=あなたのサーバに名前を付けてください +port_warning=これが初めてのサーバの場合は、ポート番号をデフォルトから変更しないでください +server_port=サーバポート +invalid_port=不適切なサーバポートです +ram_warning=RAMはPocketMine-MPが使用し得るメモリの最大値を示しています。128-256MBの範囲内で指定することを推奨します。 +server_ram=RAMの単位はMBです +gamemode_info=クリエイティブモード(1)、またはサバイバルモード(0)を選択してください +default_gamemode=デフォルトのゲームモード +max_players=最大プレイヤー数 +spawn_protection_info=スポーンプロテクションは、OPでないプレイヤーによるスポーン地点付近でのブロックの設置/破壊を制限します +spawn_protection=スポーンプロテクションを有効にしますか? + +op_info=OPとはそのサーバの管理権限を指します。OPを持ったプレイヤーは他のプレイヤーよりも多くのコマンドを使用できます。 +op_who=OPプレイヤー名(例: あなたのゲーム内での名前) +op_warning=後から/op <プレイヤー名>コマンドを実行してOPプレイヤーを追加することもできます +whitelist_info=ホワイトリストはこのサーバに入ることのできるプレイヤーを制限します。 +whitelist_enable=ホワイトリストを有効にしますか? +whitelist_warning=プレイヤーをホワイトリストに追加してください + +query_warning1=クエリは他のツールによりあなたのサーバやプレイヤーの情報を取得するためのプロトコルです。 +query_warning2=それを無効にした場合、サーバリストを使用できなくなる可能性があります。 +query_disable=クエリを無効にしますか? +rcon_info=RCONはパスワードを用いてサーバコンソールからリモート接続するためのプロトコルです。 +rcon_enable=RCONを有効にしますか? +rcon_password=RCONパスワード(後から変更できます) +usage_info=世界中で使われているPocketMine-MPやそのプラグインの統計を算出するために匿名の使用データが送信されます。統計はこちらから確認できます。stats.pocketmine.net +usage_disable=匿名の使用データの送信を拒否しますか? +ip_get=グローバルIPとプライベートIPの取得 +ip_warning=あなたのグローバルIPは{{EXTERNAL_IP}}です。プライベートIP{{INTERNAL_IP}}をポート解放してください。 +ip_confirm=必ずポート解放ができているか確認してください。ポートが解放できていなかった場合、他のプレイヤーがサーバに入れなくなる恐れがあります。[Enterキーを押してください] + +you_have_finished=セットアップは正しく終了しました +pocketmine_will_start=PocketMine_MPを起動します。/helpと入力すれば使用可能なコマンド一覧を表示できます。 +pocketmine_plugins=拡張機能や管理システム、ミニゲームなどを追加できるプラグインリポジトリも確認してみてください diff --git a/src/lang/Installer/ko_KR.ini b/src/lang/Installer/ko_KR.ini new file mode 100644 index 00000000..9b5a6269 --- /dev/null +++ b/src/lang/Installer/ko_KR.ini @@ -0,0 +1,45 @@ +language_has_been_selected=한국어가 언어로 선택되었습니다. +skip_installer=설치 마법사를 건너뛰겠습니까? + +welcome_to_pocketmine=PocketMine-MP에 오신 것을 환영합니다!\n서버 설치를 시작하기 전, 약관에 동의해야 합니다. \nPocketMine-MP는 GNU 약소 일반 공중 사용 허가서(LGPL) 하에 배포되고 있습니다. \n이 폴더에서 약관을 읽을 수 있습니다. +accept_license=약관에 동의하십니까? +you_have_to_accept_the_license=GNU 약소 일반 공중 사용 허가서(LGPL)에 동의하셔야 PocketMine-MP를 사용할 수 있습니다. + +setting_up_server_now=서버 설정을 시작합니다. +default_values_info=기본값을 수정하고 싶지 않으면, 엔터를 누르십시기 바랍니다. +server_properties=이 설정들은 server.properties 파일에서 세부적으로 변경이 가능합니다. + +name_your_server=당신의 서버 이름을 입력하시기 바랍니다. +port_warning=만약 당신이 서버를 처음 설정한다면 포트 값을 변경하지 마세요. +server_port=서버 포트 +invalid_port=서버 포트가 잘못 입력되었습니다. +ram_warning=RAM 값은 PocketMine-MP에 할당할 메모리의 크기입니다. 128~256MB를 권장합니다. +server_ram=서버 RAM (MB) +gamemode_info=크리에이티브 (1) 또는 서바이벌 (0) 게임모드 중 하나를 고르세요. +default_gamemode=기본 게임 모드 +max_players=최대 동시 접속 인원 수 +spawn_protection_info=스폰 보호는 OP를 제외한 유저들이 스폰 지역 근처에서 블럭을 놓거나 부수는것을 방지합니다. +spawn_protection=스폰 지역 보호를 사용하겠습니까? + +op_info=OP는 서버 관리자를 뜻합니다. OP는 일반 플레이어보다 훨씬 많은 명령어들을 사용할 수 있습니다 +op_who=OP 권한을 줄 플레이어 이름(예: 당신의 닉네임) +op_warning=또는 이후에 /op <플레이어 이름> 을 입력해 그 유저에게 OP 권한을 줄 수도 있습니다 +whitelist_info=화이트리스트를 사용하면 허용된 플레이어들만 서버에 접속할 수 있습니다. +whitelist_enable=화이트리스트를 사용하겠습니까? +whitelist_warning=당신은 접속을 허용할 플레이어들의 이름을 적어야 합니다 + +query_warning1=쿼리 (Query)는 당신의 서버와 현재 접속한 플레이어들의 정보를 알 수 있게 해주는 여러가지 기능이 담긴 프로토콜입니다. +query_warning2=쿼리를 사용하지 않으면, 당신은 서버 리스트를 사용할 수 없게 됩니다. +query_disable=쿼리를 사용하지 않겠습니까? +rcon_info=RCON은 비밀 번호를 사용하여 서버 명령창에 원격으로 접소갈 수 있는 프로토콜입니다. +rcon_enable=RCON 을 사용하시겠습니까? +rcon_password=RCON 비밀번호 설정 (나중에 server.properties 에서 변경이 가능합니다.) +usage_info=익명 사용 통계 전송을 허용하면 PocketMine-MP가 세계의 서버 상황과 플러그인들을 통계화하는 데 사용할 수 있습니다. 당신은 stats.pocketmine.net에서 이를 확인할 수 있습니다 +usage_disable=익명 사용 통계 전송을 사용하지 않으시겠습니까? +ip_get=내/외부 IP 주소 얻기 +ip_warning=당신의 외부 IP는 {{EXTERNAL_IP}}입니다. 당신의 내부 IP {{INTERNAL_IP}}로 포트포워딩이 필요할 수 있습니다 +ip_confirm=신중하게 확인하세요. 만약 포트 포워딩이 필요하지만 하지 않을 경우 외부에서 플레이어들이 접속할 수 없게 됩니다. [계속 하시려면 엔터를 누르세요] + +you_have_finished=PocketMine-MP의 설치가 모두 완료되었습니다. +pocketmine_will_start=PocketMine-MP 서버를 구동합니다. /help로 사용 가능한 모든 명령어의 목록을 보시기 바랍니다. +pocketmine_plugins=플러그인 저장소에서 새로운 기능을 추가하세요. 새로운 기능, 미니게임을 추가하거나 고급 기능으로 당신의 서버를 보호할 수 있습니다 diff --git a/src/lang/Installer/lv_LV.ini b/src/lang/Installer/lv_LV.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/lv_LV.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/ms_MY.ini b/src/lang/Installer/ms_MY.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/ms_MY.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/mt_MT.ini b/src/lang/Installer/mt_MT.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/mt_MT.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/nl_NL.ini b/src/lang/Installer/nl_NL.ini new file mode 100644 index 00000000..fb35e004 --- /dev/null +++ b/src/lang/Installer/nl_NL.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Nederlands is nu geselecteerd. +skip_installer=Wil je de set-up help overslaan? + +welcome_to_pocketmine=Welkom op de PocketMine-MP!\nVoordat je je nieuwe server klaarmaakt, moet je onze gebruikersovereenkomst accepteren.\nPocketMine-MP is gelicenseerd onder LGPL License,\nwat je kunt lezen door de LICENSE file in deze map te openen. +accept_license=Accepteer je de gebruikersvoorwaarden? +you_have_to_accept_the_license=Je moet de LGPL gebruikersvoorwaarden accepteren voordat je verder gaat met het gebruiken van de services van PocketMine-MP + +setting_up_server_now=Je gaat nu een server klaarmaken voor gebruik. +default_values_info=Druk op Enter als je de gebruikelijke waarde niet wilt veranderen. +server_properties=Je kunt ze later veranderen in het server.properties bestand. + +name_your_server=Geef een naam aan je server +port_warning=Verander de gebruikelijke poort niet als dit je eerste server is. +server_port=Server poort +invalid_port=Ongeldige server poort +ram_warning=De RAM is het maximale aantal memory wat PocketMine-MP zal gebruiken. Een aantal tussen de 128 en de 256 MB is aanbevolen +server_ram=Server RAM in MB +gamemode_info=Kies tussen Creative (1) of Survival (0) +default_gamemode=Gebruikelijke spelmodus +max_players=Maximale online spelers +spawn_protection_info=De spawnbeveiliging verbiedt het plaatsen/slopen van blokken in het spawn gebied behalve voor OP's +spawn_protection=Wil je spawnbeveiliging aanzetten? + +op_info=Een OP is de beheerder van de server. OP's kunnen meer commando's gebruiken dan normale spelers +op_who=OP speler naam (voorbeeld: je username) +op_warning=Je kunt later meerdere OP's toevoegen met het commando /op +whitelist_info=De whitelist laat alleen de spelers die in de lijst staan op de server. +whitelist_enable=Wil je de whitelist aanzetten? +whitelist_warning=Je moet wel spelers aan de whitelist toevoegen. + +query_warning1=Query is een protocol dat gebruikt wordt door verschillende programma's om informatie te verkrijgen van je server en welke spelers ingelogd zijn. +query_warning2=Als je het uitzet, zul je geen mogelijkheid hebben om server lijsten te gebruiken. +query_disable=Wil je Query uitschakelen? +rcon_info=RCON is een protocol om je server op afstand te beheren via de server console door middel van een wachtwoord. +rcon_enable=Wil je RCON aanzetten? +rcon_password=RCON wachtwoord (deze kun je later veranderen) +usage_info=De anonieme gebruikersdata laat ons toe om de globale statistieken voor PocketMine-ML te zien en zijn plugins. Je kunt de statistieken zien op stats.pocketmine.net +usage_disable=Wil je anonieme data uitschakelen? +ip_get=Je externe IP en interne IP verkrijgen +ip_warning=Je externe IP is {{EXTERNAL_IP}}. Het is mogelijk dat je moet port-forwarden naar je interne IP:{{INTERNAL_IP}} +ip_confirm=Wees niet bang om het te controleren, als je moet port-forwarden en je slaat dit over, kunnen externe spelers niet op de server. + +you_have_finished=Je hebt de set-up help volledig beëindigd. +pocketmine_will_start=PocketMine-MP zal nu opstarten. Type /help om de lijst van beschikbare commando's te weergeven. +pocketmine_plugins=Check de Plugin Opslag om nieuwe features, minigames of geavanceerde spawnbeveiliging toe te voegen aan je server diff --git a/src/lang/Installer/no_NO.ini b/src/lang/Installer/no_NO.ini new file mode 100644 index 00000000..47bddd41 --- /dev/null +++ b/src/lang/Installer/no_NO.ini @@ -0,0 +1,20 @@ +language_has_been_selected=Norsk har blitt valgt. +skip_installer=Vil du hoppe over utpakking trollmannen? + +welcome_to_pocketmine=Velkommen til PocketMine-MP!\nFør vi starter med å sette opp din nye server må du akseptere vår lisens.\nPocketMine-MP er lisensiert under LGPL lisensen,\nat du kan lese LISENS filen i denne mappen. +accept_license=Aksepterer du lisensen? +you_have_to_accept_the_license=Du må akseptere LGPL lisensen for å fortsette med å bruke PocketMine-MP + +setting_up_server_now=Nå skal du sette opp din server. +default_values_info=Hvis du ikke vil gjøre forskjell med den ordinære verdien, så trenger du bare å trykke Enter. +server_properties=Du kan redigere dem senere i server.properties filen. + +name_your_server=Gi et navn til din server +port_warning=Ikke bytt på den vanlige port verdien vis dette er din første server. +server_port=Server port +invalid_port=Ugyldig server port +ram_warning=RAMMEN er den maksimale beløpet PocketMine-MP vil bruke. A verdien av 128-256 MB er anbefalt +server_ram=Server RAMMEN i MB + + + diff --git a/src/lang/Installer/pl_PL.ini b/src/lang/Installer/pl_PL.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/pl_PL.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/pt_PT.ini b/src/lang/Installer/pt_PT.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/pt_PT.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/ru_RU.ini b/src/lang/Installer/ru_RU.ini new file mode 100644 index 00000000..3975abef --- /dev/null +++ b/src/lang/Installer/ru_RU.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Английский был выбран правильно. +skip_installer=Вы хотите пропустить мастер настройки? + +welcome_to_pocketmine=Добро пожаловать в PocketMine-MP!\nПеред началом установки нового сервера, вы должны согласиться с лицензией. \nPocketMine-MP лицензировано на условиях LGPL лицензии, \nс которой вы можете ознакомиться, открыв файл LICENSE в этой папке. +accept_license=Принимаете ли вы лицензию? +you_have_to_accept_the_license=Вы должны принять LGPL лицензию, чтобы продолжить использование PocketMine-MP + +setting_up_server_now=Теперь вы можете настроить сервер. +default_values_info=Если вы не хотите изменять стандартное значение, просто нажмите Enter. +server_properties=Вы можете редактировать их позже в файле server.properties. + +name_your_server=Дайте имя вашему серверу +port_warning=Не изменяйте значение порта по умолчанию, если это ваш первый сервер. +server_port=Порт сервера +invalid_port=Неверный порт сервера +ram_warning=RAM - максимальный объем памяти, котооый будет использовать PocketMine-MP, рекомендуемое значение 128-256 МБ +server_ram=Оперативная память сервера в МБ +gamemode_info=Выберите между Креативом-(1), или Выживанием (0) +default_gamemode=Режим игры по умолчанию +max_players=Максимум онлайн игроков +spawn_protection_info=Защита спавна запрещает размещение/разрушение блоков на спавне, за исключением операторов +spawn_protection=Включить защиту спавна? + +op_info=Оператор - Администратор сервера, который может использовать больше команд, чем обычный игрок +op_who=Имя оператора (К примеру ваш ник в игре) +op_warning=Вы можете добавить оператора позже используя команду /op +whitelist_info=White-list позволяет присоединиться только игрокам в этом списке. +whitelist_enable=Вы хотите включить white-list? +whitelist_warning=Вам придётся добавить игроков в white-list + +query_warning1=Query это протокол, используемый разными инструментами, чтобы получить информацию о вашем сервере и о зашедших игроках. +query_warning2=Если вы отключите его, вы не сможете использовать списки серверов. +query_disable=Вы хотите отключить Query? +rcon_info=RCON - это протокол для удаленного управления сервером через консоль, с использованием пароля. +rcon_enable=Вы хотите включить RCON? +rcon_password=RCON пароль (вы сможете изменить его позже) +usage_info=Сбор анонимных данных о использовании поможет нам проанализировать глобальную статистику для PocketMine-MP и плагинов. Статистика доступна по адресу stats.pocketmine.net +usage_disable=Вы хотите отключить сбор анонимных данных о использовании? +ip_get=Получение вашего внешнего и внутреннего IP адреса +ip_warning=Ваш внешний IP адрес: {{EXTERNAL_IP}}. Возможно вам необходимо открыть порты к вашему внутреннему IP адресу: {{INTERNAL_IP}} +ip_confirm=Убедитесь в том, что вы открыли порты, в противном случае игроки вне вашей локальной сети не смогут подключится. [Нажмите Enter] + +you_have_finished=Вы закончили работу с мастером установки +pocketmine_will_start=PocketMine-MP сейчас запустится. Введите /help для просмотра доступных вам команд. +pocketmine_plugins=Посетите репозиторий плагинов для получения новых функций, мини-игр, или повышения защиты вашего сервера diff --git a/src/lang/Installer/sv_SE.ini b/src/lang/Installer/sv_SE.ini new file mode 100644 index 00000000..86b9fab5 --- /dev/null +++ b/src/lang/Installer/sv_SE.ini @@ -0,0 +1,45 @@ +language_has_been_selected=Svenska har bilvit valt. +skip_installer=Vill du hoppa över Installations programmet? + +welcome_to_pocketmine=Välkommen till PocketMine-MP! Före du börja ställa in din server måste du godkänna licensen. PocketMIne-MP är licenserat under LGPL Licensen som du kan läsa genom att öppna LICENSE filen i den här mappen. +accept_license=Accepterar du Licensen? +you_have_to_accept_the_license=Du måste godkänna LGPL licensen för att fortsätta använda PocketMine-MP + +setting_up_server_now=Du håller på att börja ställa in din server nu. +default_values_info=Om du inte vill ändra standard värdet, tryck bara ENTER. +server_properties=Du kan redigera dem senare i server.properies filen. + +name_your_server=Ge ett namn till din server +port_warning=ändra INTE standard porten om detta är din första server. +server_port=Server port +invalid_port=Ogiltig Server port +ram_warning=RAM är max mängden minne PocketMine-MP kommer använda. Ett väre av 128-256 MB är rekommenderat +server_ram=Server RAM i MB +gamemode_info=Välj mellan Kreativt läge (1) eller Överlevnad (0) +default_gamemode=Standard spelläge +max_players=Max spelare online +spawn_protection_info=Spawn skydd stoppar spelare från att bygga / krossa block i Spawn-zonen förutom för OPs +spawn_protection=Aktivera Spawn-skydd? + +op_info=En OP är en spelar Administratör på servern. OPs kan köra fler kommandon än vanliga spelare +op_who=OP spelar namn (Ditt IGN här) +op_warning=Du kommer kunna lägga till fler OPs senare me /op +whitelist_info=whitelisten är en lista på spelare som får komma in på servern. +whitelist_enable=Vill du aktivera whitelisten? +whitelist_warning=Du måste i så fall lägga till spelare på whitelisten + +query_warning1=Query är ett protokoll som används av olika verktyg för att samla in information om din server och spelare loggade in. +query_warning2=Om du stänger av den så kommer du inte kunna använda serverlistor. +query_disable=Vill du stänga av Query? +rcon_info=RCON är ett protocol för att trådlöst ansluta till server konsolen med ett lösenord. +rcon_enable=Vill du aktivera RCON? +rcon_password=RCON lösenord (kan bytas senare) +usage_info=Anonym data användning tillåter oss att räkna ut global statistik för PocketMine-MP och dess plugin. Du kan se dessa på stats.pocketmine.net +usage_disable=Vill du stänga av anonym data använding? +ip_get=Hämtar din externa IP och interna IP +ip_warning=Din externa Ip är {{EXTERNAL_IP}}} Du kan behöva göra en "port-foward" till din Interna IP {{INTERNAL_IP}} +ip_confirm=Var säker på att du kollar den. Om du måste göra en "port-foward" men skippar det så kommer inga externa spelare att kunna logga in på din server. [Tryck på ENTER] + +you_have_finished=Du är nu klar. Allt har genomförts korrekt +pocketmine_will_start=Din Server kommer nu att starta. skriv /help eller /? för en list på tillgängliga kommandon. +pocketmine_plugins=Kolla in Plugin Hemsidan för att lägga till nya saker till din server, minispel, eller avancerat skydd diff --git a/src/lang/Installer/th_TH.ini b/src/lang/Installer/th_TH.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/th_TH.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/tlh_AA.ini b/src/lang/Installer/tlh_AA.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/tlh_AA.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/tr_TR.ini b/src/lang/Installer/tr_TR.ini new file mode 100644 index 00000000..afbb875f --- /dev/null +++ b/src/lang/Installer/tr_TR.ini @@ -0,0 +1,12 @@ +language_has_been_selected=İngilizce seçildi. +skip_installer=Kurulum yazılımını atlamak istiyormusunuz? + +accept_license=Lisansı kabul ediyormusunuz? +you_have_to_accept_the_license=PocketMine-MP'yi kullanabilmeniz için LGPL lisansını kabul etmeniz gereklidir + +setting_up_server_now=Sunucunuz şimdi kurulacak, Devam edilsin mi? + +invalid_port=Yanlış sunucu port'u + + + diff --git a/src/lang/Installer/uk_UA.ini b/src/lang/Installer/uk_UA.ini new file mode 100644 index 00000000..6fb66a5e --- /dev/null +++ b/src/lang/Installer/uk_UA.ini @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/lang/Installer/vi_VN.ini b/src/lang/Installer/vi_VN.ini new file mode 100644 index 00000000..c2bf66de --- /dev/null +++ b/src/lang/Installer/vi_VN.ini @@ -0,0 +1,31 @@ +language_has_been_selected=Tiếng Anh đã được chọn. +skip_installer=Bạn có muốn bỏ qua hướng dẫn set-up? + +welcome_to_pocketmine=Chào mừng tới PocketMine-MP!\nTrước khi bắt đầu, bạn phải chấp nhận hợp đồng. \nPocketMine-MP được hợp đồng bởi LGPL License,\nbạn có thể đọc file LICENSE trong thư mục này. +accept_license=Bạn có chấp nhận hợp đồng ? +you_have_to_accept_the_license=Bạn phải chấp nhận LGPL license để sử dụng PocketMine-MP + +setting_up_server_now=Bạn sẽ bắt đầu set up server của bạn ngay. +default_values_info=Nếu bạn không muốn đổi giá trị mặc định, nhấn Enter. +server_properties=Bạn có thể chỉnh sửa lại vào file server.properties . + +name_your_server=Đặt tên server +port_warning=Không được đổi giá trị port mặc định nếu đây là server đầu tiên của bạn. +server_port=Server port +invalid_port=Server port không đúng +ram_warning=RAM là tất cả bộ nhớ mà PocketMine-MP sẽ sử dụng. 128/256 MB là cần thiết +server_ram=Server RAM theo MB +gamemode_info=Chọn Creative (1) hoặc Survival (0) +default_gamemode=Chế độ mặc định +max_players=Giới hạn lượng người chơi +spawn_protection_info=Spawn protection không cho phép đặt/đập trong khu vực hồi sinh trừ OPs +spawn_protection=Mở Spawn protection? + +op_info=OP là chủ/quản lí server. OPs có nhiều quyền hạn hơn người thường +op_who=Tên OP (ví dụ, tên bạn) +op_warning=Bạn có thể thêm OP bằng lệnh /op +whitelist_info=White-list chỉ cho người có phép của quản lí tham gia. +whitelist_enable=Bạn có muốn bật white-list? +whitelist_warning=Bạn sẽ phải thêm người chơi vào white-list + + diff --git a/src/lang/Installer/zh_CN.ini b/src/lang/Installer/zh_CN.ini new file mode 100644 index 00000000..4f04f81b --- /dev/null +++ b/src/lang/Installer/zh_CN.ini @@ -0,0 +1,46 @@ +language_has_been_selected=您现在选择了简体中文. +skip_installer=您想跳过安装向导吗? + +welcome_to_pocketmine=欢迎来到PocketMine-MP!\n在开始使用您的新服务器之前您需要接受以下协议\nPocketMine-MP使用了LGPL协议,\n你可以在这个文件夹中找到LICENCE文件. +accept_license=您接受协议内容吗? +you_have_to_accept_the_license=您接受了LGPL协议来继续使用PocketMine-MP + +setting_up_server_now=你现在要开始设置您的服务器了 +default_values_info=如果您希望留住默认设置请直接按下回车键. +server_properties=您以后可以在server.properties中修改设置. + +name_your_server=命名您的服务器: +port_warning=尽量不要改变端口如果这是您第一次设置服务器. +server_port=服务器端口: +invalid_port=不正确的服务器端口. +ram_warning=RAM是PocketMine-MP可用的最大内存. 推荐范围: 128-256 MB +server_ram=分配给服务器的内存(MB): +gamemode_info=选择模式: (1)生存模式 或 (2)创造模式 +default_gamemode=默认游戏模式 +max_players=最大在线人数 +spawn_protection_info=出生点保护可以在出生点范围内保护所有方块不被摆放/破坏. +spawn_protection=启用出生点保护? + +op_info=OP是一个服务器的管理员, 可以执行比普通玩家更多的命令. +op_who=OP的用户名是什么? +op_warning=你可以执行\"/op <用户名>\"来添加OP. +whitelist_info=白名单可以只允许在其列表内的玩家加入. +whitelist_enable=您想启用白名单吗? +whitelist_warning=你可以用"/whitelist add <用户名>"把别人加入白名单. + +query_warning1=请求是一个用于不同的程序的协议用来获取您服务器数据和登录的玩家. +query_warning2=如果您禁止了它, 您将不能使用服务器列表. +query_disable=您希望禁用Query请求吗? +rcon_info=RCON是一个用来远程连接到服务器控制台的协议(需要密码). +rcon_enable=您希望启用RCON吗? +rcon_password=RCON密码 (您也以后更改它) : +usage_info=匿名数据让我们可以获得全球的PocketMine-MP和它的插件的统计信息. 您可以在 stats.pocketmine.net 查看统计信息. + +usage_disable=您希望禁用匿名数据吗? +ip_get=获得你的外部IP和内部IP +ip_warning=您的外部IP是 {{EXTERNAL_IP}} . 您可能需要端口转发到您的内网IP {{INTERNAL_IP}} . +ip_confirm=请确认您检查了它, 如果您直接进入下一步并跳过这一步, 没有外部的玩家可以加入. [按\"回车\"键] + +you_have_finished=您已经成功完成了服务器设置向导. +pocketmine_will_start=PocketMine-MP现在开始运行. 输入 \"/help\" 来看所有可用的命令. +pocketmine_plugins=请查看插件源来添加新的功能, 迷你游戏或者对服务器的高级保护. diff --git a/src/lang/Installer/zu_ZA.ini b/src/lang/Installer/zu_ZA.ini new file mode 100644 index 00000000..a47ed8d9 --- /dev/null +++ b/src/lang/Installer/zu_ZA.ini @@ -0,0 +1,45 @@ +language_has_been_selected={crwdns106:0}{crwdne106:0} +skip_installer={crwdns107:0}{crwdne107:0} + +welcome_to_pocketmine={crwdns108:0}{crwdne108:0} +accept_license={crwdns109:0}{crwdne109:0} +you_have_to_accept_the_license={crwdns110:0}{crwdne110:0} + +setting_up_server_now={crwdns111:0}{crwdne111:0} +default_values_info={crwdns112:0}{crwdne112:0} +server_properties={crwdns113:0}{crwdne113:0} + +name_your_server={crwdns114:0}{crwdne114:0} +port_warning={crwdns115:0}{crwdne115:0} +server_port={crwdns116:0}{crwdne116:0} +invalid_port={crwdns117:0}{crwdne117:0} +ram_warning={crwdns118:0}{crwdne118:0} +server_ram={crwdns119:0}{crwdne119:0} +gamemode_info={crwdns120:0}{crwdne120:0} +default_gamemode={crwdns121:0}{crwdne121:0} +max_players={crwdns122:0}{crwdne122:0} +spawn_protection_info={crwdns123:0}{crwdne123:0} +spawn_protection={crwdns124:0}{crwdne124:0} + +op_info={crwdns125:0}{crwdne125:0} +op_who={crwdns126:0}{crwdne126:0} +op_warning={crwdns127:0}{crwdne127:0} +whitelist_info={crwdns128:0}{crwdne128:0} +whitelist_enable={crwdns129:0}{crwdne129:0} +whitelist_warning={crwdns130:0}{crwdne130:0} + +query_warning1={crwdns131:0}{crwdne131:0} +query_warning2={crwdns132:0}{crwdne132:0} +query_disable={crwdns133:0}{crwdne133:0} +rcon_info={crwdns134:0}{crwdne134:0} +rcon_enable={crwdns135:0}{crwdne135:0} +rcon_password={crwdns136:0}{crwdne136:0} +usage_info={crwdns137:0}{crwdne137:0} +usage_disable={crwdns138:0}{crwdne138:0} +ip_get={crwdns139:0}{crwdne139:0} +ip_warning={crwdns140:0}{{EXTERNAL_IP}}{crwdnd140:0}{{INTERNAL_IP}}{crwdne140:0} +ip_confirm={crwdns141:0}{crwdne141:0} + +you_have_finished={crwdns142:0}{crwdne142:0} +pocketmine_will_start={crwdns143:0}{crwdne143:0} +pocketmine_plugins={crwdns144:0}{crwdne144:0} diff --git a/src/material/block/DoorBlock.php b/src/material/block/DoorBlock.php index 06c0c4bc..185dd414 100644 --- a/src/material/block/DoorBlock.php +++ b/src/material/block/DoorBlock.php @@ -125,13 +125,13 @@ class DoorBlock extends TransparentBlock{ $this->level->setBlock($down, BlockAPI::get($this->id, $meta), true, false, true); $players = ServerAPI::request()->api->player->getAll($this->level); unset($players[$player->CID]); - ServerAPI::request()->api->player->broadcastPacket($players, MC_LEVEL_EVENT, array( - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "evid" => 1003, - "data" => 0 - )); + $pk = new LevelEventPacket; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->evid = 1003; + $pk->data = 0; + ServerAPI::request()->api->player->broadcastPacket($players, $pk); return true; } return false; @@ -140,13 +140,13 @@ class DoorBlock extends TransparentBlock{ $this->level->setBlock($this, $this, true, false, true); $players = ServerAPI::request()->api->player->getAll($this->level); unset($players[$player->CID]); - ServerAPI::request()->api->player->broadcastPacket($players, MC_LEVEL_EVENT, array( - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "evid" => 1003, - "data" => 0 - )); + $pk = new LevelEventPacket; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->evid = 1003; + $pk->data = 0; + ServerAPI::request()->api->player->broadcastPacket($players, $pk); } return true; } diff --git a/src/material/block/liquid/Lava.php b/src/material/block/liquid/Lava.php index 1f7fd557..4e2c2266 100644 --- a/src/material/block/liquid/Lava.php +++ b/src/material/block/liquid/Lava.php @@ -99,7 +99,7 @@ class LavaBlock extends LiquidBlock{ $b = $this->getSide($side); if($b instanceof LavaBlock){ - }else if($b->isFlowable === true){ + }elseif($b->isFlowable === true){ $this->level->setBlock($b, new LavaBlock( min($level + 2,7) ), false, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); } diff --git a/src/material/block/misc/Bed.php b/src/material/block/misc/Bed.php index e664cae8..1e9f46fe 100644 --- a/src/material/block/misc/Bed.php +++ b/src/material/block/misc/Bed.php @@ -29,9 +29,9 @@ class BedBlock extends TransparentBlock{ public function onActivate(Item $item, Player $player){ if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){ - $player->dataPacket(MC_CLIENT_MESSAGE, array( - "message" => "You can only sleep at night" - )); + $pk = new ChatPacket; + $pk->message = "You can only sleep at night"; + $player->dataPacket($pk); return true; } @@ -51,17 +51,17 @@ class BedBlock extends TransparentBlock{ }elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ $b = $blockWest; }else{ - $player->dataPacket(MC_CLIENT_MESSAGE, array( - "message" => "The bed is incomplete" - )); + $pk = new ChatPacket; + $pk->message = "This bed is incomplete"; + $player->dataPacket($pk); return true; } } if($player->sleepOn($b) === false){ - $player->dataPacket(MC_CLIENT_MESSAGE, array( - "message" => "This bed is occupied" - )); + $pk = new ChatPacket; + $pk->message = "This bed is occupied"; + $player->dataPacket($pk); } return true; } diff --git a/src/material/block/solid/Grass.php b/src/material/block/solid/Grass.php index 8082dbcc..fdfa0b3c 100644 --- a/src/material/block/solid/Grass.php +++ b/src/material/block/solid/Grass.php @@ -33,10 +33,10 @@ class GrassBlock extends SolidBlock{ public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ - TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2); if(($player->gamemode & 0x01) === 0){ $player->removeItem(DYE,0x0F,1); } + TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2); return true; }elseif($item->isHoe()){ if(($player->gamemode & 0x01) === 0){ diff --git a/src/math/Vector2.php b/src/math/Vector2.php index 406cd95b..5713f30e 100644 --- a/src/math/Vector2.php +++ b/src/math/Vector2.php @@ -47,6 +47,8 @@ class Vector2{ if(($x instanceof Vector2) === true){ return $this->add($x->x, $x->y); }else{ + $this->x += $x; + $this->y += $y; return new Vector2($this->x + $x, $this->y + $y); } } diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index f3288c9e..f7e149c0 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -20,241 +20,80 @@ */ class MinecraftInterface{ - public $client; public $bandwidth; private $socket; - private $data; - private $chunked; - private $toChunk; - private $needCheck; - function __construct($object, $server, $port = 25565, $listen = false, $client = false, $serverip = "0.0.0.0"){ - $this->socket = new UDPSocket($server, $port, (bool) $listen, $serverip); + private $packets; + function __construct($server, $port = 25565, $serverip = "0.0.0.0"){ + $this->socket = new UDPSocket($server, $port, true, $serverip); if($this->socket->connected === false){ - console("[ERROR] Couldn't bind to $serverip:".$port, true, true, 0); + console("[SEVERE] Couldn't bind to $serverip:".$port, true, true, 0); exit(1); } $this->bandwidth = array(0, 0, microtime(true)); - $this->client = (bool) $client; $this->start = microtime(true); - $this->chunked = array(); - $this->toChunk = array(); - $this->needCheck = array(); - $object->schedule(1, array($this, "checkChunked"), array(), true); + $this->packets = array(); } public function close(){ return $this->socket->close(false); } - protected function getStruct($pid){ - if(isset(Protocol::$raknet[$pid])){ - return Protocol::$raknet[$pid]; - } - return false; - } - public function readPacket(){ - $pk = $this->popPacket(); if($this->socket->connected === false){ - return $pk; + return false; } $buf = ""; $source = false; $port = 1; $len = $this->socket->read($buf, $source, $port); if($len === false or $len === 0){ - return $pk; + return false; } $this->bandwidth[0] += $len; - $this->parsePacket($buf, $source, $port); - return ($pk !== false ? $pk : $this->popPacket()); + return $this->parsePacket($buf, $source, $port); } - private function parsePacket($buf, $source, $port){ - $pid = ord($buf{0}); - $struct = $this->getStruct($pid); - if($struct === false){ - if(ServerAPI::request()->api->dhandle("server.unknownpacket", array( - "pid" => $pid, - "data" => array(), - "raw" => $buf, - "ip" => $source, - "port" => $port - )) !== true){ - console("[ERROR] Unknown Packet ID 0x".Utils::strToHex(chr($pid)), true, true, 2); + private function parsePacket($buffer, $source, $port){ + $pid = ord($buffer{0}); + + if(RakNetInfo::isValid($pid)){ + $parser = new RakNetParser($buffer); + if($parser->packet !== false){ + $parser->packet->ip = $source; + $parser->packet->port = $port; + if(EventHandler::callEvent(new PacketReceiveEvent($parser->packet)) === BaseEvent::DENY){ + return false; + } + return $parser->packet; } return false; - } - - $packet = new Packet($pid, $struct, $buf); - @$packet->parse(); - if($pid === 0x99){ - $CID = PocketMinecraftServer::clientID($source, $port); - if(!isset($this->chunked[$CID]) and $packet->data[0] !== 0){ //Drop packet + }elseif($pid === 0xfe and $buffer{1} === "\xfd" and ServerAPI::request()->api->query instanceof QueryHandler){ + $packet = new QueryPacket; + $packet->ip = $source; + $packet->port = $port; + $packet->buffer = $buffer; + if(EventHandler::callEvent(new PacketReceiveEvent($packet)) === BaseEvent::DENY){ return false; } - switch($packet->data[0]){ - case 0: - $this->initChunked($CID, $source, $port); - return false; - case 1: - $this->stopChunked($CID); - return false; - case 3: - $this->ackChunked($CID, $data[1]["id"], $data[1]["index"]); - return false; - case 4: - $this->receiveChunked($CID, $data[1]["id"], $data[1]["index"], $data[1]["count"], $data[1]["data"]); - return true; - } - } - $this->data[] = array($pid, $packet->data, $buf, $source, $port); - return true; - } - - public function checkChunked($CID){ - $time = microtime(true); - foreach($this->needCheck as $CID => $packets){ - if($packets[-1] < $time){ - $d = $this->chunked[$CID]; - unset($packets[-1]); - foreach($packets as $packet){ - $this->writePacket(0x99, $packet, true, $d[1], $d[2], true); - } - $this->needCheck[$CID][-1] = $time + 5; - } - } - foreach($this->toChunk as $CID => $packets){ - $d = $this->chunked[$CID]; - $raw = ""; - $MTU = 512; - foreach($packets as $packet){ - $raw .= $packet; - if(($len = strlen($packet)) > $MTU){ - $MTU = $len; - } - } - if($MTU > $d[0][2]){ - $this->chunked[$CID][0][2] = $MTU; - }else{ - $MTU = $d[0][2]; - } - $raw = str_split(gzdeflate($raw, DEFLATEPACKET_LEVEL), $MTU - 9); // - 1 - 2 - 2 - 2 - 2 - $count = count($raw); - $messageID = $this->chunked[$CID][0][0]++; - $this->chunked[$CID][0][0] &= 0xFFFF; - if(!isset($this->needCheck[$CID])){ - $this->needCheck[$CID] = array(); - } - $this->needCheck[$CID][$messageID] = array(-1 => $time + 1); - foreach($raw as $index => $r){ - $p = "\x99\x02".Utils::writeShort($messageID).Utils::writeShort($index).Utils::writeShort($count).Utils::writeShort(strlen($r)).$r; - $this->needCheck[$CID][$messageID][$index] = $p; - $this->writePacket(0x99, $p, true, $d[1], $d[2], true); - } - unset($this->toChunk[$CID]); - } - } - - public function isChunked($CID){ - return isset($this->chunked[$CID]); - } - - private function initChunked($CID, $source, $port){ - console("[DEBUG] Starting DEFLATEPacket for $source:$port", true, true, 2); - $this->chunked[$CID] = array( - 0 => array(0, 0, 0), //index, sent/received; MTU - 1 => $source, - 2 => $port, - 3 => array(), //Received packets - ); - $this->writePacket(0x99, array( - 0 => 0, //start - ), false, $source, $port, true); - } - - public function stopChunked($CID){ - if(!isset($this->chunked[$CID])){ + ServerAPI::request()->api->query->handle($packet); + }else{ + $packet = new Packet(); + $packet->ip = $source; + $packet->port = $port; + $packet->buffer = $buffer; + EventHandler::callEvent(new PacketReceiveEvent($packet)); return false; } - $this->writePacket(0x99, array( - 0 => 1, //stop - ), false, $this->chunked[$CID][1], $this->chunked[$CID][2], true); - console("[DEBUG] Stopping DEFLATEPacket for ".$this->chunked[$CID][1].":".$this->chunked[$CID][2], true, true, 2); - $this->chunked[$CID][3] = null; - $this->chunked[$CID][4] = null; - unset($this->chunked[$CID]); - unset($this->toChunk[$CID]); - unset($this->needCheck[$CID]); } - private function ackChunked($CID, $ID, $index){ - unset($this->needCheck[$CID][$ID][$index]); - if(count($this->needCheck[$CID][$ID]) <= 1){ - unset($this->needCheck[$CID][$ID]); - } - } - - private function receiveChunked($CID, $ID, $index, $count, $data){ - if(!isset($this->chunked[$CID][3][$ID])){ - $this->chunked[$CID][3][$ID] = array(); - } - $this->chunked[$CID][3][$ID][$index] = $data; - - if(count($this->chunked[$CID][3][$ID]) === $count){ - ksort($this->chunked[$CID][3][$ID]); - $data = gzinflate(implode($this->chunked[$CID][3][$ID]), 524280); - unset($this->chunked[$CID][3][$ID]); - if($data === false or strlen($data) === 0){ - console("[ERROR] Invalid DEFLATEPacket for ".$this->chunked[$CID][1].":".$this->chunked[$CID][2], true, true, 2); - } - $offset = 0; - while(($plen = Utils::readShort(substr($data, $offset, 2), false)) !== 0xFFFF or $offset >= $len){ - $offset += 2; - $packet = substr($data, $offset, $plen); - $this->parsePacket($packet, $this->chunked[$CID][1], $this->chunked[$CID][2]); - } - } - } - - public function popPacket(){ - if(count($this->data) > 0){ - $p = each($this->data); - unset($this->data[$p[0]]); - $p = $p[1]; - return array("pid" => $p[0], "data" => $p[1], "raw" => $p[2], "ip" => $p[3], "port" => $p[4]); - } - return false; - } - - public function writePacket($pid, $data = array(), $raw = false, $dest = false, $port = false, $force = false){ - $CID = PocketMinecraftServer::clientID($dest, $port); - if($raw === false){ - $packet = new Packet($pid, $this->getStruct($pid)); - $packet->data = $data; - @$packet->create(); - if($force === false and $this->isChunked($CID)){ - if(!isset($this->toChunk[$CID])){ - $this->toChunk[$CID] = array(); - } - $this->toChunk[$CID][] = $packet->raw; - $write = strlen($packet->raw); - }else{ - $write = $this->socket->write($packet->raw, $dest, $port); - $this->bandwidth[1] += $write; - } - }else{ - if($force === false and $this->isChunked($CID)){ - if(!isset($this->toChunk[$CID])){ - $this->toChunk[$CID] = array(); - } - $this->toChunk[$CID][] = $data; - $write = strlen($data); - }else{ - $write = $this->socket->write($data, $dest, $port); - $this->bandwidth[1] += $write; - } + public function writePacket(Packet $packet){ + if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){ + return 0; + }elseif($packet instanceof RakNetPacket){ + $codec = new RakNetCodec($packet); } + $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); + $this->bandwidth[1] += $write; return $write; } diff --git a/src/network/Packet.php b/src/network/Packet.php index 578e9468..abfa75f9 100644 --- a/src/network/Packet.php +++ b/src/network/Packet.php @@ -19,325 +19,9 @@ * */ - -class Packet{ - private $struct; - protected $pid, $packet; - public $data, $raw; - - function __construct($pid, $struct, $data = ""){ - $this->pid = $pid; - $this->offset = 1; - $this->raw = $data; - $this->data = array(); - if($data === ""){ - $this->addRaw(chr($pid)); - } - $this->struct = $struct; - } - - public function create($raw = false){ - foreach($this->struct as $field => $type){ - if(!isset($this->data[$field])){ - $this->data[$field] = ""; - } - if($raw === true){ - $this->addRaw($this->data[$field]); - continue; - } - switch($type){ - case "special1": - switch($this->pid){ - case 0x99: - if($this->data[0] >= 2){ - $this->addRaw(Utils::writeShort($this->data[1]["id"])); - $this->addRaw(Utils::writeShort($this->data[1]["index"])); - if($this->data[0] === 2){ - $this->addRaw(Utils::writeShort($this->data[1]["count"])); - $this->addRaw(Utils::writeShort(strlen($this->data[1]["data"])).$this->data[1]["data"]); - } - } - break; - case 0xc0: - case 0xa0: - $payload = ""; - $records = 0; - $pointer = 0; - sort($this->data[$field], SORT_NUMERIC); - $max = count($this->data[$field]); - while($pointer < $max){ - $type = true; - $curr = $start = $this->data[$field][$pointer]; - for($i = $start + 1; $i < $max; ++$i){ - $n = $this->data[$field][$i]; - if(($n - $curr) === 1){ - $curr = $end = $n; - $type = false; - $pointer = $i + 1; - }else{ - break; - } - } - ++$pointer; - if($type === false){ - $payload .= Utils::writeBool(false); - $payload .= strrev(Utils::writeTriad($start)); - $payload .= strrev(Utils::writeTriad($end)); - }else{ - $payload .= Utils::writeBool(true); - $payload .= strrev(Utils::writeTriad($start)); - } - ++$records; - } - $this->addRaw(Utils::writeShort($records) . $payload); - break; - case 0x05: - $this->addRaw($this->data[$field]); - break; - } - break; - case "customData": - $this->addRaw(chr($this->data[1])); - if($this->data[2]["id"] === false){ - $this->addRaw($this->data[2]["raw"]); - }else{ - switch($this->data[1]){ - case 0x40: - $reply = new CustomPacketHandler($this->data[2]["id"], "", $this->data[2], true); - $this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3)); - $this->addRaw(strrev(Utils::writeTriad($this->data[2]["count"]))); - $this->addRaw(chr($this->data[2]["id"])); - $this->addRaw($reply->raw); - break; - case 0x00: - $raw = new CustomPacketHandler($this->data[2]["id"], "", $this->data[2], true); - $raw = $raw->raw; - $this->addRaw(Utils::writeShort((strlen($raw) + 1) << 3)); - $this->addRaw(chr($this->data[2]["id"])); - $this->addRaw($raw); - break; - } - } - - break; - case "magic": - $this->addRaw(RAKNET_MAGIC); - break; - case "float": - $this->addRaw(Utils::writeFloat($this->data[$field])); - break; - case "triad": - $this->addRaw(Utils::writeTriad($this->data[$field])); - break; - case "itriad": - $this->addRaw(strrev(Utils::writeTriad($this->data[$field]))); - break; - case "int": - $this->addRaw(Utils::writeInt($this->data[$field])); - break; - case "double": - $this->addRaw(Utils::writeDouble($this->data[$field])); - break; - case "long": - $this->addRaw(Utils::writeLong($this->data[$field])); - break; - case "bool": - case "boolean": - $this->addRaw(Utils::writeBool($this->data[$field])); - break; - case "ubyte": - case "byte": - $this->addRaw(Utils::writeByte($this->data[$field])); - break; - case "short": - $this->addRaw(Utils::writeShort($this->data[$field])); - break; - case "string": - $this->addRaw(Utils::writeShort(strlen($this->data[$field]))); - $this->addRaw($this->data[$field]); - break; - default: - $this->addRaw(Utils::writeByte($this->data[$field])); - break; - } - } - } - - private function get($len = true){ - if($len === true){ - $data = substr($this->raw, $this->offset); - $this->offset = strlen($this->raw); - return $data; - } - $data = substr($this->raw, $this->offset, $len); - $this->offset += $len; - return $data; - } - - private function feof(){ - return !isset($this->raw{$this->offset}); - } - - protected function addRaw($str){ - $this->raw .= $str; - return $str; - } - - public function parse(){ - foreach($this->struct as $field => $type){ - switch($type){ - case "special1": - switch($this->pid){ - case 0x07: - $this->data[] = $this->get(5); - break; - case 0x99: - if($this->data[0] >= 2){ // - $messageID = Utils::readShort($this->get(2), false); - $messageIndex = Utils::readShort($this->get(2), false); - $this->data[1] = array("id" => $messageID, "index" => $messageIndex); - if($this->data[0] === 2){ - $this->data[1]["count"] = Utils::readShort($this->get(2), false); - $dataLength = Utils::readShort($this->get(2), false); - $this->data[1]["data"] = $this->get($dataLength); - } - } - break; - case 0xc0: - case 0xa0: - $cnt = Utils::readShort($this->get(2), false); - $this->data[$field] = array(); - for($i = 0; $i < $cnt and !$this->feof(); ++$i){ - if(Utils::readBool($this->get(1)) === false){ - $start = Utils::readTriad(strrev($this->get(3))); - $end = min(Utils::readTriad(strrev($this->get(3))), $start + 4096); - for($c = $start; $c <= $end; ++$c){ - $this->data[$field][] = $c; - } - }else{ - $this->data[$field][] = Utils::readTriad(strrev($this->get(3))); - } - } - break; - case 0x05: - $this->data[] = $this->get(true); - break; - } - break; - case "customData": - $raw = $this->get(true); - $len = strlen($raw); - $offset = 0; - $this->data["packets"] = array(); - while($len > $offset){ - $pid = ord($raw{$offset}); - ++$offset; - $reliability = ($pid & 0b11100000) >> 5; - $hasSplit = ($pid & 0b00010000) >> 4; - $length = Utils::readShort(substr($raw, $offset, 2), false); - $offset += 2; - if($reliability === 2 - or $reliability === 3 - or $reliability === 4 - or $reliability === 6 - or $reliability === 7){ - $messageIndex = Utils::readTriad(strrev(substr($raw, $offset, 3))); - $offset += 3; - }else{ - $messageIndex = 0; - } - - if($reliability === 1 - or $reliability === 3 - or $reliability === 4 - or $reliability === 7){ - $orderIndex = Utils::readTriad(strrev(substr($raw, $offset, 3))); - $offset += 3; - $orderChannel = ord($raw{$offset}); //5 bits, 32 values - ++$offset; - }else{ - $orderIndex = 0; - $orderChannel = 0; - } - - if($hasSplit === 1){ - $splitCount = Utils::readInt(substr($raw, $offset, 4)); - $offset += 4; - $splitID = Utils::readShort(substr($raw, $offset, 2)); - $offset += 2; - $splitIndex = Utils::readInt(substr($raw, $offset, 4)); - $offset += 4; - //error! no split packets allowed! - break; - }else{ - $splitCount = 0; - $splitID = 0; - $splitIndex = 0; - } - - if($length == 0 - or $orderChannel >= 32 - or ($hasSplit === 1 and $splitIndex >= $splitCount)){ - continue; - } - $ln = ceil($length / 8); - $id = ord($raw{$offset}); - ++$offset; - $pak = substr($raw, $offset, $ln - 1); - $offset += $ln - 1; - $pk = new CustomPacketHandler($id, $pak); - $pk->data["length"] = $ln; - $pk->data["id"] = $id; - $pk->data["counter"] = $messageIndex; - $pk->data["packetName"] = $pk->name; - $this->data["packets"][] = array($pid, $pk->data, $pak); - } - break; - case "magic": - $this->data[] = $this->get(16); - break; - case "triad": - $this->data[] = Utils::readTriad($this->get(3)); - break; - case "itriad": - $this->data[] = Utils::readTriad(strrev($this->get(3))); - break; - case "int": - $this->data[] = Utils::readInt($this->get(4)); - break; - case "string": - $this->data[] = $this->get(Utils::readShort($this->get(2))); - break; - case "long": - $this->data[] = Utils::readLong($this->get(8)); - break; - case "byte": - $this->data[] = Utils::readByte($this->get(1)); - break; - case "ubyte": - $this->data[] = ord($this->get(1)); - break; - case "float": - $this->data[] = Utils::readFloat($this->get(4)); - break; - case "double": - $this->data[] = Utils::readDouble($this->get(8)); - break; - case "ushort": - $this->data[] = Utils::readShort($this->get(2), false); - break; - case "short": - $this->data[] = Utils::readShort($this->get(2)); - break; - case "bool": - case "boolean": - $this->data[] = Utils::readBool($this->get(1)); - break; - } - } - } - - - +class Packet extends stdClass{ + public $ip; + public $port; + public $buffer; } \ No newline at end of file diff --git a/src/network/RCON.php b/src/network/RCON.php index 82190c69..c46ca8e5 100644 --- a/src/network/RCON.php +++ b/src/network/RCON.php @@ -55,6 +55,8 @@ class RCON{ for($n = 0; $n < $this->threads; ++$n){ $this->workers[$n]->close(); $this->workers[$n]->join(); + usleep(50000); + $this->workers[$n]->kill(); } @socket_close($this->socket); $this->threads = 0; diff --git a/src/network/UDPSocket.php b/src/network/UDPSocket.php index e21d4a99..72355beb 100644 --- a/src/network/UDPSocket.php +++ b/src/network/UDPSocket.php @@ -64,11 +64,11 @@ class UDPSocket{ return @socket_recvfrom($this->sock, $buf, 65535, 0, $source, $port); } - public function write($data, $dest = false, $port = false){ + public function write($data, $dest, $port){ if($this->connected === false){ return 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, $port); } } diff --git a/src/network/protocol/ProtocolInfo.php b/src/network/protocol/ProtocolInfo.php new file mode 100644 index 00000000..b321c4c2 --- /dev/null +++ b/src/network/protocol/ProtocolInfo.php @@ -0,0 +1,160 @@ + "UnknownPacket", + ProtocolInfo::PING_PACKET => "PingPacket", + ProtocolInfo::PONG_PACKET => "PongPacket", + ProtocolInfo::CLIENT_CONNECT_PACKET => "ClientConnectPacket", + ProtocolInfo::SERVER_HANDSHAKE_PACKET => "ServerHandshakePacket", + ProtocolInfo::DISCONNECT_PACKET => "DisconnectPacket", + ProtocolInfo::LOGIN_PACKET => "LoginPacket", + ProtocolInfo::LOGIN_STATUS_PACKET => "LoginStatusPacket", + ProtocolInfo::READY_PACKET => "ReadyPacket", + ProtocolInfo::MESSAGE_PACKET => "MessagePacket", + ProtocolInfo::SET_TIME_PACKET => "SetTimePacket", + ProtocolInfo::START_GAME_PACKET => "StartGamePacket", + ProtocolInfo::ADD_MOB_PACKET => "AddMobPacket", + ProtocolInfo::ADD_PLAYER_PACKET => "AddPlayerPacket", + ProtocolInfo::REMOVE_PLAYER_PACKET => "RemovePlayerPacket", + ProtocolInfo::ADD_ENTITY_PACKET => "AddEntityPacket", + ProtocolInfo::REMOVE_ENTITY_PACKET => "RemoveEntityPacket", + ProtocolInfo::ADD_ITEM_ENTITY_PACKET => "AddItemEntityPacket", + ProtocolInfo::TAKE_ITEM_ENTITY_PACKET => "TakeItemEntityPacket", + ProtocolInfo::MOVE_ENTITY_PACKET => "MoveEntityPacket", + ProtocolInfo::MOVE_ENTITY_PACKET_POSROT => "MoveEntityPacket_PosRot", + ProtocolInfo::ROTATE_HEAD_PACKET => "RotateHeadPacket", + ProtocolInfo::MOVE_PLAYER_PACKET => "MovePlayerPacket", + ProtocolInfo::REMOVE_BLOCK_PACKET => "RemoveBlockPacket", + ProtocolInfo::UPDATE_BLOCK_PACKET => "UpdateBlockPacket", + ProtocolInfo::ADD_PAINTING_PACKET => "AddPaintingPacket", + ProtocolInfo::EXPLODE_PACKET => "ExplodePacket", + ProtocolInfo::LEVEL_EVENT_PACKET => "LevelEventPacket", + ProtocolInfo::TILE_EVENT_PACKET => "TileEventPacket", + ProtocolInfo::ENTITY_EVENT_PACKET => "EntityEventPacket", + ProtocolInfo::REQUEST_CHUNK_PACKET => "RequestChunkPacket", + ProtocolInfo::CHUNK_DATA_PACKET => "ChunkDataPacket", + ProtocolInfo::PLAYER_EQUIPMENT_PACKET => "PlayerEquipmentPacket", + ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET => "PlayerArmorEquipmentPacket", + ProtocolInfo::INTERACT_PACKET => "InteractPacket", + ProtocolInfo::USE_ITEM_PACKET => "UseItemPacket", + ProtocolInfo::PLAYER_ACTION_PACKET => "PlayerActionPacket", + ProtocolInfo::HURT_ARMOR_PACKET => "HurtArmorPacket", + ProtocolInfo::SET_ENTITY_DATA_PACKET => "SetEntityDataPacket", + ProtocolInfo::SET_ENTITY_MOTION_PACKET => "SetEntityMotionPacket", + ProtocolInfo::SET_HEALTH_PACKET => "SetHealthPacket", + ProtocolInfo::SET_SPAWN_POSITION_PACKET => "SetSpawnPositionPacket", + ProtocolInfo::ANIMATE_PACKET => "AnimatePacket", + ProtocolInfo::RESPAWN_PACKET => "RespawnPacket", + ProtocolInfo::SEND_INVENTORY_PACKET => "SendInventoryPacket", + ProtocolInfo::DROP_ITEM_PACKET => "DropItemPacket", + ProtocolInfo::CONTAINER_OPEN_PACKET => "ContainerOpenPacket", + ProtocolInfo::CONTAINER_CLOSE_PACKET => "ContainerClosePacket", + ProtocolInfo::CONTAINER_SET_SLOT_PACKET => "ContainerSetSlotPacket", + ProtocolInfo::CONTAINER_SET_DATA_PACKET => "ContainerSetDataPacket", + ProtocolInfo::CONTAINER_SET_CONTENT_PACKET => "ContainerSetContentPacket", + ProtocolInfo::CHAT_PACKET => "ChatPacket", + ProtocolInfo::ADVENTURE_SETTINGS_PACKET => "AdventureSettingsPacket", + ProtocolInfo::ENTITY_DATA_PACKET => "EntityDataPacket", + ); + +} + +/***REM_START***/ +require_once(FILE_PATH . "src/network/raknet/RakNetDataPacket.php"); +/***REM_END***/ \ No newline at end of file diff --git a/src/network/protocol/packet/AddEntityPacket.php b/src/network/protocol/packet/AddEntityPacket.php new file mode 100644 index 00000000..9635fb09 --- /dev/null +++ b/src/network/protocol/packet/AddEntityPacket.php @@ -0,0 +1,56 @@ +reset(); + $this->putInt($this->eid); + $this->putByte($this->type); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putInt($this->did); + if($this->did > 0){ + $this->putShort($this->speedX); + $this->putShort($this->speedY); + $this->putShort($this->speedZ); + } + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AddItemEntityPacket.php b/src/network/protocol/packet/AddItemEntityPacket.php new file mode 100644 index 00000000..adc76c0a --- /dev/null +++ b/src/network/protocol/packet/AddItemEntityPacket.php @@ -0,0 +1,52 @@ +reset(); + $this->putInt($this->eid); + $this->putSlot($this->item); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putByte($this->yaw); + $this->putByte($this->pitch); + $this->putByte($this->roll); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AddMobPacket.php b/src/network/protocol/packet/AddMobPacket.php new file mode 100644 index 00000000..3a7f41cb --- /dev/null +++ b/src/network/protocol/packet/AddMobPacket.php @@ -0,0 +1,52 @@ +reset(); + $this->putInt($this->eid); + $this->putInt($this->type); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putByte($this->yaw); + $this->putByte($this->pitch); + $this->put(Utils::writeMetadata($this->metadata)); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AddPaintingPacket.php b/src/network/protocol/packet/AddPaintingPacket.php new file mode 100644 index 00000000..6d0557ce --- /dev/null +++ b/src/network/protocol/packet/AddPaintingPacket.php @@ -0,0 +1,48 @@ +reset(); + $this->putInt($this->eid); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + $this->putInt($this->direction); + $this->putString($this->title); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AddPlayerPacket.php b/src/network/protocol/packet/AddPlayerPacket.php new file mode 100644 index 00000000..426ef480 --- /dev/null +++ b/src/network/protocol/packet/AddPlayerPacket.php @@ -0,0 +1,58 @@ +reset(); + $this->putLong($this->clientID); + $this->putString($this->username); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putByte($this->yaw); + $this->putByte($this->pitch); + $this->putShort($this->unknown1); + $this->putShort($this->unknown2); + $this->put(Utils::writeMetadata($this->metadata)); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AdventureSettingsPacket.php b/src/network/protocol/packet/AdventureSettingsPacket.php new file mode 100644 index 00000000..93094101 --- /dev/null +++ b/src/network/protocol/packet/AdventureSettingsPacket.php @@ -0,0 +1,38 @@ +reset(); + $this->putInt($this->flags); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/AnimatePacket.php b/src/network/protocol/packet/AnimatePacket.php new file mode 100644 index 00000000..d8266f6a --- /dev/null +++ b/src/network/protocol/packet/AnimatePacket.php @@ -0,0 +1,41 @@ +action = $this->getByte(); + $this->eid = $this->getInt(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->action); + $this->putInt($this->eid); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ChatPacket.php b/src/network/protocol/packet/ChatPacket.php new file mode 100644 index 00000000..8c142976 --- /dev/null +++ b/src/network/protocol/packet/ChatPacket.php @@ -0,0 +1,38 @@ +reset(); + $this->putString($this->message); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ChunkDataPacket.php b/src/network/protocol/packet/ChunkDataPacket.php new file mode 100644 index 00000000..05ccb67f --- /dev/null +++ b/src/network/protocol/packet/ChunkDataPacket.php @@ -0,0 +1,42 @@ +reset(); + $this->putInt($this->chunkX); + $this->putInt($this->chunkZ); + $this->put($this->data); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ClientConnectPacket.php b/src/network/protocol/packet/ClientConnectPacket.php new file mode 100644 index 00000000..d5187caa --- /dev/null +++ b/src/network/protocol/packet/ClientConnectPacket.php @@ -0,0 +1,41 @@ +clientID = $this->getLong(); + $this->session = $this->getLong(); + $this->unknown1 = $this->get(1); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ClientHandshakePacket.php b/src/network/protocol/packet/ClientHandshakePacket.php new file mode 100644 index 00000000..b718ebfc --- /dev/null +++ b/src/network/protocol/packet/ClientHandshakePacket.php @@ -0,0 +1,51 @@ +cookie = $this->get(4); + $this->security = $this->get(1); + $this->port = $this->getShort(true); + $this->dataArray0 = $this->get($this->getByte()); + $this->dataArray = $this->getDataArray(9); + $this->timestamp = $this->get(2); + $this->session2 = $this->getLong(); + $this->session = $this->getLong(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerClosePacket.php b/src/network/protocol/packet/ContainerClosePacket.php new file mode 100644 index 00000000..1b962e4f --- /dev/null +++ b/src/network/protocol/packet/ContainerClosePacket.php @@ -0,0 +1,38 @@ +windowid = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->windowid); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerOpenPacket.php b/src/network/protocol/packet/ContainerOpenPacket.php new file mode 100644 index 00000000..a1e9f55a --- /dev/null +++ b/src/network/protocol/packet/ContainerOpenPacket.php @@ -0,0 +1,48 @@ +reset(); + $this->putByte($this->windowid); + $this->putByte($this->type); + $this->putByte($this->slots); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerSetContentPacket.php b/src/network/protocol/packet/ContainerSetContentPacket.php new file mode 100644 index 00000000..e648c94d --- /dev/null +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -0,0 +1,60 @@ +windowid = $this->getByte(); + $count = $this->getShort(); + for($s = 0; $s < $count and !$this->feof(); ++$s){ + $this->slots[$s] = $this->getSlot(); + } + if($this->windowid === 0){ + $count = $this->getShort(); + for($s = 0; $s < $count and !$this->feof(); ++$s){ + $this->hotbar[$s] = $this->getInt(); + } + } + } + + public function encode(){ + $this->reset(); + $this->putByte($this->windowid); + $this->putShort(count($this->slots)); + foreach($this->slots as $slot){ + $this->putSlot($slot); + } + if($this->windowid === 0 and count($this->hotbar) > 0){ + $this->putShort(count($this->hotbar)); + foreach($this->hotbar as $slot){ + $this->putInt($slot); + } + } + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerSetDataPacket.php b/src/network/protocol/packet/ContainerSetDataPacket.php new file mode 100644 index 00000000..e18b6cb7 --- /dev/null +++ b/src/network/protocol/packet/ContainerSetDataPacket.php @@ -0,0 +1,42 @@ +reset(); + $this->putByte($this->windowid); + $this->putShort($this->property); + $this->putShort($this->value); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerSetSlotPacket.php b/src/network/protocol/packet/ContainerSetSlotPacket.php new file mode 100644 index 00000000..6f1a2079 --- /dev/null +++ b/src/network/protocol/packet/ContainerSetSlotPacket.php @@ -0,0 +1,44 @@ +windowid = $this->getByte(); + $this->slot = $this->getShort(); + $this->item = $this->getSlot(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->windowid); + $this->putShort($this->slot); + $this->putSlot($this->item); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/DisconnectPacket.php b/src/network/protocol/packet/DisconnectPacket.php new file mode 100644 index 00000000..42bfaba8 --- /dev/null +++ b/src/network/protocol/packet/DisconnectPacket.php @@ -0,0 +1,35 @@ +reset(); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/DropItemPacket.php b/src/network/protocol/packet/DropItemPacket.php new file mode 100644 index 00000000..e6851d76 --- /dev/null +++ b/src/network/protocol/packet/DropItemPacket.php @@ -0,0 +1,41 @@ +eid = $this->getInt(); + $this->unknown = $this->getByte(); + $this->item = $this->getSlot(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/EntityDataPacket.php b/src/network/protocol/packet/EntityDataPacket.php new file mode 100644 index 00000000..16a59db1 --- /dev/null +++ b/src/network/protocol/packet/EntityDataPacket.php @@ -0,0 +1,47 @@ +x = $this->getShort(); + $this->y = $this->getByte(); + $this->z = $this->getShort(); + $this->namedtag = $this->get(true); + } + + public function encode(){ + $this->reset(); + $this->putShort($this->x); + $this->putByte($this->y); + $this->putShort($this->z); + $this->put($this->namedtag); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/EntityEventPacket.php b/src/network/protocol/packet/EntityEventPacket.php new file mode 100644 index 00000000..8764de02 --- /dev/null +++ b/src/network/protocol/packet/EntityEventPacket.php @@ -0,0 +1,41 @@ +eid = $this->getInt(); + $this->event = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putByte($this->event); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ExplodePacket.php b/src/network/protocol/packet/ExplodePacket.php new file mode 100644 index 00000000..d3c1ef1c --- /dev/null +++ b/src/network/protocol/packet/ExplodePacket.php @@ -0,0 +1,53 @@ +reset(); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putFloat($this->radius); + $this->putInt(@count($this->records)); + if(@count($this->records) > 0){ + foreach($this->records as $record){ + $this->putByte($record->x); + $this->putByte($record->y); + $this->putByte($record->z); + } + } + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/HurtArmorPacket.php b/src/network/protocol/packet/HurtArmorPacket.php new file mode 100644 index 00000000..48a14869 --- /dev/null +++ b/src/network/protocol/packet/HurtArmorPacket.php @@ -0,0 +1,38 @@ +reset(); + $this->putByte($this->health); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/InteractPacket.php b/src/network/protocol/packet/InteractPacket.php new file mode 100644 index 00000000..f1ebd8c4 --- /dev/null +++ b/src/network/protocol/packet/InteractPacket.php @@ -0,0 +1,44 @@ +action = $this->getByte(); + $this->eid = $this->getInt(); + $this->target = $this->getInt(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->action); + $this->putInt($this->eid); + $this->putInt($this->target); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/LevelEventPacket.php b/src/network/protocol/packet/LevelEventPacket.php new file mode 100644 index 00000000..22a44ab5 --- /dev/null +++ b/src/network/protocol/packet/LevelEventPacket.php @@ -0,0 +1,46 @@ +reset(); + $this->putShort($this->evid); + $this->putShort($this->x); + $this->putShort($this->y); + $this->putShort($this->z); + $this->putInt($this->data); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/LoginPacket.php b/src/network/protocol/packet/LoginPacket.php new file mode 100644 index 00000000..a357a27e --- /dev/null +++ b/src/network/protocol/packet/LoginPacket.php @@ -0,0 +1,45 @@ +username = $this->getString(); + $this->protocol1 = $this->getInt(); + $this->protocol2 = $this->getInt(); + $this->clientId = $this->getInt(); + $this->loginData = $this->getString(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/LoginStatusPacket.php b/src/network/protocol/packet/LoginStatusPacket.php new file mode 100644 index 00000000..fce48a7e --- /dev/null +++ b/src/network/protocol/packet/LoginStatusPacket.php @@ -0,0 +1,38 @@ +reset(); + $this->putInt($this->status); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/MessagePacket.php b/src/network/protocol/packet/MessagePacket.php new file mode 100644 index 00000000..11377510 --- /dev/null +++ b/src/network/protocol/packet/MessagePacket.php @@ -0,0 +1,41 @@ +source = $this->getString(); + $this->message = $this->getString(); + } + + public function encode(){ + $this->reset(); + $this->putString($this->source); + $this->putString($this->message); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/MoveEntityPacket.php b/src/network/protocol/packet/MoveEntityPacket.php new file mode 100644 index 00000000..ba0a672d --- /dev/null +++ b/src/network/protocol/packet/MoveEntityPacket.php @@ -0,0 +1,36 @@ +reset(); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/MoveEntityPacket_PosRot.php b/src/network/protocol/packet/MoveEntityPacket_PosRot.php new file mode 100644 index 00000000..fbb046d1 --- /dev/null +++ b/src/network/protocol/packet/MoveEntityPacket_PosRot.php @@ -0,0 +1,48 @@ +reset(); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putFloat($this->yaw); + $this->putFloat($this->pitch); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/MovePlayerPacket.php b/src/network/protocol/packet/MovePlayerPacket.php new file mode 100644 index 00000000..3730f69e --- /dev/null +++ b/src/network/protocol/packet/MovePlayerPacket.php @@ -0,0 +1,56 @@ +eid = $this->getInt(); + $this->x = $this->getFloat(); + $this->y = $this->getFloat(); + $this->z = $this->getFloat(); + $this->yaw = $this->getFloat(); + $this->pitch = $this->getFloat(); + $this->bodyYaw = $this->getFloat(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putFloat($this->yaw); + $this->putFloat($this->pitch); + $this->putFloat($this->bodyYaw); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PingPacket.php b/src/network/protocol/packet/PingPacket.php new file mode 100644 index 00000000..85e01b66 --- /dev/null +++ b/src/network/protocol/packet/PingPacket.php @@ -0,0 +1,38 @@ +time = $this->getLong(); + } + + public function encode(){ + $this->reset(); + $this->putLong($this->time); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerActionPacket.php b/src/network/protocol/packet/PlayerActionPacket.php new file mode 100644 index 00000000..89701b08 --- /dev/null +++ b/src/network/protocol/packet/PlayerActionPacket.php @@ -0,0 +1,47 @@ +action = $this->getInt(); + $this->x = $this->getInt(); + $this->y = $this->getInt(); + $this->z = $this->getInt(); + $this->face = $this->getInt(); + $this->eid = $this->getInt(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php new file mode 100644 index 00000000..b2034542 --- /dev/null +++ b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php @@ -0,0 +1,47 @@ +eid = $this->getInt(); + $this->slots[0] = $this->getByte(); + $this->slots[1] = $this->getByte(); + $this->slots[2] = $this->getByte(); + $this->slots[3] = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putByte($this->slots[0]); + $this->putByte($this->slots[1]); + $this->putByte($this->slots[2]); + $this->putByte($this->slots[3]); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerEquipmentPacket.php b/src/network/protocol/packet/PlayerEquipmentPacket.php new file mode 100644 index 00000000..f323d74d --- /dev/null +++ b/src/network/protocol/packet/PlayerEquipmentPacket.php @@ -0,0 +1,47 @@ +eid = $this->getInt(); + $this->item = $this->getShort(); + $this->meta = $this->getShort(); + $this->slot = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putShort($this->item); + $this->putShort($this->meta); + $this->putByte($this->slot); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/PongPacket.php b/src/network/protocol/packet/PongPacket.php new file mode 100644 index 00000000..453b6514 --- /dev/null +++ b/src/network/protocol/packet/PongPacket.php @@ -0,0 +1,41 @@ +ptime = $this->getLong(); + $this->time = $this->getLong(); + } + + public function encode(){ + $this->reset(); + $this->putLong($this->ptime); + $this->putLong($this->time); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ReadyPacket.php b/src/network/protocol/packet/ReadyPacket.php new file mode 100644 index 00000000..c77fc391 --- /dev/null +++ b/src/network/protocol/packet/ReadyPacket.php @@ -0,0 +1,37 @@ +status = $this->getByte(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RemoveBlockPacket.php b/src/network/protocol/packet/RemoveBlockPacket.php new file mode 100644 index 00000000..2063852d --- /dev/null +++ b/src/network/protocol/packet/RemoveBlockPacket.php @@ -0,0 +1,43 @@ +eid = $this->getInt(); + $this->x = $this->getInt(); + $this->z = $this->getInt(); + $this->y = $this->getByte(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RemoveEntityPacket.php b/src/network/protocol/packet/RemoveEntityPacket.php new file mode 100644 index 00000000..70e7f912 --- /dev/null +++ b/src/network/protocol/packet/RemoveEntityPacket.php @@ -0,0 +1,38 @@ +reset(); + $this->putInt($this->eid); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RemovePlayerPacket.php b/src/network/protocol/packet/RemovePlayerPacket.php new file mode 100644 index 00000000..d0727bb2 --- /dev/null +++ b/src/network/protocol/packet/RemovePlayerPacket.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->eid); + $this->putLong($this->clientID); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RequestChunkPacket.php b/src/network/protocol/packet/RequestChunkPacket.php new file mode 100644 index 00000000..f3f3b604 --- /dev/null +++ b/src/network/protocol/packet/RequestChunkPacket.php @@ -0,0 +1,39 @@ +chunkX = $this->getInt(); + $this->chunkZ = $this->getInt(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RespawnPacket.php b/src/network/protocol/packet/RespawnPacket.php new file mode 100644 index 00000000..f9475efb --- /dev/null +++ b/src/network/protocol/packet/RespawnPacket.php @@ -0,0 +1,47 @@ +eid = $this->getInt(); + $this->x = $this->getFloat(); + $this->y = $this->getFloat(); + $this->z = $this->getFloat(); + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/RotateHeadPacket.php b/src/network/protocol/packet/RotateHeadPacket.php new file mode 100644 index 00000000..41ba3d12 --- /dev/null +++ b/src/network/protocol/packet/RotateHeadPacket.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->eid); + $this->putByte($this->yaw); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SendInventoryPacket.php b/src/network/protocol/packet/SendInventoryPacket.php new file mode 100644 index 00000000..250d3abc --- /dev/null +++ b/src/network/protocol/packet/SendInventoryPacket.php @@ -0,0 +1,61 @@ +eid = $this->getInt(); + $this->windowid = $this->getByte(); + $count = $this->getShort(); + for($s = 0; $s < $count and !$this->feof(); ++$s){ + $this->slots[$s] = $this->getSlot(); + } + if($this->windowid === 1){ //Armir is sent + for($s = 0; $s < 4; ++$s){ + $this->armor[$s] = $this->getSlot(); + } + } + } + + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putByte($this->windowid); + $this->putShort(count($this->slots)); + foreach($this->slots as $slot){ + $this->putSlot($slot); + } + if($this->windowid === 1 and count($this->armor) === 4){ + for($s = 0; $s < 4; ++$s){ + $this->putSlot($this->armor[$s]); + } + } + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/ServerHandshakePacket.php b/src/network/protocol/packet/ServerHandshakePacket.php new file mode 100644 index 00000000..3077acf9 --- /dev/null +++ b/src/network/protocol/packet/ServerHandshakePacket.php @@ -0,0 +1,57 @@ +reset(); + $this->put("\x04\x3f\x57\xfe"); //cookie + $this->put("\xcd"); //Security flags + $this->putShort($this->port); + $this->putDataArray(array( + "\xf5\xff\xff\xf5", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + "\xff\xff\xff\xff", + )); + $this->put("\x00\x00"); + $this->putLong($this->session); + $this->putLong($this->session2); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetEntityDataPacket.php b/src/network/protocol/packet/SetEntityDataPacket.php new file mode 100644 index 00000000..be9ed385 --- /dev/null +++ b/src/network/protocol/packet/SetEntityDataPacket.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->eid); + $this->put(Utils::writeMetadata($this->metadata)); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetEntityMotionPacket.php b/src/network/protocol/packet/SetEntityMotionPacket.php new file mode 100644 index 00000000..70c49232 --- /dev/null +++ b/src/network/protocol/packet/SetEntityMotionPacket.php @@ -0,0 +1,44 @@ +reset(); + $this->putInt($this->eid); + $this->putShort((int) ($this->speedX * 400)); + $this->putShort((int) ($this->speedY * 400)); + $this->putShort((int) ($this->speedZ * 400)); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetHealthPacket.php b/src/network/protocol/packet/SetHealthPacket.php new file mode 100644 index 00000000..66e8f7b5 --- /dev/null +++ b/src/network/protocol/packet/SetHealthPacket.php @@ -0,0 +1,38 @@ +health = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putByte($this->health); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetSpawnPositionPacket.php b/src/network/protocol/packet/SetSpawnPositionPacket.php new file mode 100644 index 00000000..baed71d8 --- /dev/null +++ b/src/network/protocol/packet/SetSpawnPositionPacket.php @@ -0,0 +1,42 @@ +reset(); + $this->putInt($this->x); + $this->putInt($this->z); + $this->putByte($this->y); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/SetTimePacket.php b/src/network/protocol/packet/SetTimePacket.php new file mode 100644 index 00000000..09df60f9 --- /dev/null +++ b/src/network/protocol/packet/SetTimePacket.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->time); + $this->putByte($this->started == true ? 0x80:0x00); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/StartGamePacket.php b/src/network/protocol/packet/StartGamePacket.php new file mode 100644 index 00000000..fe3ead72 --- /dev/null +++ b/src/network/protocol/packet/StartGamePacket.php @@ -0,0 +1,50 @@ +reset(); + $this->putInt($this->seed); + $this->putInt($this->generator); + $this->putInt($this->gamemode); + $this->putInt($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/TakeItemEntity.php b/src/network/protocol/packet/TakeItemEntity.php new file mode 100644 index 00000000..0d6f97cd --- /dev/null +++ b/src/network/protocol/packet/TakeItemEntity.php @@ -0,0 +1,40 @@ +reset(); + $this->putInt($this->target); + $this->putInt($this->eid); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/TileEventPacket.php b/src/network/protocol/packet/TileEventPacket.php new file mode 100644 index 00000000..16ef18cc --- /dev/null +++ b/src/network/protocol/packet/TileEventPacket.php @@ -0,0 +1,46 @@ +reset(); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + $this->putInt($this->case1); + $this->putInt($this->case2); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/UnknownPacket.php b/src/network/protocol/packet/UnknownPacket.php new file mode 100644 index 00000000..38cc2814 --- /dev/null +++ b/src/network/protocol/packet/UnknownPacket.php @@ -0,0 +1,37 @@ +packetID; + } + + public function decode(){ + + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/UpdateBlockPacket.php b/src/network/protocol/packet/UpdateBlockPacket.php new file mode 100644 index 00000000..9fea1461 --- /dev/null +++ b/src/network/protocol/packet/UpdateBlockPacket.php @@ -0,0 +1,46 @@ +reset(); + $this->putInt($this->x); + $this->putInt($this->z); + $this->putByte($this->y); + $this->putByte($this->block); + $this->putByte($this->meta); + } + +} \ No newline at end of file diff --git a/src/network/protocol/packet/UseItemPacket.php b/src/network/protocol/packet/UseItemPacket.php new file mode 100644 index 00000000..be2e988e --- /dev/null +++ b/src/network/protocol/packet/UseItemPacket.php @@ -0,0 +1,61 @@ +x = $this->getInt(); + $this->y = $this->getInt(); + $this->z = $this->getInt(); + $this->face = $this->getInt(); + $this->item = $this->getShort(); + $this->meta = $this->getByte(); //Mojang: fix this + $this->eid = $this->getInt(); + $this->fx = $this->getFloat(); + $this->fy = $this->getFloat(); + $this->fz = $this->getFloat(); + $this->posX = $this->getFloat(); + $this->posY = $this->getFloat(); + $this->posZ = $this->getFloat(); + } + + public function encode(){ + + } + +} \ No newline at end of file diff --git a/src/network/query/QueryHandler.php b/src/network/query/QueryHandler.php new file mode 100644 index 00000000..f300695b --- /dev/null +++ b/src/network/query/QueryHandler.php @@ -0,0 +1,134 @@ +server = ServerAPI::request(); + $addr = ($ip = $this->server->api->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"; + $port = $this->server->api->getProperty("server-port"); + console("[INFO] Setting query port to $port"); + /* + The Query protocol is built on top of the existing Minecraft PE UDP network stack. + Because the 0xFE packet does not exist in the MCPE protocol, + we can identify Query packets and remove them from the packet queue. + + Then, the Query class handles itself sending the packets in raw form, because + packets can conflict with the MCPE ones. + */ + + $this->server->schedule(20 * 30, array($this, "regenerateToken"), array(), true); + $this->regenerateToken(); + $this->lastToken = $this->token; + $this->regenerateInfo(); + console("[INFO] Query running on $addr:$port"); + } + + public function regenerateInfo(){ + $str = ""; + $plist = "PocketMine-MP ".MAJOR_VERSION; + $pl = $this->server->api->plugin->getList(); + if(count($pl) > 0){ + $plist .= ":"; + foreach($pl as $p){ + $plist .= " ".str_replace(array(";", ":", " "), array("", "", "_"), $p["name"])." ".str_replace(array(";", ":", " "), array("", "", "_"), $p["version"]).";"; + } + $plist = substr($plist, 0, -1); + } + $KVdata = array( + "splitnum" => chr(128), + "hostname" => $this->server->name, + "gametype" => ($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP", + "game_id" => "MINECRAFTPE", + "version" => CURRENT_MINECRAFT_VERSION, + "server_engine" => "PocketMine-MP ".MAJOR_VERSION, + "plugins" => $plist, + "map" => $this->server->api->level->getDefault()->getName(), + "numplayers" => count($this->server->clients), + "maxplayers" => $this->server->maxClients, + "whitelist" => $this->server->api->getProperty("white-list") === true ? "on":"off", + "hostport" => $this->server->api->getProperty("server-port"), + //"hostip" => $this->server->api->getProperty("server-ip", "0.0.0.0") + ); + foreach($KVdata as $key => $value){ + $str .= $key."\x00".$value."\x00"; + } + $str .= "\x00\x01player_\x00\x00"; + foreach($this->server->clients as $player){ + if($player->username != ""){ + $str .= $player->username."\x00"; + } + } + $str .= "\x00"; + $this->longData = $str; + $this->timeout = microtime(true) + 5; + } + + public function regenerateToken(){ + $this->lastToken = $this->token; + $this->token = Utils::readInt("\x00".Utils::getRandomBytes(3, false)); + } + + public function handle(QueryPacket $packet){ + $packet->decode(); + switch($packet->packetType){ + case QueryPacket::HANDSHAKE: //Handshake + $pk = new QueryPacket; + $pk->ip = $packet->ip; + $pk->port = $packet->port; + $pk->packetType = QueryPacket::HANDSHAKE; + $pk->sessionID = $packet->sessionID; + $pk->payload = $this->token."\x00"; + $pk->encode(); + $this->server->send($pk); + break; + case QueryPacket::STATISTICS: //Stat + $token = Utils::readInt(substr($packet->payload, 0, 4)); + if($token !== $this->token and $token !== $this->lastToken){ + break; + } + $pk = new QueryPacket; + $pk->ip = $packet->ip; + $pk->port = $packet->port; + $pk->packetType = QueryPacket::STATISTICS; + $pk->sessionID = $packet->sessionID; + if(strlen($packet->payload) === 8){ + if($this->timeout < microtime(true)){ + $this->regenerateInfo(); + } + $pk->payload = $this->longData; + }else{ + $pk->payload = $this->server->name."\x00".(($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP")."\x00".$this->server->api->level->getDefault()->getName()."\x00".count($this->server->clients)."\x00".$this->server->maxClients."\x00".Utils::writeLShort($this->server->api->getProperty("server-port")).$this->server->api->getProperty("server-ip", "0.0.0.0")."\x00"; + } + $pk->encode(); + $this->server->send($pk); + break; + } + } + +} \ No newline at end of file diff --git a/src/network/query/QueryPacket.php b/src/network/query/QueryPacket.php new file mode 100644 index 00000000..d0f0f148 --- /dev/null +++ b/src/network/query/QueryPacket.php @@ -0,0 +1,41 @@ +packetType = ord($this->buffer{2}); + $this->sessionID = Utils::readInt(substr($this->buffer, 3, 4)); + $this->payload = substr($this->buffer, 7); + } + + public function encode(){ + $this->buffer .= chr($this->packetType); + $this->buffer .= Utils::writeInt($this->sessionID); + $this->buffer .= $this->payload; + } +} \ No newline at end of file diff --git a/src/network/raknet/RakNetCodec.php b/src/network/raknet/RakNetCodec.php new file mode 100644 index 00000000..a009f63d --- /dev/null +++ b/src/network/raknet/RakNetCodec.php @@ -0,0 +1,184 @@ +packet = $packet; + $this->buffer =& $this->packet->buffer; + $this->encode(); + } + + private function encode(){ + if(strlen($this->packet->buffer) > 0){ + return; + } + $this->buffer .= chr($this->packet->pid()); + + switch($this->packet->pid()){ + case RakNetInfo::OPEN_CONNECTION_REPLY_1: + $this->buffer .= RakNetInfo::MAGIC; + $this->putLong($this->packet->serverID); + $this->putByte(0); //server security + $this->putShort($this->packet->mtuSize); + break; + case RakNetInfo::OPEN_CONNECTION_REPLY_2: + $this->buffer .= RakNetInfo::MAGIC; + $this->putLong($this->packet->serverID); + $this->putShort($this->packet->port); + $this->putShort($this->packet->mtuSize); + $this->putByte(0); //Server security + break; + case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION: + $this->putByte(RakNetInfo::STRUCTURE); + $this->buffer .= RakNetInfo::MAGIC; + $this->putLong($this->packet->serverID); + break; + case RakNetInfo::UNCONNECTED_PONG: + case RakNetInfo::ADVERTISE_SYSTEM: + $this->putLong($this->packet->pingID); + $this->putLong($this->packet->serverID); + $this->buffer .= RakNetInfo::MAGIC; + $this->putString($this->packet->serverType); + break; + case RakNetInfo::DATA_PACKET_0: + case RakNetInfo::DATA_PACKET_1: + case RakNetInfo::DATA_PACKET_2: + case RakNetInfo::DATA_PACKET_3: + case RakNetInfo::DATA_PACKET_4: + case RakNetInfo::DATA_PACKET_5: + case RakNetInfo::DATA_PACKET_6: + case RakNetInfo::DATA_PACKET_7: + case RakNetInfo::DATA_PACKET_8: + case RakNetInfo::DATA_PACKET_9: + case RakNetInfo::DATA_PACKET_A: + case RakNetInfo::DATA_PACKET_B: + case RakNetInfo::DATA_PACKET_C: + case RakNetInfo::DATA_PACKET_D: + case RakNetInfo::DATA_PACKET_E: + case RakNetInfo::DATA_PACKET_F: + $this->putLTriad($this->packet->seqNumber); + foreach($this->packet->data as $pk){ + $this->encodeDataPacket($pk); + } + break; + case RakNetInfo::NACK: + case RakNetInfo::ACK: + $payload = b""; + $records = 0; + $pointer = 0; + sort($this->packet->packets, SORT_NUMERIC); + $max = count($this->packet->packets); + + while($pointer < $max){ + $type = true; + $curr = $start = $this->packet->packets[$pointer]; + for($i = $start + 1; $i < $max; ++$i){ + $n = $this->packet->packets[$i]; + if(($n - $curr) === 1){ + $curr = $end = $n; + $type = false; + $pointer = $i + 1; + }else{ + break; + } + } + ++$pointer; + if($type === false){ + $payload .= "\x00"; + $payload .= strrev(Utils::writeTriad($start)); + $payload .= strrev(Utils::writeTriad($end)); + }else{ + $payload .= Utils::writeBool(true); + $payload .= strrev(Utils::writeTriad($start)); + } + ++$records; + } + $this->putShort($records); + $this->buffer .= $payload; + break; + default: + + } + + } + + private function encodeDataPacket(RakNetDataPacket $pk){ + $this->putByte(($pk->reliability << 5) | ($pk->hasSplit > 0 ? 0b00010000:0)); + $this->putShort(strlen($pk->buffer) << 3); + if($pk->reliability === 2 + or $pk->reliability === 3 + or $pk->reliability === 4 + or $pk->reliability === 6 + or $pk->reliability === 7){ + $this->putLTriad($pk->messageIndex); + } + + if($pk->reliability === 1 + or $pk->reliability === 3 + or $pk->reliability === 4 + or $pk->reliability === 7){ + $this->putLTriad($pk->orderIndex); + $this->putByte($pk->orderChannel); + } + + if($pk->hasSplit === true){ + $this->putInt($pk->splitCount); + $this->putShort($pk->splitID); + $this->putInt($pk->splitIndex); + } + + $this->buffer .= $pk->buffer; + } + + protected function put($str){ + $this->buffer .= $str; + } + + protected function putLong($v){ + $this->buffer .= Utils::writeLong($v); + } + + protected function putInt($v){ + $this->buffer .= Utils::writeInt($v); + } + + protected function putShort($v){ + $this->buffer .= Utils::writeShort($v); + } + + protected function putTriad($v){ + $this->buffer .= Utils::writeTriad($v); + } + + protected function putLTriad($v){ + $this->buffer .= strrev(Utils::writeTriad($v)); + } + + protected function putByte($v){ + $this->buffer .= chr($v); + } + + protected function putString($v){ + $this->putShort(strlen($v)); + $this->put($v); + } +} \ No newline at end of file diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php new file mode 100644 index 00000000..75ebc44b --- /dev/null +++ b/src/network/raknet/RakNetDataPacket.php @@ -0,0 +1,171 @@ +setBuffer(chr($this->pid())); + } + + public function setBuffer($buffer = ""){ + $this->buffer = $buffer; + $this->offset = 0; + } + + public function getBuffer(){ + return $this->buffer; + } + + protected function get($len){ + if($len <= 0){ + $this->offset = strlen($this->buffer) - 1; + return ""; + } + if($len === true){ + return substr($this->buffer, $this->offset); + } + $this->offset += $len; + return substr($this->buffer, $this->offset - $len, $len); + } + + protected function put($str){ + $this->buffer .= $str; + } + + protected function getLong($unsigned = false){ + return Utils::readLong($this->get(8), $unsigned); + } + + protected function putLong($v){ + $this->buffer .= Utils::writeLong($v); + } + + protected function getInt($unsigned = false){ + return Utils::readInt($this->get(4), $unsigned); + } + + protected function putInt($v){ + $this->buffer .= Utils::writeInt($v); + } + + protected function getShort($unsigned = false){ + return Utils::readShort($this->get(2), $unsigned); + } + + protected function putShort($v){ + $this->buffer .= Utils::writeShort($v); + } + + protected function getFloat(){ + return Utils::readFloat($this->get(4)); + } + + protected function putFloat($v){ + $this->buffer .= Utils::writeFloat($v); + } + + protected function getTriad(){ + return Utils::readTriad($this->get(3)); + } + + protected function putTriad($v){ + $this->buffer .= Utils::writeTriad($v); + } + + + protected function getLTriad(){ + return Utils::readTriad(strrev($this->get(3))); + } + + protected function putLTriad($v){ + $this->buffer .= strrev(Utils::writeTriad($v)); + } + + protected function getByte(){ + return ord($this->get(1)); + } + + protected function putByte($v){ + $this->buffer .= chr($v); + } + + protected function getDataArray($len = 10){ + $data = array(); + for($i = 1; $i <= $len and !$this->feof(); ++$i){ + $data[] = $this->get($this->getTriad()); + } + return $data; + } + + protected function putDataArray(array $data = array()){ + foreach($data as $v){ + $this->putTriad(strlen($v)); + $this->put($v); + } + } + + protected function getSlot(){ + $id = $this->getShort(); + $cnt = $this->getByte(); + return BlockAPI::getItem( + $id, + $this->getShort(), + $cnt + ); + } + + protected function putSlot(Item $item){ + $this->putShort($item->getID()); + $this->putByte($item->count); + $this->putShort($item->getMetadata()); + } + + protected function getString(){ + return $this->get($this->getShort(true)); + } + + protected function putString($v){ + $this->putShort(strlen($v)); + $this->put($v); + } + + protected function feof(){ + return !isset($this->buffer{$this->offset}); + } +} \ No newline at end of file diff --git a/src/network/raknet/RakNetInfo.php b/src/network/raknet/RakNetInfo.php new file mode 100644 index 00000000..485f5397 --- /dev/null +++ b/src/network/raknet/RakNetInfo.php @@ -0,0 +1,94 @@ +packetID = (int) $packetID; + } + + public function pid(){ + return $this->packetID; + } + + public function __destruct(){} +} \ No newline at end of file diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php new file mode 100644 index 00000000..fa2f6dca --- /dev/null +++ b/src/network/raknet/RakNetParser.php @@ -0,0 +1,208 @@ +buffer =& $buffer; + $this->offset = 0; + if(strlen($this->buffer) > 0){ + $this->parse(); + }else{ + $this->packet = false; + } + } + + private function get($len){ + if($len <= 0){ + $this->offset = strlen($this->buffer) - 1; + return ""; + } + if($len === true){ + return substr($this->buffer, $this->offset); + } + $this->offset += $len; + return substr($this->buffer, $this->offset - $len, $len); + } + + private function getLong($unsigned = false){ + return Utils::readLong($this->get(8), $unsigned); + } + + private function getInt($unsigned = false){ + return Utils::readInt($this->get(4), $unsigned); + } + + private function getShort($unsigned = false){ + return Utils::readShort($this->get(2), $unsigned); + } + + private function getLTriad(){ + return Utils::readTriad(strrev($this->get(3))); + } + + private function getByte(){ + return ord($this->get(1)); + } + + + private function feof(){ + return !isset($this->buffer{$this->offset}); + } + + private function parse(){ + $this->packet = new RakNetPacket(ord($this->get(1))); + $this->packet->buffer =& $this->buffer; + $this->packet->length = strlen($this->buffer); + switch($this->packet->pid()){ + case RakNetInfo::UNCONNECTED_PING: + case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS: + $this->packet->pingID = $this->getLong(); + $this->offset += 16; //Magic + break; + case RakNetInfo::OPEN_CONNECTION_REQUEST_1: + $this->offset += 16; //Magic + $this->packet->structure = $this->getByte(); + $this->packet->mtuSize = strlen($this->get(true)); + break; + case RakNetInfo::OPEN_CONNECTION_REQUEST_2: + $this->offset += 16; //Magic + $this->packet->security = $this->get(5); + $this->packet->port = $this->getShort(false); + $this->packet->mtuSize = $this->getShort(false); + $this->packet->clientID = $this->getLong(); + break; + case RakNetInfo::DATA_PACKET_0: + case RakNetInfo::DATA_PACKET_1: + case RakNetInfo::DATA_PACKET_2: + case RakNetInfo::DATA_PACKET_3: + case RakNetInfo::DATA_PACKET_4: + case RakNetInfo::DATA_PACKET_5: + case RakNetInfo::DATA_PACKET_6: + case RakNetInfo::DATA_PACKET_7: + case RakNetInfo::DATA_PACKET_8: + case RakNetInfo::DATA_PACKET_9: + case RakNetInfo::DATA_PACKET_A: + case RakNetInfo::DATA_PACKET_B: + case RakNetInfo::DATA_PACKET_C: + case RakNetInfo::DATA_PACKET_D: + case RakNetInfo::DATA_PACKET_E: + case RakNetInfo::DATA_PACKET_F: + $this->packet->seqNumber = $this->getLTriad(); + $this->packet->data = array(); + while(!$this->feof() and ($pk = $this->parseDataPacket()) instanceof RakNetDataPacket){ + $this->packet->data[] = $pk; + } + break; + case RakNetInfo::NACK: + case RakNetInfo::ACK: + $count = $this->getShort(); + $this->packet->packets = array(); + for($i = 0; $i < $count and !$this->feof(); ++$i){ + if($this->getByte() === 0){ + $start = $this->getLTriad(); + $end = $this->getLTriad(); + if(($end - $start) > 4096){ + $end = $start + 4096; + } + for($c = $start; $c <= $end; ++$c){ + $this->packet->packets[] = $c; + } + }else{ + $this->packet->packets[] = $this->getLTriad(); + } + } + break; + default: + $this->packet = false; + break; + } + } + + private function parseDataPacket(){ + $packetFlags = $this->getByte(); + $reliability = ($packetFlags & 0b11100000) >> 5; + $hasSplit = ($packetFlags & 0b00010000) > 0; + $length = (int) ceil($this->getShort() / 8); + if($reliability === 2 + or $reliability === 3 + or $reliability === 4 + or $reliability === 6 + or $reliability === 7){ + $messageIndex = $this->getLTriad(); + }else{ + $messageIndex = false; + } + + if($reliability === 1 + or $reliability === 3 + or $reliability === 4 + or $reliability === 7){ + $orderIndex = $this->getLTriad(); + $orderChannel = $this->getByte(); + }else{ + $orderIndex = false; + $orderChannel = false; + } + + if($hasSplit == true){ + $splitCount = $this->getInt(); + $splitID = $this->getShort(); + $splitIndex = $this->getInt(); + }else{ + $splitCount = false; + $splitID = false; + $splitIndex = false; + } + + if($length <= 0 + or $orderChannel >= 32 + or ($hasSplit === true and $splitIndex >= $splitCount)){ + return false; + }else{ + $pid = $this->getByte(); + $buffer = $this->get($length - 1); + if(strlen($buffer) < ($length - 1)){ + return false; + } + if(isset(ProtocolInfo::$packets[$pid])){ + $data = new ProtocolInfo::$packets[$pid]; + }else{ + $data = new UnknownPacket(); + $data->packetID = $pid; + } + $data->reliability = $reliability; + $data->hasSplit = $hasSplit; + $data->messageIndex = $messageIndex; + $data->orderIndex = $orderIndex; + $data->orderChannel = $orderChannel; + $data->splitCount = $splitCount; + $data->splitID = $splitID; + $data->splitIndex = $splitIndex; + $data->setBuffer($buffer); + } + return $data; + } + +} \ No newline at end of file diff --git a/src/utils/Cache.php b/src/utils/Cache.php index e20a58bf..3d05eee6 100644 --- a/src/utils/Cache.php +++ b/src/utils/Cache.php @@ -21,26 +21,27 @@ class Cache{ public static $cached = array(); - + public static function add($identifier, $blob, $minTTL = 30){ - self::$cached[$identifier] = array($blob, microtime(true) + $minTTL); + self::$cached[$identifier] = array($blob, microtime(true) + $minTTL, $minTTL); } - + public static function get($identifier){ if(isset(self::$cached[$identifier])){ + self::$cached[$identifier][1] = microtime(true) + self::$cached[$identifier][2]; return self::$cached[$identifier][0]; } return false; } - + public static function exists($identifier){ return isset(self::$cached[$identifier]); } - + public static function remove($identifier){ unset(self::$cached[$identifier]); } - + public static function cleanup(){ $time = microtime(true); foreach(self::$cached as $index => $data){ @@ -50,4 +51,4 @@ class Cache{ } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/utils/Config.php b/src/utils/Config.php index 4ef1ea5b..ace15d21 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -86,6 +86,10 @@ class Config{ $this->load($this->file); $correct = $this->check(); } + + public function fixYAMLIndexes($str){ + return preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", $str); + } /** * @param string $file @@ -125,7 +129,8 @@ class Config{ $this->config = @json_decode($content, true); break; case CONFIG_YAML: - $this->config = Spyc::YAMLLoad($content); + $content = $this->fixYAMLIndexes($content); + $this->config = yaml_parse($content); break; case CONFIG_SERIALIZED: $this->config = @unserialize($content); @@ -172,7 +177,7 @@ class Config{ $content = json_encode($this->config, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING); break; case CONFIG_YAML: - $content = Spyc::YAMLDump($this->config); + $content = yaml_emit($this->config, YAML_UTF8_ENCODING); break; case CONFIG_SERIALIZED: $content = @serialize($this->config); diff --git a/src/utils/Java.php b/src/utils/Java.php index 88c8c153..ba589fbf 100644 --- a/src/utils/Java.php +++ b/src/utils/Java.php @@ -63,58 +63,4 @@ class Java_String{ } return $h; } -} - - -class Java_Random{ - private $haveNextNextGaussian, $nextNextGaussian, $seed, $n1, $n2, $n3, $zero; - - public function __construct($seed = false){ - $this->n1 = new Math_BigInteger(0x5DEECE66D); - $this->n2 = new Math_BigInteger(1); - $this->n2 = $this->n2->bitwise_leftShift(48)->subtract($this->n2); - $this->n3 = new Math_BigInteger(0xB); - $this->zero = new Math_BigInteger(0); - if($seed === false){ - $seed = microtime(true) * 1000000; - } - $this->setSeed($seed); - } - - public function setSeed($seed){ - $seed = new Math_BigInteger($seed); - $this->seed = $seed->bitwise_xor($this->n1)->bitwise_and($this->n2); - $this->haveNextNextGaussian = false; - } - - protected function next($bits){ - $bits = (int) $bits; - $this->seed = $this->seed->multiply($this->n1)->add($this->n3)->bitwise_and($this->n2); - return $this->_tripleRightShift($this->seed, (48 - $bits)); - } - - private function _tripleRightShift($number, $places){ - if($number->compare($this->zero) >= 0){ - return $number->bitwise_rightShift($places); - } - $n1 = new Math_BigInteger(2); - return $number->bitwise_rightShift($places)->add($n1->bitwise_leftShift(~$places)); - } - - public function nextBytes($bytes){ - $bytes = (int) $bytes; - $b = b""; - $max = $bytes & ~0x3; - for($i = 0; $i < $max; $i += 4){ - $b .= $this->next(32)->toBytes(); - } - if($max < $bytes){ - $random = $this->next(32)->toBytes(); - for($j = $max; $j < $bytes; ++$j){ - $b .= $random{$j-$max}; - } - } - return $b; - } - } \ No newline at end of file diff --git a/src/utils/NBT.php b/src/utils/NBT.php index 7b7481e9..f85f637b 100644 --- a/src/utils/NBT.php +++ b/src/utils/NBT.php @@ -43,7 +43,7 @@ class NBT{ $this->offset += $n; return substr($this->binary, $this->offset - $n, $n); } - + private function feof(){ return !isset($this->binary{$this->offset}); } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index e999c992..fff7aa29 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -28,7 +28,15 @@ class Utils{ public static $ip = false; public static function isOnline(){ - return ((@fsockopen("google.com", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.linux.org", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.php.net", 80, $e = null, $n = null, 2) !== false) ? true:false); + return ((@fsockopen("8.8.8.8", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.linux.org", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.php.net", 80, $e = null, $n = null, 2) !== false) ? true:false); + } + + public static function getCallableIdentifier(callable $variable){ + if(is_array($variable)){ + return sha1(strtolower(get_class($variable[0]))."::".strtolower($variable[1])); + }else{ + return sha1(strtolower($variable)); + } } public static function getUniqueID($raw = false, $extra = ""){ @@ -90,13 +98,23 @@ class Utils{ } public static function getOS(){ - $uname = trim(strtoupper(php_uname("s"))); - if(strpos($uname, "DARWIN") !== false){ - return "mac"; - }elseif(strpos($uname, "WIN") !== false){ + $uname = php_uname("s"); + if(stripos($uname, "Darwin") !== false){ + if(strpos(php_uname("m"), "iP") === 0){ + return "ios"; + }else{ + return "mac"; + } + }elseif(stripos($uname, "Win") !== false or $uname === "Msys"){ return "win"; - }elseif(strpos($uname, "LINUX") !== false){ - return "linux"; + }elseif(stripos($uname, "Linux") !== false){ + if(@file_exists("/system/build.prop")){ + return "android"; + }else{ + return "linux"; + } + }elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){ + return "bsd"; }else{ return "other"; } diff --git a/src/world/Entity.php b/src/world/Entity.php index 08cda07d..3f473604 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -271,7 +271,6 @@ class Entity extends Position{ $this->close(); //Despawn timer return false; } - } if($this->class === ENTITY_MOB){ @@ -370,7 +369,7 @@ class Entity extends Position{ case FIRE: //Fire block damage if($this->inBlock(new Vector3($x, $y, $z))){ $this->harm(1, "fire"); - $this->fire = 150; + $this->fire = 300; $this->updateMetadata(); $hasUpdate = true; } @@ -574,24 +573,24 @@ class Entity extends Position{ $players = $this->server->api->player->getAll($this->level); if($this->player instanceof Player){ unset($players[$this->player->CID]); - $this->server->api->player->broadcastPacket($players, MC_MOVE_PLAYER, array( - "eid" => $this->eid, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "yaw" => $this->yaw, - "pitch" => $this->pitch, - "bodyYaw" => $this->yaw, - )); + $pk = new MovePlayerPacket; + $pk->eid = $this->eid; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->yaw = $this->yaw; + $pk->pitch = $this->pitch; + $pk->bodyYaw = $this->yaw; + $this->server->api->player->broadcastPacket($players, $pk); }else{ - $this->server->api->player->broadcastPacket($players, MC_MOVE_ENTITY_POSROT, array( - "eid" => $this->eid, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "yaw" => $this->yaw, - "pitch" => $this->pitch, - )); + $pk = new MoveEntityPacket_PosRot; + $pk->eid = $this->eid; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->yaw = $this->yaw; + $pk->pitch = $this->pitch; + $this->server->api->player->broadcastPacket($players, $pk); } } }else{ @@ -603,7 +602,7 @@ class Entity extends Position{ public function getDirection(){ $rotation = ($this->yaw - 90) % 360; - if ($rotation < 0) { + if($rotation < 0) { $rotation += 360.0; } if((0 <= $rotation and $rotation < 45) or (315 <= $rotation and $rotation < 360)){ @@ -663,134 +662,135 @@ class Entity extends Position{ if($this->player->connected !== true or $this->player->spawned === false){ return false; } - $player->dataPacket(MC_ADD_PLAYER, array( - "clientID" => 0,/*$this->player->clientID,*/ - "username" => $this->player->username, - "eid" => $this->eid, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "yaw" => 0, - "pitch" => 0, - "unknown1" => 0, - "unknown2" => 0, - "metadata" => $this->getMetadata(), - )); - $player->dataPacket(MC_PLAYER_EQUIPMENT, array( - "eid" => $this->eid, - "block" => $this->player->getSlot($this->player->slot)->getID(), - "meta" => $this->player->getSlot($this->player->slot)->getMetadata(), - "slot" => 0, - )); + + $pk = new AddPlayerPacket; + $pk->clientID = 0; //$this->player->clientID; + $pk->username = $this->player->username; + $pk->eid = $this->eid; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->yaw = 0; + $pk->pitch = 0; + $pk->unknown1 = 0; + $pk->unknown2 = 0; + $pk->metadata = $this->getMetadata(); + $player->dataPacket($pk); + + $pk = new SetEntityMotionPacket; + $pk->eid = $this->eid; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); + + $pk = new PlayerEquipmentPacket; + $pk->eid = $this->eid; + $pk->item = $this->player->getSlot($this->player->slot)->getID(); + $pk->meta = $this->player->getSlot($this->player->slot)->getMetadata(); + $pk->slot = 0; + $player->dataPacket($pk); $this->player->sendArmor($player); break; case ENTITY_ITEM: - $player->dataPacket(MC_ADD_ITEM_ENTITY, array( - "eid" => $this->eid, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "yaw" => $this->yaw, - "pitch" => $this->pitch, - "roll" => 0, - "block" => $this->type, - "meta" => $this->meta, - "stack" => $this->stack, - )); - $player->dataPacket(MC_SET_ENTITY_MOTION, array( - "eid" => $this->eid, - "speedX" => (int) ($this->speedX * 400), - "speedY" => (int) ($this->speedY * 400), - "speedZ" => (int) ($this->speedZ * 400), - )); + $pk = new AddItemEntityPacket; + $pk->eid = $this->eid; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->yaw = $this->yaw; + $pk->pitch = $this->pitch; + $pk->roll = 0; + $pk->item = BlockAPI::getItem($this->type, $this->meta, $this->stack); + $pk->metadata = $this->getMetadata(); + $player->dataPacket($pk); + + $pk = new SetEntityMotionPacket; + $pk->eid = $this->eid; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); break; case ENTITY_MOB: - $player->dataPacket(MC_ADD_MOB, array( - "type" => $this->type, - "eid" => $this->eid, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "yaw" => 0, - "pitch" => 0, - "metadata" => $this->getMetadata(), - )); - $player->dataPacket(MC_SET_ENTITY_MOTION, array( - "eid" => $this->eid, - "speedX" => (int) ($this->speedX * 400), - "speedY" => (int) ($this->speedY * 400), - "speedZ" => (int) ($this->speedZ * 400), - )); + $pk = new AddMobPacket; + $pk->eid = $this->eid; + $pk->type = $this->type; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->yaw = $this->yaw; + $pk->pitch = $this->pitch; + $pk->metadata = $this->getMetadata(); + $player->dataPacket($pk); + + $pk = new SetEntityMotionPacket; + $pk->eid = $this->eid; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); break; case ENTITY_OBJECT: if($this->type === OBJECT_PAINTING){ - $player->dataPacket(MC_ADD_PAINTING, array( - "eid" => $this->eid, - "x" => (int) $this->x, - "y" => (int) $this->y, - "z" => (int) $this->z, - "direction" => $this->getDirection(), - "title" => $this->data["Motive"], - )); + $pk = new AddPaintingPacket; + $pk->eid = $this->eid; + $pk->x = (int) $this->x; + $pk->y = (int) $this->y; + $pk->z = (int) $this->z; + $pk->direction = $this->getDirection(); + $pk->title = $this->data["Motive"]; + $player->dataPacket($pk); }elseif($this->type === OBJECT_PRIMEDTNT){ - $player->dataPacket(MC_ADD_ENTITY, array( - "eid" => $this->eid, - "type" => $this->type, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "did" => 0, - )); - }elseif($this->type === OBJECT_SNOWBALL){ - $player->dataPacket(MC_ADD_ENTITY, array( - "eid" => $this->eid, - "type" => $this->type, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "did" => 0, - )); - }elseif($this->type === OBJECT_MINECART){ - $player->dataPacket(MC_ADD_ENTITY, array( - "eid" => $this->eid, - "type" => $this->type, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "did" => 0, - )); + $pk = new AddEntityPacket; + $pk->eid = $this->eid; + $pk->type = $this->type; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->did = 0; + $player->dataPacket($pk); + + $pk = new SetEntityMotionPacket; + $pk->eid = $this->eid; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); }elseif($this->type === OBJECT_ARROW){ - $player->dataPacket(MC_ADD_ENTITY, array( - "eid" => $this->eid, - "type" => $this->type, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "did" => 0, - )); - $player->dataPacket(MC_SET_ENTITY_MOTION, array( - "eid" => $this->eid, - "speedX" => (int) ($this->speedX * 400), - "speedY" => (int) ($this->speedY * 400), - "speedZ" => (int) ($this->speedZ * 400), - )); + $pk = new AddEntityPacket; + $pk->eid = $this->eid; + $pk->type = $this->type; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->did = 0; + $player->dataPacket($pk); + + $pk = new SetEntityMotionPacket; + $pk->eid = $this->eid; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); } break; case ENTITY_FALLING: - $player->dataPacket(MC_ADD_ENTITY, array( - "eid" => $this->eid, - "type" => $this->type, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "did" => -$this->data["Tile"], - )); - $player->dataPacket(MC_SET_ENTITY_MOTION, array( - "eid" => $this->eid, - "speedX" => (int) ($this->speedX * 400), - "speedY" => (int) ($this->speedY * 400), - "speedZ" => (int) ($this->speedZ * 400), - )); + $pk = new AddEntityPacket; + $pk->eid = $this->eid; + $pk->type = $this->type; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->did = -$this->data["Tile"]; + $player->dataPacket($pk); + + $pk = new SetEntityMotionPacket; + $pk->eid = $this->eid; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); break; } } @@ -1001,9 +1001,9 @@ class Entity extends Position{ $this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 2)); //Ouch! sound } if($this->player instanceof Player){ - $this->player->dataPacket(MC_SET_HEALTH, array( - "health" => $this->health, - )); + $pk = new SetHealthPacket; + $pk->health = $this->health; + $this->player->dataPacket($pk); } if($this->health <= 0 and $this->dead === false){ $this->spawnDrops(); @@ -1015,14 +1015,14 @@ class Entity extends Position{ $this->updateMetadata(); $this->dead = true; if($this->player instanceof Player){ - $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), MC_MOVE_ENTITY_POSROT, array( - "eid" => $this->eid, - "x" => -256, - "y" => 128, - "z" => -256, - "yaw" => 0, - "pitch" => 0, - )); + $pk = new MoveEntityPacket_PosRot; + $pk->eid = $this->eid; + $pk->x = -256; + $pk->y = 128; + $pk->z = -256; + $pk->yaw = 0; + $pk->pitch = 0; + $this->server->api->player->broadcastPacket($this->level->players, $pk); }else{ $this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 3)); //Entity dead } diff --git a/src/world/Explosion.php b/src/world/Explosion.php index c2075c95..751b3a73 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -106,23 +106,21 @@ class Explosion{ $server->api->entity->spawnToAll($e); }elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){ if(isset(self::$specialDrops[$block->getID()])){ - //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0)); - return; + $server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0)); }else{ - //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z))); - return; + $server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z))); } } $this->level->level->setBlockID($block->x, $block->y, $block->z, 0); $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); } - $server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_EXPLOSION, array( - "x" => $this->source->x, - "y" => $this->source->y, - "z" => $this->source->z, - "radius" => $this->size, - "records" => $send, - )); + $pk = new ExplodePacket; + $pk->x = $this->source->x; + $pk->y = $this->source->y; + $pk->z = $this->source->z; + $pk->radius = $this->size; + $pk->records = $send; + $server->api->player->broadcastPacket($this->level->players, $pk); } } diff --git a/src/world/Level.php b/src/world/Level.php index 8ac18ce2..33c8f3fd 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -34,7 +34,7 @@ class Level{ $this->nextSave = $this->startCheck = microtime(true); $this->nextSave += 90; $this->stopTime = false; - $this->server->schedule(2, array($this, "checkThings"), array(), true); + $this->server->schedule(15, array($this, "checkThings"), array(), true); $this->server->schedule(20 * 13, array($this, "checkTime"), array(), true); $this->name = $name; $this->usedChunks = array(); @@ -78,10 +78,11 @@ class Level{ } if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){ $this->time = $time; - $this->server->api->player->broadcastPacket($this->players, MC_SET_TIME, array( - "time" => (int) $this->time, - "started" => $this->stopTime == false, - )); + + $pk = new SetTimePacket; + $pk->time = (int) $this->time; + $pk->started = $this->stopTime == false; + $this->server->api->player->broadcastPacket($this->players, $pk); } } @@ -109,13 +110,13 @@ class Level{ if(count($this->changedBlocks) > 0){ foreach($this->changedBlocks as $blocks){ foreach($blocks as $b){ - $this->server->api->player->broadcastPacket($this->players, MC_UPDATE_BLOCK, array( - "x" => $b->x, - "y" => $b->y, - "z" => $b->z, - "block" => $b->getID(), - "meta" => $b->getMetadata(), - )); + $pk = new UpdateBlockPacket; + $pk->x = $b->x; + $pk->y = $b->y; + $pk->z = $b->z; + $pk->block = $b->getID(); + $pk->meta = $b->getMetadata(); + $this->server->api->player->broadcastPacket($this->players, $pk); } } $this->changedBlocks = array(); @@ -127,10 +128,10 @@ class Level{ if(count($c) === 0){ unset($this->usedChunks[$i]); $X = explode(".", $i); - $Z = (int) array_pop($X); - $X = (int) array_pop($X); + $Z = array_pop($X); + $X = array_pop($X); if(!$this->isSpawnChunk($X, $Z)){ - $this->level->unloadChunk($X, $Z, $this->server->saveEnabled); + $this->level->unloadChunk((int) array_pop($X), (int) $Z, $this->server->saveEnabled); } } } @@ -179,7 +180,7 @@ class Level{ "id" => $entity->type, "TileX" => $entity->x, "TileY" => $entity->y, - "TileX" => $entity->z, + "TileZ" => $entity->z, "Health" => $entity->health, "Motive" => $entity->data["Motive"], "Pos" => array( @@ -289,13 +290,13 @@ class Level{ public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){ if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false){ if($direct === true){ - $this->server->api->player->broadcastPacket($this->players, MC_UPDATE_BLOCK, array( - "x" => $pos->x, - "y" => $pos->y, - "z" => $pos->z, - "block" => $block->getID(), - "meta" => $block->getMetadata(), - )); + $pk = new UpdateBlockPacket; + $pk->x = $pos->x; + $pk->y = $pos->y; + $pk->z = $pos->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->server->api->player->broadcastPacket($this->players, $pk); }elseif($direct === false){ if(!($pos instanceof Position)){ $pos = new Position($pos->x, $pos->y, $pos->z, $this); @@ -329,13 +330,13 @@ class Level{ $block->position($pos); if($direct === true){ - $this->server->api->player->broadcastPacket($this->players, MC_UPDATE_BLOCK, array( - "x" => $pos->x, - "y" => $pos->y, - "z" => $pos->z, - "block" => $block->getID(), - "meta" => $block->getMetadata(), - )); + $pk = new UpdateBlockPacket; + $pk->x = $pos->x; + $pk->y = $pos->y; + $pk->z = $pos->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->server->api->player->broadcastPacket($this->players, $pk); }else{ $i = ($pos->x >> 4).":".($pos->y >> 4).":".($pos->z >> 4); if(!isset($this->changedBlocks[$i])){ @@ -434,7 +435,7 @@ class Level{ } if(ADVANCED_CACHE == true and $Yndex == 0xff){ Cache::add($identifier, $ordered, 60); - } + } return $ordered; } @@ -545,4 +546,4 @@ class Level{ } return $this->server->api->block->scheduleBlockUpdate($pos, $delay, $type); } -} \ No newline at end of file +} diff --git a/src/world/Tile.php b/src/world/Tile.php index d095850b..b7ccd428 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -142,26 +142,27 @@ class Tile extends Position{ }else{ $player->windows[$id] = $this; } - $player->dataPacket(MC_CONTAINER_OPEN, array( - "windowid" => $id, - "type" => WINDOW_CHEST, - "slots" => is_array($player->windows[$id]) ? CHEST_SLOTS << 1:CHEST_SLOTS, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - )); + + $pk = new ContainerOpenPacket; + $pk->windowid = $id; + $pk->type = WINDOW_CHEST; + $pk->slots = is_array($player->windows[$id]) ? CHEST_SLOTS << 1:CHEST_SLOTS; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $player->dataPacket($pk); $slots = array(); if(is_array($player->windows[$id])){ $all = $this->server->api->player->getAll($this->level); - foreach($player->windows[$id] as $ob){ - $this->server->api->player->broadcastPacket($all, MC_TILE_EVENT, array( - "x" => $ob->x, - "y" => $ob->y, - "z" => $ob->z, - "case1" => 1, - "case2" => 2, - )); + foreach($player->windows[$id] as $ob){ + $pk = new TileEventPacket; + $pk->x = $ob->x; + $pk->y = $ob->y; + $pk->z = $ob->z; + $pk->case1 = 1; + $pk->case2 = 2; + $this->server->api->player->broadcastPacket($all, $pk); for($s = 0; $s < CHEST_SLOTS; ++$s){ $slot = $ob->getSlot($s); if($slot->getID() > AIR and $slot->count > 0){ @@ -172,13 +173,13 @@ class Tile extends Position{ } } }else{ - $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), MC_TILE_EVENT, array( - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "case1" => 1, - "case2" => 2, - )); + $pk = new TileEventPacket; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->case1 = 1; + $pk->case2 = 2; + $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk); for($s = 0; $s < CHEST_SLOTS; ++$s){ $slot = $this->getSlot($s); if($slot->getID() > AIR and $slot->count > 0){ @@ -188,24 +189,26 @@ class Tile extends Position{ } } } - $player->dataPacket(MC_CONTAINER_SET_CONTENT, array( - "windowid" => $id, - "count" => count($slots), - "slots" => $slots, - )); + + $pk = new ContainerSetContentPacket; + $pk->windowid = $id; + $pk->slots = $slots; + $player->dataPacket($pk); return true; }elseif($this->class === TILE_FURNACE){ $player->windowCnt++; $player->windowCnt = $id = max(2, $player->windowCnt % 99); $player->windows[$id] = $this; - $player->dataPacket(MC_CONTAINER_OPEN, array( - "windowid" => $id, - "type" => WINDOW_FURNACE, - "slots" => FURNACE_SLOTS, - "x" => $this->x, - "y" => $this->y, - "z" => $this->z - )); + + $pk = new ContainerOpenPacket; + $pk->windowid = $id; + $pk->type = WINDOW_FURNACE; + $pk->slots = FURNACE_SLOTS; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $player->dataPacket($pk); + $slots = array(); for($s = 0; $s < FURNACE_SLOTS; ++$s){ $slot = $this->getSlot($s); @@ -215,11 +218,10 @@ class Tile extends Position{ $slots[] = BlockAPI::getItem(AIR, 0, 0); } } - $player->dataPacket(MC_CONTAINER_SET_CONTENT, array( - "windowid" => $id, - "count" => count($slots), - "slots" => $slots - )); + $pk = new ContainerSetContentPacket; + $pk->windowid = $id; + $pk->slots = $slots; + $player->dataPacket($pk); return true; } } @@ -383,12 +385,12 @@ class Tile extends Position{ $nbt->write(chr(NBT::TAG_END)); - $player->dataPacket(MC_ENTITY_DATA, array( - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "namedtag" => $nbt->binary, - )); + $pk = new EntityDataPacket; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->namedtag = $nbt->binary; + $player->dataPacket($pk); break; case TILE_SIGN: $nbt = new NBT(); @@ -428,12 +430,12 @@ class Tile extends Position{ $nbt->write(chr(NBT::TAG_END)); - $player->dataPacket(MC_ENTITY_DATA, array( - "x" => $this->x, - "y" => $this->y, - "z" => $this->z, - "namedtag" => $nbt->binary, - )); + $pk = new EntityDataPacket; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->namedtag = $nbt->binary; + $player->dataPacket($pk); break; } } diff --git a/src/world/generator/object/tree/PineTreeObject.php b/src/world/generator/object/tree/PineTreeObject.php index ed3276aa..eb78dd98 100644 --- a/src/world/generator/object/tree/PineTreeObject.php +++ b/src/world/generator/object/tree/PineTreeObject.php @@ -64,17 +64,17 @@ class PineTreeObject extends TreeObject{ $firstMaxedRadius = false; for($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY) { $yy = $this->totalHeight - $leavesY; - for ($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) { - for ($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) { - if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { + for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) { + for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) { + if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { $level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new LeavesBlock($this->type)); } } } - if ($leavesRadius >= $leavesMaxRadius) { + if($leavesRadius >= $leavesMaxRadius) { $leavesRadius = $firstMaxedRadius ? 1 : 0; $firstMaxedRadius = true; - if (++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius) { + if(++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius) { $leavesMaxRadius = $this->leavesAbsoluteMaxRadius; } }else{ diff --git a/src/world/generator/object/tree/SmallTreeObject.php b/src/world/generator/object/tree/SmallTreeObject.php index 394887e5..cd7b1610 100644 --- a/src/world/generator/object/tree/SmallTreeObject.php +++ b/src/world/generator/object/tree/SmallTreeObject.php @@ -36,7 +36,7 @@ class SmallTreeObject extends TreeObject{ public function canPlaceObject(Level $level, Vector3 $pos, Random $random){ $radiusToCheck = 0; for ($yy = 0; $yy < $this->trunkHeight + 3; ++$yy) { - if ($yy == 1 or $yy === $this->trunkHeight) { + if($yy == 1 or $yy === $this->trunkHeight) { ++$radiusToCheck; } for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){ @@ -94,7 +94,7 @@ class SmallTreeObject extends TreeObject{ } // Place the trunk last - if( $leaflevel > 1 ) + if($leaflevel > 1) { $trunkpos = new Vector3( $pos->x, $pos->y + $yy, $pos->z ); $level->setBlockRaw($trunkpos, new WoodBlock( $this->type ) ); diff --git a/src/world/generator/object/tree/SpruceTreeObject.php b/src/world/generator/object/tree/SpruceTreeObject.php index c027ac64..e705764d 100644 --- a/src/world/generator/object/tree/SpruceTreeObject.php +++ b/src/world/generator/object/tree/SpruceTreeObject.php @@ -62,7 +62,7 @@ class SpruceTreeObject extends TreeObject{ for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){ for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) { for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) { - if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { + if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { $level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new LeavesBlock($this->type)); } }