mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 19:59:11 +00:00
Updated directory structure
This commit is contained in:
813
src/API/BlockAPI.php
Normal file
813
src/API/BlockAPI.php
Normal file
@@ -0,0 +1,813 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
define("BLOCK_UPDATE_NORMAL", 0);
|
||||
define("BLOCK_UPDATE_RANDOM", 1);
|
||||
define("BLOCK_UPDATE_SCHEDULED", 2);
|
||||
define("BLOCK_UPDATE_WEAK", 3);
|
||||
|
||||
|
||||
|
||||
class BlockAPI{
|
||||
private $server;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->addHandler("world.block.update", array($this, "updateBlockRemote"), 1);
|
||||
$this->server->addHandler("player.block.break", array($this, "blockBreak"), 1);
|
||||
$this->server->addHandler("player.block.action", array($this, "blockAction"), 1);
|
||||
}
|
||||
|
||||
public function blockBreak($data, $event){
|
||||
if($event !== "player.block.break"){
|
||||
return;
|
||||
}
|
||||
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
if(isset(Material::$unbreakable[$target[0]])){
|
||||
return false;
|
||||
}
|
||||
$drop = array(
|
||||
$target[0], //Block
|
||||
$target[1], //Meta
|
||||
1, //Count
|
||||
);
|
||||
switch($target[0]){
|
||||
case 16:
|
||||
$drop = array(263, 0, 1);
|
||||
break;
|
||||
case 21:
|
||||
$drop = array(351, 4, mt_rand(4, 8));
|
||||
break;
|
||||
case 56:
|
||||
$drop = array(264, 0, 1);
|
||||
break;
|
||||
case 73:
|
||||
case 74:
|
||||
$drop = array(351, 4, mt_rand(4, 5));
|
||||
break;
|
||||
case 18:
|
||||
$drop = false;
|
||||
if(mt_rand(1,20) === 1){ //Saplings
|
||||
$drop = array(6, $target[1], 1);
|
||||
}
|
||||
if($target[1] === 0 and mt_rand(1,200) === 1){ //Apples
|
||||
$this->drop($data["x"], $data["y"], $data["z"], 260, 0, 1);
|
||||
}
|
||||
break;
|
||||
case 59:
|
||||
if($target[1] >= 0x07){ //Seeds
|
||||
$drop = array(296, 0, 1);
|
||||
$this->drop($data["x"], $data["y"], $data["z"], 295, 0, mt_rand(0,3));
|
||||
}else{
|
||||
$drop = array(295, 0, 1);
|
||||
}
|
||||
break;
|
||||
case 31:
|
||||
$drop = false;
|
||||
if(mt_rand(1,10) === 1){ //Seeds
|
||||
$drop = array(295, 0, 1);
|
||||
}
|
||||
break;
|
||||
case 20:
|
||||
$drop = false;
|
||||
break;
|
||||
case 30:
|
||||
$drop = false;
|
||||
break;
|
||||
case 51:
|
||||
$drop = false;
|
||||
break;
|
||||
case 52:
|
||||
$drop = false;
|
||||
break;
|
||||
case 43:
|
||||
$drop = array(
|
||||
44,
|
||||
$target[1],
|
||||
2,
|
||||
);
|
||||
break;
|
||||
case 60:
|
||||
case 2:
|
||||
$drop = array(3, 0, 1);
|
||||
break;
|
||||
case 64: //Door
|
||||
$drop = array(324, 0, 1);
|
||||
if(($target[1] & 0x08) === 0x08){
|
||||
$down = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]);
|
||||
if($down[0] === 64){
|
||||
$data2 = $data;
|
||||
--$data2["y"];
|
||||
$this->server->trigger("player.block.break", $data2);
|
||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}else{
|
||||
$up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
|
||||
if($up[0] === 64){
|
||||
$data2 = $data;
|
||||
++$data2["y"];
|
||||
$this->server->trigger("player.block.break", $data2);
|
||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if($drop !== false and $drop[0] !== 0 and $drop[2] > 0){
|
||||
$this->drop($data["x"], $data["y"], $data["z"], $drop[0], $drop[1] & 0x0F, $drop[2] & 0xFF);
|
||||
}
|
||||
$this->server->trigger("player.block.break", $data);
|
||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function drop($x, $y, $z, $block, $meta, $stack = 1){
|
||||
if($block === 0 or $stack <= 0 or $this->server->gamemode === 1){
|
||||
return;
|
||||
}
|
||||
$data = array(
|
||||
"x" => $x,
|
||||
"y" => $y,
|
||||
"z" => $z,
|
||||
"meta" => $meta,
|
||||
"stack" => $stack,
|
||||
);
|
||||
$data["x"] += mt_rand(2, 8) / 10;
|
||||
$data["y"] += mt_rand(2, 8) / 10;
|
||||
$data["z"] += mt_rand(2, 8) / 10;
|
||||
$e = $this->server->api->entity->add(ENTITY_ITEM, $block, $data);
|
||||
$this->server->api->entity->spawnToAll($e->eid);
|
||||
}
|
||||
|
||||
public function blockAction($data, $event){
|
||||
if($event !== "player.block.action"){
|
||||
return;
|
||||
}
|
||||
if($data["face"] < 0 or $data["face"] > 5){
|
||||
return false;
|
||||
}
|
||||
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
$cancelPlace = false;
|
||||
if(isset(Material::$activable[$target[0]])){
|
||||
switch($target[0]){
|
||||
case 6:
|
||||
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
|
||||
Sapling::growTree($this->server->api->level, $target, $target[1] & 0x03);
|
||||
$cancelPlace = true;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
if($data["block"] === 292){ //Hoe
|
||||
$data["block"] = 60;
|
||||
$data["meta"] = 0;
|
||||
$this->server->trigger("player.block.place", $data);
|
||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||
$cancelPlace = true;
|
||||
}
|
||||
case 59:
|
||||
case 105:
|
||||
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
|
||||
$data["block"] = $target[0];
|
||||
$data["meta"] = 0x07;
|
||||
$this->server->trigger("player.block.place", $data);
|
||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||
$cancelPlace = true;
|
||||
}
|
||||
break;
|
||||
case 64: //Door
|
||||
if(($target[1] & 0x08) === 0x08){
|
||||
$down = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]);
|
||||
if($down[0] === 64){
|
||||
$down[1] = $down[1] ^ 0x04;
|
||||
$data2 = array(
|
||||
"x" => $data["x"],
|
||||
"z" => $data["z"],
|
||||
"y" => $data["y"] - 1,
|
||||
"block" => $down[0],
|
||||
"meta" => $down[1],
|
||||
"eid" => $data["eid"],
|
||||
);
|
||||
$this->server->trigger("player.block.update", $data2);
|
||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}else{
|
||||
$data["block"] = $target[0];
|
||||
$data["meta"] = $target[1] ^ 0x04;
|
||||
$this->server->trigger("player.block.update", $data);
|
||||
$up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
|
||||
if($up[0] === 64){
|
||||
$data2 = $data;
|
||||
$data2["meta"] = $up[1];
|
||||
++$data2["y"];
|
||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$cancelPlace = true;
|
||||
break;
|
||||
case 96: //Trapdoor
|
||||
case 107: //Fence gates
|
||||
$data["block"] = $target[0];
|
||||
$data["meta"] = $target[1] ^ 0x04;
|
||||
$this->server->trigger("player.block.update", $data);
|
||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||
$cancelPlace = true;
|
||||
break;
|
||||
default:
|
||||
$cancelPlace = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($cancelPlace === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
$replace = false;
|
||||
switch($target[0]){
|
||||
case 44: //Slabs
|
||||
if($data["face"] !== 1){
|
||||
break;
|
||||
}
|
||||
if(($target[1] & 0x07) === ($data["meta"] & 0x07)){
|
||||
$replace = true;
|
||||
$data["block"] = 43;
|
||||
$data["meta"] = $data["meta"] & 0x07;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if($replace === false){
|
||||
BlockFace::setPosition($data, $data["face"]);
|
||||
}
|
||||
|
||||
if($data["y"] >= 127){
|
||||
return false;
|
||||
}
|
||||
|
||||
$block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
|
||||
if($replace === false and !isset(Material::$replaceable[$block[0]])){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isset(Material::$placeable[$data["block"]])){
|
||||
$data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
$direction = $this->server->api->entity->get($data["eid"])->getDirection();
|
||||
|
||||
switch($data["block"]){
|
||||
case 6:
|
||||
if($target[0] === 60){
|
||||
break;
|
||||
}
|
||||
case 37:
|
||||
case 38:
|
||||
if($target[0] !== 2 and $target[0] !== 3){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 39://Mushrooms
|
||||
case 40:
|
||||
$blockDown = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]);
|
||||
if(isset(Material::$transparent[$blockDown[0]])){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 83: //Sugarcane
|
||||
$blockDown = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]);
|
||||
if($blockDown[0] !== 2 and $blockDown[0] !== 3 and $blockDown[0] !== 12){
|
||||
return false;
|
||||
}
|
||||
$block0 = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"] + 1);
|
||||
$block1 = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"] - 1);
|
||||
$block2 = $this->server->api->level->getBlock($data["x"] + 1, $data["y"], $data["z"]);
|
||||
$block3 = $this->server->api->level->getBlock($data["x"] - 1, $data["y"], $data["z"]);
|
||||
if($block0[0] === 9 or $block0[0] === 8 or $block1[0] === 9 or $block1[0] === 8 or $block2[0] === 9 or $block2[0] === 8 or $block3[0] === 9 or $block3[0] === 8){
|
||||
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 50: //Torch
|
||||
if(isset(Material::$transparent[$target[0]])){
|
||||
return false;
|
||||
}
|
||||
$faces = array(
|
||||
0 => 6,
|
||||
1 => 5,
|
||||
2 => 4,
|
||||
3 => 3,
|
||||
4 => 2,
|
||||
5 => 1,
|
||||
);
|
||||
if(!isset($faces[$data["face"]])){
|
||||
return false;
|
||||
}
|
||||
$data["meta"] = $faces[$data["face"]];
|
||||
break;
|
||||
case 53://Stairs
|
||||
case 67:
|
||||
case 108:
|
||||
$faces = array(
|
||||
0 => 0,
|
||||
1 => 2,
|
||||
2 => 1,
|
||||
3 => 3,
|
||||
);
|
||||
$data["meta"] = $faces[$direction] & 0x03;
|
||||
break;
|
||||
case 96: //trapdoor
|
||||
if(isset(Material::$transparent[$target[0]])){
|
||||
return false;
|
||||
}
|
||||
$faces = array(
|
||||
2 => 0,
|
||||
3 => 1,
|
||||
4 => 2,
|
||||
5 => 3,
|
||||
);
|
||||
if(!isset($faces[$data["face"]])){
|
||||
return false;
|
||||
}
|
||||
$data["meta"] = $faces[$data["face"]] & 0x03;
|
||||
break;
|
||||
case 107: //Fence gate
|
||||
$faces = array(
|
||||
0 => 3,
|
||||
1 => 0,
|
||||
2 => 1,
|
||||
3 => 2,
|
||||
);
|
||||
$data["meta"] = $faces[$direction] & 0x03;
|
||||
break;
|
||||
case 64://Door placing
|
||||
$blockUp = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
|
||||
$blockDown = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]);
|
||||
if(!isset(Material::$replaceable[$blockUp[0]]) or isset(Material::$transparent[$blockDown[0]])){
|
||||
return false;
|
||||
}else{
|
||||
$data2 = $data;
|
||||
$data2["meta"] = 0x08;
|
||||
$data["meta"] = $direction & 0x03;
|
||||
++$data2["y"];
|
||||
$this->server->trigger("player.block.place", $data2);
|
||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
break;
|
||||
case 54:
|
||||
case 61:
|
||||
$faces = array(
|
||||
0 => 4,
|
||||
1 => 2,
|
||||
2 => 5,
|
||||
3 => 3,
|
||||
);
|
||||
$data["meta"] = $faces[$direction];
|
||||
break;
|
||||
case 26: //bed
|
||||
$face = array(
|
||||
0 => 3,
|
||||
1 => 4,
|
||||
2 => 2,
|
||||
3 => 5,
|
||||
);
|
||||
$next = $this->server->api->level->getBlockFace($block, $face[(($direction + 3) % 4)]);
|
||||
if(!isset(Material::$replaceable[$next[0]])){
|
||||
return false;
|
||||
}
|
||||
$data["meta"] = (($direction + 3) % 4) & 0x3;
|
||||
$data2 = $data;
|
||||
$data2["meta"] = $data2["meta"] | 0x08;
|
||||
$data2["x"] = $next[2][0];
|
||||
$data2["y"] = $next[2][1];
|
||||
$data2["z"] = $next[2][2];
|
||||
$this->server->trigger("player.block.place", $data2);
|
||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
||||
break;
|
||||
case 65: //Ladder
|
||||
if(isset(Material::$transparent[$target[0]])){
|
||||
return false;
|
||||
}
|
||||
$faces = array(
|
||||
2 => 2,
|
||||
3 => 3,
|
||||
4 => 4,
|
||||
5 => 5,
|
||||
);
|
||||
if(!isset($faces[$data["face"]])){
|
||||
return false;
|
||||
}
|
||||
$data["meta"] = $faces[$data["face"]];
|
||||
break;
|
||||
case 59://Seeds
|
||||
case 105:
|
||||
$blockDown = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]);
|
||||
if($blockDown[0] !== 60){
|
||||
return false;
|
||||
}
|
||||
$data["meta"] = 0;
|
||||
break;
|
||||
case 81: //Cactus
|
||||
$blockDown = $this->server->api->level->getBlock($data["x"], $data["y"] - 1, $data["z"]);
|
||||
$block0 = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"] + 1);
|
||||
$block1 = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"] - 1);
|
||||
$block2 = $this->server->api->level->getBlock($data["x"] + 1, $data["y"], $data["z"]);
|
||||
$block3 = $this->server->api->level->getBlock($data["x"] - 1, $data["y"], $data["z"]);
|
||||
if($blockDown[0] !== 12 or !isset(Material::$transparent[$block0[0]]) or !isset(Material::$transparent[$block1[0]]) or !isset(Material::$transparent[$block2[0]]) or !isset(Material::$transparent[$block3[0]])){
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$this->server->trigger("player.block.place", $data);
|
||||
$this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function blockScheduler($data){
|
||||
$this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_SCHEDULED);
|
||||
}
|
||||
|
||||
public function updateBlockRemote($data, $event){
|
||||
if($event !== "world.block.update"){
|
||||
return;
|
||||
}
|
||||
$this->updateBlock($data["x"], $data["y"], $data["z"], isset($data["type"]) ? $data["type"]:BLOCK_UPDATE_RANDOM);
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function flowWaterOn($source, $face){
|
||||
$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);
|
||||
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);
|
||||
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);
|
||||
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:
|
||||
if(!$this->flowWaterOn($block, 0) or $block[0] === 9){
|
||||
$this->flowWaterOn($block, 2);
|
||||
$this->flowWaterOn($block, 3);
|
||||
$this->flowWaterOn($block, 4);
|
||||
$this->flowWaterOn($block, 5);
|
||||
}
|
||||
if($block[0] === 8){
|
||||
$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);
|
||||
}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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 74:
|
||||
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){
|
||||
$changed = true;
|
||||
$this->server->api->level->setBlock($x, $y, $z, 73, $block[1]);
|
||||
$type = BLOCK_UPDATE_WEAK;
|
||||
}
|
||||
break;
|
||||
case 73:
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
$changed = true;
|
||||
$this->server->api->level->setBlock($x, $y, $z, 74, $block[1]);
|
||||
$this->server->schedule(mt_rand(40, 100), array($this, "blockScheduler"), array(
|
||||
"x" => $x,
|
||||
"y" => $y,
|
||||
"z" => $z,
|
||||
));
|
||||
$type = BLOCK_UPDATE_WEAK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if($type === BLOCK_TYPE_SCHEDULED){
|
||||
$type = BLOCK_UPDATE_WEAK;
|
||||
}
|
||||
if($changed === true){
|
||||
$this->updateBlocksAround($x, $y, $z, $type);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBlocksAround($x, $y, $z, $type){
|
||||
$this->updateBlock($x + 1, $y, $z, $type);
|
||||
$this->updateBlock($x, $y + 1, $z, $type);
|
||||
$this->updateBlock($x, $y, $z + 1, $type);
|
||||
$this->updateBlock($x - 1, $y, $z, $type);
|
||||
$this->updateBlock($x, $y - 1, $z, $type);
|
||||
$this->updateBlock($x, $y, $z - 1, $type);
|
||||
}
|
||||
}
|
31
src/API/ChatAPI.php
Normal file
31
src/API/ChatAPI.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class ChatAPI{
|
||||
|
||||
|
||||
}
|
250
src/API/ConsoleAPI.php
Normal file
250
src/API/ConsoleAPI.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class ConsoleAPI{
|
||||
private $input, $server, $event;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->help = array();
|
||||
$this->server = $server;
|
||||
$this->input = fopen(FILE_PATH."console.in", "w+b");
|
||||
$this->last = microtime(true);
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->event = $this->server->event("server.tick", array($this, "handle"));
|
||||
}
|
||||
|
||||
function __destroy(){
|
||||
$this->server->deleteEvent($this->event);
|
||||
fclose($this->input);
|
||||
}
|
||||
|
||||
public function defaultCommands($cmd, $params){
|
||||
switch($cmd){
|
||||
case "invisible":
|
||||
$p = strtolower(array_shift($params));
|
||||
switch($p){
|
||||
case "on":
|
||||
case "true":
|
||||
case "1":
|
||||
console("[INFO] Server is invisible");
|
||||
$this->server->api->setProperty("invisible", true);
|
||||
break;
|
||||
case "off":
|
||||
case "false":
|
||||
case "0":
|
||||
console("[INFO] Server is visible");
|
||||
$this->server->api->setProperty("invisible", false);
|
||||
break;
|
||||
default:
|
||||
console("[INFO] Usage: /invisible <on | off>");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "status":
|
||||
case "lag":
|
||||
$info = $this->server->debugInfo();
|
||||
console("[INFO] TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"].")");
|
||||
break;
|
||||
case "update-done":
|
||||
$this->server->api->setProperty("last-update", time());
|
||||
break;
|
||||
case "stop":
|
||||
console("[INFO] Stopping the server...");
|
||||
$this->server->close();
|
||||
break;
|
||||
/*case "restart":
|
||||
console("[INFO] Restarting the server...");
|
||||
$this->server->api->restart = true;
|
||||
$this->server->close();
|
||||
break;*/
|
||||
case "banip":
|
||||
$p = strtolower(array_shift($params));
|
||||
switch($p){
|
||||
case "pardon":
|
||||
case "remove":
|
||||
$ip = trim(implode($params));
|
||||
$new = array();
|
||||
foreach(explode("\n", str_replace(array("\r","\t"), "", file_get_contents(FILE_PATH."banned-ips.txt"))) as $i){
|
||||
if($i == $ip){
|
||||
console("[INFO] IP \"$ip\" removed from ban list");
|
||||
continue;
|
||||
}
|
||||
$new[$i] = $i;
|
||||
}
|
||||
file_put_contents(FILE_PATH."banned-ips.txt", implode("\r\n", $new));
|
||||
$this->server->reloadConfig();
|
||||
break;
|
||||
case "add":
|
||||
case "ban":
|
||||
$ip = trim(implode($params));
|
||||
file_put_contents(FILE_PATH."banned-ips.txt", "\r\n".$ip, FILE_APPEND);
|
||||
console("[INFO] IP \"$ip\" added to ban list");
|
||||
$this->server->reloadConfig();
|
||||
break;
|
||||
case "reload":
|
||||
$this->server->reloadConfig();
|
||||
break;
|
||||
case "list":
|
||||
console("[INFO] IP ban list: ".implode(", ", explode("\n", str_replace(array("\t","\r"), "", file_get_contents(FILE_PATH."banned-ips.txt")))));
|
||||
break;
|
||||
default:
|
||||
console("[INFO] Usage: /banip <add | remove | list | reload> [IP]");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "gamemode":
|
||||
$s = trim(array_shift($params));
|
||||
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){
|
||||
console("[INFO] Usage: /gamemode <0 | 1>");
|
||||
break;
|
||||
}
|
||||
$this->server->api->setProperty("gamemode", (int) $s);
|
||||
console("[INFO] Gamemode changed to ".$this->server->gamemode);
|
||||
break;
|
||||
case "difficulty":
|
||||
$s = trim(array_shift($params));
|
||||
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){
|
||||
console("[INFO] Usage: /difficulty <0 | 1>");
|
||||
break;
|
||||
}
|
||||
$this->server->api->setProperty("difficulty", (int) $s);
|
||||
console("[INFO] Difficulty changed to ".$this->server->difficulty);
|
||||
loadConfig(true);
|
||||
break;
|
||||
case "say":
|
||||
$s = implode(" ", $params);
|
||||
if(trim($s) == ""){
|
||||
console("[INFO] Usage: /say <message>");
|
||||
break;
|
||||
}
|
||||
$this->server->chat(false, $s);
|
||||
break;
|
||||
case "whitelist":
|
||||
$p = strtolower(array_shift($params));
|
||||
switch($p){
|
||||
case "remove":
|
||||
$user = trim(implode(" ", $params));
|
||||
$new = array();
|
||||
foreach(explode("\n", str_replace(array("\r","\t"), "", file_get_contents(FILE_PATH."white-list.txt"))) as $u){
|
||||
if($u == $user){
|
||||
console("[INFO] Player \"$user\" removed from white-list");
|
||||
continue;
|
||||
}
|
||||
$new[$u] = $u;
|
||||
}
|
||||
file_put_contents(FILE_PATH."white-list.txt", implode("\r\n", $new));
|
||||
$this->server->reloadConfig();
|
||||
break;
|
||||
case "add":
|
||||
$user = trim(implode(" ", $params));
|
||||
file_put_contents(FILE_PATH."white-list.txt", "\r\n".$user, FILE_APPEND);
|
||||
console("[INFO] Player \"$user\" added to white-list");
|
||||
$this->server->reloadConfig();
|
||||
break;
|
||||
case "reload":
|
||||
$this->server->reloadConfig();
|
||||
break;
|
||||
case "list":
|
||||
console("[INFO] White-list: ".implode(", ", explode("\n", str_replace(array("\t","\r"), "", file_get_contents(FILE_PATH."white-list.txt")))));
|
||||
break;
|
||||
case "on":
|
||||
case "true":
|
||||
case "1":
|
||||
console("[INFO] White-list turned on");
|
||||
$this->server->api->setProperty("white-list", true);
|
||||
break;
|
||||
case "off":
|
||||
case "false":
|
||||
case "0":
|
||||
console("[INFO] White-list turned off");
|
||||
$this->server->api->setProperty("white-list", false);
|
||||
break;
|
||||
default:
|
||||
console("[INFO] Usage: /whitelist <on | off | add | remove | reload | list> [username]");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "save-all":
|
||||
$this->server->save();
|
||||
break;
|
||||
case "block":
|
||||
foreach($this->server->clients as $client){
|
||||
$b = $this->server->map->getBlock(round($client->entity->position["x"] - 0.5), round($client->entity->position["y"] - 1), round($client->entity->position["z"] - 0.5));
|
||||
console("[INFO] EID ".$client->eid." is over block ".$b[0].":".$b[1]);
|
||||
}
|
||||
break;
|
||||
case "help":
|
||||
case "?":
|
||||
console("[INFO] /help: Show available commands");
|
||||
console("[INFO] /status: Show server TPS and memory usage");
|
||||
console("[INFO] /gamemode: Changes default gamemode");
|
||||
console("[INFO] /difficulty: Changes difficulty");
|
||||
console("[INFO] /invisible: Manages server visibility");
|
||||
console("[INFO] /say: Broadcasts mesages");
|
||||
console("[INFO] /save-all: Saves pending changes");
|
||||
console("[INFO] /whitelist: Manages whitelisting");
|
||||
console("[INFO] /banip: Manages IP ban");
|
||||
console("[INFO] /stop: Stops the server");
|
||||
//console("[INFO] /restart: Restarts the server");
|
||||
foreach($this->help as $c => $h){
|
||||
console("[INFO] /$c: ".$h[0]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console("[ERROR] Command doesn't exist! Use /help");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function register($cmd, $help,$callback){
|
||||
if(!is_callable($callback)){
|
||||
return false;
|
||||
}
|
||||
$this->help[strtolower(trim($cmd))] = array($help, $callback);
|
||||
}
|
||||
|
||||
public function handle($time){
|
||||
while(($line = fgets($this->input)) !== false){
|
||||
$line = trim($line);
|
||||
if($line === ""){
|
||||
continue;
|
||||
}
|
||||
$params = explode(" ", $line);
|
||||
$cmd = strtolower(array_shift($params));
|
||||
console("[INFO] Issued server command: /$cmd ".implode(" ", $params));
|
||||
if(isset($this->help[$cmd]) and is_callable($this->help[$cmd][1])){
|
||||
call_user_func($this->help[$cmd][1], $cmd, $params);
|
||||
}elseif($this->server->trigger("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){
|
||||
$this->defaultCommands($cmd, $params);
|
||||
}
|
||||
}
|
||||
ftruncate($this->input, 0);
|
||||
fseek($this->input, 0);
|
||||
}
|
||||
|
||||
}
|
133
src/API/EntityAPI.php
Normal file
133
src/API/EntityAPI.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class EntityAPI{
|
||||
private $server;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->addHandler("player.death", array($this, "handle"), 1);
|
||||
$this->server->api->console->register("give", "Give items to a player [DUMMY]", array($this, "commandHandler"));
|
||||
}
|
||||
|
||||
public function handle($data, $event){
|
||||
switch($event){
|
||||
case "player.death":
|
||||
$message = $data["name"];
|
||||
if(is_numeric($data["cause"]) and isset($this->entities[$data["cause"]])){
|
||||
$e = $this->api->entity->get($data["cause"]);
|
||||
switch($e->class){
|
||||
case ENTITY_PLAYER:
|
||||
$message .= " was killed by ".$e->name;
|
||||
break;
|
||||
default:
|
||||
$message .= " was killed";
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
switch($data["cause"]){
|
||||
default:
|
||||
$message .= " was killed";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->server->chat(false, $message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $params){
|
||||
switch($cmd){
|
||||
case "give":
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function get($eid){
|
||||
if(isset($this->server->entities[$eid])){
|
||||
return $this->server->entities[$eid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getAll(){
|
||||
return $this->server->entities;
|
||||
}
|
||||
|
||||
public function heal($eid, $heal = 1, $cause){
|
||||
$this->harm($eid, -$heal, $cause);
|
||||
}
|
||||
|
||||
public function harm($eid, $attack = 1, $cause){
|
||||
$e = $this->get($eid);
|
||||
if($e === false or $e->dead === true){
|
||||
return false;
|
||||
}
|
||||
$e->setHealth($e->getHealth()-$attack, $cause);
|
||||
}
|
||||
|
||||
public function add($class, $type = 0, $data = array()){
|
||||
$eid = $this->server->eidCnt++;
|
||||
$this->server->entities[$eid] = new Entity($this->server, $eid, $class, $type, $data);
|
||||
return $this->server->entities[$eid];
|
||||
}
|
||||
|
||||
public function spawnTo($eid, $player){
|
||||
$e = $this->get($eid);
|
||||
if($e === false){
|
||||
return false;
|
||||
}
|
||||
$e->spawn($player);
|
||||
}
|
||||
|
||||
public function spawnToAll($eid){
|
||||
$e = $this->get($eid);
|
||||
if($e === false){
|
||||
return false;
|
||||
}
|
||||
foreach($this->server->api->player->getAll() as $player){
|
||||
if($player->eid !== false){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnAll($player){
|
||||
foreach($this->getAll() as $e){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
|
||||
public function remove($eid){
|
||||
if(isset($this->server->entities[$eid])){
|
||||
$this->server->entities[$eid]->close();
|
||||
unset($this->server->entities[$eid]);
|
||||
}
|
||||
}
|
||||
}
|
126
src/API/LevelAPI.php
Normal file
126
src/API/LevelAPI.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class LevelAPI{
|
||||
private $server, $map;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
$this->map = $this->server->map;
|
||||
$this->heightMap = array_fill(0, 256, array());
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->event("player.block.break", array($this, "handle"));
|
||||
$this->server->event("player.block.place", array($this, "handle"));
|
||||
$this->server->event("player.block.update", array($this, "handle"));
|
||||
}
|
||||
|
||||
public function handle($data, $event){
|
||||
switch($event){
|
||||
case "player.block.place":
|
||||
case "player.block.update":
|
||||
console("[DEBUG] EID ".$data["eid"]." placed ".$data["block"].":".$data["meta"]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
|
||||
$this->setBlock($data["x"], $data["y"], $data["z"], $data["block"], $data["meta"]);
|
||||
break;
|
||||
case "player.block.break":
|
||||
$block = $this->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
console("[DEBUG] EID ".$data["eid"]." broke ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
|
||||
|
||||
if($block[0] === 0){
|
||||
break;
|
||||
}
|
||||
$this->setBlock($data["x"], $data["y"], $data["z"], 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSpawn(){
|
||||
return $this->server->spawn;
|
||||
}
|
||||
|
||||
public function getChunk($X, $Z){
|
||||
return $this->map->map[$X][$Z];
|
||||
}
|
||||
|
||||
public function getBlockFace($block, $face){
|
||||
$data = array("x" => $block[2][0], "y" => $block[2][1], "z" => $block[2][2]);
|
||||
BlockFace::setPosition($data, $face);
|
||||
return $this->getBlock($data["x"], $data["y"], $data["z"]);
|
||||
}
|
||||
|
||||
public function getBlock($x, $y, $z){
|
||||
$b = $this->map->getBlock($x, $y, $z);
|
||||
$b[2] = array($x, $y, $z);
|
||||
return $b;
|
||||
}
|
||||
|
||||
public function getFloor($x, $z){
|
||||
if(!isset($this->heightMap[$z][$x])){
|
||||
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
|
||||
}
|
||||
return $this->heightMap[$z][$x];
|
||||
}
|
||||
|
||||
public function setBlock($x, $y, $z, $block, $meta = 0){
|
||||
$this->map->setBlock($x, $y, $z, $block, $meta);
|
||||
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
|
||||
$this->server->trigger("world.block.change", array(
|
||||
"x" => $x,
|
||||
"y" => $y,
|
||||
"z" => $z,
|
||||
"block" => $block,
|
||||
"meta" => $meta,
|
||||
));
|
||||
}
|
||||
|
||||
public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){
|
||||
$columnsPerPacket = max(1, (int) $columnsPerPacket);
|
||||
$c = $this->getChunk($X, $Z);
|
||||
$ordered = array();
|
||||
$i = 0;
|
||||
$cnt = 0;
|
||||
$ordered[$i] = "";
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
if($cnt >= $columnsPerPacket){
|
||||
++$i;
|
||||
$ordered[$i] = str_repeat("\x00", $i * $columnsPerPacket);
|
||||
$cnt = 0;
|
||||
}
|
||||
$ordered[$i] .= "\xff";
|
||||
$block = $this->map->getChunkColumn($X, $Z, $x, $z, 0);
|
||||
$meta = $this->map->getChunkColumn($X, $Z, $x, $z, 1);
|
||||
for($k = 0; $k < 8; ++$k){
|
||||
$ordered[$i] .= substr($block, $k << 4, 16);
|
||||
$ordered[$i] .= substr($meta, $k << 3, 8);
|
||||
}
|
||||
++$cnt;
|
||||
}
|
||||
}
|
||||
return $ordered;
|
||||
}
|
||||
}
|
216
src/API/PlayerAPI.php
Normal file
216
src/API/PlayerAPI.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class PlayerAPI{
|
||||
private $server;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->event("server.regeneration", array($this, "handle"));
|
||||
$this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("kill", "Kills a player", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
|
||||
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
|
||||
}
|
||||
|
||||
public function handle($data, $event){
|
||||
switch($event){
|
||||
case "server.regeneration":
|
||||
$result = $this->server->query("SELECT ip,port FROM players WHERE EID = (SELECT EID FROM entities WHERE health < 20);", true);
|
||||
if($result !== true and $result !== false){
|
||||
while(false !== ($player = $result->fetchArray())){
|
||||
$player->entity->setHealth(min(20, $player->entity->getHealth() + $data), "regeneration");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $params){
|
||||
switch($cmd){
|
||||
case "tp":
|
||||
$name = array_shift($params);
|
||||
$target = array_shift($params);
|
||||
if($name == null or $target == null){
|
||||
console("[INFO] Usage: /tp <player> <target>");
|
||||
break;
|
||||
}
|
||||
if($this->teleport($name, $target)){
|
||||
console("[INFO] \"$name\" teleported to \"$target\"");
|
||||
}else{
|
||||
console("[ERROR] Couldn't teleport");
|
||||
}
|
||||
break;
|
||||
case "tppos":
|
||||
$z = array_pop($params);
|
||||
$y = array_pop($params);
|
||||
$x = array_pop($params);
|
||||
$name = implode(" ", $params);
|
||||
if($name == null or $x === null or $y === null or $z === null){
|
||||
console("[INFO] Usage: /tp <player> <x> <y> <z>");
|
||||
break;
|
||||
}
|
||||
if($this->tppos($name, $x, $y, $z)){
|
||||
console("[INFO] \"$name\" teleported to ($x, $y, $z)");
|
||||
}else{
|
||||
console("[ERROR] Couldn't teleport");
|
||||
}
|
||||
break;
|
||||
case "kill":
|
||||
$player = $this->get(implode(" ", $params));
|
||||
if($player !== false){
|
||||
$this->server->api->entity->harm($player->eid, 20, "console");
|
||||
}else{
|
||||
console("[INFO] Usage: /kill <player>");
|
||||
}
|
||||
break;
|
||||
case "list":
|
||||
console("[INFO] Player list:");
|
||||
foreach($this->server->clients as $c){
|
||||
console("[INFO] ".$c->username." (".$c->ip.":".$c->port."), ClientID ".$c->clientID.", (".round($c->entity->x, 2).", ".round($c->entity->y, 2).", ".round($c->entity->z, 2).")");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function teleport($name, $target){
|
||||
$target = $this->get($target);
|
||||
if($target !== false){
|
||||
return $this->tppos($name, $target->entity->x, $target->entity->y, $target->entity->z);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function tppos($name, $x, $y, $z){
|
||||
$player = $this->get($name);
|
||||
if($player !== false){
|
||||
$player->dataPacket(MC_MOVE_PLAYER, array(
|
||||
"eid" => 0,
|
||||
"x" => $x,
|
||||
"y" => $y,
|
||||
"z" => $z,
|
||||
"yaw" => 0,
|
||||
"pitch" => 0,
|
||||
));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get($name){
|
||||
$CID = $this->server->query("SELECT ip,port FROM players WHERE name = '".str_replace("'", "", $name)."';", true);
|
||||
$CID = $this->server->clientID($CID["ip"], $CID["port"]);
|
||||
if(isset($this->server->clients[$CID])){
|
||||
return $this->server->clients[$CID];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getAll(){
|
||||
return $this->server->clients;
|
||||
}
|
||||
|
||||
public function getByEID($eid){
|
||||
$eid = (int) $eid;
|
||||
$CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true);
|
||||
$CID = $this->server->clientID($CID["ip"], $CID["port"]);
|
||||
if(isset($this->server->clients[$CID])){
|
||||
return $this->server->clients[$CID];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getByClientID($clientID){
|
||||
$clientID = (int) $clientID;
|
||||
$CID = $this->server->query("SELECT ip,port FROM players WHERE clientID = '".$clientID."';", true);
|
||||
$CID = $this->server->clientID($CID["ip"], $CID["port"]);
|
||||
if(isset($this->server->clients[$CID])){
|
||||
return $this->server->clients[$CID];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function online(){
|
||||
$o = array();
|
||||
foreach($this->server->clients as $p){
|
||||
if($p->auth === true){
|
||||
$o[] = $p->username;
|
||||
}
|
||||
}
|
||||
return $o;
|
||||
}
|
||||
|
||||
public function add($CID){
|
||||
if(isset($this->server->clients[$CID])){
|
||||
$player = $this->server->clients[$CID];
|
||||
console("[INFO] Player \"".$player->username."\" connected from ".$player->ip.":".$player->port);
|
||||
$player->data = $this->getOffline($player->username);
|
||||
$this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".$player->username."');");
|
||||
}
|
||||
}
|
||||
|
||||
public function remove($CID){
|
||||
if(isset($this->server->clients[$CID])){
|
||||
$player = $this->server->clients[$CID];
|
||||
if(is_object($player->entity)){
|
||||
$player->entity->close();
|
||||
}
|
||||
$this->saveOffline($player->username, $player->data);
|
||||
$this->server->query("DELETE FROM players WHERE name = '".$player->username."';");
|
||||
unset($this->server->entities[$player->eid]);
|
||||
unset($this->server->clients[$player->CID]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getOffline($name){
|
||||
if(!file_exists(FILE_PATH."players/".$name.".dat")){
|
||||
console("[NOTICE] Player data not found for \"".$name."\", creating new profile");
|
||||
$data = array(
|
||||
"spawn" => array(
|
||||
"x" => $this->server->spawn["x"],
|
||||
"y" => $this->server->spawn["y"],
|
||||
"z" => $this->server->spawn["z"],
|
||||
),
|
||||
"health" => 20,
|
||||
"lastIP" => "",
|
||||
"lastID" => 0,
|
||||
);
|
||||
$this->saveOffline($name, $data);
|
||||
}else{
|
||||
$data = unserialize(file_get_contents(FILE_PATH."players/".$name.".dat"));
|
||||
}
|
||||
$this->server->handle("api.player.offline.get", $data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function saveOffline($name, $data){
|
||||
$this->server->handle("api.player.offline.save", $data);
|
||||
file_put_contents(FILE_PATH."players/".str_replace("/", "", $name).".dat", serialize($data));
|
||||
}
|
||||
}
|
179
src/API/PluginAPI.php
Normal file
179
src/API/PluginAPI.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class PluginAPI extends stdClass{
|
||||
private $server, $plugins;
|
||||
public function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
$this->plugins = array();
|
||||
require_once("classes/Spyc.class.php"); //YAML parser
|
||||
}
|
||||
|
||||
public function getList(){
|
||||
$list = array();
|
||||
foreach($this->plugins as $p){
|
||||
$list[] = $p[1];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getInfo($className){
|
||||
if(!isset($this->plugins[$className])){
|
||||
return false;
|
||||
}
|
||||
$plugin = $this->plugins[$className];
|
||||
return array($plugin[1], get_class_methods($plugin[0]));
|
||||
}
|
||||
|
||||
public function load($file){
|
||||
$content = file_get_contents($file);
|
||||
$info = strstr($content, "*/", true);
|
||||
$content = substr(strstr($content, "*/"),2);
|
||||
if(preg_match_all('#([a-zA-Z0-9\-_]*)=([^\r\n]*)#u', $info, $matches) == 0){ //false or 0 matches
|
||||
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file));
|
||||
return false;
|
||||
}
|
||||
$info = array();
|
||||
foreach($matches[1] as $k => $i){
|
||||
$v = $matches[2][$k];
|
||||
switch(strtolower($v)){
|
||||
case "on":
|
||||
case "true":
|
||||
case "yes":
|
||||
$v = true;
|
||||
break;
|
||||
case "off":
|
||||
case "false":
|
||||
case "no":
|
||||
$v = false;
|
||||
break;
|
||||
}
|
||||
$info[$i] = $v;
|
||||
}
|
||||
if(!isset($info["name"]) or !isset($info["version"]) or !isset($info["class"]) or !isset($info["author"])){
|
||||
console("[ERROR] [PluginAPI] Failed parsing of ".basename($file));
|
||||
}
|
||||
console("[INFO] [PluginAPI] Loading plugin \"".$info["name"]."\" ".$info["version"]." by ".$info["author"]);
|
||||
if(class_exists($info["class"])){
|
||||
console("[ERROR] [PluginAPI] Failed loading plugin: class exists");
|
||||
}
|
||||
if(eval($content) === false or !class_exists($info["class"])){
|
||||
console("[ERROR] [PluginAPI] Failed loading plugin: evaluation error");
|
||||
}
|
||||
$className = trim($info["class"]);
|
||||
if(isset($info["api"]) and $info["api"] !== true){
|
||||
console("[NOTICE] [PluginAPI] Plugin \"".$info["name"]."\" got raw access to Server methods");
|
||||
}
|
||||
$object = new $className($this->server->api, ((isset($info["api"]) and $info["api"] !== true) ? $this->server:false));
|
||||
if(!($object instanceof Plugin)){
|
||||
console("[ERROR] [PluginAPI] Plugin \"".$info["name"]."\" doesn't use the Plugin Interface");
|
||||
if(method_exists($object, "__destruct")){
|
||||
$object->__destruct();
|
||||
}
|
||||
$object = null;
|
||||
unset($object);
|
||||
}else{
|
||||
$this->plugins[$className] = array($object, $info);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Plugin $plugin){
|
||||
foreach($this->plugins as &$p){
|
||||
if($p[0] === $plugin){
|
||||
return $p;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function createConfig(Plugin $plugin, $default = array()){
|
||||
$p = $this->get($plugin);
|
||||
if($p === false){
|
||||
return false;
|
||||
}
|
||||
$path = FILE_PATH."plugins/".$p[1]["name"]."/";
|
||||
$this->plugins[$p[1]["class"]][1]["path"] = $path;
|
||||
if(!file_exists($path."config.yml")){
|
||||
@mkdir($path, 0777);
|
||||
$this->writeYAML($path."config.yml", $default);
|
||||
}else{
|
||||
$data = $this->readYAML($path."config.yml");
|
||||
$this->fillDefaults($default, $data);
|
||||
$this->writeYAML($path."config.yml", $data);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function fillDefaults($default, &$yaml){
|
||||
foreach($default as $k => $v){
|
||||
if(is_array($v)){
|
||||
if(!isset($yaml[$k]) or !is_array($yaml[$k])){
|
||||
$yaml[$k] = array();
|
||||
}
|
||||
$this->fillDefaults($v, $yaml[$k]);
|
||||
}elseif(!isset($yaml[$k])){
|
||||
$yaml[$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function readYAML($file){
|
||||
return Spyc::YAMLLoad(file_get_contents($file));
|
||||
}
|
||||
|
||||
public function writeYAML($file, $data){
|
||||
return file_put_contents($file, Spyc::YAMLDump($data));
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->event("server.start", array($this, "loadAll"));
|
||||
}
|
||||
|
||||
public function loadAll(){
|
||||
console("[INFO] Loading Plugins...");
|
||||
$dir = dir(FILE_PATH."plugins/");
|
||||
while(false !== ($file = $dir->read())){
|
||||
if($file !== "." and $file !== ".."){
|
||||
if(strtolower(substr($file, -3)) === "php"){
|
||||
$this->load(FILE_PATH."plugins/" . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($this->plugins as $p){
|
||||
if(method_exists($p[0], "init")){
|
||||
$p[0]->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface Plugin{
|
||||
public function __construct(ServerAPI $api, $server = false);
|
||||
public function init();
|
||||
public function __destruct();
|
||||
}
|
386
src/API/ServerAPI.php
Normal file
386
src/API/ServerAPI.php
Normal file
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class ServerAPI extends stdClass{ //Yay! I can add anything to this class in runtime!
|
||||
var $restart = false;
|
||||
private $server, $config, $apiList = array();
|
||||
function __construct(){
|
||||
console("[INFO] Starting ServerAPI server handler...");
|
||||
file_put_contents(FILE_PATH."packets.log", "");
|
||||
file_put_contents(FILE_PATH."console.in", "");
|
||||
if(!file_exists(FILE_PATH."test.bin.log") or md5_file(FILE_PATH."test.bin.log") !== TEST_MD5){
|
||||
console("[NOTICE] Executing integrity tests...");
|
||||
console("[INFO] OS: ".PHP_OS.", ".Utils::getOS());
|
||||
console("[INFO] uname -a: ".php_uname("a"));
|
||||
console("[INFO] PHP Version: ".phpversion());
|
||||
console("[INFO] Endianness: ".ENDIANNESS);
|
||||
$test = b"";
|
||||
$test .= Utils::writeLong("5567381823242127440");
|
||||
$test .= Utils::writeLong("2338608908624488819");
|
||||
$test .= Utils::writeLong("2333181766244987936");
|
||||
$test .= Utils::writeLong("2334669371112169504");
|
||||
$test .= Utils::writeShort(Utils::readShort("\xff\xff\xff\xff"));
|
||||
$test .= Utils::writeShort(Utils::readShort("\xef\xff\xff\xff"));
|
||||
$test .= Utils::writeInt(Utils::readInt("\xff\xff\xff\xff"));
|
||||
$test .= Utils::writeInt(1);
|
||||
$test .= Utils::writeInt(-1);
|
||||
$test .= Utils::writeFloat(Utils::readfloat("\xff\xff\xff\xff"));
|
||||
$test .= Utils::writeFloat(-1.584563155838E+29);
|
||||
$test .= Utils::writeFloat(1);
|
||||
$test .= Utils::writeLDouble(Utils::readLDouble("\xff\xff\xff\xff\xff\xff\xff\xff"));
|
||||
$test .= Utils::writeLong("-1152921504606846977");
|
||||
$test .= Utils::writeLong("-1152921504606846976");
|
||||
$test .= Utils::writeTriad(16777215);
|
||||
$test .= Utils::writeTriad(16777216);
|
||||
$str = new Java_String("THIS_IS_ a TEsT_SEED1_123456789^.,.,\xff\x00\x15");
|
||||
$test .= Utils::writeLong($str->hashCode());
|
||||
$test .= Utils::writeDataArray(array("a", "b", "c", "\xff\xff\xff\xff"));
|
||||
$test .= Utils::hexToStr("012334567890");
|
||||
file_put_contents(FILE_PATH."test.bin.log", $test);
|
||||
if(md5($test) !== TEST_MD5){
|
||||
console("[ERROR] Test error, please send your console.log + test.bin.log to the Github repo");
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
if(!file_exists(FILE_PATH."white-list.txt")){
|
||||
console("[NOTICE] No white-list.txt found, creating blank file");
|
||||
file_put_contents(FILE_PATH."white-list.txt", "");
|
||||
}
|
||||
|
||||
if(!file_exists(FILE_PATH."banned-ips.txt")){
|
||||
console("[NOTICE] No banned-ips.txt found, creating blank file");
|
||||
file_put_contents(FILE_PATH."banned-ips.txt", "");
|
||||
}
|
||||
|
||||
if(!file_exists(FILE_PATH."server.properties")){
|
||||
console("[NOTICE] No server.properties found, using default settings");
|
||||
copy(FILE_PATH."src/common/default.properties", FILE_PATH."server.properties");
|
||||
}
|
||||
|
||||
console("[DEBUG] Checking data folders...", true, true, 2);
|
||||
@mkdir(FILE_PATH."players/", 0777, true);
|
||||
@mkdir(FILE_PATH."worlds/", 0777);
|
||||
@mkdir(FILE_PATH."plugins/", 0777);
|
||||
|
||||
console("[DEBUG] Loading server.properties...", true, true, 2);
|
||||
$this->parseProperties();
|
||||
define("DEBUG", $this->config["debug"]);
|
||||
$this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), false, CURRENT_PROTOCOL, $this->getProperty("port"), $this->getProperty("server-id"));
|
||||
$this->server->api = $this;
|
||||
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
|
||||
console("[INFO] Checking for new server version");
|
||||
console("[INFO] Last check: ".date("Y-m-d H:i:s", $this->getProperty("last-update")));
|
||||
$channel = "stable";
|
||||
if($this->getProperty("update-channel") == "dev" or $this->getProperty("update-channel") == "development"){
|
||||
$channel = "dev";
|
||||
}
|
||||
$this->setProperty("update-channel", $channel);
|
||||
|
||||
if($channel === "dev"){
|
||||
$info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/PocketMine-MP"), true);
|
||||
if($info === false or !isset($info["updated_at"])){
|
||||
console("[ERROR] GitHub API Error");
|
||||
}else{
|
||||
$last = new DateTime($info["updated_at"]);
|
||||
$last = $last->getTimestamp();
|
||||
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false){
|
||||
console("[NOTICE] A new DEVELOPMENT version of PocketMine-MP has been released");
|
||||
console("[NOTICE] If you want to update, get the latest version at https://github.com/shoghicp/PocketMine-MP/archive/master.zip");
|
||||
console("[NOTICE] This message will dissapear when you issue the command \"/update-done\"");
|
||||
sleep(3);
|
||||
}else{
|
||||
$this->setProperty("last-update", time());
|
||||
console("[INFO] This is the latest DEVELOPMENT version");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$info = json_decode(Utils::curl_get("https://api.github.com/repos/shoghicp/PocketMine-MP/tags"), true);
|
||||
if($info === false or !isset($info[0])){
|
||||
console("[ERROR] GitHub API Error");
|
||||
}else{
|
||||
$info = $info[0];
|
||||
if($info["name"] != MAJOR_VERSION){
|
||||
console("[NOTICE] A new STABLE version of PocketMine-MP has been released");
|
||||
console("[NOTICE] Version \"".$info["name"]."\" [".substr($info["commit"]["sha"], 0, 10)."]");
|
||||
console("[NOTICE] Download it at ".$info["zipball_url"]);
|
||||
console("[NOTICE] This message will dissapear as soon as you update\"");
|
||||
sleep(5);
|
||||
}else{
|
||||
$this->setProperty("last-update", time());
|
||||
console("[INFO] This is the latest STABLE version");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(file_exists(FILE_PATH."worlds/level.dat")){
|
||||
console("[NOTICE] Detected unimported map data. Importing...");
|
||||
$this->importMap(FILE_PATH."worlds/", true);
|
||||
}
|
||||
$this->server->mapName = $this->getProperty("level-name");
|
||||
$this->server->mapDir = FILE_PATH."worlds/".$this->server->mapName."/";
|
||||
if($this->server->mapName === false or trim($this->server->mapName) === "" or !file_exists($this->server->mapDir."chunks.dat")){
|
||||
if($this->server->mapName === false or trim($this->server->mapName) === ""){
|
||||
$this->server->mapName = "world";
|
||||
}
|
||||
$this->server->mapDir = FILE_PATH."worlds/".$this->server->mapName."/";
|
||||
$generator = "SuperflatGenerator";
|
||||
if($this->getProperty("generator") !== false and class_exists($this->getProperty("generator"))){
|
||||
$generator = $this->getProperty("generator");
|
||||
}
|
||||
$this->gen = new WorldGenerator($generator, $this->server->seed);
|
||||
if($this->getProperty("generator-settings") !== false and trim($this->getProperty("generator-settings")) != ""){
|
||||
$this->gen->set("preset", $this->getProperty("generator-settings"));
|
||||
}
|
||||
$this->gen->init();
|
||||
$this->gen->generate();
|
||||
$this->gen->save($this->server->mapDir, $this->server->mapName);
|
||||
$this->setProperty("level-name", $this->server->mapName);
|
||||
$this->setProperty("gamemode", 1);
|
||||
}
|
||||
$this->loadProperties();
|
||||
$this->server->loadMap();
|
||||
|
||||
//Autoload all default APIs
|
||||
console("[INFO] Loading default APIs");
|
||||
$dir = dir(FILE_PATH."src/API/");
|
||||
while(false !== ($file = $dir->read())){
|
||||
if($file !== "." and $file !== ".."){
|
||||
$API = basename($file, ".php");
|
||||
if(strtolower($API) !== "serverapi"){
|
||||
$name = strtolower(substr($API, 0, -3));
|
||||
$this->loadAPI($name, $API);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($this->apiList as $ob){
|
||||
if(is_callable(array($ob, "init"))){
|
||||
$ob->init();
|
||||
}
|
||||
}
|
||||
|
||||
$this->server->loadEntities();
|
||||
}
|
||||
|
||||
private function loadProperties(){
|
||||
if(isset($this->config["memory-limit"])){
|
||||
@ini_set("memory_limit", $this->config["memory-limit"]);
|
||||
}else{
|
||||
$this->config["memory-limit"] = "256M";
|
||||
}
|
||||
if(!isset($this->config["invisible"])){
|
||||
$this->config["invisible"] = false;
|
||||
}
|
||||
if(is_object($this->server)){
|
||||
$this->server->setType($this->config["server-type"]);
|
||||
$this->server->timePerSecond = $this->config["time-per-second"];
|
||||
$this->server->invisible = $this->config["invisible"];
|
||||
$this->server->maxClients = $this->config["max-players"];
|
||||
$this->server->description = $this->config["description"];
|
||||
$this->server->motd = $this->config["motd"];
|
||||
$this->server->gamemode = $this->config["gamemode"];
|
||||
$this->server->difficulty = $this->config["difficulty"];
|
||||
$this->server->whitelist = $this->config["white-list"];
|
||||
$this->server->reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private function writeProperties(){
|
||||
if(is_object($this->server)){
|
||||
$this->config["server-id"] = $this->server->serverID;
|
||||
}
|
||||
$config = $this->config;
|
||||
$config["white-list"] = $config["white-list"] === true ? "true":"false";
|
||||
$config["invisible"] = $config["invisible"] === true ? "true":"false";
|
||||
$prop = "#Pocket Minecraft PHP server properties\r\n#".date("D M j H:i:s T Y")."\r\n";
|
||||
foreach($config as $n => $v){
|
||||
$prop .= $n."=".$v."\r\n";
|
||||
}
|
||||
file_put_contents(FILE_PATH."server.properties", $prop);
|
||||
}
|
||||
|
||||
private function parseProperties(){
|
||||
$prop = file_get_contents(FILE_PATH."server.properties");
|
||||
$prop = explode("\n", str_replace("\r", "", $prop));
|
||||
$this->config = array();
|
||||
foreach($prop as $line){
|
||||
if(trim($line) == "" or $line{0} == "#"){
|
||||
continue;
|
||||
}
|
||||
$d = explode("=", $line);
|
||||
$n = strtolower(array_shift($d));
|
||||
$v = implode("=", $d);
|
||||
switch(strtolower(trim($v))){
|
||||
case "on":
|
||||
case "true":
|
||||
case "yes":
|
||||
$v = true;
|
||||
break;
|
||||
case "off":
|
||||
case "false":
|
||||
case "no":
|
||||
$v = false;
|
||||
break;
|
||||
}
|
||||
switch($n){
|
||||
case "last-update":
|
||||
if($v === false){
|
||||
$v = time();
|
||||
}else{
|
||||
$v = (int) $v;
|
||||
}
|
||||
break;
|
||||
case "gamemode":
|
||||
case "max-players":
|
||||
case "port":
|
||||
case "debug":
|
||||
case "difficulty":
|
||||
case "time-per-second":
|
||||
$v = (int) $v;
|
||||
break;
|
||||
case "server-id":
|
||||
if($v !== false){
|
||||
$v = preg_match("/[^0-9\-]/", $v) > 0 ? Utils::readInt(substr(md5($v, true), 0, 4)):$v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$this->config[$n] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
public function start(){
|
||||
$this->server->start();
|
||||
unregister_tick_function(array($this->server, "tick"));
|
||||
unset($this->server);
|
||||
return $this->restart;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
public function addHandler($e, $c, $p = 5){
|
||||
return $this->server->addHandler($e, $c, $p);
|
||||
}
|
||||
|
||||
public function handle($e, &$d){
|
||||
return $this->server->handle($e, $d);
|
||||
}
|
||||
|
||||
public function action($t, $c, $r = true){
|
||||
return $this->server->action($t, $c, $r);
|
||||
}
|
||||
|
||||
public function schedule($t, $c, $d, $r = false, $e = "server.schedule"){
|
||||
return $this->server->schedule($t, $c, $d, $r, $e);
|
||||
}
|
||||
|
||||
public function event($e, $d){
|
||||
return $this->server->event($e, $d);
|
||||
}
|
||||
|
||||
public function trigger($e, $d){
|
||||
return $this->server->trigger($e, $d);
|
||||
}
|
||||
|
||||
public function deleteEvent($id){
|
||||
return $this->server->deleteEvent($id);
|
||||
}
|
||||
|
||||
public function importMap($dir, $remove = false){
|
||||
if(file_exists($dir."level.dat")){
|
||||
$nbt = new NBT();
|
||||
$level = parseNBTData($nbt->loadFile($dir."level.dat"));
|
||||
console("[DEBUG] Importing map \"".$level["LevelName"]."\" gamemode ".$level["GameType"]." with seed ".$level["RandomSeed"], true, true, 2);
|
||||
unset($level["Player"]);
|
||||
$lvName = $level["LevelName"]."/";
|
||||
@mkdir(FILE_PATH."worlds/".$lvName, 0777);
|
||||
file_put_contents(FILE_PATH."worlds/".$lvName."level.dat", serialize($level));
|
||||
$entities = parseNBTData($nbt->loadFile($dir."entities.dat"));
|
||||
file_put_contents(FILE_PATH."worlds/".$lvName."entities.dat", serialize($entities["Entities"]));
|
||||
if(!isset($entities["TileEntities"])){
|
||||
$entities["TileEntities"] = array();
|
||||
}
|
||||
file_put_contents(FILE_PATH."worlds/".$lvName."tileEntities.dat", serialize($entities["TileEntities"]));
|
||||
console("[DEBUG] Imported ".count($entities["Entities"])." Entities and ".count($entities["TileEntities"])." TileEntities", true, true, 2);
|
||||
|
||||
if($remove === true){
|
||||
rename($dir."chunks.dat", FILE_PATH."worlds/".$lvName."chunks.dat");
|
||||
unlink($dir."level.dat");
|
||||
@unlink($dir."level.dat_old");
|
||||
@unlink($dir."player.dat");
|
||||
unlink($dir."entities.dat");
|
||||
}else{
|
||||
copy($dir."chunks.dat", FILE_PATH."worlds/".$lvName."chunks.dat");
|
||||
}
|
||||
if($this->getProperty("level-name") === false){
|
||||
console("[INFO] Setting default level to \"".$level["LevelName"]."\"");
|
||||
$this->setProperty("level-name", $level["LevelName"]);
|
||||
$this->setProperty("gamemode", $level["GameType"]);
|
||||
$this->server->seed = $level["RandomSeed"];
|
||||
$this->server->spawn = array("x" => $level["SpawnX"], "y" => $level["SpawnY"], "z" => $level["SpawnZ"]);
|
||||
$this->writeProperties();
|
||||
}
|
||||
console("[INFO] Map \"".$level["LevelName"]."\" importing done!");
|
||||
unset($level, $entities, $nbt);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getProperty($name){
|
||||
if(isset($this->config[$name])){
|
||||
return $this->config[$name];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setProperty($name, $value){
|
||||
$this->config[$name] = $value;
|
||||
$this->writeProperties();
|
||||
$this->loadProperties();
|
||||
}
|
||||
|
||||
public function getList(){
|
||||
return $this->apiList;
|
||||
}
|
||||
|
||||
public function loadAPI($name, $class, $dir = false){
|
||||
if($dir === false){
|
||||
$dir = FILE_PATH."src/API/";
|
||||
}
|
||||
$file = $dir.$class.".php";
|
||||
if(!file_exists($file)){
|
||||
console("[ERROR] API ".$name." [".$class."] in ".$dir." doesn't exist", true, true, 0);
|
||||
return false;
|
||||
}
|
||||
require_once($file);
|
||||
$this->$name = new $class($this->server);
|
||||
$this->apiList[] = $this->$name;
|
||||
console("[INFO] API ".$name." [".$class."] loaded");
|
||||
}
|
||||
|
||||
}
|
127
src/API/TimeAPI.php
Normal file
127
src/API/TimeAPI.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class TimeAPI{
|
||||
var $phases = array(
|
||||
"day" => 0,
|
||||
"sunset" => 9500,
|
||||
"night" => 10900,
|
||||
"sunrise" => 17800,
|
||||
);
|
||||
private $server;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
$this->server = $server;
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("time", "Manages server time", array($this, "commandHandler"));
|
||||
}
|
||||
|
||||
public function commandHandler($cmd, $params){
|
||||
switch($cmd){
|
||||
case "time":
|
||||
$p = strtolower(array_shift($params));
|
||||
switch($p){
|
||||
case "check":
|
||||
console("[INFO] Time: ".$this->getDate().", ".$this->getPhase()." (".$this->get(true).")");
|
||||
break;
|
||||
case "add":
|
||||
$this->add(array_shift($params));
|
||||
break;
|
||||
case "set":
|
||||
$this->set(array_shift($params));
|
||||
break;
|
||||
case "sunrise":
|
||||
$this->sunrise();
|
||||
break;
|
||||
case "day":
|
||||
$this->day();
|
||||
break;
|
||||
case "sunset":
|
||||
$this->sunset();
|
||||
break;
|
||||
case "night":
|
||||
$this->night();
|
||||
break;
|
||||
default:
|
||||
console("[INFO] Usage: /time <check | set | add | sunrise | day | sunset | night> [time]");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function night(){
|
||||
$this->set("night");
|
||||
}
|
||||
public function day(){
|
||||
$this->set("day");
|
||||
}
|
||||
public function sunrise(){
|
||||
$this->set("sunrise");
|
||||
}
|
||||
public function sunset(){
|
||||
$this->set("sunset");
|
||||
}
|
||||
|
||||
public function get($raw = false){
|
||||
return $raw === true ? $this->server->time:abs($this->server->time) % 19200;
|
||||
}
|
||||
|
||||
public function add($time){
|
||||
$this->server->time += (int) $time;
|
||||
}
|
||||
|
||||
public function getDate($time = false){
|
||||
$time = $time === false ? $this->get():$time;
|
||||
return str_pad(strval((floor($time /800) + 6) % 24), 2, "0", STR_PAD_LEFT).":".str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function getPhase($time = false){
|
||||
$time = $time === false ? $this->get():$time;
|
||||
if($time < $this->phase["sunset"]){
|
||||
$time = "day";
|
||||
}elseif($time < $this->phase["night"]){
|
||||
$time = "sunset";
|
||||
}elseif($time < $this->phase["sunrise"]){
|
||||
$time = "night";
|
||||
}else{
|
||||
$time = "sunrise";
|
||||
}
|
||||
return $time;
|
||||
}
|
||||
|
||||
public function set($time){
|
||||
if(is_string($time) and isset($this->phases[$time])){
|
||||
$this->server->time = $this->phases[$time];
|
||||
}else{
|
||||
$this->server->time = (int) $time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
3630
src/classes/BigInteger.class.php
Normal file
3630
src/classes/BigInteger.class.php
Normal file
File diff suppressed because it is too large
Load Diff
221
src/classes/ChunkParser.class.php
Normal file
221
src/classes/ChunkParser.class.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class ChunkParser{
|
||||
private $location, $raw = b"", $file;
|
||||
var $sectorLength = 4096; //16 * 16 * 16
|
||||
var $chunkLength = 86016; //21 * $sectorLength
|
||||
var $map;
|
||||
|
||||
function __construct(){
|
||||
$map = array();
|
||||
}
|
||||
|
||||
private function loadLocationTable(){
|
||||
$this->location = array();
|
||||
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
||||
$chunkCnt = 0;
|
||||
for($offset = 0; $offset < 0x1000; $offset += 4){
|
||||
$data = substr($this->raw, $offset, 4);
|
||||
$sectors = ord($data{0});
|
||||
if($sectors === 0){
|
||||
continue;
|
||||
}
|
||||
$x = ord($data{1});
|
||||
$z = ord($data{2});
|
||||
$X = $chunkCnt % 16;
|
||||
$Z = $chunkCnt >> 4;
|
||||
//$unused = ord($data{3});
|
||||
if(!isset($this->location[$X])){
|
||||
$this->location[$X] = array();
|
||||
}
|
||||
$this->location[$X][$Z] = $this->getOffset($X, $Z, $sectors);
|
||||
++$chunkCnt;
|
||||
}
|
||||
}
|
||||
|
||||
public function loadFile($file){
|
||||
if(!file_exists($file)){
|
||||
return false;
|
||||
}
|
||||
$this->file = $file;
|
||||
$this->raw = file_get_contents($file);
|
||||
$this->chunkLength = $this->sectorLength * ord($this->raw{0});
|
||||
return true;
|
||||
}
|
||||
|
||||
public function loadRaw($raw, $file){
|
||||
$this->file = $file;
|
||||
$this->raw = $raw;
|
||||
$this->chunkLength = $this->sectorLength * ord($this->raw{0});
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getOffsetPosition($X, $Z){
|
||||
$data = substr($this->raw, ($X << 2) + ($Z << 7), 4); //$X * 4 + $Z * 128
|
||||
return array(ord($data{0}), ord($data{1}), ord($data{2}), ord($data{3}));
|
||||
}
|
||||
|
||||
private function getOffset($X, $Z, $sectors = 21){
|
||||
return 0x1000 + (($X * $sectors) << 12) + (($Z * $sectors) << 16);
|
||||
}
|
||||
|
||||
private function getOffsetLocation($X, $Z){
|
||||
return $X << 2 + $Z << 7;
|
||||
}
|
||||
|
||||
public function getChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
return substr($this->raw, $this->getOffset($X, $Z), $this->chunkLength);
|
||||
}
|
||||
|
||||
public function writeChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
if(!isset($this->map[$X][$Z])){
|
||||
return false;
|
||||
}
|
||||
$chunk = "";
|
||||
foreach($this->map[$X][$Z] as $section => $data){
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$chunk .= $data[$i];
|
||||
}
|
||||
}
|
||||
return Utils::writeLInt(strlen($chunk)).$chunk;
|
||||
}
|
||||
|
||||
public function parseChunk($X, $Z){
|
||||
$X = (int) $X;
|
||||
$Z = (int) $Z;
|
||||
$offset = $this->location[$X][$Z];
|
||||
$len = Utils::readLInt(substr($this->raw, $offset, 4));
|
||||
$offset += 4;
|
||||
$chunk = array(
|
||||
0 => array(), //Block
|
||||
1 => array(), //Data
|
||||
2 => array(), //SkyLight
|
||||
3 => array(), //BlockLight
|
||||
);
|
||||
foreach($chunk as $section => &$data){
|
||||
$l = $section === 0 ? 128:64;
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$data[$i] = substr($this->raw, $offset, $l);
|
||||
$offset += $l;
|
||||
}
|
||||
}
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
public function loadMap(){
|
||||
if($this->raw == ""){
|
||||
return false;
|
||||
}
|
||||
$this->loadLocationTable();
|
||||
console("[DEBUG] Loading chunks...", true, true, 2);
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$this->map[$x] = array();
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$this->map[$x][$z] = $this->parseChunk($x, $z);
|
||||
}
|
||||
}
|
||||
$this->raw = b"";
|
||||
console("[DEBUG] Chunks loaded!", true, true, 2);
|
||||
}
|
||||
|
||||
public function saveMap(){
|
||||
console("[DEBUG] Saving chunks...", true, true, 2);
|
||||
$fp = fopen($this->file, "r+b");
|
||||
flock($fp, LOCK_EX);
|
||||
foreach($this->map as $x => $d){
|
||||
foreach($d as $z => $chunk){
|
||||
fseek($fp, $this->location[$x][$z]);
|
||||
fwrite($fp, $this->writeChunk($x, $z), $this->chunkLength);
|
||||
}
|
||||
}
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public function getFloor($x, $z){
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$aX = $x - ($X << 4);
|
||||
$aZ = $z - ($Z << 4);
|
||||
$index = $aZ + ($aX << 4);
|
||||
for($y = 127; $y <= 0; --$y){
|
||||
if($this->map[$X][$Z][0][$index]{$y} !== "\x00"){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $y;
|
||||
}
|
||||
|
||||
public function getBlock($x, $y, $z){
|
||||
$x = (int) $x;
|
||||
$y = (int) $y;
|
||||
$z = (int) $z;
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$aX = $x - ($X << 4);
|
||||
$aZ = $z - ($Z << 4);
|
||||
$index = $aZ + ($aX << 4);
|
||||
$block = ord($this->map[$X][$Z][0][$index]{$y});
|
||||
$meta = ord($this->map[$X][$Z][1][$index]{$y >> 1});
|
||||
if(($y & 1) === 0){
|
||||
$meta = $meta & 0x0F;
|
||||
}else{
|
||||
$meta = $meta >> 4;
|
||||
}
|
||||
return array($block, $meta);
|
||||
}
|
||||
|
||||
public function getChunkColumn($X, $Z, $x, $z, $type = 0){
|
||||
$index = $z + ($x << 4);
|
||||
return $this->map[$X][$Z][$type][$index];
|
||||
}
|
||||
|
||||
public function setBlock($x, $y, $z, $block, $meta = 0){
|
||||
$x = (int) $x;
|
||||
$y = (int) $y;
|
||||
$z = (int) $z;
|
||||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$aX = $x - ($X << 4);
|
||||
$aZ = $z - ($Z << 4);
|
||||
$index = $aZ + ($aX << 4);
|
||||
$this->map[$X][$Z][0][$index]{$y} = chr($block);
|
||||
$old_meta = ord($this->map[$X][$Z][1][$index]{$y >> 1});
|
||||
if(($y & 1) === 0){
|
||||
$meta = ($old_meta & 0xF0) | ($meta & 0x0F);
|
||||
}else{
|
||||
$meta = (($meta << 4) & 0xF0) | ($old_meta & 0x0F);
|
||||
}
|
||||
$this->map[$X][$Z][1][$index]{$y >> 1} = chr($meta);
|
||||
}
|
||||
|
||||
}
|
515
src/classes/CustomPacketHandler.class.php
Normal file
515
src/classes/CustomPacketHandler.class.php
Normal file
@@ -0,0 +1,515 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class CustomPacketHandler{
|
||||
var $offset, $raw, $c, $data, $name = "";
|
||||
|
||||
private function get($len = true, $check = true){
|
||||
if($len === true){
|
||||
$data = substr($this->raw, $this->offset);
|
||||
if($check === true){
|
||||
$this->offset = strlen($this->raw);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
$data = substr($this->raw, $this->offset, $len);
|
||||
if($check === true){
|
||||
$this->offset += $len;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function __construct($pid, $raw = "", $data = array(), $create = false){
|
||||
$this->raw = $raw;
|
||||
$this->data = $data;
|
||||
$this->offset = 0;
|
||||
$this->c = (bool) $create;
|
||||
switch($pid){
|
||||
case MC_KEEP_ALIVE:
|
||||
if($this->c === false){
|
||||
$this->data["payload"] = Utils::readLong($this->get(8));
|
||||
}else{
|
||||
$this->raw .= Utils::writeLong($this->data["payload"]);
|
||||
}
|
||||
break;
|
||||
case MC_CLIENT_CONNECT:
|
||||
if($this->c === false){
|
||||
$this->data["clientID"] = Utils::readLong($this->get(8));
|
||||
$this->data["session"] = Utils::readLong($this->get(8));
|
||||
$this->data["unknown2"] = $this->get(1);
|
||||
}else{
|
||||
$this->raw .= Utils::writeLong($this->data["clientID"]);
|
||||
$this->raw .= Utils::writeLong($this->data["session"]);
|
||||
$this->raw .= "\x00";
|
||||
}
|
||||
break;
|
||||
case MC_SERVER_HANDSHAKE:
|
||||
if($this->c === false){
|
||||
$this->data["cookie"] = $this->get(4); // 043f57fe
|
||||
$this->data["security"] = $this->get(1);
|
||||
$this->data["port"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 10, $offset);
|
||||
$this->get($offset);
|
||||
$this->data["unknown1"] = $this->get(2);
|
||||
$this->data["session"] = Utils::readLong($this->get(8));
|
||||
$this->data["session2"] = Utils::readLong($this->get(8));
|
||||
}else{
|
||||
$this->raw .= "\x04\x3f\x57\xfe";
|
||||
$this->raw .= "\xcd";
|
||||
$this->raw .= Utils::writeShort($this->data["port"]);
|
||||
$this->raw .= Utils::writeDataArray(array(
|
||||
"\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",
|
||||
"\xff\xff\xff\xff",
|
||||
));
|
||||
$this->raw .= "\x00\x00";
|
||||
$this->raw .= Utils::writeLong($this->data["session"]);
|
||||
$this->raw .= Utils::writeLong($this->data["session2"]);
|
||||
}
|
||||
break;
|
||||
case MC_CLIENT_HANDSHAKE:
|
||||
if($this->c === false){
|
||||
$this->data["cookie"] = $this->get(4); // 043f57fe
|
||||
$this->data["security"] = $this->get(1);
|
||||
$this->data["port"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["dataArray0"] = $this->get(ord($this->get(1)));
|
||||
$this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 9, $offset);
|
||||
$this->get($offset);
|
||||
$this->data["unknown1"] = $this->get(2);
|
||||
$this->data["session2"] = Utils::readLong($this->get(8));
|
||||
$this->data["session"] = Utils::readLong($this->get(8));
|
||||
}else{
|
||||
$this->raw .= "\x04\x3f\x57\xfe";
|
||||
$this->raw .= "\xed";
|
||||
$this->raw .= Utils::writeShort($this->data["port"]);
|
||||
$w = array_shift($this->data["dataArray"]);
|
||||
$this->raw .= chr(strlen($w)).$w;
|
||||
$this->raw .= Utils::writeDataArray($this->data["dataArray"]);
|
||||
$this->raw .= "\x00\x00";
|
||||
$this->raw .= Utils::writeLong($this->data["session2"]);
|
||||
$this->raw .= Utils::writeLong($this->data["session"]);
|
||||
}
|
||||
break;
|
||||
case MC_DISCONNECT:
|
||||
//null
|
||||
break;
|
||||
case 0x18:
|
||||
//null
|
||||
break;
|
||||
case MC_LOGIN:
|
||||
if($this->c === false){
|
||||
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
$this->data["maxX"] = Utils::readInt($this->get(4));
|
||||
$this->data["maxY"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
|
||||
$this->raw .= "\x00\x00\x00\x08\x00\x00\x00\x08";
|
||||
}
|
||||
break;
|
||||
case MC_LOGIN_STATUS:
|
||||
if($this->c === false){
|
||||
$this->data["status"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["status"]);
|
||||
}
|
||||
break;
|
||||
case MC_READY:
|
||||
if($this->c === false){
|
||||
$this->data["status"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= chr($this->data["status"]);
|
||||
}
|
||||
break;
|
||||
case MC_CHAT:
|
||||
if($this->c === false){
|
||||
$this->data["message"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
}else{
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"];
|
||||
}
|
||||
break;
|
||||
case MC_SET_TIME:
|
||||
if($this->c === false){
|
||||
$this->data["time"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["time"]);
|
||||
}
|
||||
break;
|
||||
case MC_START_GAME:
|
||||
if($this->c === false){
|
||||
$this->data["seed"] = Utils::readInt($this->get(4));
|
||||
$this->data["unknown1"] = Utils::readInt($this->get(4));
|
||||
$this->data["gamemode"] = Utils::readInt($this->get(4));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["seed"]);
|
||||
$this->raw .= Utils::writeInt($this->data["unknown1"]);
|
||||
$this->raw .= Utils::writeInt($this->data["gamemode"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
}
|
||||
break;
|
||||
case MC_ADD_MOB:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["type"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
$this->data["metadata"] = Utils::readMetadata($this->get(true));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["type"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::writeMetadata(array(
|
||||
1 => array("type" => 1, "value" => 300),
|
||||
16 => array("type" => 0, "value" => 0),
|
||||
17 => array("type" => 6, "value" => array(0, 0, 0)),
|
||||
));
|
||||
}
|
||||
break;
|
||||
case MC_ADD_PLAYER:
|
||||
if($this->c === false){
|
||||
$this->data["clientID"] = Utils::readLong($this->get(8));
|
||||
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
$this->data["metadata"] = Utils::readMetadata($this->get(true));
|
||||
}else{
|
||||
$this->raw .= Utils::writeLong($this->data["clientID"]);
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::writeMetadata(array(
|
||||
1 => array("type" => 1, "value" => 300),
|
||||
16 => array("type" => 0, "value" => 0),
|
||||
17 => array("type" => 6, "value" => array(0, 0, 0)),
|
||||
));
|
||||
}
|
||||
break;
|
||||
case MC_ADD_ENTITY:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["type"] = ord($this->get(1));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= chr($this->data["type"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::hexToStr("000000020000ffd30000");//Utils::writeInt(0);
|
||||
/*$this->raw .= Utils::writeShort(0);
|
||||
$this->raw .= Utils::writeShort(0);
|
||||
$this->raw .= Utils::writeShort(0);*/
|
||||
}
|
||||
break;
|
||||
case MC_REMOVE_ENTITY:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
}
|
||||
break;
|
||||
case MC_ADD_ITEM_ENTITY:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["block"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["stack"] = ord($this->get(1));
|
||||
$this->data["meta"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
$this->data["yaw"] = Utils::readByte($this->get(1));
|
||||
$this->data["pitch"] = Utils::readByte($this->get(1));
|
||||
$this->data["roll"] = Utils::readByte($this->get(1));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeShort($this->data["block"]);
|
||||
$this->raw .= chr($this->data["stack"]);
|
||||
$this->raw .= Utils::writeShort($this->data["meta"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::writeByte($this->data["yaw"]);
|
||||
$this->raw .= Utils::writeByte($this->data["pitch"]);
|
||||
$this->raw .= Utils::writeByte($this->data["roll"]);
|
||||
}
|
||||
break;
|
||||
case MC_MOVE_ENTITY:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
}
|
||||
break;
|
||||
case MC_MOVE_ENTITY_POSROT:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
$this->data["yaw"] = Utils::readFloat($this->get(4));
|
||||
$this->data["pitch"] = Utils::readFloat($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["yaw"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["pitch"]);
|
||||
}
|
||||
break;
|
||||
case MC_MOVE_PLAYER:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
$this->data["yaw"] = Utils::readFloat($this->get(4));
|
||||
$this->data["pitch"] = Utils::readFloat($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["yaw"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["pitch"]);
|
||||
}
|
||||
break;
|
||||
case MC_PLACE_BLOCK:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
$this->data["y"] = ord($this->get(1));
|
||||
$this->data["block"] = ord($this->get(1));
|
||||
$this->data["meta"] = ord($this->get(1));
|
||||
$this->data["face"] = Utils::readByte($this->get(1));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
$this->raw .= chr($this->data["y"]);
|
||||
$this->raw .= chr($this->data["block"]);
|
||||
$this->raw .= chr($this->data["meta"]);
|
||||
$this->raw .= chr($this->data["face"]);
|
||||
}
|
||||
break;
|
||||
case MC_REMOVE_BLOCK:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
$this->data["y"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
$this->raw .= chr($this->data["y"]);
|
||||
}
|
||||
break;
|
||||
case MC_UPDATE_BLOCK:
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
$this->data["y"] = ord($this->get(1));
|
||||
$this->data["block"] = ord($this->get(1));
|
||||
$this->data["meta"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
$this->raw .= chr($this->data["y"]);
|
||||
$this->raw .= chr($this->data["block"]);
|
||||
$this->raw .= chr($this->data["meta"]);
|
||||
}
|
||||
break;
|
||||
case MC_REQUEST_CHUNK:
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
}
|
||||
break;
|
||||
case MC_CHUNK_DATA:
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
$this->data["data"] = $this->get(true);
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["x"]);
|
||||
$this->raw .= Utils::writeInt($this->data["z"]);
|
||||
$this->raw .= $this->data["data"];
|
||||
}
|
||||
break;
|
||||
case MC_PLAYER_EQUIPMENT:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["block"] = Utils::readShort($this->get(2), false);
|
||||
$this->data["meta"] = Utils::readShort($this->get(2), false);
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeShort($this->data["block"]);
|
||||
$this->raw .= Utils::writeShort($this->data["meta"]);
|
||||
}
|
||||
break;
|
||||
case MC_INTERACT:
|
||||
if($this->c === false){
|
||||
$this->data["action"] = Utils::readByte($this->get(1));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["target"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["target"]);
|
||||
}
|
||||
break;
|
||||
case MC_USE_ITEM:
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readInt($this->get(4));
|
||||
$this->data["y"] = Utils::readInt($this->get(4));
|
||||
$this->data["z"] = Utils::readInt($this->get(4));
|
||||
$this->data["face"] = Utils::readInt($this->get(4));
|
||||
$this->data["block"] = Utils::readShort($this->get(2));
|
||||
$this->data["meta"] = Utils::readByte($this->get(1));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["fx"] = Utils::readFloat($this->get(4));
|
||||
$this->data["fy"] = Utils::readFloat($this->get(4));
|
||||
$this->data["fz"] = Utils::readFloat($this->get(4));
|
||||
}else{
|
||||
/*$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["target"]);*/
|
||||
}
|
||||
break;
|
||||
case MC_SET_ENTITY_DATA:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeMetadata(array(
|
||||
|
||||
));
|
||||
}
|
||||
break;
|
||||
case MC_SET_HEALTH:
|
||||
if($this->c === false){
|
||||
$this->data["health"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= chr($this->data["health"]);
|
||||
}
|
||||
break;
|
||||
case MC_ANIMATE:
|
||||
if($this->c === false){
|
||||
$this->data["action"] = Utils::readByte($this->get(1));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
}
|
||||
break;
|
||||
case MC_RESPAWN:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["x"] = Utils::readFloat($this->get(4));
|
||||
$this->data["y"] = Utils::readFloat($this->get(4));
|
||||
$this->data["z"] = Utils::readFloat($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["x"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["y"]);
|
||||
$this->raw .= Utils::writeFloat($this->data["z"]);
|
||||
}
|
||||
break;
|
||||
case MC_CLIENT_MESSAGE:
|
||||
if($this->c === false){
|
||||
$this->data["message"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
}else{
|
||||
$this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"];
|
||||
}
|
||||
break;
|
||||
case MC_SIGN_UPDATE:
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readShort($this->get(2));
|
||||
$this->data["y"] = ord($this->get(1));
|
||||
$this->data["z"] = Utils::readShort($this->get(2));
|
||||
for($i = 0; $i < 4; ++$i){
|
||||
$this->data["line$i"] = $this->get(Utils::readLShort($this->get(2), false));
|
||||
}
|
||||
}else{
|
||||
$this->raw .= Utils::writeShort($this->data["x"]);
|
||||
$this->raw .= chr($this->data["y"]);
|
||||
$this->raw .= Utils::writeShort($this->data["z"]);
|
||||
for($i = 0; $i < 4; ++$i){
|
||||
$this->raw .= Utils::writeLShort(strlen($this->data["line$i"])).$this->data["line$i"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_ADVENTURE_SETTINGS:
|
||||
if($this->c === false){
|
||||
$this->data["x"] = Utils::readShort($this->get(2));
|
||||
$this->data["y"] = ord($this->get(1));
|
||||
$this->data["z"] = Utils::readShort($this->get(2));
|
||||
for($i = 0; $i < 4; ++$i){
|
||||
$this->data["line$i"] = $this->get(Utils::readLShort($this->get(2), false));
|
||||
}
|
||||
}else{
|
||||
$this->raw .= $this->data["unknown1"];
|
||||
$this->raw .= $this->data["unknown2"];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
241
src/classes/Data.class.php
Normal file
241
src/classes/Data.class.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class BlockFace{
|
||||
const BOTTOM = 0;
|
||||
const TOP = 1;
|
||||
const DOWN = 0;
|
||||
const UP = 1;
|
||||
const SOUTH = 3;
|
||||
const EAST = 5;
|
||||
const NORTH = 2;
|
||||
const WEST = 4;
|
||||
public static function setPosition(&$data, $face){
|
||||
switch((int) $face){
|
||||
case 0:
|
||||
--$data["y"];
|
||||
break;
|
||||
case 1:
|
||||
++$data["y"];
|
||||
break;
|
||||
case 2:
|
||||
--$data["z"];
|
||||
break;
|
||||
case 3:
|
||||
++$data["z"];
|
||||
break;
|
||||
case 4:
|
||||
--$data["x"];
|
||||
break;
|
||||
case 5:
|
||||
++$data["x"];
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Material{
|
||||
static $flowable = array(
|
||||
0 => true,
|
||||
6 => true,
|
||||
30 => true,
|
||||
31 => true,
|
||||
32 => true,
|
||||
37 => true,
|
||||
38 => true,
|
||||
39 => true,
|
||||
40 => true,
|
||||
50 => true,
|
||||
51 => true,
|
||||
55 => true,
|
||||
59 => true,
|
||||
78 => true,
|
||||
105 => true,
|
||||
);
|
||||
static $unbreakable = array(
|
||||
0 => true,
|
||||
//7 => true,
|
||||
8 => true,
|
||||
9 => true,
|
||||
10 => true,
|
||||
11 => true,
|
||||
);
|
||||
static $transparent = array(
|
||||
0 => true,
|
||||
6 => true,
|
||||
8 => true,
|
||||
9 => true,
|
||||
10 => true,
|
||||
11 => true,
|
||||
18 => true,
|
||||
20 => true,
|
||||
26 => true,
|
||||
30 => true,
|
||||
31 => true,
|
||||
32 => true,
|
||||
37 => true,
|
||||
38 => true,
|
||||
39 => true,
|
||||
40 => true,
|
||||
46 => true,
|
||||
50 => true,
|
||||
51 => true,
|
||||
53 => true,
|
||||
59 => true,
|
||||
65 => true,
|
||||
67 => true,
|
||||
78 => true,
|
||||
79 => true,
|
||||
81 => true,
|
||||
83 => true,
|
||||
89 => true,
|
||||
96 => true,
|
||||
102 => true,
|
||||
105 => true,
|
||||
107 => true,
|
||||
108 => true,
|
||||
);
|
||||
static $replaceable = array(
|
||||
0 => true,
|
||||
8 => true,
|
||||
9 => true,
|
||||
10 => true,
|
||||
11 => true,
|
||||
31 => true,
|
||||
51 => true,
|
||||
78 => true,
|
||||
);
|
||||
static $activable = array(
|
||||
2 => true,
|
||||
3 => true,
|
||||
6 => true,
|
||||
26 => true,
|
||||
31 => true,
|
||||
46 => true,
|
||||
51 => true,
|
||||
54 => true,
|
||||
58 => true,
|
||||
59 => true,
|
||||
61 => true,
|
||||
62 => true,
|
||||
64 => true,
|
||||
78 => true,
|
||||
96 => true,
|
||||
105 => true,
|
||||
107 => true,
|
||||
247 => true,
|
||||
);
|
||||
static $placeable = array(
|
||||
1 => true,
|
||||
2 => true,
|
||||
3 => true,
|
||||
4 => true,
|
||||
5 => true,
|
||||
6 => true,
|
||||
//7 => true,
|
||||
8 => true,
|
||||
9 => true,
|
||||
10 => true,
|
||||
11 => true,
|
||||
12 => true,
|
||||
13 => true,
|
||||
14 => true,
|
||||
15 => true,
|
||||
16 => true,
|
||||
17 => true,
|
||||
18 => true,
|
||||
19 => true,
|
||||
20 => true,
|
||||
21 => true,
|
||||
22 => true,
|
||||
24 => true,
|
||||
355 => 26,
|
||||
30 => true,
|
||||
35 => true,
|
||||
37 => true,
|
||||
38 => true,
|
||||
39 => true,
|
||||
40 => true,
|
||||
41 => true,
|
||||
42 => true,
|
||||
43 => true,
|
||||
44 => true,
|
||||
45 => true,
|
||||
46 => true,
|
||||
47 => true,
|
||||
48 => true,
|
||||
49 => true,
|
||||
50 => true,
|
||||
53 => true,
|
||||
54 => true,
|
||||
56 => true,
|
||||
59 => true,
|
||||
57 => true,
|
||||
58 => true,
|
||||
295 => 59,
|
||||
61 => true,
|
||||
324 => 64,
|
||||
65 => true,
|
||||
67 => true,
|
||||
73 => true,
|
||||
79 => true,
|
||||
80 => true,
|
||||
81 => true,
|
||||
82 => true,
|
||||
83 => true,
|
||||
85 => true,
|
||||
86 => true,
|
||||
87 => true,
|
||||
88 => true,
|
||||
89 => true,
|
||||
91 => true,
|
||||
96 => true,
|
||||
98 => true,
|
||||
102 => true,
|
||||
103 => true,
|
||||
362 => 105,
|
||||
107 => true,
|
||||
108 => true,
|
||||
246 => true,
|
||||
247 => true,
|
||||
);
|
||||
static $blocks = array(
|
||||
0 => "Air",
|
||||
1 => "Stone",
|
||||
2 => "Grass",
|
||||
3 => "Dirt",
|
||||
4 => "Cobblestone",
|
||||
5 => "Wooden Planks",
|
||||
6 => "Sapling",
|
||||
7 => "Bedrock",
|
||||
);
|
||||
|
||||
|
||||
}
|
236
src/classes/Entity.class.php
Normal file
236
src/classes/Entity.class.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
define("ENTITY_PLAYER", 0);
|
||||
define("ENTITY_MOB", 1);
|
||||
define("ENTITY_OBJECT", 2);
|
||||
define("ENTITY_ITEM", 3);
|
||||
define("ENTITY_PAINTING", 4);
|
||||
|
||||
class Entity extends stdClass{
|
||||
var $eid, $type, $name, $x, $y, $z, $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player;
|
||||
|
||||
function __construct($server, $eid, $class, $type = 0, $data = array()){
|
||||
$this->server = $server;
|
||||
$this->eid = (int) $eid;
|
||||
$this->type = (int) $type;
|
||||
$this->class = (int) $class;
|
||||
$this->player = false;
|
||||
$this->attach = false;
|
||||
$this->data = $data;
|
||||
$this->status = 0;
|
||||
$this->health = 20;
|
||||
$this->dead = false;
|
||||
$this->closed = false;
|
||||
$this->name = "";
|
||||
$this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");");
|
||||
$this->metadata = array();
|
||||
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
|
||||
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
|
||||
$this->z = isset($this->data["z"]) ? $this->data["z"]:0;
|
||||
$this->yaw = isset($this->data["yaw"]) ? $this->data["yaw"]:0;
|
||||
$this->pitch = isset($this->data["pitch"]) ? $this->data["pitch"]:0;
|
||||
$this->position = array("x" => &$this->x, "y" => &$this->y, "z" => &$this->z, "yaw" => &$this->yaw, "pitch" => &$this->pitch);
|
||||
switch($this->class){
|
||||
case ENTITY_PLAYER:
|
||||
$this->player = $this->data["player"];
|
||||
$this->health = &$this->player->data["health"];
|
||||
break;
|
||||
case ENTITY_ITEM:
|
||||
$this->meta = (int) $this->data["meta"];
|
||||
$this->stack = (int) $this->data["stack"];
|
||||
break;
|
||||
case ENTITY_MOB:
|
||||
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
||||
break;
|
||||
case ENTITY_OBJECT:
|
||||
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDirection(){
|
||||
$rotation = ($this->yaw - 90) % 360;
|
||||
if ($rotation < 0) {
|
||||
$rotation += 360.0;
|
||||
}
|
||||
if(0 <= $rotation && $rotation < 45) {
|
||||
return 2;
|
||||
}elseif(45 <= $rotation && $rotation < 135) {
|
||||
return 3;
|
||||
}elseif(135 <= $rotation && $rotation < 225) {
|
||||
return 0;
|
||||
}elseif(225 <= $rotation && $rotation < 315) {
|
||||
return 1;
|
||||
}elseif(315 <= $rotation && $rotation < 360) {
|
||||
return 2;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
if(!is_object($player)){
|
||||
$player = $this->server->api->player->get($player);
|
||||
}
|
||||
if($player->eid === $this->eid){
|
||||
return false;
|
||||
}
|
||||
switch($this->class){
|
||||
case ENTITY_PLAYER:
|
||||
$player->dataPacket(MC_ADD_PLAYER, array(
|
||||
"clientID" => $this->player->clientID,
|
||||
"username" => $this->player->username,
|
||||
"eid" => $this->eid,
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z,
|
||||
));
|
||||
$player->dataPacket(MC_PLAYER_EQUIPMENT, array(
|
||||
"eid" => $this->eid,
|
||||
"block" => $this->player->equipment[0],
|
||||
"meta" => $this->player->equipment[1],
|
||||
));
|
||||
break;
|
||||
case ENTITY_ITEM:
|
||||
$player->dataPacket(MC_ADD_ITEM_ENTITY, array(
|
||||
"eid" => $this->eid,
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z,
|
||||
"block" => $this->type,
|
||||
"meta" => $this->meta,
|
||||
"stack" => $this->stack,
|
||||
));
|
||||
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,
|
||||
));
|
||||
break;
|
||||
case ENTITY_OBJECT:
|
||||
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function close(){
|
||||
if($this->closed === false){
|
||||
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
|
||||
$this->server->trigger("entity.remove", $this->eid);
|
||||
$this->closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function getEID(){
|
||||
return $this->eid;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name){
|
||||
$this->name = $name;
|
||||
$this->server->query("UPDATE entities SET name = '".str_replace("'", "", $this->name)."' WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
public function look($pos2){
|
||||
$pos = $this->getPosition();
|
||||
$angle = Utils::angle3D($pos2, $pos);
|
||||
$this->yaw = $angle["yaw"];
|
||||
$this->pitch = $angle["pitch"];
|
||||
$this->server->query("UPDATE entities SET pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
public function setCoords($x, $y, $z){
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->z = $z;
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z." WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
public function move($x, $y, $z, $yaw = 0, $pitch = 0){
|
||||
$this->x += $x;
|
||||
$this->y += $y;
|
||||
$this->z += $z;
|
||||
$this->yaw += $yaw;
|
||||
$this->yaw %= 360;
|
||||
$this->pitch += $pitch;
|
||||
$this->pitch %= 90;
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
public function setPosition($x, $y, $z, $yaw, $pitch){
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
$this->z = $z;
|
||||
$this->yaw = $yaw;
|
||||
$this->pitch = $pitch;
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getPosition($round = false){
|
||||
return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position);
|
||||
}
|
||||
|
||||
public function setHealth($health, $cause = ""){
|
||||
$this->health = (int) $health;
|
||||
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
|
||||
$this->server->trigger("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause));
|
||||
if($this->player !== false){
|
||||
$this->player->dataPacket(MC_SET_HEALTH, array(
|
||||
"health" => $this->health,
|
||||
));
|
||||
}
|
||||
if($this->health <= 0 and $this->dead === false){
|
||||
$this->dead = true;
|
||||
if($this->player !== false){
|
||||
$this->server->handle("player.death", array("name" => $this->name, "cause" => $cause));
|
||||
}
|
||||
}elseif($this->health > 0){
|
||||
$this->dead = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getHealth(){
|
||||
return $this->health;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
355
src/classes/Generator.class.php
Normal file
355
src/classes/Generator.class.php
Normal file
@@ -0,0 +1,355 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class WorldGenerator{
|
||||
private $gen, $seed, $raw;
|
||||
public function __construct($genName, $seed){
|
||||
$this->seed = (int) $seed;
|
||||
$this->raw = b"";
|
||||
$this->gen = new $genName($this->seed);
|
||||
}
|
||||
|
||||
public function getSpawn(){
|
||||
return $this->gen->getSpawn();
|
||||
}
|
||||
|
||||
public function set($name, $value){
|
||||
$this->gen->set($name, $value);
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->raw = "\x15\x01\x00\x00\x15\x16\x00\x00\x15\x2b\x00\x00\x15\x40\x00\x00". //Location Header
|
||||
"\x15\x55\x00\x00\x15\x6a\x00\x00\x15\x7f\x00\x00\x15\x94\x00\x00".
|
||||
"\x15\xa9\x00\x00\x15\xbe\x00\x00\x15\xd3\x00\x00\x15\xe8\x00\x00".
|
||||
"\x15\xfd\x00\x00\x15\x12\x01\x00\x15\x27\x01\x00\x15\x3c\x01\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x51\x01\x00\x15\x66\x01\x00\x15\x7b\x01\x00\x15\x90\x01\x00".
|
||||
"\x15\xa5\x01\x00\x15\xba\x01\x00\x15\xcf\x01\x00\x15\xe4\x01\x00".
|
||||
"\x15\xf9\x01\x00\x15\x0e\x02\x00\x15\x23\x02\x00\x15\x38\x02\x00".
|
||||
"\x15\x4d\x02\x00\x15\x62\x02\x00\x15\x77\x02\x00\x15\x8c\x02\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\xa1\x02\x00\x15\xb6\x02\x00\x15\xcb\x02\x00\x15\xe0\x02\x00".
|
||||
"\x15\xf5\x02\x00\x15\x0a\x03\x00\x15\x1f\x03\x00\x15\x34\x03\x00".
|
||||
"\x15\x49\x03\x00\x15\x5e\x03\x00\x15\x73\x03\x00\x15\x88\x03\x00".
|
||||
"\x15\x9d\x03\x00\x15\xb2\x03\x00\x15\xc7\x03\x00\x15\xdc\x03\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\xf1\x03\x00\x15\x06\x04\x00\x15\x1b\x04\x00\x15\x30\x04\x00".
|
||||
"\x15\x45\x04\x00\x15\x5a\x04\x00\x15\x6f\x04\x00\x15\x84\x04\x00".
|
||||
"\x15\x99\x04\x00\x15\xae\x04\x00\x15\xc3\x04\x00\x15\xd8\x04\x00".
|
||||
"\x15\xed\x04\x00\x15\x02\x05\x00\x15\x17\x05\x00\x15\x2c\x05\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x41\x05\x00\x15\x56\x05\x00\x15\x6b\x05\x00\x15\x80\x05\x00".
|
||||
"\x15\x95\x05\x00\x15\xaa\x05\x00\x15\xbf\x05\x00\x15\xd4\x05\x00".
|
||||
"\x15\xe9\x05\x00\x15\xfe\x05\x00\x15\x13\x06\x00\x15\x28\x06\x00".
|
||||
"\x15\x3d\x06\x00\x15\x52\x06\x00\x15\x67\x06\x00\x15\x7c\x06\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x91\x06\x00\x15\xa6\x06\x00\x15\xbb\x06\x00\x15\xd0\x06\x00".
|
||||
"\x15\xe5\x06\x00\x15\xfa\x06\x00\x15\x0f\x07\x00\x15\x24\x07\x00".
|
||||
"\x15\x39\x07\x00\x15\x4e\x07\x00\x15\x63\x07\x00\x15\x78\x07\x00".
|
||||
"\x15\x8d\x07\x00\x15\xa2\x07\x00\x15\xb7\x07\x00\x15\xcc\x07\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\xe1\x07\x00\x15\xf6\x07\x00\x15\x0b\x08\x00\x15\x20\x08\x00".
|
||||
"\x15\x35\x08\x00\x15\x4a\x08\x00\x15\x5f\x08\x00\x15\x74\x08\x00".
|
||||
"\x15\x89\x08\x00\x15\x9e\x08\x00\x15\xb3\x08\x00\x15\xc8\x08\x00".
|
||||
"\x15\xdd\x08\x00\x15\xf2\x08\x00\x15\x07\x09\x00\x15\x1c\x09\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x31\x09\x00\x15\x46\x09\x00\x15\x5b\x09\x00\x15\x70\x09\x00".
|
||||
"\x15\x85\x09\x00\x15\x9a\x09\x00\x15\xaf\x09\x00\x15\xc4\x09\x00".
|
||||
"\x15\xd9\x09\x00\x15\xee\x09\x00\x15\x03\x0a\x00\x15\x18\x0a\x00".
|
||||
"\x15\x2d\x0a\x00\x15\x42\x0a\x00\x15\x57\x0a\x00\x15\x6c\x0a\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x81\x0a\x00\x15\x96\x0a\x00\x15\xab\x0a\x00\x15\xc0\x0a\x00".
|
||||
"\x15\xd5\x0a\x00\x15\xea\x0a\x00\x15\xff\x0a\x00\x15\x14\x0b\x00".
|
||||
"\x15\x29\x0b\x00\x15\x3e\x0b\x00\x15\x53\x0b\x00\x15\x68\x0b\x00".
|
||||
"\x15\x7d\x0b\x00\x15\x92\x0b\x00\x15\xa7\x0b\x00\x15\xbc\x0b\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\xd1\x0b\x00\x15\xe6\x0b\x00\x15\xfb\x0b\x00\x15\x10\x0c\x00".
|
||||
"\x15\x25\x0c\x00\x15\x3a\x0c\x00\x15\x4f\x0c\x00\x15\x64\x0c\x00".
|
||||
"\x15\x79\x0c\x00\x15\x8e\x0c\x00\x15\xa3\x0c\x00\x15\xb8\x0c\x00".
|
||||
"\x15\xcd\x0c\x00\x15\xe2\x0c\x00\x15\xf7\x0c\x00\x15\x0c\x0d\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x21\x0d\x00\x15\x36\x0d\x00\x15\x4b\x0d\x00\x15\x60\x0d\x00".
|
||||
"\x15\x75\x0d\x00\x15\x8a\x0d\x00\x15\x9f\x0d\x00\x15\xb4\x0d\x00".
|
||||
"\x15\xc9\x0d\x00\x15\xde\x0d\x00\x15\xf3\x0d\x00\x15\x08\x0e\x00".
|
||||
"\x15\x1d\x0e\x00\x15\x32\x0e\x00\x15\x47\x0e\x00\x15\x5c\x0e\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x71\x0e\x00\x15\x86\x0e\x00\x15\x9b\x0e\x00\x15\xb0\x0e\x00".
|
||||
"\x15\xc5\x0e\x00\x15\xda\x0e\x00\x15\xef\x0e\x00\x15\x04\x0f\x00".
|
||||
"\x15\x19\x0f\x00\x15\x2e\x0f\x00\x15\x43\x0f\x00\x15\x58\x0f\x00".
|
||||
"\x15\x6d\x0f\x00\x15\x82\x0f\x00\x15\x97\x0f\x00\x15\xac\x0f\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\xc1\x0f\x00\x15\xd6\x0f\x00\x15\xeb\x0f\x00\x15\x00\x10\x00".
|
||||
"\x15\x15\x10\x00\x15\x2a\x10\x00\x15\x3f\x10\x00\x15\x54\x10\x00".
|
||||
"\x15\x69\x10\x00\x15\x7e\x10\x00\x15\x93\x10\x00\x15\xa8\x10\x00".
|
||||
"\x15\xbd\x10\x00\x15\xd2\x10\x00\x15\xe7\x10\x00\x15\xfc\x10\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x11\x11\x00\x15\x26\x11\x00\x15\x3b\x11\x00\x15\x50\x11\x00".
|
||||
"\x15\x65\x11\x00\x15\x7a\x11\x00\x15\x8f\x11\x00\x15\xa4\x11\x00".
|
||||
"\x15\xb9\x11\x00\x15\xce\x11\x00\x15\xe3\x11\x00\x15\xf8\x11\x00".
|
||||
"\x15\x0d\x12\x00\x15\x22\x12\x00\x15\x37\x12\x00\x15\x4c\x12\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\x61\x12\x00\x15\x76\x12\x00\x15\x8b\x12\x00\x15\xa0\x12\x00".
|
||||
"\x15\xb5\x12\x00\x15\xca\x12\x00\x15\xdf\x12\x00\x15\xf4\x12\x00".
|
||||
"\x15\x09\x13\x00\x15\x1e\x13\x00\x15\x33\x13\x00\x15\x48\x13\x00".
|
||||
"\x15\x5d\x13\x00\x15\x72\x13\x00\x15\x87\x13\x00\x15\x9c\x13\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x15\xb1\x13\x00\x15\xc6\x13\x00\x15\xdb\x13\x00\x15\xf0\x13\x00".
|
||||
"\x15\x05\x14\x00\x15\x1a\x14\x00\x15\x2f\x14\x00\x15\x44\x14\x00".
|
||||
"\x15\x59\x14\x00\x15\x6e\x14\x00\x15\x83\x14\x00\x15\x98\x14\x00".
|
||||
"\x15\xad\x14\x00\x15\xc2\x14\x00\x15\xd7\x14\x00\x15\xec\x14\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
$this->gen->init();
|
||||
}
|
||||
|
||||
public function generate(){
|
||||
for($Z = 0; $Z < 16; ++$Z){
|
||||
for($X = 0; $X < 16; ++$X){
|
||||
$chunk = str_pad($this->getChunk($X, $Z), 86012, "\x00", STR_PAD_RIGHT);
|
||||
$this->raw .= Utils::writeLInt(strlen($chunk)) . $chunk;
|
||||
}
|
||||
console("[DEBUG] Generating level ".ceil(($Z + 1)/0.16)."%", true, true, 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getChunk($X, $Z){
|
||||
$chunk = b"";
|
||||
$columns = array();
|
||||
$X *= 16;
|
||||
$Z *= 16;
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$columns[$x * 16 + $z] = $this->gen->getColumn($X + $x, $Z + $z);
|
||||
}
|
||||
}
|
||||
for($i = 0; $i < 4; ++$i){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$chunk .= $columns[$x * 16 + $z][$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($columns);
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
public function save($dir, $name){
|
||||
@mkdir($dir, 0777, true);
|
||||
file_put_contents($dir."chunks.dat", $this->raw);
|
||||
$s = $this->getSpawn();
|
||||
$array = array();
|
||||
file_put_contents($dir."entities.dat", serialize($array));
|
||||
file_put_contents($dir."tileEntities.dat", serialize($array));
|
||||
$level = array(
|
||||
"LevelName" => $name,
|
||||
"Time" => 0,
|
||||
"Gamemode" => 1,
|
||||
"RandomSeed" => $this->seed,
|
||||
"SpawnX" => $s[0],
|
||||
"SpawnY" => $s[1],
|
||||
"SpawnZ" => $s[2],
|
||||
);
|
||||
file_put_contents($dir."level.dat", serialize($level));
|
||||
}
|
||||
|
||||
}
|
126
src/classes/Java.class.php
Normal file
126
src/classes/Java.class.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class Java_String{
|
||||
private $value = "", $count = 0, $hash = 0;
|
||||
|
||||
public function __construct($string = false){
|
||||
if($string !== false){
|
||||
$this->value = (string) $string;
|
||||
$this->count = strlen($this->value);
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function lenght(){
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
public function isEmpty(){
|
||||
return $this->count === 0;
|
||||
}
|
||||
|
||||
public function charAt($index){
|
||||
$index = (int) $index;
|
||||
if($index < 0 or $index >= $this->count){
|
||||
trigger_error("Undefined offset $index", E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
return $this->value{$index};
|
||||
}
|
||||
|
||||
public function hashCode(){
|
||||
$h = $this->hash;
|
||||
if($h === 0 and $this->count > 0){
|
||||
for($i = 0; $i < $this->count; ++$i){
|
||||
$h = (($h << 5) - $h) + ord($this->charAt($i));
|
||||
$h = $h & 0xFFFFFFFF;
|
||||
$this->hash = $h;
|
||||
}
|
||||
$this->hash = $h;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
136
src/classes/MinecraftInterface.class.php
Normal file
136
src/classes/MinecraftInterface.class.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class MinecraftInterface{
|
||||
var $pstruct, $name, $protocol, $client, $dataName;
|
||||
private $socket, $data;
|
||||
function __construct($server, $protocol = CURRENT_PROTOCOL, $port = 25565, $listen = false, $client = true){
|
||||
$this->socket = new UDPSocket($server, $port, (bool) $listen);
|
||||
$this->protocol = (int) $protocol;
|
||||
require("pstruct/RakNet.php");
|
||||
require("pstruct/packetName.php");
|
||||
require("pstruct/".$this->protocol.".php");
|
||||
require("pstruct/dataName.php");
|
||||
$this->pstruct = $pstruct;
|
||||
$this->name = $packetName;
|
||||
$this->dataName = $dataName;
|
||||
$this->buffer = array();
|
||||
$this->client = (bool) $client;
|
||||
$this->start = microtime(true);
|
||||
}
|
||||
|
||||
public function close(){
|
||||
return $this->socket->close();
|
||||
}
|
||||
|
||||
protected function getStruct($pid){
|
||||
if(isset($this->pstruct[$pid])){
|
||||
return $this->pstruct[$pid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
|
||||
if(LOG === true and DEBUG >= 3){
|
||||
$p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".(isset($data["id"]) ? "MC Packet ".$this->dataName[$pid]:$this->name[$pid])." (0x".Utils::strTohex(chr($pid)).") [length ".strlen($raw)."]".PHP_EOL;
|
||||
$p .= Utils::hexdump($raw);
|
||||
if(is_array($data)){
|
||||
foreach($data as $i => $d){
|
||||
$p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special" or is_int($this->pstruct[$pid][$i])) ? Utils::strToHex($d):Utils::printable($d)).")":$this->pstruct[$pid][$i]."(\"".serialize(array_map("Utils::printable", $d))."\")").PHP_EOL;
|
||||
}
|
||||
}
|
||||
$p .= PHP_EOL;
|
||||
logg($p, "packets", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function readPacket(){
|
||||
$p = $this->popPacket();
|
||||
if($p !== false){
|
||||
return $p;
|
||||
}
|
||||
if($this->socket->connected === false){
|
||||
return false;
|
||||
}
|
||||
$data = $this->socket->read();
|
||||
if($data[3] === false){
|
||||
return false;
|
||||
}
|
||||
$pid = ord($data[0]);
|
||||
$struct = $this->getStruct($pid);
|
||||
if($struct === false){
|
||||
console("[ERROR] Unknown Packet ID 0x".Utils::strToHex(chr($pid)), true, true, 0);
|
||||
$p = "[".(microtime(true) - $this->start)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: Error, bad packet id 0x".Utils::strTohex(chr($pid))." [length ".strlen($raw)."]".PHP_EOL;
|
||||
$p .= Utils::hexdump($data[0]);
|
||||
$p .= PHP_EOL;
|
||||
logg($p, "packets", true, 2);
|
||||
return false;
|
||||
}
|
||||
|
||||
$packet = new Packet($pid, $struct, $data[0]);
|
||||
$packet->protocol = $this->protocol;
|
||||
$packet->parse();
|
||||
$this->data[] = array($pid, $packet->data, $data[0], $data[1], $data[2]);
|
||||
return $this->popPacket();
|
||||
}
|
||||
|
||||
public function popPacket(){
|
||||
if(count($this->data) > 0){
|
||||
$p = array_shift($this->data);
|
||||
if(isset($p[1]["packets"]) and is_array($p[1]["packets"])){
|
||||
foreach($p[1]["packets"] as $d){
|
||||
$this->data[] = array($p[0], $d[1], $d[2], $p[3], $p[4]);
|
||||
}
|
||||
}
|
||||
$c = (isset($p[1]["id"]) ? true:false);
|
||||
$p[2] = $c ? chr($p[1]["id"]).$p[2]:$p[2];
|
||||
$this->writeDump(($c ? $p[1]["id"]:$p[0]), $p[2], $p[1], "server", $p[3], $p[4]);
|
||||
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){
|
||||
$struct = $this->getStruct($pid);
|
||||
if($raw === false){
|
||||
$packet = new Packet($pid, $struct);
|
||||
$packet->protocol = $this->protocol;
|
||||
$packet->data = $data;
|
||||
$packet->create();
|
||||
$write = $this->socket->write($packet->raw, $dest, $port);
|
||||
$this->writeDump($pid, $packet->raw, $data, "client", $dest, $port);
|
||||
}else{
|
||||
$write = $this->socket->write($data, $dest, $port);
|
||||
$this->writeDump($pid, $data, false, "client", $dest, $port);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
102
src/classes/NBT.class.php
Normal file
102
src/classes/NBT.class.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* Class for reading in NBT-format files.
|
||||
*
|
||||
* @author Justin Martin <frozenfire@thefrozenfire.com>
|
||||
* @version 1.0
|
||||
* MODIFIED BY @shoghicp
|
||||
*
|
||||
* Dependencies:
|
||||
* PHP 4.3+ (5.3+ recommended)
|
||||
*/
|
||||
|
||||
class NBT {
|
||||
public $root = array();
|
||||
|
||||
const TAG_END = 0;
|
||||
const TAG_BYTE = 1;
|
||||
const TAG_SHORT = 2;
|
||||
const TAG_INT = 3;
|
||||
const TAG_LONG = 4;
|
||||
const TAG_FLOAT = 5;
|
||||
const TAG_DOUBLE = 6;
|
||||
const TAG_BYTE_ARRAY = 7;
|
||||
const TAG_STRING = 8;
|
||||
const TAG_LIST = 9;
|
||||
const TAG_COMPOUND = 10;
|
||||
|
||||
public function loadFile($filename) {
|
||||
if(is_file($filename)) {
|
||||
$fp = fopen($filename, "rb");
|
||||
}else{
|
||||
trigger_error("First parameter must be a filename", E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
switch(basename($filename, ".dat")){
|
||||
case "level":
|
||||
$version = Utils::readLInt(fread($fp, 4));
|
||||
$lenght = Utils::readLInt(fread($fp, 4));
|
||||
break;
|
||||
case "entities":
|
||||
fread($fp, 12);
|
||||
break;
|
||||
}
|
||||
$this->traverseTag($fp, $this->root);
|
||||
return end($this->root);
|
||||
}
|
||||
|
||||
public function traverseTag($fp, &$tree) {
|
||||
if(feof($fp)) {
|
||||
return false;
|
||||
}
|
||||
$tagType = $this->readType($fp, self::TAG_BYTE); // Read type byte.
|
||||
if($tagType == self::TAG_END) {
|
||||
return false;
|
||||
} else {
|
||||
$tagName = $this->readType($fp, self::TAG_STRING);
|
||||
$tagData = $this->readType($fp, $tagType);
|
||||
$tree[] = array("type"=>$tagType, "name"=>$tagName, "value"=>$tagData);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function readType($fp, $tagType) {
|
||||
switch($tagType) {
|
||||
case self::TAG_BYTE: // Signed byte (8 bit)
|
||||
return Utils::readByte(fread($fp, 1));
|
||||
case self::TAG_SHORT: // Signed short (16 bit, big endian)
|
||||
return Utils::readLShort(fread($fp, 2));
|
||||
case self::TAG_INT: // Signed integer (32 bit, big endian)
|
||||
return Utils::readLInt(fread($fp, 4));
|
||||
case self::TAG_LONG: // Signed long (64 bit, big endian)
|
||||
return Utils::readLLong(fread($fp, 8));
|
||||
case self::TAG_FLOAT: // Floating point value (32 bit, big endian, IEEE 754-2008)
|
||||
return Utils::readLFloat(fread($fp, 4));
|
||||
case self::TAG_DOUBLE: // Double value (64 bit, big endian, IEEE 754-2008)
|
||||
return Utils::readLDouble(fread($fp, 8));
|
||||
case self::TAG_BYTE_ARRAY: // Byte array
|
||||
$arrayLength = $this->readType($fp, self::TAG_INT);
|
||||
$array = array();
|
||||
for($i = 0; $i < $arrayLength; $i++) $array[] = $this->readType($fp, self::TAG_BYTE);
|
||||
return $array;
|
||||
case self::TAG_STRING: // String
|
||||
if(!$stringLength = $this->readType($fp, self::TAG_SHORT)) return "";
|
||||
$string = fread($fp, $stringLength); // Read in number of bytes specified by string length, and decode from utf8.
|
||||
return $string;
|
||||
case self::TAG_LIST: // List
|
||||
$tagID = $this->readType($fp, self::TAG_BYTE);
|
||||
$listLength = $this->readType($fp, self::TAG_INT);
|
||||
$list = array("type"=>$tagID, "value"=>array());
|
||||
for($i = 0; $i < $listLength; $i++) {
|
||||
if(feof($fp)) break;
|
||||
$list["value"][] = $this->readType($fp, $tagID);
|
||||
}
|
||||
return $list;
|
||||
case self::TAG_COMPOUND: // Compound
|
||||
$tree = array();
|
||||
while($this->traverseTag($fp, $tree));
|
||||
return $tree;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
238
src/classes/Packet.class.php
Normal file
238
src/classes/Packet.class.php
Normal file
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class Packet{
|
||||
private $struct, $sock;
|
||||
protected $pid, $packet;
|
||||
public $data, $raw, $protocol;
|
||||
|
||||
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;
|
||||
$this->sock = $sock;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if(is_int($type)){
|
||||
$this->addRaw($this->data[$field]);
|
||||
continue;
|
||||
}
|
||||
switch($type){
|
||||
case "special1":
|
||||
switch($this->pid){
|
||||
case 0xc0:
|
||||
case 0xa0:
|
||||
if($this->data[1] === false){
|
||||
$this->addRaw($this->data[$field]);
|
||||
}
|
||||
break;
|
||||
case 0x05:
|
||||
$this->addRaw($this->data[$field]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "customData":
|
||||
switch($this->data[1]){
|
||||
case 0x40:
|
||||
$reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true);
|
||||
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
|
||||
$this->addRaw(Utils::writeTriad($this->data[$field]["count"]));
|
||||
$this->addRaw(chr($this->data[$field]["id"]));
|
||||
$this->addRaw($reply->raw);
|
||||
break;
|
||||
case 0x00:
|
||||
$reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true);
|
||||
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
|
||||
$this->addRaw(chr($this->data[$field]["id"]));
|
||||
$this->addRaw($reply->raw);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "magic":
|
||||
$this->addRaw(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 "byteArray":
|
||||
$this->addRaw($this->data[$field]);
|
||||
break;
|
||||
case "string":
|
||||
$this->addRaw(Utils::writeShort(strlen($this->data[$field])));
|
||||
$this->addRaw($this->data[$field]);
|
||||
break;
|
||||
case "slotData":
|
||||
$this->addRaw(Utils::writeShort($this->data[$field][0]));
|
||||
if($this->data[$field][0]!=-1){
|
||||
$this->addRaw(Utils::writeByte($this->data[$field][1]));
|
||||
$this->addRaw(Utils::writeShort($this->data[$field][2]));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
protected function addRaw($str){
|
||||
$this->raw .= $str;
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function parse(){
|
||||
$continue = true;
|
||||
foreach($this->struct as $field => $type){
|
||||
if(is_int($type)){
|
||||
$this->data[] = $this->get($type);
|
||||
continue;
|
||||
}
|
||||
switch($type){
|
||||
case "special1":
|
||||
switch($this->pid){
|
||||
case 0xc0:
|
||||
case 0xa0:
|
||||
if($this->data[1] === false){
|
||||
$this->data[] = $this->get(3);
|
||||
}
|
||||
break;
|
||||
case 0x05:
|
||||
$this->data[] = $this->get(true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "customData":
|
||||
$d = new SerializedPacketHandler($this->data[1], $this->get(true));
|
||||
if(isset($d->data["packets"])){
|
||||
$this->data["packets"] = $d->data["packets"];
|
||||
}else{
|
||||
$this->data[] = $d->data;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if($continue === false){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
395
src/classes/Player.class.php
Normal file
395
src/classes/Player.class.php
Normal file
@@ -0,0 +1,395 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class Player{
|
||||
private $server, $timeout, $connected, $evid, $queue, $buffer;
|
||||
var $clientID, $ip, $port, $counter, $username, $eid, $data, $entity, $auth, $CID, $MTU, $spawned, $equipment;
|
||||
function __construct($server, $clientID, $ip, $port, $MTU){
|
||||
$this->queue = array();
|
||||
$this->buffer = array();
|
||||
$this->MTU = $MTU;
|
||||
$this->server = $server;
|
||||
$this->clientID = $clientID;
|
||||
$this->CID = $this->server->clientID($ip, $port);
|
||||
$this->eid = false;
|
||||
$this->data = array();
|
||||
$this->ip = $ip;
|
||||
$this->entity = false;
|
||||
$this->port = $port;
|
||||
$this->timeout = microtime(true) + 25;
|
||||
$this->evid = array();
|
||||
$this->equipment = array(1, 0);
|
||||
$this->spawned = false;
|
||||
$this->evid[] = $this->server->event("server.tick", array($this, "onTick"));
|
||||
$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);
|
||||
$this->connected = true;
|
||||
$this->auth = false;
|
||||
$this->counter = array(0, 0, 0);
|
||||
}
|
||||
|
||||
public function onTick($time, $event){
|
||||
if($event !== "server.tick"){
|
||||
return;
|
||||
}
|
||||
if($time > $this->timeout){
|
||||
$this->close("timeout");
|
||||
}else{
|
||||
if(!empty($this->queue)){
|
||||
$cnt = 0;
|
||||
while($cnt < 4){
|
||||
$p = array_shift($this->queue);
|
||||
if($p === null){
|
||||
break;
|
||||
}
|
||||
switch($p[0]){
|
||||
case 0:
|
||||
$this->dataPacket($p[1], $p[2], false, $p[3]);
|
||||
break;
|
||||
case 1:
|
||||
eval($p[1]);
|
||||
break;
|
||||
}
|
||||
++$cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function save(){
|
||||
if(is_object($this->entity)){
|
||||
$this->data["spawn"] = array(
|
||||
"x" => $this->entity->x,
|
||||
"y" => $this->entity->y,
|
||||
"z" => $this->entity->z,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function close($reason = "", $msg = true){
|
||||
$reason = $reason == "" ? "server stop":$reason;
|
||||
$this->save();
|
||||
foreach($this->evid as $ev){
|
||||
$this->server->deleteEvent($ev);
|
||||
}
|
||||
$this->eventHandler("You have been kicked. Reason: ".$reason, "server.chat");
|
||||
$this->dataPacket(MC_LOGIN_STATUS, array(
|
||||
"status" => 1,
|
||||
));
|
||||
$this->dataPacket(MC_DISCONNECT);
|
||||
|
||||
$this->connected = false;
|
||||
if($msg === true){
|
||||
$this->server->trigger("server.chat", $this->username." left the game");
|
||||
}
|
||||
console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason);
|
||||
$this->server->api->player->remove($this->CID);
|
||||
}
|
||||
|
||||
public function eventHandler($data, $event){
|
||||
switch($event){
|
||||
case "player.equipment.change":
|
||||
if($data["eid"] === $this->eid){
|
||||
break;
|
||||
}
|
||||
$this->dataPacket(MC_PLAYER_EQUIPMENT, $data);
|
||||
break;
|
||||
case "world.block.change":
|
||||
$this->dataPacket(MC_UPDATE_BLOCK, $data);
|
||||
break;
|
||||
case "entity.move":
|
||||
if($data === $this->eid){
|
||||
break;
|
||||
}
|
||||
$entity = $this->server->entities[$data];
|
||||
$this->dataPacket(MC_MOVE_ENTITY_POSROT, array(
|
||||
"eid" => $data,
|
||||
"x" => $entity->x,
|
||||
"y" => $entity->y,
|
||||
"z" => $entity->z,
|
||||
"yaw" => $entity->yaw,
|
||||
"pitch" => $entity->pitch,
|
||||
));
|
||||
break;
|
||||
case "entity.remove":
|
||||
if($data === $this->eid){
|
||||
break;
|
||||
}
|
||||
$this->dataPacket(MC_ENTITY_REMOVE, array(
|
||||
"eid" => $data,
|
||||
));
|
||||
break;
|
||||
case "server.time.change":
|
||||
$this->dataPacket(MC_SET_TIME, array(
|
||||
"time" => $data,
|
||||
));
|
||||
break;
|
||||
case "entity.animate":
|
||||
if($data["eid"] === $this->eid){
|
||||
break;
|
||||
}
|
||||
$this->dataPacket(MC_ANIMATE, array(
|
||||
"eid" => $data["eid"],
|
||||
"action" => $data["action"],
|
||||
));
|
||||
break;
|
||||
case "server.chat":
|
||||
$this->dataPacket(MC_CHAT, array(
|
||||
"message" => str_replace("@username", $this->username, $data),
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function handle($pid, $data){
|
||||
if($this->connected === true){
|
||||
$this->timeout = microtime(true) + 25;
|
||||
switch($pid){
|
||||
case 0xa0: //NACK
|
||||
if(isset($this->buffer[$data[2]])){
|
||||
array_unshift($this->queue, array(0, $this->buffer[$data[2]][0], $this->buffer[$data[2]][1], $data[2]));
|
||||
}
|
||||
if(isset($data[3])){
|
||||
if(isset($this->buffer[$data[3]])){
|
||||
array_unshift($this->queue, array(0, $this->buffer[$data[3]][0], $this->buffer[$data[3]][1], $data[3]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0xc0: //ACK
|
||||
$diff = $data[2] - $this->counter[2];
|
||||
if($diff > 8){ //Packet recovery
|
||||
array_unshift($this->queue, array(0, $this->buffer[$data[2]][0], $this->buffer[$data[2]][1], $data[2]));
|
||||
}
|
||||
$this->counter[2] = $data[2];
|
||||
unset($this->buffer[$data[2]]);
|
||||
|
||||
if(isset($data[3])){
|
||||
$diff = $data[3] - $this->counter[2];
|
||||
if($diff > 8){ //Packet recovery
|
||||
array_unshift($this->queue, array(0, $this->buffer[$data[3]][0], $this->buffer[$data[3]][1], $data[3]));
|
||||
}
|
||||
$this->counter[2] = $data[3];
|
||||
unset($this->buffer[$data[3]]);
|
||||
}
|
||||
break;
|
||||
case 0x07:
|
||||
$this->send(0x08, array(
|
||||
MAGIC,
|
||||
$this->server->serverID,
|
||||
$this->port,
|
||||
$data[3],
|
||||
0,
|
||||
));
|
||||
break;
|
||||
case 0x80:
|
||||
case 0x84:
|
||||
case 0x88:
|
||||
case 0x8c:
|
||||
if(isset($data[0])){
|
||||
$diff = $data[0] - $this->counter[1];
|
||||
if($diff > 1){ //Packet recovery
|
||||
for($i = $this->counter[1]; $i < $data[0]; ++$i){
|
||||
$this->send(0xa0, array(1, true, $i));
|
||||
}
|
||||
$this->counter[1] = $data[0];
|
||||
}elseif($diff === 1){
|
||||
$this->counter[1] = $data[0];
|
||||
}
|
||||
$this->send(0xc0, array(1, true, $data[0]));
|
||||
}
|
||||
switch($data["id"]){
|
||||
case MC_DISCONNECT:
|
||||
$this->connected = false;
|
||||
$this->close("client disconnect");
|
||||
break;
|
||||
case MC_CLIENT_CONNECT:
|
||||
$this->dataPacket(MC_SERVER_HANDSHAKE, array(
|
||||
"port" => $this->port,
|
||||
"session" => $data["session"],
|
||||
"session2" => Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9"),
|
||||
));
|
||||
break;
|
||||
case MC_CLIENT_HANDSHAKE:
|
||||
|
||||
break;
|
||||
case MC_LOGIN:
|
||||
$this->username = str_replace("/", "", $data["username"]);
|
||||
if($this->username == ""){
|
||||
$this->close("bad username", false);
|
||||
break;
|
||||
}
|
||||
$o = $this->server->api->player->getOffline($this->username);
|
||||
if($this->server->whitelist !== false and (!in_array($this->username, $this->server->whitelist)/* or ($o["lastID"] != 0 and $o["lastID"] != $this->clientID)*/)){
|
||||
$this->close("\"".$this->username."\" not being on white-list", false);
|
||||
break;
|
||||
}
|
||||
$u = $this->server->api->player->get($this->username);
|
||||
$c = $this->server->api->player->getByClientID($this->clientID);
|
||||
if($u !== false){
|
||||
$u->close("logged in from another location");
|
||||
}
|
||||
if($c !== false){
|
||||
$c->close("logged in from another location");
|
||||
}
|
||||
$this->server->api->player->add($this->CID);
|
||||
$this->auth = true;
|
||||
$this->data["lastIP"] = $this->ip;
|
||||
$this->data["lastID"] = $this->clientID;
|
||||
$this->server->api->player->saveOffline($this->username, $this->data);
|
||||
$this->dataPacket(MC_LOGIN_STATUS, array(
|
||||
"status" => 0,
|
||||
));
|
||||
$this->dataPacket(MC_START_GAME, array(
|
||||
"seed" => $this->server->seed,
|
||||
"x" => $this->data["spawn"]["x"],
|
||||
"y" => $this->data["spawn"]["y"],
|
||||
"z" => $this->data["spawn"]["z"],
|
||||
"unknown1" => 0,
|
||||
"gamemode" => $this->server->gamemode,
|
||||
"eid" => 0,
|
||||
));
|
||||
break;
|
||||
case MC_READY:
|
||||
if($this->spawned !== false){
|
||||
break;
|
||||
}
|
||||
$this->spawned = true;
|
||||
$this->entity = $this->server->api->entity->add(ENTITY_PLAYER, 0, array("player" => $this));
|
||||
$this->eid = $this->entity->eid;
|
||||
$this->server->query("UPDATE players SET EID = ".$this->eid." WHERE clientID = ".$this->clientID.";");
|
||||
$this->entity->setName($this->username);
|
||||
$this->entity->data["clientID"] = $this->clientID;
|
||||
$this->server->api->entity->spawnAll($this);
|
||||
$this->server->api->entity->spawnToAll($this->eid);
|
||||
$this->evid[] = $this->server->event("server.time.change", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("server.chat", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("entity.remove", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("entity.move", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("player.equipment.change", array($this, "eventHandler"));
|
||||
$this->evid[] = $this->server->event("world.block.change", array($this, "eventHandler"));
|
||||
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
|
||||
|
||||
$this->eventHandler($this->server->motd, "server.chat");
|
||||
if($this->MTU <= 548){
|
||||
$this->eventHandler("Your connection is bad, you may experience lag and slow map loading.", "server.chat");
|
||||
}
|
||||
break;
|
||||
case MC_MOVE_PLAYER:
|
||||
if(is_object($this->entity)){
|
||||
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]);
|
||||
$this->server->trigger("entity.move", $this->eid);
|
||||
}
|
||||
break;
|
||||
case MC_PLAYER_EQUIPMENT:
|
||||
$data["eid"] = $this->eid;
|
||||
if($this->server->handle("player.equipment.change", $data) !== false){
|
||||
$this->equipment[0] = $data["block"];
|
||||
$this->equipment[1] = $data["meta"];
|
||||
console("[DEBUG] EID ".$this->eid." has now ".$data["block"].":".$data["meta"]." in their hands!", true, true, 2);
|
||||
}
|
||||
break;
|
||||
case MC_REQUEST_CHUNK:
|
||||
$this->actionQueue('
|
||||
$max = max(1, floor(($this->MTU - 16 - 255) / 192));
|
||||
$chunk = $this->server->api->level->getOrderedChunk('.$data["x"].', '.$data["z"].', $max);
|
||||
foreach($chunk as $d){
|
||||
$this->dataPacket(MC_CHUNK_DATA, array(
|
||||
"x" => '.$data["x"].',
|
||||
"z" => '.$data["z"].',
|
||||
"data" => $d,
|
||||
), true);
|
||||
}
|
||||
');
|
||||
console("[INTERNAL] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 3);
|
||||
break;
|
||||
case MC_USE_ITEM:
|
||||
$data["eid"] = $this->eid;
|
||||
$this->server->handle("player.block.action", $data);
|
||||
break;
|
||||
case MC_PLACE_BLOCK:
|
||||
|
||||
break;
|
||||
case MC_REMOVE_BLOCK:
|
||||
$data["eid"] = $this->eid;
|
||||
$this->server->handle("player.block.break", $data);
|
||||
break;
|
||||
case MC_INTERACT:
|
||||
if(isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
||||
console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2);
|
||||
if($this->server->gamemode !== 1 and $this->server->difficulty > 0){
|
||||
$this->server->api->entity->harm($data["target"], $this->server->difficulty, $this->eid);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_ANIMATE:
|
||||
$this->server->trigger("entity.animate", array("eid" => $this->eid, "action" => $data["action"]));
|
||||
break;
|
||||
case MC_RESPAWN:
|
||||
$this->entity->setHealth(20, "respawn");
|
||||
$this->entity->setPosition($data["x"], $data["y"], $data["z"], 0, 0);
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function send($pid, $data = array(), $raw = false){
|
||||
if($this->connected === true){
|
||||
$this->server->send($pid, $data, $raw, $this->ip, $this->port);
|
||||
}
|
||||
}
|
||||
|
||||
public function actionQueue($code){
|
||||
$this->queue[] = array(1, $code);
|
||||
}
|
||||
|
||||
public function dataPacket($id, $data = array(), $queue = false, $count = false){
|
||||
if($queue === true){
|
||||
$this->queue[] = array(0, $id, $data, $count);
|
||||
}else{
|
||||
if($count === false){
|
||||
$count = $this->counter[0];
|
||||
++$this->counter[0];
|
||||
if(count($this->buffer) >= 512){
|
||||
array_shift($this->buffer);
|
||||
}
|
||||
$this->buffer[$count] = array($id, $data);
|
||||
}
|
||||
$data["id"] = $id;
|
||||
$this->send(0x80, array(
|
||||
$count,
|
||||
0x00,
|
||||
$data,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
546
src/classes/PocketMinecraftServer.class.php
Normal file
546
src/classes/PocketMinecraftServer.class.php
Normal file
@@ -0,0 +1,546 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class PocketMinecraftServer extends stdClass{
|
||||
var $invisible, $tickMeasure, $preparedSQL, $seed, $protocol, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond, $responses, $spawn, $entities, $mapDir, $mapName, $map, $level, $tileEntities;
|
||||
private $database, $interface, $evCnt, $handCnt, $events, $handlers, $version, $serverType, $lastTick;
|
||||
function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){
|
||||
$this->port = (int) $port; //19132 - 19135
|
||||
console("[INFO] PocketMine-MP ".MAJOR_VERSION." by @shoghicp, LGPL License. http://bit.ly/TbrimG", true, true, 0);
|
||||
console("[INFO] Starting Minecraft PE Server at *:".$this->port);
|
||||
if($this->port < 19132 or $this->port > 19135){
|
||||
console("[WARNING] You've selected a not-standard port. Normal port range is from 19132 to 19135 included");
|
||||
}
|
||||
console("[INFO] Loading database...");
|
||||
$this->startDatabase();
|
||||
$this->gamemode = (int) $gamemode;
|
||||
$this->version = (int) $version;
|
||||
$this->name = $name;
|
||||
$this->mapDir = false;
|
||||
$this->mapName = false;
|
||||
$this->events = array();
|
||||
$this->handlers = array();
|
||||
$this->map = false;
|
||||
$this->invisible = false;
|
||||
$this->level = false;
|
||||
$this->difficulty = 1;
|
||||
$this->tileEntities = array();
|
||||
$this->entities = array();
|
||||
$this->custom = array();
|
||||
$this->evCnt = 0;
|
||||
$this->handCnt = 0;
|
||||
$this->eidCnt = 1;
|
||||
$this->maxClients = 20;
|
||||
$this->schedule = array();
|
||||
$this->scheduleCnt = 0;
|
||||
$this->description = "";
|
||||
$this->whitelist = false;
|
||||
$this->bannedIPs = array();
|
||||
$this->motd = "Welcome to ".$name;
|
||||
$this->serverID = $serverID === false ? Utils::readLong(Utils::getRandomBytes(8)):$serverID;
|
||||
$this->seed = $seed === false ? Utils::readInt(Utils::getRandomBytes(4)):$seed;
|
||||
$this->clients = array();
|
||||
$this->protocol = (int) $protocol;
|
||||
$this->spawn = array("x" => 128.5,"y" => 100,"z" => 128.5);
|
||||
$this->time = 0;
|
||||
$this->timePerSecond = 10;
|
||||
$this->tickMeasure = array_fill(0, 40, 0);
|
||||
$this->setType("normal");
|
||||
$this->interface = new MinecraftInterface("255.255.255.255", $this->protocol, $this->port, true, false);
|
||||
$this->reloadConfig();
|
||||
console("[INFO] Server Name: ".$this->name);
|
||||
console("[INFO] Server GUID: ".$this->serverID);
|
||||
console("[INFO] Protocol Version: ".$this->protocol);
|
||||
console("[INFO] Max Clients: ".$this->maxClients);
|
||||
$this->stop = false;
|
||||
}
|
||||
|
||||
public function getTPS(){
|
||||
$v = array_values($this->tickMeasure);
|
||||
$tps = 40 / ($v[39] - $v[0]);
|
||||
return round($tps, 4);
|
||||
}
|
||||
|
||||
public function loadEvents(){
|
||||
$this->event("server.chat", array($this, "eventHandler"));
|
||||
$this->event("player.new", array($this, "eventHandler"));
|
||||
|
||||
$this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->trigger("server.time.change", $this->time);');
|
||||
$this->action(5000000, 'if($this->difficulty < 2){$this->trigger("server.regeneration", 1);}');
|
||||
$this->action(1000000 * 60, '$this->reloadConfig();');
|
||||
$this->action(1000000 * 60 * 10, '$this->custom = array();');
|
||||
if($this->api !== false){
|
||||
$this->action(1000000 * 80, '$this->chat(false, count($this->clients)."/".$this->maxClients." online: ".implode(", ",$this->api->player->online()));');
|
||||
}
|
||||
$this->action(1000000 * 75, '$this->debugInfo(true);');
|
||||
}
|
||||
|
||||
public function startDatabase(){
|
||||
$this->preparedSQL = new stdClass();
|
||||
$this->database = new SQLite3(":memory:");
|
||||
//$this->query("PRAGMA journal_mode = OFF;");
|
||||
//$this->query("PRAGMA encoding = \"UTF-8\";");
|
||||
//$this->query("PRAGMA secure_delete = OFF;");
|
||||
$this->query("CREATE TABLE players (clientID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT UNIQUE);");
|
||||
$this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, type NUMERIC, class NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);");
|
||||
$this->query("CREATE TABLE metadata (EID INTEGER PRIMARY KEY, name TEXT, value TEXT);");
|
||||
$this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);");
|
||||
$this->query("CREATE TABLE events (ID INTEGER PRIMARY KEY, name TEXT);");
|
||||
$this->query("CREATE TABLE handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);");
|
||||
//$this->query("PRAGMA synchronous = OFF;");
|
||||
$this->preparedSQL->selectHandlers = $this->database->prepare("SELECT ID FROM handlers WHERE name = :name ORDER BY priority DESC;");
|
||||
$this->preparedSQL->selectEvents = $this->database->prepare("SELECT ID FROM events WHERE name = :name;");
|
||||
$this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);");
|
||||
$this->preparedSQL->updateActions = $this->database->prepare("UPDATE actions SET last = :time WHERE last <= (:time - interval);");
|
||||
}
|
||||
|
||||
public function query($sql, $fetch = false){
|
||||
console("[INTERNAL] [SQL] ".$sql, true, true, 3);
|
||||
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0);
|
||||
if($fetch === true and ($result !== false and $result !== true)){
|
||||
$result = $result->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function reloadConfig(){
|
||||
if($this->whitelist === true or is_array($this->whitelist)){
|
||||
$this->whitelist = explode("\n", str_replace(array("\t","\r"), "", file_get_contents(FILE_PATH."white-list.txt")));
|
||||
}
|
||||
$this->bannedIPs = explode("\n", str_replace(array(" ","\t","\r"), "", file_get_contents(FILE_PATH."banned-ips.txt")));
|
||||
}
|
||||
|
||||
public function debugInfo($console = false){
|
||||
$info = array();
|
||||
$info["tps"] = $this->getTPS();
|
||||
$info["memory_usage"] = round((memory_get_usage(true) / 1024) / 1024, 2)."MB";
|
||||
$info["memory_peak_usage"] = round((memory_get_peak_usage(true) / 1024) / 1024, 2)."MB";
|
||||
$info["entities"] = $this->query("SELECT count(EID) as count FROM entities;", true);
|
||||
$info["entities"] = $info["entities"]["count"];
|
||||
$info["events"] = $this->query("SELECT count(ID) as count FROM events;", true);
|
||||
$info["events"] = $info["events"]["count"];
|
||||
$info["actions"] = $this->query("SELECT count(ID) as count FROM actions;", true);
|
||||
$info["actions"] = $info["actions"]["count"];
|
||||
$info["garbage"] = gc_collect_cycles();
|
||||
if($console === true){
|
||||
console("[DEBUG] TPS: ".$info["tps"].", Memory usage: ".$info["memory_usage"]." (Peak ".$info["memory_peak_usage"]."), Entities: ".$info["entities"].", Events: ".$info["events"].", Actions: ".$info["actions"].", Garbage: ".$info["garbage"], true, true, 2);
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function close($reason = "stop"){
|
||||
if($this->stop !== true){
|
||||
$this->chat(false, "Stopping server...");
|
||||
$this->save();
|
||||
$this->stop = true;
|
||||
$this->trigger("server.close");
|
||||
$this->interface->close();
|
||||
}
|
||||
}
|
||||
|
||||
public function chat($owner, $text, $target = true){
|
||||
$message = "";
|
||||
if($owner !== false){
|
||||
$message = "<".$owner."> ";
|
||||
}
|
||||
$message .= $text;
|
||||
$this->trigger("server.chat", $message);
|
||||
}
|
||||
|
||||
public function setType($type = "normal"){
|
||||
switch($type){
|
||||
case "normal":
|
||||
$this->serverType = "MCCPP;Demo;";
|
||||
break;
|
||||
case "minecon":
|
||||
$this->serverType = "MCCPP;MINECON;";
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function addHandler($event, $callable, $priority = 5){
|
||||
if(!is_callable($callable)){
|
||||
return false;
|
||||
}
|
||||
$priority = (int) $priority;
|
||||
$this->handlers[$this->handCnt] = $callable;
|
||||
$this->query("INSERT INTO handlers (ID, name, priority) VALUES (".$this->handCnt.", '".str_replace("'", "\\'", $event)."', ".$priority.");");
|
||||
console("[INTERNAL] New handler ".(is_array($callable) ? get_class($callable[0])."::".$callable[1]:$callable)." to special event ".$event." (ID ".$this->handCnt.")", true, true, 3);
|
||||
return $this->handCnt++;
|
||||
}
|
||||
|
||||
public function handle($event, &$data){
|
||||
$this->preparedSQL->selectHandlers->reset();
|
||||
$this->preparedSQL->selectHandlers->clear();
|
||||
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
|
||||
$handlers = $this->preparedSQL->selectHandlers->execute();
|
||||
$result = true;
|
||||
if($handlers !== false and $handlers !== true){
|
||||
while(false !== ($hn = $handlers->fetchArray(SQLITE3_ASSOC)) and $result !== false){
|
||||
$handler = $this->handlers[(int) $hn["ID"]];
|
||||
if(is_array($handler)){
|
||||
$method = $handler[1];
|
||||
$result = $handler[0]->$method($data, $event);
|
||||
}else{
|
||||
$result = $handler($data, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
$handlers->finalize();
|
||||
if($result !== false){
|
||||
$this->trigger($event, $data);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function eventHandler($data, $event){
|
||||
switch($event){
|
||||
case "player.new":
|
||||
console("[DEBUG] Player \"".$data["username"]."\" EID ".$data["eid"]." spawned at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
|
||||
break;
|
||||
case "server.chat":
|
||||
console("[CHAT] $data");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function loadMap(){
|
||||
if($this->mapName !== false and trim($this->mapName) !== ""){
|
||||
$this->level = unserialize(file_get_contents($this->mapDir."level.dat"));
|
||||
console("[INFO] Map: ".$this->level["LevelName"]);
|
||||
$this->time = (int) $this->level["Time"];
|
||||
$this->seed = (int) $this->level["RandomSeed"];
|
||||
if(isset($this->level["SpawnX"])){
|
||||
$this->spawn = array("x" => $this->level["SpawnX"], "y" => $this->level["SpawnY"], "z" => $this->level["SpawnZ"]);
|
||||
}else{
|
||||
$this->level["SpawnX"] = $this->spawn["x"];
|
||||
$this->level["SpawnY"] = $this->spawn["y"];
|
||||
$this->level["SpawnZ"] = $this->spawn["z"];
|
||||
}
|
||||
$this->level["Time"] = &$this->time;
|
||||
console("[INFO] Spawn: X ".$this->level["SpawnX"]." Y ".$this->level["SpawnY"]." Z ".$this->level["SpawnZ"]);
|
||||
console("[INFO] Time: ".$this->time);
|
||||
console("[INFO] Seed: ".$this->seed);
|
||||
console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative"));
|
||||
$d = array(0 => "peaceful", 1 => "easy", 2 => "normal", 3 => "hard");
|
||||
console("[INFO] Difficulty: ".$d[$this->difficulty]);
|
||||
console("[INFO] Loading map...");
|
||||
$this->map = new ChunkParser();
|
||||
if(!$this->map->loadFile($this->mapDir."chunks.dat")){
|
||||
console("[ERROR] Couldn't load the map \"".$this->level["LevelName"]."\"!", true, true, 0);
|
||||
$this->map = false;
|
||||
}else{
|
||||
$this->map->loadMap();
|
||||
}
|
||||
}else{
|
||||
console("[INFO] Time: ".$this->time);
|
||||
console("[INFO] Seed: ".$this->seed);
|
||||
console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative"));
|
||||
}
|
||||
}
|
||||
|
||||
public function loadEntities(){
|
||||
if($this->map !== false){
|
||||
console("[INFO] Loading entities...");
|
||||
$entities = unserialize(file_get_contents($this->mapDir."entities.dat"));
|
||||
foreach($entities as $entity){
|
||||
if(!isset($entity["id"])){
|
||||
break;
|
||||
}
|
||||
if(isset($this->api) and $this->api !== false){
|
||||
if($entity["id"] === 64){ //Item Drop
|
||||
$e = $this->api->entity->add(ENTITY_ITEM, $entity["Item"]["id"], array(
|
||||
"meta" => $entity["Item"]["Damage"],
|
||||
"stack" => $entity["Item"]["Count"],
|
||||
"x" => $entity["Pos"][0],
|
||||
"y" => $entity["Pos"][1],
|
||||
"z" => $entity["Pos"][2],
|
||||
"yaw" => $entity["Rotation"][0],
|
||||
"pitch" => $entity["Rotation"][1],
|
||||
));
|
||||
}else{
|
||||
$e = $this->api->entity->add(ENTITY_MOB, $entity["id"]);
|
||||
$e->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]);
|
||||
$e->setHealth($entity["Health"]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
console("[DEBUG] Loaded ".count($this->entities)." Entities", true, true, 2);
|
||||
$this->action(1000000 * 60 * 15, '$this->chat(false, "Forcing save...");$this->save();$this->chat(false, "Done");');
|
||||
}
|
||||
}
|
||||
|
||||
public function save(){
|
||||
if($this->mapName !== false){
|
||||
file_put_contents($this->mapDir."level.dat", serialize($this->level));
|
||||
$this->map->saveMap();
|
||||
console("[INFO] Saving entities...");
|
||||
foreach($this->entities as $entity){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function start(){
|
||||
if($this->mapName !== false and $this->map === false){
|
||||
$this->loadMap();
|
||||
$this->loadEntities();
|
||||
}
|
||||
console("[INFO] Loading events...");
|
||||
$this->loadEvents();
|
||||
declare(ticks=15);
|
||||
register_tick_function(array($this, "tick"));
|
||||
register_shutdown_function(array($this, "close"));
|
||||
$this->trigger("server.start", microtime(true));
|
||||
console("[INFO] Server started!");
|
||||
$this->process();
|
||||
}
|
||||
|
||||
public function tick(){
|
||||
$time = microtime(true);
|
||||
if($this->lastTick <= ($time - 0.05)){
|
||||
array_shift($this->tickMeasure);
|
||||
$this->tickMeasure[] = $this->lastTick = $time;
|
||||
$this->tickerFunction($time);
|
||||
$this->trigger("server.tick", $time);
|
||||
}
|
||||
}
|
||||
|
||||
public function clientID($ip, $port){
|
||||
return md5($pi . $port, true);
|
||||
}
|
||||
|
||||
public function packetHandler($packet){
|
||||
$data =& $packet["data"];
|
||||
$CID = $this->clientID($packet["ip"], $packet["port"]);
|
||||
if(isset($this->clients[$CID])){
|
||||
$this->clients[$CID]->handle($packet["pid"], $data);
|
||||
}else{
|
||||
switch($packet["pid"]){
|
||||
case 0x02:
|
||||
if($this->invisible === true){
|
||||
$this->send(0x1c, array(
|
||||
$data[0],
|
||||
$this->serverID,
|
||||
MAGIC,
|
||||
$this->serverType,
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
break;
|
||||
}
|
||||
if(in_array($packet["ip"], $this->bannedIPs)){
|
||||
$this->send(0x1c, array(
|
||||
$data[0],
|
||||
$this->serverID,
|
||||
MAGIC,
|
||||
$this->serverType. $this->name . " [You're banned]",
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
break;
|
||||
}
|
||||
if(!isset($this->custom["times_".$CID])){
|
||||
$this->custom["times_".$CID] = 0;
|
||||
}
|
||||
$ln = 15;
|
||||
$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,
|
||||
MAGIC,
|
||||
$this->serverType. $this->name . " [".($this->gamemode === 1 ? "C":"S").($this->whitelist !== false ? "W":"")." ".count($this->clients)."/".$this->maxClients."] ".$txt,
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
|
||||
break;
|
||||
case 0x05:
|
||||
if(in_array($packet["ip"], $this->bannedIPs) or count($this->clients) >= $this->maxClients){
|
||||
$this->send(0x80, array(
|
||||
0,
|
||||
0x00,
|
||||
array(
|
||||
"id" => MC_LOGIN_STATUS,
|
||||
"status" => 1,
|
||||
),
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
$this->send(0x80, array(
|
||||
1,
|
||||
0x00,
|
||||
array(
|
||||
"id" => MC_DISCONNECT,
|
||||
),
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
break;
|
||||
}
|
||||
$version = $data[1];
|
||||
$size = strlen($data[2]);
|
||||
if($version !== $this->protocol){
|
||||
$this->send(0x1a, array(
|
||||
$this->protocol,
|
||||
MAGIC,
|
||||
$this->serverID,
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
}else{
|
||||
$this->send(0x06, array(
|
||||
MAGIC,
|
||||
$this->serverID,
|
||||
0,
|
||||
strlen($packet["raw"]),
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
}
|
||||
break;
|
||||
case 0x07:
|
||||
if(in_array($packet["ip"], $this->bannedIPs) or count($this->clients) >= $this->maxClients){
|
||||
$this->send(0x80, array(
|
||||
0,
|
||||
0x00,
|
||||
array(
|
||||
"id" => MC_LOGIN_STATUS,
|
||||
"status" => 1,
|
||||
),
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
$this->send(0x80, array(
|
||||
1,
|
||||
0x00,
|
||||
array(
|
||||
"id" => MC_DISCONNECT,
|
||||
),
|
||||
), false, $packet["ip"], $packet["port"]);
|
||||
break;
|
||||
}
|
||||
$port = $data[2];
|
||||
$MTU = $data[3];
|
||||
$clientID = $data[4];
|
||||
$this->clients[$CID] = new Player($this, $clientID, $packet["ip"], $packet["port"], $MTU);
|
||||
$this->clients[$CID]->handle(0x07, $data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function send($pid, $data = array(), $raw = false, $dest = false, $port = false){
|
||||
$this->interface->writePacket($pid, $data, $raw, $dest, $port);
|
||||
}
|
||||
|
||||
public function process(){
|
||||
while($this->stop === false){
|
||||
$packet = @$this->interface->readPacket();
|
||||
if($packet !== false){
|
||||
$this->packetHandler($packet);
|
||||
}else{
|
||||
usleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function trigger($event, $data = ""){
|
||||
$this->preparedSQL->selectEvents->reset();
|
||||
$this->preparedSQL->selectEvents->clear();
|
||||
$this->preparedSQL->selectEvents->bindValue(":name", $event, SQLITE3_TEXT);
|
||||
$events = $this->preparedSQL->selectEvents->execute();
|
||||
if($events === false or $events === true){
|
||||
return;
|
||||
}
|
||||
while(false !== ($evn = $events->fetchArray(SQLITE3_ASSOC))){
|
||||
$ev = $this->events[(int) $evn["ID"]];
|
||||
if(is_array($ev)){
|
||||
$method = $ev[1];
|
||||
$this->responses[(int) $evn["ID"]] = $ev[0]->$method($data, $event);
|
||||
}else{
|
||||
$this->responses[(int) $evn["ID"]] = $ev($data, $event);
|
||||
}
|
||||
}
|
||||
$events->finalize();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function response($eid){
|
||||
if(isset($this->responses[$eid])){
|
||||
$res = $this->responses[$eid];
|
||||
unset($this->responses[$eid]);
|
||||
return $res;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function schedule($ticks, $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){
|
||||
if(!is_callable($callback)){
|
||||
return false;
|
||||
}
|
||||
$add = "";
|
||||
if($repeat === false){
|
||||
$add = ' unset($this->schedule['.$this->scheduleCnt.']);';
|
||||
}
|
||||
$this->schedule[$this->scheduleCnt] = array($callback, $data, $eventName);
|
||||
$this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.' call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat);
|
||||
return $this->scheduleCnt++;
|
||||
}
|
||||
|
||||
public function action($microseconds, $code, $repeat = true){
|
||||
$this->query("INSERT INTO actions (interval, last, code, repeat) VALUES(".($microseconds / 1000000).", ".microtime(true).", '".base64_encode($code)."', ".($repeat === true ? 1:0).");");
|
||||
console("[INTERNAL] Attached to action ".$microseconds, true, true, 3);
|
||||
}
|
||||
|
||||
public function tickerFunction($time){
|
||||
//actions that repeat every x time will go here
|
||||
$this->preparedSQL->selectActions->reset();
|
||||
$this->preparedSQL->selectActions->clear();
|
||||
$this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$actions = $this->preparedSQL->selectActions->execute();
|
||||
|
||||
if($actions === false or $actions === true){
|
||||
return;
|
||||
}
|
||||
while(false !== ($action = $actions->fetchArray(SQLITE3_ASSOC))){
|
||||
eval(base64_decode($action["code"]));
|
||||
if($action["repeat"] === 0){
|
||||
$this->query("DELETE FROM actions WHERE ID = ".$action["ID"].";");
|
||||
}
|
||||
}
|
||||
$actions->finalize();
|
||||
$this->preparedSQL->updateActions->reset();
|
||||
$this->preparedSQL->updateActions->clear();
|
||||
$this->preparedSQL->updateActions->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||
$this->preparedSQL->updateActions->execute();
|
||||
}
|
||||
|
||||
public function event($event, $func){
|
||||
if(!is_callable($func)){
|
||||
return false;
|
||||
}
|
||||
$this->events[$this->evCnt] = $func;
|
||||
$this->query("INSERT INTO events (ID, name) VALUES (".$this->evCnt.", '".str_replace("'", "\\'", $event)."');");
|
||||
console("[INTERNAL] Attached ".(is_array($func) ? get_class($func[0])."::".$func[1]:$func)." to event ".$event." (ID ".$this->evCnt.")", true, true, 3);
|
||||
return $this->evCnt++;
|
||||
}
|
||||
|
||||
public function deleteEvent($id){
|
||||
$id = (int) $id;
|
||||
unset($this->events[$id]);
|
||||
$this->query("DELETE FROM events WHERE ID = ".$id.";");
|
||||
}
|
||||
|
||||
}
|
87
src/classes/SerializedPacketHandler.class.php
Normal file
87
src/classes/SerializedPacketHandler.class.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class SerializedPacketHandler{
|
||||
var $offset, $raw, $c, $data, $name = "";
|
||||
|
||||
private function get($len = true, $check = true){
|
||||
if($len === true){
|
||||
$data = substr($this->raw, $this->offset);
|
||||
if($check === true){
|
||||
$this->offset = strlen($this->raw);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
$data = substr($this->raw, $this->offset, $len);
|
||||
if($check === true){
|
||||
$this->offset += $len;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function __construct($pid, $raw = "", $data = array(), $create = false){
|
||||
$this->raw = $raw;
|
||||
$this->data = $data;
|
||||
$this->offset = 0;
|
||||
$this->c = (bool) $create;
|
||||
switch($pid){
|
||||
case 0x60:
|
||||
case 0x40:
|
||||
case 0x00:
|
||||
if($this->c === false){
|
||||
$this->data["packets"] = array();
|
||||
$i = 0;
|
||||
while($this->offset < strlen($this->raw)){
|
||||
if($i > 0){
|
||||
$pid = ord($this->get(1));
|
||||
}
|
||||
|
||||
$len = ceil(Utils::readShort($this->get(2), false) / 8); //Utils::readShort($this->get(2), false) >> 3;
|
||||
if($pid !== 0x00){
|
||||
$c = Utils::readTriad($this->get(3));
|
||||
}
|
||||
if($pid === 0x60 and $i === 0){
|
||||
$this->data["unknown1"] = $this->get(4);
|
||||
}
|
||||
$id = ord($this->get(1));
|
||||
$raw = $this->get($len - 1);
|
||||
$pk = new CustomPacketHandler($id, $raw);
|
||||
$pk->data["length"] = $len;
|
||||
$pk->data["id"] = $id;
|
||||
if($pid !== 0x00){
|
||||
$pk->data["counter"] = $c;
|
||||
}
|
||||
$pk->data["packetName"] = $pk->name;
|
||||
$this->data["packets"][] = array($pid, $pk->data, $raw);
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1057
src/classes/Spyc.class.php
Normal file
1057
src/classes/Spyc.class.php
Normal file
File diff suppressed because it is too large
Load Diff
107
src/classes/SuperflatGenerator.class.php
Normal file
107
src/classes/SuperflatGenerator.class.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class SuperflatGenerator{
|
||||
private $config, $spawn, $structure;
|
||||
public function __construct($seed){
|
||||
$this->config = array(
|
||||
"preset" => "7;20x1;3x3;2",
|
||||
"spawn-surface" => 24,
|
||||
"spawn-radius" => 10,
|
||||
"torches" => 0,
|
||||
"seed" => (int) $seed,
|
||||
);
|
||||
$this->parsePreset();
|
||||
}
|
||||
|
||||
public function set($name, $value){
|
||||
$this->config[$name] = $value;
|
||||
if($name === "preset"){
|
||||
$this->parsePreset();
|
||||
}
|
||||
}
|
||||
|
||||
private function parsePreset(){
|
||||
$this->structure = array(
|
||||
0 => "",
|
||||
1 => "",
|
||||
2 => str_repeat("\x00", 64),
|
||||
3 => str_repeat("\x00", 64),
|
||||
);
|
||||
$preset = explode(";", trim($this->config["preset"]));
|
||||
foreach($preset as $i => $data){
|
||||
$num = 1;
|
||||
if(preg_match('#([a-zA-Z\-_]*)\((.*)\)#', $data, $matches) > 0){ //Property
|
||||
$this->config[$matches[1]] = $matches[2];
|
||||
continue;
|
||||
}elseif(preg_match('#([0-9]*)x([0-9:]*)#', $data, $matches) > 0){
|
||||
$num = (int) $matches[1];
|
||||
$d = explode(":", $matches[2]);
|
||||
}else{
|
||||
$d = explode(":", $data);
|
||||
}
|
||||
$block = (int) array_shift($d);
|
||||
$meta = (int) @array_shift($d);
|
||||
for($j = 0; $j < $num; ++$j){
|
||||
$this->structure[0] .= chr($block & 0xFF);
|
||||
$this->structure[1] .= substr(dechex($meta & 0x0F), -1);
|
||||
}
|
||||
}
|
||||
$this->structure[1] = pack("h*", str_pad($this->structure[1], (strlen($this->structure[1])&0xFE) + 2, "0", STR_PAD_RIGHT)); //invert nibbles
|
||||
$this->structure[0] = substr($this->structure[0], 0, 128);
|
||||
$this->structure[1] = substr($this->structure[1], 0, 64);
|
||||
$this->structure[2] = substr($this->structure[2], 0, 64);
|
||||
$this->structure[3] = substr($this->structure[3], 0, 64);
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->spawn = array(128, strlen($this->structure[0]), 128);
|
||||
}
|
||||
|
||||
public function getSpawn(){
|
||||
return $this->spawn;
|
||||
}
|
||||
|
||||
public function getColumn($x, $z){
|
||||
$x = (int) $x;
|
||||
$z = (int) $z;
|
||||
$column = $this->structure;
|
||||
if(floor(sqrt(pow($x - $this->spawn[0], 2) + pow($z - $this->spawn[2], 2))) <= $this->config["spawn-radius"]){
|
||||
$column[0]{strlen($column[0])-1} = chr($this->config["spawn-surface"]);
|
||||
}
|
||||
if(($x % 8) === 0 and ($z % 8) === 0 and $this->config["torches"] == "1"){
|
||||
$column[0] .= chr(50);
|
||||
}
|
||||
$column[0] .= str_repeat(chr(0), 128 - strlen($column[0]));
|
||||
$column[1] .= str_repeat(chr(0), 64 - strlen($column[1]));
|
||||
$column[2] .= str_repeat(chr(0), 64 - strlen($column[2]));
|
||||
$column[3] .= str_repeat(chr(0), 64 - strlen($column[3]));
|
||||
return $column;
|
||||
}
|
||||
|
||||
}
|
102
src/classes/UDPSocket.class.php
Normal file
102
src/classes/UDPSocket.class.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class UDPSocket{
|
||||
private $encrypt;
|
||||
var $buffer, $connected, $errors, $sock, $server;
|
||||
|
||||
function __construct($server, $port, $listen = false, $socket = false){
|
||||
$this->errors = array_fill(88,(125 - 88) + 1, true);
|
||||
$this->server = $server;
|
||||
$this->port = $port;
|
||||
if($socket !== false){
|
||||
$this->sock = $socket;
|
||||
$this->connected = true;
|
||||
$this->buffer = array();
|
||||
$this->unblock();
|
||||
}else{
|
||||
$this->sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
socket_set_option($this->sock, SOL_SOCKET, SO_BROADCAST, 1);
|
||||
if($listen !== true){
|
||||
$this->connected = true;
|
||||
$this->buffer = array();
|
||||
$this->unblock();
|
||||
}else{
|
||||
if(socket_bind($this->sock, "0.0.0.0", $port) === true){
|
||||
$this->unblock();
|
||||
}else{
|
||||
console("[ERROR] Couldn't bind to 0.0.0.0:".$port, true, true, 0);
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function listenSocket(){
|
||||
$sock = @socket_accept($this->sock);
|
||||
if($sock !== false){
|
||||
$sock = new Socket(false, false, false, $sock);
|
||||
$sock->unblock();
|
||||
return $sock;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function close($error = 125){
|
||||
$this->connected = false;
|
||||
if($error === false){
|
||||
console("[ERROR] [Socket] Socket closed, Error: End of Stream");
|
||||
}else{
|
||||
console("[ERROR] [Socket] Socket closed, Error $error: ".socket_strerror($error));
|
||||
}
|
||||
return @socket_close($this->sock);
|
||||
}
|
||||
|
||||
public function block(){
|
||||
socket_set_block($this->sock);
|
||||
}
|
||||
|
||||
public function unblock(){
|
||||
socket_set_nonblock($this->sock);
|
||||
}
|
||||
|
||||
public function read(){
|
||||
$source = false;
|
||||
$port = 1;
|
||||
$len = @socket_recvfrom($this->sock, $buf, 65536, 0, $source, $port);
|
||||
return array($buf, $source, $port, $len);
|
||||
}
|
||||
|
||||
public function write($data, $dest = false, $port = false){
|
||||
return @socket_sendto($this->sock, $data, strlen($data), 0, ($dest === false ? $this->server:$dest), ($port === false ? $this->port:$port));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
490
src/classes/Utils.class.php
Normal file
490
src/classes/Utils.class.php
Normal file
@@ -0,0 +1,490 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
if(!defined("HEX2BIN")){
|
||||
@define("HEX2BIN", false);
|
||||
}
|
||||
|
||||
|
||||
define("BIG_ENDIAN", 0x00);
|
||||
define("LITTLE_ENDIAN", 0x01);
|
||||
define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN));
|
||||
|
||||
abstract class Utils{
|
||||
|
||||
public static function getOS(){
|
||||
$uname = strtoupper(php_uname("s"));
|
||||
if(strpos($uname, "WIN") !== false){
|
||||
return "win";
|
||||
}else{
|
||||
return "linux";
|
||||
}
|
||||
}
|
||||
|
||||
public static function hexdump($bin){
|
||||
$output = "";
|
||||
$bin = str_split($bin, 16);
|
||||
foreach($bin as $counter => $line){
|
||||
$hex = chunk_split(chunk_split(str_pad(bin2hex($line), 32, " ", STR_PAD_RIGHT), 2, " "), 24, " ");
|
||||
$ascii = preg_replace('#([^\x20-\x7E])#', ".", $line);
|
||||
$output .= str_pad(dechex($counter << 4), 4, "0", STR_PAD_LEFT). " " . $hex . " " . $ascii . PHP_EOL;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function printable($str){
|
||||
return preg_replace('#([^\x20-\x7E])#', '.', $str);
|
||||
}
|
||||
|
||||
public static function readTriad($str){
|
||||
list(,$unpacked) = unpack("N", "\x00".$str);
|
||||
return (int) $unpacked;
|
||||
}
|
||||
|
||||
public static function writeTriad($value){
|
||||
return substr(pack("N", $value), 1);
|
||||
}
|
||||
|
||||
public static function writeMetadata($data){
|
||||
$m = "";
|
||||
foreach($data as $bottom => $d){
|
||||
$m .= chr(($d["type"] << 5) & (0xE0 | $bottom));
|
||||
switch($d["type"]){
|
||||
case 0:
|
||||
$m .= Utils::writeByte($data["value"]);
|
||||
break;
|
||||
case 1:
|
||||
$m .= Utils::writeLShort($data["value"]);
|
||||
break;
|
||||
case 2:
|
||||
$m .= Utils::writeLInt($data["value"]);
|
||||
break;
|
||||
case 3:
|
||||
$m .= Utils::writeLFloat($data["value"]);
|
||||
break;
|
||||
case 4:
|
||||
$m .= Utils::writeLShort(strlen($data["value"]));
|
||||
$m .= $data["value"];
|
||||
break;
|
||||
case 5:
|
||||
$m .= Utils::writeLShort($data["value"][0]);
|
||||
$m .= Utils::writeByte($data["value"][1]);
|
||||
$m .= Utils::writeLShort($data["value"][2]);
|
||||
break;
|
||||
case 6:
|
||||
for($i=0; $i < 3; ++$i){
|
||||
$m .= Utils::writeLInt($data["value"][$i]);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
$m .= "\x7f";
|
||||
return $m;
|
||||
}
|
||||
|
||||
public static function readMetadata($value, $types = false){
|
||||
$offset = 0;
|
||||
$m = array();
|
||||
$b = ord($value{$offset});
|
||||
++$offset;
|
||||
while($b !== 127){
|
||||
$bottom = $b & 0x1F;
|
||||
$type = $b >> 5;
|
||||
switch($type){
|
||||
case 0:
|
||||
$r = Utils::readByte($value{$offset});
|
||||
++$offset;
|
||||
break;
|
||||
case 1:
|
||||
$r = Utils::readLShort(substr($value, $offset, 2));
|
||||
$offset += 2;
|
||||
break;
|
||||
case 2:
|
||||
$r = Utils::readLInt(substr($value, $offset, 4));
|
||||
$offset += 4;
|
||||
break;
|
||||
case 3:
|
||||
$r = Utils::readLFloat(substr($value, $offset, 4));
|
||||
$offset += 4;
|
||||
break;
|
||||
case 4:
|
||||
$len = Utils::readLShort(substr($value, $offset, 2));
|
||||
$offset += 2;
|
||||
$r = substr($value, $offset, $len);
|
||||
$offset += $len;
|
||||
break;
|
||||
case 5:
|
||||
$r = array();
|
||||
$r[] = Utils::readLShort(substr($value, $offset, 2));
|
||||
$offset += 2;
|
||||
$r[] = Utils::readByte($value{$offset});
|
||||
++$offset;
|
||||
$r[] = Utils::readLShort(substr($value, $offset, 2));
|
||||
$offset += 2;
|
||||
break;
|
||||
case 6:
|
||||
$r = array();
|
||||
for($i=0; $i < 3; ++$i){
|
||||
$r[] = Utils::readLInt(substr($value, $offset, 4));
|
||||
$offset += 4;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
if($types === true){
|
||||
$m[$bottom] = array($r, $type);
|
||||
}else{
|
||||
$m[$bottom] = $r;
|
||||
}
|
||||
$b = ord($value{$offset});
|
||||
++$offset;
|
||||
}
|
||||
return $m;
|
||||
}
|
||||
|
||||
public static function readDataArray($str, $len = 10, &$offset = null){
|
||||
$data = array();
|
||||
$offset = 0;
|
||||
for($i = 1; $i <= $len; ++$i){
|
||||
$l = Utils::readTriad(substr($str, $offset, 3));
|
||||
$offset += 3;
|
||||
$data[] = substr($str, $offset, $l);
|
||||
$offset += $l;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function writeDataArray($data){
|
||||
$raw = "";
|
||||
foreach($data as $v){
|
||||
$raw .= Utils::writeTriad(strlen($v));
|
||||
$raw .= $v;
|
||||
}
|
||||
return $raw;
|
||||
}
|
||||
|
||||
public static function getRandomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0){
|
||||
$output = b"";
|
||||
$length = abs((int) $length);
|
||||
$secureValue = "";
|
||||
$rounds = 0;
|
||||
$drop = 0;
|
||||
while(!isset($output{$length - 1})){
|
||||
//some entropy, but works ^^
|
||||
$weakEntropy = array(
|
||||
is_array($startEntropy) ? implode($startEntropy):$startEntropy,
|
||||
serialize(stat(__FILE__)),
|
||||
__DIR__,
|
||||
PHP_OS,
|
||||
microtime(),
|
||||
(string) lcg_value(),
|
||||
serialize($_SERVER),
|
||||
serialize(get_defined_constants()),
|
||||
get_current_user(),
|
||||
serialize(ini_get_all()),
|
||||
(string) memory_get_usage(),
|
||||
php_uname(),
|
||||
phpversion(),
|
||||
extension_loaded("gmp") ? gmp_strval(gmp_random(4)):microtime(),
|
||||
zend_version(),
|
||||
(string) getmypid(),
|
||||
(string) mt_rand(),
|
||||
(string) rand(),
|
||||
function_exists("zend_thread_id") ? ((string) zend_thread_id()):microtime(),
|
||||
var_export(@get_browser(), true),
|
||||
function_exists("sys_getloadavg") ? implode(";", sys_getloadavg()):microtime(),
|
||||
serialize(get_loaded_extensions()),
|
||||
sys_get_temp_dir(),
|
||||
(string) disk_free_space("."),
|
||||
(string) disk_total_space("."),
|
||||
uniqid(microtime(),true),
|
||||
);
|
||||
|
||||
shuffle($weakEntropy);
|
||||
$value = hash("sha256", implode($weakEntropy), true);
|
||||
foreach($weakEntropy as $k => $c){ //mixing entropy values with XOR and hash randomness extractor
|
||||
$c = (string) $c;
|
||||
str_shuffle($c); //randomize characters
|
||||
$value ^= hash("md5", $c . microtime() . $k, true) . hash("md5", microtime() . $k . $c, true);
|
||||
$value ^= hash("sha256", $c . microtime() . $k, true);
|
||||
}
|
||||
unset($weakEntropy);
|
||||
|
||||
if($secure === true){
|
||||
$strongEntropy = array(
|
||||
is_array($startEntropy) ? $startEntropy[($rounds + $drop) % count($startEntropy)]:$startEntropy, //Get a random index of the startEntropy, or just read it
|
||||
file_exists("/dev/urandom") ? fread(fopen("/dev/urandom", "rb"), 512):"",
|
||||
(function_exists("openssl_random_pseudo_bytes") and version_compare(PHP_VERSION, "5.3.4", ">=")) ? openssl_random_pseudo_bytes(512):"",
|
||||
function_exists("mcrypt_create_iv") ? mcrypt_create_iv(512, MCRYPT_DEV_URANDOM) : "",
|
||||
$value,
|
||||
);
|
||||
shuffle($strongEntropy);
|
||||
$strongEntropy = implode($strongEntropy);
|
||||
$value = "";
|
||||
//Von Neumann randomness extractor, increases entropy
|
||||
$len = strlen($strongEntropy) * 8;
|
||||
for($i = 0; $i < $len; $i += 2){
|
||||
$a = ord($strongEntropy{$i >> 3});
|
||||
$b = 1 << ($i % 8);
|
||||
$c = 1 << (($i % 8) + 1);
|
||||
$b = ($a & $b) === $b ? "1":"0";
|
||||
$c = ($a & $c) === $c ? "1":"0";
|
||||
if($b !== $c){
|
||||
$secureValue .= $b;
|
||||
if(isset($secureValue{7})){
|
||||
$value .= chr(bindec($secureValue));
|
||||
$secureValue = "";
|
||||
}
|
||||
++$drop;
|
||||
}else{
|
||||
$drop += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
$output .= substr($value, 0, min($length - strlen($output), $length));
|
||||
unset($value);
|
||||
++$rounds;
|
||||
}
|
||||
return $raw === false ? bin2hex($output):$output;
|
||||
}
|
||||
|
||||
public static function round($number){
|
||||
return round($number, 0, PHP_ROUND_HALF_DOWN);
|
||||
}
|
||||
|
||||
public static function distance($pos1, $pos2){
|
||||
return sqrt(pow($pos1["x"] - $pos2["x"], 2) + pow($pos1["y"] - $pos2["y"], 2) + pow($pos1["z"] - $pos2["z"], 2));
|
||||
}
|
||||
|
||||
public static function angle3D($pos1, $pos2){
|
||||
$X = $pos1["x"] - $pos2["x"];
|
||||
$Z = $pos1["z"] - $pos2["z"];
|
||||
$dXZ = sqrt(pow($X, 2) + pow($Z, 2));
|
||||
$Y = $pos1["y"] - $pos2["y"];
|
||||
$hAngle = rad2deg(atan2($Z, $X) - M_PI_2);
|
||||
$vAngle = rad2deg(-atan2($Y, $dXZ));
|
||||
return array("yaw" => $hAngle, "pitch" => $vAngle);
|
||||
}
|
||||
|
||||
public static function sha1($input){
|
||||
$number = new Math_BigInteger(sha1($input, true), -256);
|
||||
$zero = new Math_BigInteger(0);
|
||||
return ($zero->compare($number) <= 0 ? "":"-") . ltrim($number->toHex(), "0");
|
||||
}
|
||||
|
||||
public static function microtime(){
|
||||
return microtime(true);
|
||||
}
|
||||
|
||||
public static function curl_get($page){
|
||||
$ch = curl_init($page);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Minecraft PHP Client 2"));
|
||||
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
$ret = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function curl_post($page, $args, $timeout = 10){
|
||||
$ch = curl_init($page);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
|
||||
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Minecraft PHP Client 2"));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout);
|
||||
$ret = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function strToHex($str){
|
||||
return bin2hex($str);
|
||||
}
|
||||
|
||||
public static function hexToStr($hex){
|
||||
if(HEX2BIN === true){
|
||||
return hex2bin($hex);
|
||||
}
|
||||
return pack("H*" , $hex);
|
||||
}
|
||||
|
||||
public static function readBool($b){
|
||||
return Utils::readByte($b, false) === 0 ? false:true;
|
||||
}
|
||||
|
||||
public static function writeBool($b){
|
||||
return Utils::writeByte($b === true ? 1:0);
|
||||
}
|
||||
|
||||
public static function readByte($c, $signed = true){
|
||||
$b = ord($c{0});
|
||||
if($signed === true and ($b & 0x80) === 0x80){ //calculate Two's complement
|
||||
$b = -0x80 + ($b & 0x7f);
|
||||
}
|
||||
return $b;
|
||||
}
|
||||
|
||||
public static function writeByte($c){
|
||||
if($c > 0xff){
|
||||
return false;
|
||||
}
|
||||
if($c < 0 and $c >= -0x80){
|
||||
$c = 0xff + $c + 1;
|
||||
}
|
||||
return chr($c);
|
||||
}
|
||||
|
||||
public static function readShort($str, $signed = true){
|
||||
list(,$unpacked) = unpack("n", $str);
|
||||
if($unpacked > 0x7fff and $signed === true){
|
||||
$unpacked -= 0x10000; // Convert unsigned short to signed short
|
||||
}
|
||||
return $unpacked;
|
||||
}
|
||||
|
||||
public static function writeShort($value){
|
||||
if($value < 0){
|
||||
$value += 0x10000;
|
||||
}
|
||||
return pack("n", $value);
|
||||
}
|
||||
|
||||
public static function readLShort($str, $signed = true){
|
||||
list(,$unpacked) = unpack("v", $str);
|
||||
if($unpacked > 0x7fff and $signed === true){
|
||||
$unpacked -= 0x10000; // Convert unsigned short to signed short
|
||||
}
|
||||
return $unpacked;
|
||||
}
|
||||
|
||||
public static function writeLShort($value){
|
||||
if($value < 0){
|
||||
$value += 0x10000;
|
||||
}
|
||||
return pack("v", $value);
|
||||
}
|
||||
|
||||
public static function readInt($str){
|
||||
list(,$unpacked) = unpack("N", $str);
|
||||
if($unpacked >= 2147483648){
|
||||
$unpacked -= 4294967296;
|
||||
}
|
||||
return (int) $unpacked;
|
||||
}
|
||||
|
||||
public static function writeInt($value){
|
||||
if($value < 0){
|
||||
$value += 0x100000000;
|
||||
}
|
||||
return pack("N", $value);
|
||||
}
|
||||
|
||||
public static function readLInt($str){
|
||||
list(,$unpacked) = unpack("V", $str);
|
||||
if($unpacked >= 2147483648){
|
||||
$unpacked -= 4294967296;
|
||||
}
|
||||
return (int) $unpacked;
|
||||
}
|
||||
|
||||
public static function writeLInt($value){
|
||||
if($value < 0){
|
||||
$value += 0x100000000;
|
||||
}
|
||||
return pack("V", $value);
|
||||
}
|
||||
|
||||
public static function readFloat($str){
|
||||
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", $str):unpack("f", strrev($str));
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function writeFloat($value){
|
||||
return ENDIANNESS === BIG_ENDIAN ? pack("f", $value):strrev(pack("f", $value));
|
||||
}
|
||||
|
||||
public static function readLFloat($str){
|
||||
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("f", strrev($str)):unpack("f", $str);
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function writeLFloat($value){
|
||||
return ENDIANNESS === BIG_ENDIAN ? strrev(pack("f", $value)):pack("f", $value);
|
||||
}
|
||||
|
||||
public static function printFloat($value){
|
||||
return preg_replace("/(\.\d+?)0+$/", "$1", sprintf("%F", $value));
|
||||
}
|
||||
|
||||
public static function readDouble($str){
|
||||
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", $str):unpack("d", strrev($str));
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function writeDouble($value){
|
||||
return ENDIANNESS === BIG_ENDIAN ? pack("d", $value):strrev(pack("d", $value));
|
||||
}
|
||||
|
||||
public static function readLDouble($str){
|
||||
list(,$value) = ENDIANNESS === BIG_ENDIAN ? unpack("d", strrev($str)):unpack("d", $str);
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function writeLDouble($value){
|
||||
return ENDIANNESS === BIG_ENDIAN ? strrev(pack("d", $value)):pack("d", $value);
|
||||
}
|
||||
|
||||
public static function readLong($str){
|
||||
$long = new Math_BigInteger($str, -256);
|
||||
return $long->toString();
|
||||
}
|
||||
|
||||
public static function writeLong($value){
|
||||
$long = new Math_BigInteger($value, -10);
|
||||
return str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public static function readLLong($str){
|
||||
$long = new Math_BigInteger(strrev($str), -256);
|
||||
return $long->toString();
|
||||
}
|
||||
|
||||
public static function writeLLong($value){
|
||||
$long = new Math_BigInteger($value, -10);
|
||||
return strrev(str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
}
|
43
src/common/config.php
Normal file
43
src/common/config.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
set_time_limit(0);
|
||||
date_default_timezone_set(@date_default_timezone_get());
|
||||
gc_enable();
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
ini_set("allow_url_fopen", 1);
|
||||
ini_set("display_errors", 1);
|
||||
ini_set('default_charset', 'utf-8');
|
||||
define("FILE_PATH", dirname(__FILE__)."/../../");
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH . PATH_SEPARATOR . FILE_PATH . "/src/" . PATH_SEPARATOR . FILE_PATH . "/src/classes/");
|
||||
ini_set("memory_limit", "256M");
|
||||
define("CURRENT_PROTOCOL", 5);
|
||||
define("CURRENT_VERSION", 1);
|
||||
define("LOG", true);
|
||||
define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78");
|
||||
define("TEST_MD5", "5ca8eced50a5801619f7ae86d631a4e7");
|
||||
define("MAJOR_VERSION", "Alpha_1.0.1");
|
20
src/common/default.properties
Normal file
20
src/common/default.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
#PocketMine-MP default server properties
|
||||
server-name=A Minecraft Server
|
||||
description=Server made using PocketMine-MP
|
||||
motd=Welcome @username to this server!
|
||||
invisible=false
|
||||
port=19132
|
||||
memory-limit=512M
|
||||
last-update=false
|
||||
update-channel=stable
|
||||
white-list=false
|
||||
debug=2
|
||||
max-players=20
|
||||
server-type=normal
|
||||
time-per-second=20
|
||||
gamemode=1
|
||||
difficulty=1
|
||||
generator=
|
||||
generator-settings=
|
||||
level-name=false
|
||||
server-id=false
|
95
src/common/dependencies.php
Normal file
95
src/common/dependencies.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
require_once(dirname(__FILE__)."/config.php");
|
||||
require_once("common/functions.php");
|
||||
//set_error_handler("error_handler");
|
||||
|
||||
$errors = 0;
|
||||
|
||||
if(version_compare("5.3.3", PHP_VERSION) > 0){
|
||||
console("[ERROR] Use PHP >= 5.3.3", true, true, 0);
|
||||
++$errors;
|
||||
}
|
||||
|
||||
if(version_compare("5.4.0", PHP_VERSION) > 0){
|
||||
console("[NOTICE] Use PHP >= 5.4.0 to increase performance", true, true, 0);
|
||||
define("HEX2BIN", false);
|
||||
}else{
|
||||
define("HEX2BIN", true);
|
||||
}
|
||||
|
||||
if(php_sapi_name() !== "cli"){
|
||||
console("[ERROR] Use PHP-CLI to execute the library or create your own", true, true, 0);
|
||||
++$errors;
|
||||
}
|
||||
|
||||
if(!extension_loaded("sockets")){
|
||||
console("[ERROR] Unable to find Socket extension", true, true, 0);
|
||||
++$errors;
|
||||
}
|
||||
|
||||
if(!extension_loaded("pthreads")){
|
||||
console("[ERROR] Unable to find pthreads extension. [https://github.com/krakjoe/pthreads]", true, true, 0);
|
||||
++$errors;
|
||||
}
|
||||
|
||||
if(!extension_loaded("curl")){
|
||||
console("[ERROR] Unable to find cURL extension", true, true, 0);
|
||||
++$errors;
|
||||
}
|
||||
|
||||
if(!extension_loaded("sqlite3")){
|
||||
console("[ERROR] Unable to find SQLite3 extension", true, true, 0);
|
||||
++$errors;
|
||||
}
|
||||
|
||||
if($errors > 0){
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
|
||||
require_once("classes/Data.class.php");
|
||||
require_once("classes/Player.class.php");
|
||||
require_once("classes/Generator.class.php");
|
||||
require_once("classes/SuperflatGenerator.class.php");
|
||||
require_once("classes/Utils.class.php");
|
||||
require_once("classes/UDPSocket.class.php");
|
||||
require_once("classes/Packet.class.php");
|
||||
require_once("classes/Entity.class.php");
|
||||
require_once("classes/ChunkParser.class.php");
|
||||
require_once("classes/NBT.class.php");
|
||||
require_once("classes/Java.class.php");
|
||||
require_once("classes/SerializedPacketHandler.class.php");
|
||||
require_once("classes/CustomPacketHandler.class.php");
|
||||
require_once("classes/MinecraftInterface.class.php");
|
||||
require_once("classes/BigInteger.class.php");
|
||||
require_all(FILE_PATH . "src/misc/");
|
||||
|
||||
?>
|
181
src/common/functions.php
Normal file
181
src/common/functions.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
function require_all($path, &$count = 0){
|
||||
$dir = dir($path."/");
|
||||
while(false !== ($file = $dir->read())){
|
||||
if($file !== "." and $file !== ".."){
|
||||
if(!is_dir($path.$file) and strtolower(substr($file, -3)) === "php"){
|
||||
require_once($path.$file);
|
||||
++$count;
|
||||
}elseif(is_dir($path.$file)){
|
||||
require_all($path.$file."/", $count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function hard_unset(&$var){
|
||||
if(is_object($var)){
|
||||
$unset = new ReflectionClass($var);
|
||||
foreach($unset->getProperties() as $prop){
|
||||
$prop->setAccessible(true);
|
||||
@hard_unset($prop->getValue($var));
|
||||
$prop->setValue($var, null);
|
||||
}
|
||||
$var = null;
|
||||
unset($var);
|
||||
}elseif(is_array($var)){
|
||||
foreach($var as $i => $v){
|
||||
hard_unset($var[$i]);
|
||||
}
|
||||
$var = null;
|
||||
unset($var);
|
||||
}else{
|
||||
$var = null;
|
||||
unset($var);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function parseNBTData($data){
|
||||
$x = array();
|
||||
if(isset($data["value"])){
|
||||
return parseNBTData($data["value"]);
|
||||
}
|
||||
foreach($data as $d){
|
||||
if(!isset($d["value"]) and is_array($d) and count($d) == 1){
|
||||
return parseNBTData(array_pop($d));
|
||||
}elseif(!isset($d["value"]) and is_array($d)){
|
||||
$x[] = parseNBTData($d);
|
||||
}elseif(is_array($d["value"]) and isset($d["name"])){
|
||||
$x[$d["name"]] = parseNBTData($d["value"]);
|
||||
}elseif(is_array($d["value"]) and $d["type"] == 10){
|
||||
return parseNBTData($d["value"]);
|
||||
}elseif($d["name"] != ""){
|
||||
$x[$d["name"]] = $d["value"];
|
||||
}
|
||||
}
|
||||
if(count($x) == 0){
|
||||
$x = $data;
|
||||
}
|
||||
return $x;
|
||||
}
|
||||
|
||||
|
||||
function arg($name, $default){
|
||||
global $arguments, $argv;
|
||||
if(!isset($arguments)){
|
||||
$arguments = arguments($argv);
|
||||
}
|
||||
|
||||
if(isset($arguments["commands"][$name])){
|
||||
return $arguments["commands"][$name];
|
||||
}else{
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
function arguments ( $args ){
|
||||
if(!is_array($args)){
|
||||
$args = array();
|
||||
}
|
||||
array_shift( $args );
|
||||
$args = join( $args, ' ' );
|
||||
|
||||
preg_match_all('/ (--\w+ (?:[= ] [^-]+ [^\s-] )? ) | (-\w+) | (\w+) /x', $args, $match );
|
||||
$args = array_shift( $match );
|
||||
|
||||
$ret = array(
|
||||
'input' => array(),
|
||||
'commands' => array(),
|
||||
'flags' => array()
|
||||
);
|
||||
|
||||
foreach ( $args as $arg ) {
|
||||
|
||||
// Is it a command? (prefixed with --)
|
||||
if ( substr( $arg, 0, 2 ) === '--' ) {
|
||||
|
||||
$value = preg_split( '/[= ]/', $arg, 2 );
|
||||
$com = substr( array_shift($value), 2 );
|
||||
$value = join($value);
|
||||
|
||||
$ret['commands'][$com] = !empty($value) ? $value : true;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
// Is it a flag? (prefixed with -)
|
||||
if ( substr( $arg, 0, 1 ) === '-' ) {
|
||||
$ret['flags'][] = substr( $arg, 1 );
|
||||
continue;
|
||||
}
|
||||
|
||||
$ret['input'][] = $arg;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function console($message, $EOL = true, $log = true, $level = 1){
|
||||
//global $path;
|
||||
if(!defined("DEBUG") or DEBUG >= $level){
|
||||
$message .= $EOL === true ? PHP_EOL:"";
|
||||
$message = date("H:i:s"). " ". $message;
|
||||
if($log === true and (!defined("LOG") or LOG === true)){
|
||||
logg($message, "console", false, $level);
|
||||
}
|
||||
echo $message;
|
||||
}
|
||||
}
|
||||
|
||||
function error_handler($errno, $errstr, $errfile, $errline){
|
||||
console("[ERROR] A level ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
|
||||
}
|
||||
|
||||
function logg($message, $name, $EOL = true, $level = 2, $close = false){
|
||||
global $fpointers;
|
||||
if((!defined("DEBUG") or DEBUG >= $level) and (!defined("LOG") or LOG === true)){
|
||||
$message .= $EOL === true ? PHP_EOL:"";
|
||||
if(!isset($fpointers)){
|
||||
$fpointers = array();
|
||||
}
|
||||
if(!isset($fpointers[$name])){
|
||||
$fpointers[$name] = fopen(FILE_PATH."/".$name.".log", "ab");
|
||||
}
|
||||
fwrite($fpointers[$name], $message);
|
||||
if($close === true){
|
||||
fclose($fpointers[$name]);
|
||||
unset($fpointers[$name]);
|
||||
}
|
||||
}
|
||||
}
|
38
src/misc/block/plant/Sapling.php
Normal file
38
src/misc/block/plant/Sapling.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class Sapling{
|
||||
const OAK = 0;
|
||||
const SPRUCE = 1;
|
||||
const BIRCH = 2;
|
||||
const BURN_TIME = 5;
|
||||
|
||||
public static function growTree(LevelAPI $level, $block, $type){
|
||||
$type = $type & 0x03;
|
||||
TreeObject::growTree($level, $block, $type);
|
||||
}
|
||||
}
|
60
src/misc/world/generator/object/tree/SmallTreeObject.php
Normal file
60
src/misc/world/generator/object/tree/SmallTreeObject.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
require_once("misc/world/generator/object/tree/TreeObject.php");
|
||||
|
||||
class SmallTreeObject extends TreeObject{
|
||||
private $totalHeight = 6;
|
||||
private $leavesHeight = 3;
|
||||
protected $radiusIncrease = 0;
|
||||
private $addLeavesVines = false;
|
||||
private $addLogVines = false;
|
||||
private $addCocoaPlants = false;
|
||||
|
||||
public function placeObject(LevelAPI $level, $x, $y, $z, $type){
|
||||
$level->setBlock($x, $y - 1, $z, 3, 0);
|
||||
$this->totalHeight += mt_rand(-1, 3);
|
||||
$this->leavesHeight += mt_rand(0, 1);
|
||||
for($yy = ($this->totalHeight - $this->leavesHeight); $yy < ($this->totalHeight + 1); ++$yy){
|
||||
$yRadius = ($yy - $this->totalHeight);
|
||||
$xzRadius = (int) (($this->radiusIncrease + 1) - $yRadius / 2);
|
||||
for($xx = -$xzRadius; $xx < ($xzRadius + 1); ++$xx){
|
||||
for($zz = -$xzRadius; $zz < ($xzRadius + 1); ++$zz){
|
||||
if((abs($xx) != $xzRadius or abs($zz) != $xzRadius) and $yRadius != 0){
|
||||
$level->setBlock($x + $xx, $y + $yy, $z + $zz, 18, $type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
|
||||
$level->setBlock($x, $y + $yy, $z, 17, $type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
40
src/misc/world/generator/object/tree/TreeObject.php
Normal file
40
src/misc/world/generator/object/tree/TreeObject.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class TreeObject{
|
||||
|
||||
public static function growTree(LevelAPI $level, $block, $type){
|
||||
switch($type){
|
||||
default:
|
||||
case Sapling::OAK:
|
||||
$tree = new SmallTreeObject();
|
||||
break;
|
||||
}
|
||||
$tree->placeObject($level, $block[2][0], $block[2][1], $block[2][2], $type);
|
||||
}
|
||||
}
|
41
src/pstruct/4.php
Normal file
41
src/pstruct/4.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
//Protocol Version: 4
|
||||
|
||||
|
||||
define("MC_KEEP_ALIVE", 0x00);
|
||||
define("MC_CLIENT_CONNECT", 0x09);
|
||||
define("MC_SERVER_HANDSHAKE", 0x10);
|
||||
define("MC_CLIENT_HANDSHAKE", 0x13);
|
||||
define("MC_CLIENT_DISCONNECT", 0x15);
|
||||
define("MC_LOGIN", 0x86);
|
||||
define("MC_LOGIN_STATUS", 0x87);
|
||||
define("MC_READY", 0x88);
|
||||
define("MC_CHAT", 0x89);
|
||||
define("MC_SET_TIME", 0x8a);
|
||||
define("MC_START_GAME", 0x8b);
|
79
src/pstruct/5.php
Normal file
79
src/pstruct/5.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
//Protocol Version: 5
|
||||
|
||||
|
||||
define("MC_KEEP_ALIVE", 0x00);
|
||||
|
||||
define("MC_CLIENT_CONNECT", 0x09);
|
||||
define("MC_SERVER_HANDSHAKE", 0x10);
|
||||
|
||||
define("MC_CLIENT_HANDSHAKE", 0x13);
|
||||
|
||||
define("MC_DISCONNECT", 0x15);
|
||||
|
||||
define("MC_LOGIN", 0x82);
|
||||
define("MC_LOGIN_STATUS", 0x83);
|
||||
define("MC_READY", 0x84);
|
||||
define("MC_CHAT", 0x85);
|
||||
define("MC_SET_TIME", 0x86);
|
||||
define("MC_START_GAME", 0x87);
|
||||
|
||||
define("MC_ADD_MOB", 0x88);
|
||||
define("MC_ADD_PLAYER", 0x89);
|
||||
|
||||
define("MC_ADD_ENTITY", 0x8c);
|
||||
define("MC_REMOVE_ENTITY", 0x8d);
|
||||
define("MC_ADD_ITEM_ENTITY", 0x8e);
|
||||
|
||||
define("MC_MOVE_ENTITY", 0x90);
|
||||
|
||||
define("MC_MOVE_ENTITY_POSROT", 0x93);
|
||||
define("MC_MOVE_PLAYER", 0x94);
|
||||
define("MC_PLACE_BLOCK", 0x95);
|
||||
define("MC_REMOVE_BLOCK", 0x96);
|
||||
define("MC_UPDATE_BLOCK", 0x97);
|
||||
|
||||
define("MC_REQUEST_CHUNK", 0x9d);
|
||||
define("MC_CHUNK_DATA", 0x9e);
|
||||
|
||||
define("MC_PLAYER_EQUIPMENT", 0x9f);
|
||||
|
||||
define("MC_INTERACT", 0xa0);
|
||||
define("MC_USE_ITEM", 0xa1);
|
||||
define("MC_PLAYER_ACTION", 0xa2);
|
||||
define("MC_SET_ENTITY_DATA", 0xa3);
|
||||
define("MC_SET_ENTITY_MOTION", 0xa4);
|
||||
define("MC_SET_HEALTH", 0xa5);
|
||||
define("MC_SET_SPAWN_POSITION", 0xa6);
|
||||
define("MC_ANIMATE", 0xa7);
|
||||
define("MC_RESPAWN", 0xa8);
|
||||
|
||||
define("MC_CLIENT_MESSAGE", 0xb1);
|
||||
define("MC_SIGN_UPDATE", 0xb2);
|
||||
define("MC_ADVENTURE_SETTINGS", 0xb3);
|
196
src/pstruct/RakNet.php
Normal file
196
src/pstruct/RakNet.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
$pstruct = array(
|
||||
0x02 => array(
|
||||
"long", //Ping ID
|
||||
"magic",
|
||||
),
|
||||
|
||||
0x05 => array(
|
||||
"magic",
|
||||
"byte", //Protocol Version
|
||||
"special1", //MTU Size Null Lenght
|
||||
),
|
||||
|
||||
0x06 => array(
|
||||
"magic",
|
||||
"long", //Server GUID
|
||||
"byte", //Server Security
|
||||
"short", //MTU Size
|
||||
),
|
||||
|
||||
0x07 => array(
|
||||
"magic",
|
||||
5, //Security Cookie (idk why it's sent here)
|
||||
"short", //Server UDP Port
|
||||
"short", //MTU Size
|
||||
"long", //Client GUID
|
||||
),
|
||||
|
||||
0x08 => array(
|
||||
"magic",
|
||||
"long", //Server GUID
|
||||
"short", //Client UDP Port
|
||||
"short", //MTU Size
|
||||
"byte", //Security
|
||||
),
|
||||
|
||||
0x1a => array(
|
||||
"byte", //Server Version
|
||||
"magic",
|
||||
"long", //Server GUID
|
||||
),
|
||||
|
||||
0x1c => array(
|
||||
"long", //Ping ID
|
||||
"long", //Server GUID
|
||||
"magic",
|
||||
"string", //Data
|
||||
),
|
||||
|
||||
0x1d => array(
|
||||
"long", //Ping ID
|
||||
"long", //Server GUID
|
||||
"magic",
|
||||
"string", //Data
|
||||
),
|
||||
|
||||
0x80 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
|
||||
0x81 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x82 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x83 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x84 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x85 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x86 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x87 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x88 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x89 => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x8a => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x8b => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x8c => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x8d => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x8e => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
0x8f => array(
|
||||
"itriad",
|
||||
"ubyte",
|
||||
"customData",
|
||||
),
|
||||
|
||||
|
||||
|
||||
0xa0 => array(
|
||||
"short",
|
||||
"bool",
|
||||
"itriad",
|
||||
"special1",
|
||||
),
|
||||
|
||||
0xc0 => array(
|
||||
"short",
|
||||
"bool",
|
||||
"itriad",
|
||||
"special1",
|
||||
),
|
||||
|
||||
);
|
80
src/pstruct/dataName.php
Normal file
80
src/pstruct/dataName.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
$dataName = array(
|
||||
MC_KEEP_ALIVE => "KeepAlive",
|
||||
|
||||
MC_CLIENT_CONNECT => "ClientConnect",
|
||||
MC_SERVER_HANDSHAKE => "ServerHandshake",
|
||||
|
||||
MC_CLIENT_HANDSHAKE => "ClientHandshake",
|
||||
|
||||
MC_DISCONNECT => "Disconnect",
|
||||
|
||||
0x18 => "Unknown",
|
||||
|
||||
MC_LOGIN => "Login",
|
||||
MC_LOGIN_STATUS => "LoginStatus",
|
||||
MC_READY => "Ready",
|
||||
MC_CHAT => "Chat",
|
||||
MC_SET_TIME => "SetTime",
|
||||
MC_START_GAME => "StartGame",
|
||||
|
||||
MC_ADD_MOB => "AddMob",
|
||||
MC_ADD_PLAYER => "AddPlayer",
|
||||
|
||||
MC_ADD_ENTITY => "AddEntity",
|
||||
MC_REMOVE_ENTITY => "RemoveEntity",
|
||||
MC_ADD_ITEM_ENTITY => "AddItemEntity",
|
||||
|
||||
MC_MOVE_ENTITY => "MoveEntity",
|
||||
|
||||
MC_MOVE_ENTITY_POSROT => "MoveEntity_PosRot",
|
||||
MC_MOVE_PLAYER => "MovePlayer",
|
||||
MC_PLACE_BLOCK => "PlaceBlock",
|
||||
MC_REMOVE_BLOCK => "RemoveBlock",
|
||||
MC_UPDATE_BLOCK => "UpdateBlock",
|
||||
|
||||
MC_REQUEST_CHUNK => "RequestChunk",
|
||||
MC_CHUNK_DATA => "ChunkData",
|
||||
|
||||
MC_PLAYER_EQUIPMENT => "PlayerEquipment",
|
||||
|
||||
MC_INTERACT => "Interact",
|
||||
MC_USE_ITEM => "UseItem",
|
||||
MC_PLAYER_ACTION => "PlayerAction",
|
||||
MC_SET_ENTITY_DATA => "SetEntityData",
|
||||
MC_SET_ENTITY_MOTION => "SetEntityMotion",
|
||||
MC_SET_HEALTH => "SetHealth",
|
||||
MC_SET_SPAWN_POSITION => "SetSpawnPosition",
|
||||
MC_ANIMATE => "Animate",
|
||||
MC_RESPAWN => "Respawn",
|
||||
|
||||
MC_CLIENT_MESSAGE => "ClientMessage",
|
||||
MC_SIGN_UPDATE => "SignUpdate",
|
||||
MC_ADVENTURE_SETTINGS => "AdventureSettings",
|
||||
);
|
43
src/pstruct/packetName.php
Normal file
43
src/pstruct/packetName.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
$packetName = array(
|
||||
0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", //RakNet
|
||||
0x05 => "ID_OPEN_CONNECTION_REQUEST_1", //RakNet
|
||||
0x06 => "ID_OPEN_CONNECTION_REPLY_1", //RakNet
|
||||
0x07 => "ID_OPEN_CONNECTION_REQUEST_2", //RakNet
|
||||
0x08 => "ID_OPEN_CONNECTION_REPLY_2", //RakNet
|
||||
0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet
|
||||
0x1c => "ID_UNCONNECTED_PONG", //RakNet
|
||||
0x1d => "ID_ADVERTISE_SYSTEM", //RakNet
|
||||
0x80 => "Custom Packet", //Minecraft Implementation
|
||||
0x84 => "Custom Packet", //Minecraft Implementation
|
||||
0x88 => "Custom Packet", //Minecraft Implementation
|
||||
0x8c => "Custom Packet", //Minecraft Implementation
|
||||
0xa0 => "NACK", //Minecraft Implementation
|
||||
0xc0 => "ACK", //Minecraft Implementation
|
||||
);
|
Reference in New Issue
Block a user