Merge remote-tracking branch 'origin/master' into Entities

This commit is contained in:
Shoghi Cervantes 2014-02-19 15:28:23 +01:00
commit b36d754e5b
39 changed files with 470 additions and 406 deletions

View File

@ -32,7 +32,7 @@ class BanAPI{
private $ops; private $ops;
/** @var Config */ /** @var Config */
private $bannedIPs; private $bannedIPs;
private $cmdWL = array();//Command WhiteList private $cmdWhitelist = array();//Command WhiteList
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
@ -104,7 +104,6 @@ class BanAPI{
} }
} }
return; return;
break;
case "console.command"://Checks if a command is allowed with the current user permissions. case "console.command"://Checks if a command is allowed with the current user permissions.
if(isset($this->cmdWhitelist[$data["cmd"]])){ if(isset($this->cmdWhitelist[$data["cmd"]])){
return; return;
@ -118,7 +117,6 @@ class BanAPI{
return; return;
} }
return false; return false;
break;
} }
} }
@ -152,7 +150,7 @@ class BanAPI{
$player = $this->server->api->player->get($user); $player = $this->server->api->player->get($user);
if(!($player instanceof Player)){ if(!($player instanceof Player)){
$this->ops->set($user); $this->ops->set($user);
$this->ops->save($user); $this->ops->save();
$output .= $user." is now op\n"; $output .= $user." is now op\n";
break; break;
} }

View File

@ -341,7 +341,7 @@ class BlockAPI{
} }
} }
if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - $player->getLag() / 1000) + $target->getBreakTime($item, $player) - 0.1) >= microtime(true)){ if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - $player->getLag() / 1000) + $target->getBreakTime($item, $player) - 0.2) >= microtime(true)){
if($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){ if($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){
return $this->cancelAction($target, $player, false); return $this->cancelAction($target, $player, false);
} }
@ -516,13 +516,9 @@ class BlockAPI{
public function nextRandomUpdate(Position $pos){ public function nextRandomUpdate(Position $pos){
if(!isset($this->scheduledUpdates[$pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".BLOCK_UPDATE_RANDOM])){ if(!isset($this->scheduledUpdates[$pos->x.".".$pos->y.".".$pos->z.".".$pos->level->getName().".".BLOCK_UPDATE_RANDOM])){
$X = (($pos->x >> 4) << 4);
$Y = (($pos->y >> 4) << 4);
$Z = (($pos->z >> 4) << 4);
$time = microtime(true); $time = microtime(true);
$i = 0;
$offset = 0; $offset = 0;
while(true){ do{
$t = $offset + Utils::getRandomUpdateTicks() * 0.05; $t = $offset + Utils::getRandomUpdateTicks() * 0.05;
$update = $this->server->query("SELECT COUNT(*) FROM blockUpdates WHERE level = '".$pos->level->getName()."' AND type = ".BLOCK_UPDATE_RANDOM." AND delay >= ".($time + $t - 1)." AND delay <= ".($time + $t + 1).";"); $update = $this->server->query("SELECT COUNT(*) FROM blockUpdates WHERE level = '".$pos->level->getName()."' AND type = ".BLOCK_UPDATE_RANDOM." AND delay >= ".($time + $t - 1)." AND delay <= ".($time + $t + 1).";");
if($update instanceof SQLite3Result){ if($update instanceof SQLite3Result){
@ -534,7 +530,7 @@ class BlockAPI{
break; break;
} }
$offset += mt_rand(25, 75); $offset += mt_rand(25, 75);
} }while(true);
$this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM); $this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM);
} }
} }

View File

@ -26,7 +26,6 @@ class ConsoleAPI{
$this->cmds = array(); $this->cmds = array();
$this->alias = array(); $this->alias = array();
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->last = microtime(true);
} }
public function init(){ public function init(){
@ -250,7 +249,7 @@ class ConsoleAPI{
if(($d1 = $this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false if(($d1 = $this->server->api->dhandle("console.command.".$cmd, array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false
or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){ or ($d2 = $this->server->api->dhandle("console.command", array("cmd" => $cmd, "parameters" => $params, "issuer" => $issuer, "alias" => $alias))) === false){
$output = "You don't have permissions to use this command.\n"; $output = "You don't have permissions to use this command.\n";
}elseif($d1 !== true and $d2 !== true){ }elseif($d1 !== true and (isset($d2) and $d2 !== true)){
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
$output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias); $output = @call_user_func($this->cmds[$cmd], $cmd, $params, $issuer, $alias);
}elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){ }elseif($this->server->api->dhandle("console.command.unknown", array("cmd" => $cmd, "params" => $params, "issuer" => $issuer, "alias" => $alias)) !== false){
@ -326,7 +325,7 @@ class ConsoleLoop extends Thread{
} }
if(!extension_loaded("readline")){ if(!extension_loaded("readline")){
@fclose($fp); @fclose($this->fp);
} }
exit(0); exit(0);
} }

View File

@ -198,7 +198,6 @@ class LevelAPI{
$t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile); $t = $this->server->api->tile->add($this->levels[$name], $tile["id"], $tile["x"], $tile["y"], $tile["z"], $tile);
} }
$timeu = microtime(true);
foreach($blockUpdates->getAll() as $bupdate){ foreach($blockUpdates->getAll() as $bupdate){
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]); $this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"],(int) $bupdate["y"],(int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
} }

View File

@ -111,7 +111,6 @@ class PlayerAPI{
} }
$this->server->api->chat->broadcast($data["player"]->username . $message); $this->server->api->chat->broadcast($data["player"]->username . $message);
return true; return true;
break;
} }
} }
@ -196,9 +195,6 @@ class PlayerAPI{
"spectator" => VIEW, "spectator" => VIEW,
"v" => VIEW, "v" => VIEW,
); );
if($issuer instanceof Player){
$player = $issuer;
}
if(isset($params[1])){ if(isset($params[1])){
if($this->server->api->player->get($params[1]) instanceof Player){ if($this->server->api->player->get($params[1]) instanceof Player){
$player = $this->server->api->player->get($params[1]); $player = $this->server->api->player->get($params[1]);
@ -210,7 +206,15 @@ class PlayerAPI{
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n"; $output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
break; break;
} }
}elseif(isset($params[0])){
if(!($this->server->api->player->get($params[0]) instanceof Player)){
if($issuer instanceof Player){
$setgm = $params[0];
$player = $issuer;
} }
}
}
if(!($player instanceof Player) or !isset($gms[strtolower($setgm)])){ if(!($player instanceof Player) or !isset($gms[strtolower($setgm)])){
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n"; $output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
break; break;

View File

@ -196,19 +196,6 @@ class PluginAPI extends stdClass{
return $path; 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){ public function readYAML($file){
return yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file))); return yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file)));
} }

View File

@ -43,8 +43,16 @@ class EntityOLD extends Position{
public $attach; public $attach;
public $closed; public $closed;
public $player; public $player;
public $status;
public $fallY; public $fallY;
public $health;
public $fire;
public $crouched;
public $invincible;
public $fallStart; public $fallStart;
public $stack;
public $meta;
private $position;
private $tickCounter; private $tickCounter;
private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0); private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0);
private $server; private $server;
@ -164,7 +172,7 @@ class EntityOLD extends Position{
} }
public function getDrops(){ public function getDrops(){
if($this->class === ENTITY_PLAYER and ($this->player->gamemode & 0x01) === 0){ if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){
$inv = array(); $inv = array();
for($i = 0; $i < PLAYER_SURVIVAL_SLOTS; ++$i){ for($i = 0; $i < PLAYER_SURVIVAL_SLOTS; ++$i){
$slot = $this->player->getSlot($i); $slot = $this->player->getSlot($i);
@ -526,8 +534,8 @@ class EntityOLD extends Position{
} }
}elseif($this->fallY !== false){ //Fall damage! }elseif($this->fallY !== false){ //Fall damage!
if($y < $this->fallY){ if($y < $this->fallY){
$d = $this->level->getBlock(new Vector3($x, $y + 1, $z)); $d = $this->level->getBlock(new Vector3($this->x, $y + 1, $this->z));
$d2 = $this->level->getBlock(new Vector3($x, $y + 2, $z)); $d2 = $this->level->getBlock(new Vector3($this->x, $y + 2, $this->z));
$dmg = ($this->fallY - $y) - 3; $dmg = ($this->fallY - $y) - 3;
if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER and $d->getID() !== COBWEB and !($d2 instanceof LiquidBlock) and $d2->getID() !== LADDER and $d2->getID() !== COBWEB){ if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER and $d->getID() !== COBWEB and !($d2 instanceof LiquidBlock) and $d2->getID() !== LADDER and $d2->getID() !== COBWEB){
$this->harm($dmg, "fall"); $this->harm($dmg, "fall");
@ -562,10 +570,10 @@ class EntityOLD extends Position{
if($this->isStatic === false and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){ if($this->isStatic === false and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){
if($this->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){ if($this->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){
if($this->server->api->handle("entity.move", $this) === false){ if($this->server->api->handle("entity.move", $this) === false){
if($this->class === ENTITY_PLAYER){ if($this->class === ENTITY_PLAYER and $this->player instanceof Player){
$this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]); $this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]);
}else{ }else{
$this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]); $this->setPosition(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]);
} }
}else{ }else{
$this->updateLast(); $this->updateLast();
@ -593,7 +601,7 @@ class EntityOLD extends Position{
} }
} }
}else{ }else{
$this->updatePosition($this->x, $this->y, $this->z, $this->yaw, $this->pitch); $this->updatePosition();
} }
} }
$this->lastUpdate = $now; $this->lastUpdate = $now;
@ -658,7 +666,7 @@ class EntityOLD extends Position{
} }
switch($this->class){ switch($this->class){
case ENTITY_PLAYER: case ENTITY_PLAYER:
if($this->player->connected !== true or $this->player->spawned === false){ if(!($this->player instanceof Player) or $this->player->connected !== true or $this->player->spawned === false){
return false; return false;
} }

View File

@ -63,6 +63,7 @@ class Player{
public $blocked = true; public $blocked = true;
public $achievements = array(); public $achievements = array();
public $chunksLoaded = array(); public $chunksLoaded = array();
private $viewDistance;
private $chunksOrder = array(); private $chunksOrder = array();
private $lastMeasure = 0; private $lastMeasure = 0;
private $bandwidthRaw = 0; private $bandwidthRaw = 0;
@ -112,6 +113,7 @@ class Player{
$this->armor = array(); $this->armor = array();
$this->gamemode = $this->server->gamemode; $this->gamemode = $this->server->gamemode;
$this->level = $this->server->api->level->getDefault(); $this->level = $this->server->api->level->getDefault();
$this->viewDistance = (int) $this->server->api->getProperty("view-distance");
$this->slot = 0; $this->slot = 0;
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1); $this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
$this->packetStats = array(0,0); $this->packetStats = array(0,0);
@ -148,22 +150,35 @@ class Player{
if(!($this->entity instanceof Entity) or $this->connected === false){ if(!($this->entity instanceof Entity) or $this->connected === false){
return false; return false;
} }
$X = ($this->entity->x - 0.5) / 16;
$Z = ($this->entity->z - 0.5) / 16; $newOrder = array();
$v = new Vector2($X, $Z); $lastLoaded = $this->chunksLoaded;
$this->chunksOrder = array(); $centerX = intval(($this->entity->x - 0.5) / 16);
for($x = 0; $x < 16; ++$x){ $centerZ = intval(($this->entity->z - 0.5) / 16);
for($z = 0; $z < 16; ++$z){ $startX = $centerX - $this->viewDistance;
$dist = $v->distance(new Vector2($x, $z)); $startZ = $centerZ - $this->viewDistance;
for($y = 0; $y < 8; ++$y){ $finalX = $centerX + $this->viewDistance;
$d = $x.":".$y.":".$z; $finalZ = $centerZ + $this->viewDistance;
if(!isset($this->chunksLoaded[$d])){ for($X = $startX; $X <= $finalX; ++$X){
$this->chunksOrder[$d] = $dist; for($Z = $startZ; $Z <= $finalZ; ++$Z){
$distance = abs($X - $centerX) + abs($Z - $centerZ);
for($Y = 0; $Y < 8; ++$Y){
$index = "$X:$Y:$Z";
if(!isset($lastLoaded[$index])){
$newOrder[$index] = $distance;
}else{
unset($lastLoaded[$index]);
} }
} }
} }
} }
asort($this->chunksOrder); asort($newOrder);
$this->chunksOrder = $newOrder;
foreach($lastLoaded as $index => $distance){
$id = explode(":", $index);
$this->level->freeChunk($id[0], $id[2], $this);
unset($this->chunksLoaded[$index]);
}
} }
public function getNextChunk(){ public function getNextChunk(){
@ -195,8 +210,8 @@ class Player{
$c = key($this->chunksOrder); $c = key($this->chunksOrder);
$d = @$this->chunksOrder[$c]; $d = @$this->chunksOrder[$c];
if($c === null or $d > $this->server->api->getProperty("view-distance")){ if($c === null or $d === null){
$this->server->schedule(50, array($this, "getNextChunk")); $this->server->schedule(40, array($this, "getNextChunk"));
return false; return false;
} }
unset($this->chunksOrder[$c]); unset($this->chunksOrder[$c]);
@ -207,7 +222,6 @@ class Player{
$Y = $id[1]; $Y = $id[1];
$x = $X << 4; $x = $X << 4;
$z = $Z << 4; $z = $Z << 4;
$y = $Y << 4;
$this->level->useChunk($X, $Z, $this); $this->level->useChunk($X, $Z, $this);
$Yndex = 1 << $Y; $Yndex = 1 << $Y;
for($iY = 0; $iY < 8; ++$iY){ for($iY = 0; $iY < 8; ++$iY){
@ -313,7 +327,7 @@ class Player{
$this->chunksLoaded = array(); $this->chunksLoaded = array();
$this->chunksOrder = array(); $this->chunksOrder = array();
$this->chunkCount = array(); $this->chunkCount = array();
$this->cratingItems = array(); $this->craftingItems = array();
$this->received = array(); $this->received = array();
} }
} }
@ -683,11 +697,10 @@ class Player{
return; return;
}else{ }else{
$message = $data->get(); $message = $data->get();
$this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", $message["message"]), $message["player"]); //Remove ANSI codes from chat $this->sendChat($message["message"], $message["player"]);
} }
}else{ }else{
$message = (string) $data; $this->sendChat((string) $data);
$this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", (string) $data)); //Remove ANSI codes from chat
} }
break; break;
} }
@ -1311,7 +1324,7 @@ class Player{
$this->close("Incorrect protocol #".$packet->protocol1, false); $this->close("Incorrect protocol #".$packet->protocol1, false);
return; return;
} }
if(preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console"){ if(preg_match('#^[a-zA-Z0-9_]{3,16}$#', $this->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console"){
$this->close("Bad username", false); $this->close("Bad username", false);
return; return;
} }
@ -1362,9 +1375,9 @@ class Player{
$inv[] = array($item[0], $item[1], 1); $inv[] = array($item[0], $item[1], 1);
} }
} }
}
$this->data->set("inventory", $inv); $this->data->set("inventory", $inv);
} }
}
$this->achievements = $this->data->get("achievements"); $this->achievements = $this->data->get("achievements");
$this->data->set("caseusername", $this->username); $this->data->set("caseusername", $this->username);
$this->inventory = array(); $this->inventory = array();
@ -1468,7 +1481,7 @@ class Player{
} }
$this->sendInventory(); $this->sendInventory();
$this->sendSettings(); $this->sendSettings();
$this->server->schedule(50, array($this, "orderChunks"), array(), true); $this->server->schedule(30, array($this, "orderChunks"), array(), true);
$this->blocked = false; $this->blocked = false;
$pk = new SetTimePacket; $pk = new SetTimePacket;
@ -1645,7 +1658,7 @@ class Player{
$this->entity->updateMetadata(); $this->entity->updateMetadata();
} }
if($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 10)){ if($this->blocked === true or ($this->entity instanceof Entity and $blockVector->distance($this->entity) > 10)){
}elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){ }elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){
$this->sendInventorySlot($this->slot); $this->sendInventorySlot($this->slot);
@ -1992,6 +2005,7 @@ class Player{
$packet->item = $this->getSlot($this->slot); $packet->item = $this->getSlot($this->slot);
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = array(); $this->toCraft = array();
$data = array();
$data["eid"] = $packet->eid; $data["eid"] = $packet->eid;
$data["unknown"] = $packet->unknown; $data["unknown"] = $packet->unknown;
$data["item"] = $packet->item; $data["item"] = $packet->item;
@ -2155,6 +2169,7 @@ class Player{
if($item->getID() !== AIR and $slot->getID() == $item->getID()){ if($item->getID() !== AIR and $slot->getID() == $item->getID()){
if($slot->count < $item->count){ if($slot->count < $item->count){
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){
$this->sendInventory();
break; break;
} }
}elseif($slot->count > $item->count){ }elseif($slot->count > $item->count){
@ -2162,6 +2177,7 @@ class Player{
} }
}else{ }else{
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){
$this->sendInventory();
break; break;
} }
$this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false);
@ -2201,6 +2217,7 @@ class Player{
if($item->getID() !== AIR and $slot->getID() == $item->getID()){ if($item->getID() !== AIR and $slot->getID() == $item->getID()){
if($slot->count < $item->count){ if($slot->count < $item->count){
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){
$this->sendInventory();
break; break;
} }
}elseif($slot->count > $item->count){ }elseif($slot->count > $item->count){
@ -2208,6 +2225,7 @@ class Player{
} }
}else{ }else{
if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){
$this->sendInventory();
break; break;
} }
$this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false);
@ -2307,6 +2325,7 @@ class Player{
} }
public function sendBuffer(){ public function sendBuffer(){
if($this->connected === true){
if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket){ if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket){
$this->buffer->seqNumber = $this->counter[0]++; $this->buffer->seqNumber = $this->counter[0]++;
$this->send($this->buffer); $this->send($this->buffer);
@ -2316,6 +2335,7 @@ class Player{
$this->buffer->data = array(); $this->buffer->data = array();
$this->nextBuffer = microtime(true) + 0.1; $this->nextBuffer = microtime(true) + 0.1;
} }
}
private function directBigRawPacket(RakNetDataPacket $packet){ private function directBigRawPacket(RakNetDataPacket $packet){
if($this->connected === false){ if($this->connected === false){
@ -2353,7 +2373,7 @@ class Player{
return $cnts; return $cnts;
} }
public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $recover = true){ public function directDataPacket(RakNetDataPacket $packet, $recover = true){
if($this->connected === false){ if($this->connected === false){
return false; return false;
} }
@ -2361,7 +2381,6 @@ class Player{
if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){
return array(); return array();
} }
$packet->encode(); $packet->encode();
$pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0);
$pk->data[] = $packet; $pk->data[] = $packet;
@ -2403,7 +2422,7 @@ class Player{
$packet->messageIndex = $this->counter[3]++; $packet->messageIndex = $this->counter[3]++;
$packet->reliability = 2; $packet->reliability = 2;
$this->buffer->data[] = $packet; @$this->buffer->data[] = $packet;
$this->bufferLen += 6 + $len; $this->bufferLen += 6 + $len;
return array(); return array();
} }

View File

@ -21,8 +21,8 @@
class PocketMinecraftServer{ class PocketMinecraftServer{
public $tCnt; public $tCnt;
public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $spawn, $whitelist, $seed, $stop, $gamemode, $difficulty, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = array(), $asyncID = 0; private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $doTick, $ticks, $memoryStats, $schedule, $asyncThread, $async = array(), $asyncID = 0;
/** /**
* @var ServerAPI * @var ServerAPI
@ -45,10 +45,7 @@ class PocketMinecraftServer{
$this->eventsID = array(); $this->eventsID = array();
$this->handlers = array(); $this->handlers = array();
$this->invisible = false; $this->invisible = false;
$this->levelData = false;
$this->difficulty = 1; $this->difficulty = 1;
$this->tiles = array();
$this->entities = array();
$this->custom = array(); $this->custom = array();
$this->evCnt = 1; $this->evCnt = 1;
$this->handCnt = 1; $this->handCnt = 1;
@ -57,11 +54,11 @@ class PocketMinecraftServer{
$this->schedule = array(); $this->schedule = array();
$this->scheduleCnt = 1; $this->scheduleCnt = 1;
$this->description = ""; $this->description = "";
$this->whitelist = false;
$this->memoryStats = array(); $this->memoryStats = array();
$this->clients = array(); $this->clients = array();
$this->spawn = false; $this->spawn = false;
$this->saveEnabled = true; $this->saveEnabled = true;
$this->whitelist = false;
$this->tickMeasure = array_fill(0, 40, 0); $this->tickMeasure = array_fill(0, 40, 0);
$this->setType("normal"); $this->setType("normal");
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip); $this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip);
@ -129,7 +126,7 @@ class PocketMinecraftServer{
public function startDatabase(){ public function startDatabase(){
$this->preparedSQL = new stdClass(); $this->preparedSQL = new stdClass();
$this->preparedSQL->entity = new stdClass(); $this->preparedSQL->entity = new stdClass();
$this->database = new SQLite3(":memory:"); $this->database = new SQLite3(":memory:", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
$this->query("PRAGMA journal_mode = OFF;"); $this->query("PRAGMA journal_mode = OFF;");
$this->query("PRAGMA encoding = \"UTF-8\";"); $this->query("PRAGMA encoding = \"UTF-8\";");
$this->query("PRAGMA secure_delete = OFF;"); $this->query("PRAGMA secure_delete = OFF;");
@ -316,7 +313,6 @@ class PocketMinecraftServer{
$handlers->finalize(); $handlers->finalize();
foreach($call as $hnid => $boolean){ foreach($call as $hnid => $boolean){
if($result !== false and $result !== true){ if($result !== false and $result !== true){
$called[$hnid] = true;
$handler = $this->handlers[$hnid]; $handler = $this->handlers[$hnid];
if(is_array($handler)){ if(is_array($handler)){
$method = $handler[1]; $method = $handler[1];

View File

@ -1,17 +1,16 @@
#!/bin/bash #!/bin/bash
COMPILER_VERSION="0.16"
PHP_VERSION="5.5.9" PHP_VERSION="5.5.9"
ZEND_VM="GOTO" ZEND_VM="GOTO"
LIBEDIT_VERSION="0.3"
ZLIB_VERSION="1.2.8" ZLIB_VERSION="1.2.8"
OPENSSL_VERSION="0.9.8y"
CURL_VERSION="curl-7_35_0"
LIBEDIT_VERSION="0.3"
PTHREADS_VERSION="0.1.0" PTHREADS_VERSION="0.1.0"
PHPYAML_VERSION="1.1.1" PHPYAML_VERSION="1.1.1"
YAML_VERSION="0.1.4" YAML_VERSION="0.1.4"
CURL_VERSION="curl-7_35_0"
echo "[PocketMine] PHP installer and compiler for Linux & Mac" echo "[PocketMine] PHP compiler for Linux, MacOS and Android"
DIR="$(pwd)" DIR="$(pwd)"
date > "$DIR/install.log" 2>&1 date > "$DIR/install.log" 2>&1
uname -a >> "$DIR/install.log" 2>&1 uname -a >> "$DIR/install.log" 2>&1
@ -46,16 +45,29 @@ if [ "$1" == "rpi" ]; then
[ -z "$march" ] && march=armv6zk; [ -z "$march" ] && march=armv6zk;
[ -z "$mtune" ] && mtune=arm1176jzf-s; [ -z "$mtune" ] && mtune=arm1176jzf-s;
[ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp";
OPENSSL_TARGET="linux-armv4"
echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float" echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float"
elif [ "$1" == "mac" ]; then elif [ "$1" == "mac" ]; then
[ -z "$march" ] && march=prescott; [ -z "$march" ] && march=prescott;
[ -z "$mtune" ] && mtune=generic; [ -z "$mtune" ] && mtune=generic;
[ -z "$CFLAGS" ] && CFLAGS="-fomit-frame-pointer"; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer -mmacosx-version-min=10.5";
echo "[INFO] Compiling for Intel MacOS" [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib";
export DYLD_LIBRARY_PATH="@loader_path/../lib"
OPENSSL_TARGET="darwin-i386-cc"
echo "[INFO] Compiling for Intel MacOS x86"
elif [ "$1" == "mac64" ]; then
[ -z "$march" ] && march=core2;
[ -z "$mtune" ] && mtune=generic;
[ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer -mmacosx-version-min=10.5";
[ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib";
export DYLD_LIBRARY_PATH="@loader_path/../lib"
OPENSSL_TARGET="darwin64-x86_64-cc"
echo "[INFO] Compiling for Intel MacOS x86_64"
elif [ "$1" == "ios" ]; then elif [ "$1" == "ios" ]; then
[ -z "$march" ] && march=armv6; [ -z "$march" ] && march=armv6;
[ -z "$mtune" ] && mtune=cortex-a8; [ -z "$mtune" ] && mtune=cortex-a8;
echo "[INFO] Compiling for iOS ARMv6" echo "[INFO] Compiling for iOS ARMv6"
OPENSSL_TARGET="linux-armv4"
elif [ "$1" == "crosscompile" ]; then elif [ "$1" == "crosscompile" ]; then
HAVE_MYSQLI="--without-mysqli" HAVE_MYSQLI="--without-mysqli"
if [ "$2" == "android" ] || [ "$2" == "android-armv6" ]; then if [ "$2" == "android" ] || [ "$2" == "android-armv6" ]; then
@ -65,9 +77,9 @@ elif [ "$1" == "crosscompile" ]; then
TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi"
export CC="$TOOLCHAIN_PREFIX-gcc" export CC="$TOOLCHAIN_PREFIX-gcc"
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6"
CFLAGS="-uclibc --static $CFLAGS"; CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS"
LDFLAGS="--static"
echo "[INFO] Cross-compiling for Android ARMv6" echo "[INFO] Cross-compiling for Android ARMv6"
OPENSSL_TARGET="android"
elif [ "$2" == "android-armv7" ]; then elif [ "$2" == "android-armv7" ]; then
COMPILE_FOR_ANDROID=yes COMPILE_FOR_ANDROID=yes
[ -z "$march" ] && march=armv7-a; [ -z "$march" ] && march=armv7-a;
@ -75,9 +87,9 @@ elif [ "$1" == "crosscompile" ]; then
TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi"
export CC="$TOOLCHAIN_PREFIX-gcc" export CC="$TOOLCHAIN_PREFIX-gcc"
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6"
CFLAGS="-uclibc --static $CFLAGS"; CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS"
LDFLAGS="--static"
echo "[INFO] Cross-compiling for Android ARMv7" echo "[INFO] Cross-compiling for Android ARMv7"
OPENSSL_TARGET="android-armv7"
elif [ "$2" == "rpi" ]; then elif [ "$2" == "rpi" ]; then
TOOLCHAIN_PREFIX="arm-linux-gnueabihf" TOOLCHAIN_PREFIX="arm-linux-gnueabihf"
[ -z "$march" ] && march=armv6zk; [ -z "$march" ] && march=armv6zk;
@ -86,6 +98,7 @@ elif [ "$1" == "crosscompile" ]; then
export CC="$TOOLCHAIN_PREFIX-gcc" export CC="$TOOLCHAIN_PREFIX-gcc"
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX"
[ -z "$CFLAGS" ] && CFLAGS="-uclibc"; [ -z "$CFLAGS" ] && CFLAGS="-uclibc";
OPENSSL_TARGET="linux-armv4"
echo "[INFO] Cross-compiling for Raspberry Pi ARMv6zk hard float" echo "[INFO] Cross-compiling for Raspberry Pi ARMv6zk hard float"
elif [ "$2" == "mac" ]; then elif [ "$2" == "mac" ]; then
[ -z "$march" ] && march=prescott; [ -z "$march" ] && march=prescott;
@ -96,33 +109,39 @@ elif [ "$1" == "crosscompile" ]; then
CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX"
#zlib doesn't use the correct ranlib #zlib doesn't use the correct ranlib
RANLIB=$TOOLCHAIN_PREFIX-ranlib RANLIB=$TOOLCHAIN_PREFIX-ranlib
OPENSSL_TARGET="darwin64-x86_64-cc"
echo "[INFO] Cross-compiling for Intel MacOS" echo "[INFO] Cross-compiling for Intel MacOS"
elif [ "$2" == "ios" ] || [ "$2" == "ios-armv6" ]; then elif [ "$2" == "ios" ] || [ "$2" == "ios-armv6" ]; then
[ -z "$march" ] && march=armv6; [ -z "$march" ] && march=armv6;
[ -z "$mtune" ] && mtune=generic-armv6; [ -z "$mtune" ] && mtune=generic-armv6;
CONFIGURE_FLAGS="--target=arm-apple-darwin10" CONFIGURE_FLAGS="--target=arm-apple-darwin10"
OPENSSL_TARGET="linux-armv4"
elif [ "$2" == "ios-armv7" ]; then elif [ "$2" == "ios-armv7" ]; then
[ -z "$march" ] && march=armv7-a; [ -z "$march" ] && march=armv7-a;
[ -z "$mtune" ] && mtune=generic-armv7-a; [ -z "$mtune" ] && mtune=generic-armv7-a;
CONFIGURE_FLAGS="--target=arm-apple-darwin10" CONFIGURE_FLAGS="--target=arm-apple-darwin10"
OPENSSL_TARGET="linux-armv4"
else else
echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile" echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile"
exit 1 exit 1
fi fi
elif [ -z "$CFLAGS" ]; then elif [ -z "$CFLAGS" ]; then
if [ `getconf LONG_BIT` = "64" ]; then if [ `getconf LONG_BIT` == "64" ]; then
echo "[INFO] Compiling for current machine using 64-bit" echo "[INFO] Compiling for current machine using 64-bit"
CFLAGS="-m64 $CFLAGS" CFLAGS="-m64 $CFLAGS"
OPENSSL_TARGET="linux-x86_64"
else else
echo "[INFO] Compiling for current machine using 32-bit" echo "[INFO] Compiling for current machine using 32-bit"
CFLAGS="-m32 $CFLAGS" CFLAGS="-m32 $CFLAGS"
OPENSSL_TARGET="linux-generic32"
fi fi
fi fi
cat > test.c <<'CTEST' cat > test.c <<'CTEST'
#include <stdio.h> #include <stdio.h>
main(){ int main(void){
printf("Hello world\n"); printf("Hello world\n");
return 0;
} }
CTEST CTEST
@ -133,7 +152,7 @@ type $CC >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"$CC\
[ -z "$march" ] && march=native; [ -z "$march" ] && march=native;
[ -z "$mtune" ] && mtune=native; [ -z "$mtune" ] && mtune=native;
[ -z "$CFLAGS" ] && CFLAGS=""; [ -z "$CFLAGS" ] && CFLAGS="";
[ -z "$LDFLAGS" ] && LDFLAGS=""; [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib'";
[ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS=""; [ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS="";
@ -149,16 +168,17 @@ else
fi fi
fi fi
rm test.* >> "$DIR/install.log" 2>&1
rm test >> "$DIR/install.log" 2>&1 rm test >> "$DIR/install.log" 2>&1
rm test.c >> "$DIR/install.log" 2>&1
export CFLAGS="-O2 $CFLAGS" export CFLAGS="-O2 $CFLAGS"
export LDFLAGS="$LDFLAGS" export LDFLAGS="$LDFLAGS"
rm -r -f install_data/ >> "$DIR/install.log" 2>&1 rm -r -f install_data/ >> "$DIR/install.log" 2>&1
rm -r -f bin/ >> "$DIR/install.log" 2>&1 rm -r -f bin/ >> "$DIR/install.log" 2>&1
mkdir -m 0777 install_data >> "$DIR/install.log" 2>&1 mkdir -m 0755 install_data >> "$DIR/install.log" 2>&1
mkdir -m 0777 bin >> "$DIR/install.log" 2>&1 mkdir -m 0755 bin >> "$DIR/install.log" 2>&1
mkdir -m 0755 bin/php5 >> "$DIR/install.log" 2>&1
cd install_data cd install_data
set -e set -e
@ -168,38 +188,43 @@ download_file "http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror" | ta
mv php-$PHP_VERSION php mv php-$PHP_VERSION php
echo " done!" echo " done!"
if [ 1 ] || [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ]; then if [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ] || [ "$1" == "mac" ]; then
HAVE_LIBEDIT="--without-libedit" HAVE_LIBEDIT="--without-readline --without-libedit"
else else
#libedit #libedit
set +e
echo -n "[libedit] downloading $LIBEDIT_VERSION..." echo -n "[libedit] downloading $LIBEDIT_VERSION..."
download_file "http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 download_file "http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1
echo -n " checking..." echo -n " checking..."
cd libedit cd libedit
./configure --prefix="$DIR/install_data/php/ext/libedit" --enable-static >> "$DIR/install.log" 2>&1 ./configure --prefix="$DIR/bin/php5" \
--enable-shared=yes \
--enable-static=no \
$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1
echo -n " compiling..." echo -n " compiling..."
if make -j $THREADS >> "$DIR/install.log" 2>&1; then if make -j $THREADS >> "$DIR/install.log" 2>&1; then
echo -n " installing..." echo -n " installing..."
make install >> "$DIR/install.log" 2>&1 make install >> "$DIR/install.log" 2>&1
HAVE_LIBEDIT="--with-libedit=\"$DIR/install_data/php/ext/libedit\"" HAVE_LIBEDIT="--without-readline --with-libedit=\"$DIR/bin/php5\""
else else
echo -n " disabling..." echo -n " disabling..."
HAVE_LIBEDIT="--without-libedit" HAVE_LIBEDIT="--without-readline --without-libedit"
fi fi
echo -n " cleaning..." echo -n " cleaning..."
cd .. cd ..
rm -r -f ./libedit rm -r -f ./libedit
echo " done!" echo " done!"
set -e
fi fi
#zlib #zlib
download_file "https://github.com/madler/zlib/archive/v$ZLIB_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1
echo -n "[zlib] downloading $ZLIB_VERSION..." echo -n "[zlib] downloading $ZLIB_VERSION..."
download_file "http://zlib.net/zlib-$ZLIB_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1
mv zlib-$ZLIB_VERSION zlib mv zlib-$ZLIB_VERSION zlib
echo -n " checking..." echo -n " checking..."
cd zlib cd zlib
RANLIB=$RANLIB ./configure --prefix="$DIR/install_data/php/ext/zlib" \ RANLIB=$RANLIB ./configure --prefix="$DIR/bin/php5" \
--static >> "$DIR/install.log" 2>&1 --shared >> "$DIR/install.log" 2>&1
echo -n " compiling..." echo -n " compiling..."
make -j $THREADS >> "$DIR/install.log" 2>&1 make -j $THREADS >> "$DIR/install.log" 2>&1
echo -n " installing..." echo -n " installing..."
@ -209,6 +234,45 @@ cd ..
rm -r -f ./zlib rm -r -f ./zlib
echo " done!" echo " done!"
if [ "$2" == "openssl" ] || [ "$2" == "curl" ] && [ "$1" != "crosscompile" ]; then
#OpenSSL
WITH_SSL="--with-ssl=$DIR/bin/php5"
WITH_OPENSSL="--with-openssl=$DIR/bin/php5"
echo -n "[OpenSSL] downloading $OPENSSL_VERSION..."
download_file "http://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1
mv openssl-$OPENSSL_VERSION openssl
echo -n " checking..."
cd openssl
RANLIB=$RANLIB ./Configure \
$OPENSSL_TARGET \
--prefix="$DIR/bin/php5" \
--openssldir="$DIR/bin/php5" \
--with-zlib-lib="$DIR/bin/php5/lib" \
--with-zlib-include="$DIR/bin/php5/include" \
zlib-dynamic \
shared \
no-asm \
no-hw \
no-engines \
no-static \
$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1
echo -n " compiling..."
make depend >> "$DIR/install.log" 2>&1
make >> "$DIR/install.log" 2>&1
echo -n " installing..."
make install >> "$DIR/install.log" 2>&1
echo -n " cleaning..."
cd ..
rm -r -f ./openssh
echo " done!"
else
WITH_SSL="--with-ssl"
WITH_OPENSSL="--without-ssl"
if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then
WITH_SSL="--with-darwinssl"
fi
fi
if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then
HAVE_CURL="shared,/usr" HAVE_CURL="shared,/usr"
else else
@ -221,13 +285,14 @@ else
if [ ! -f ./configure ]; then if [ ! -f ./configure ]; then
./buildconf --force >> "$DIR/install.log" 2>&1 ./buildconf --force >> "$DIR/install.log" 2>&1
fi fi
./configure --disable-dependency-tracking \ RANLIB=$RANLIB ./configure --disable-dependency-tracking \
--enable-ipv6 \ --enable-ipv6 \
--enable-optimize \ --enable-optimize \
--enable-http \ --enable-http \
--enable-ftp \ --enable-ftp \
--disable-dict \ --disable-dict \
--enable-file \ --enable-file \
--without-librtmp \
--disable-gopher \ --disable-gopher \
--disable-imap \ --disable-imap \
--disable-pop3 \ --disable-pop3 \
@ -238,8 +303,10 @@ else
--disable-ldap \ --disable-ldap \
--disable-ldaps \ --disable-ldaps \
--without-libidn \ --without-libidn \
--with-zlib="$DIR/bin/php5" \
$WITH_SSL \
--enable-threaded-resolver \ --enable-threaded-resolver \
--prefix="$DIR/install_data/php/ext/curl" \ --prefix="$DIR/bin/php5" \
--disable-shared \ --disable-shared \
--enable-static \ --enable-static \
$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1
@ -251,7 +318,7 @@ else
cd .. cd ..
rm -r -f ./curl rm -r -f ./curl
echo " done!" echo " done!"
HAVE_CURL="$DIR/install_data/php/ext/curl" HAVE_CURL="$DIR/bin/php5"
fi fi
#pthreads #pthreads
@ -273,9 +340,9 @@ mv yaml-$YAML_VERSION yaml
echo -n " checking..." echo -n " checking..."
cd yaml cd yaml
RANLIB=$RANLIB ./configure \ RANLIB=$RANLIB ./configure \
--prefix="$DIR/install_data/php/ext/yaml" \ --prefix="$DIR/bin/php5" \
--enable-static \ --disable-static \
--disable-shared \ --enable-shared \
$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1
echo -n " compiling..." echo -n " compiling..."
make -j $THREADS >> "$DIR/install.log" 2>&1 make -j $THREADS >> "$DIR/install.log" 2>&1
@ -293,7 +360,7 @@ if which free >/dev/null; then
else else
MAX_MEMORY=$(top -l 1 | grep PhysMem: | awk '{print $10}' | tr -d 'a-zA-Z') MAX_MEMORY=$(top -l 1 | grep PhysMem: | awk '{print $10}' | tr -d 'a-zA-Z')
fi fi
if [ $MAX_MEMORY -gt 512 ] && [ "$1" != "crosscompile" ]; then if [ $MAX_MEMORY -gt 512 2>> /dev/null ] && [ "$1" != "crosscompile" ]; then
echo -n " enabling optimizations..." echo -n " enabling optimizations..."
OPTIMIZATION="--enable-inline-optimization " OPTIMIZATION="--enable-inline-optimization "
else else
@ -310,14 +377,12 @@ if [ "$1" == "crosscompile" ]; then
sed -i 's/pthreads_working=no/pthreads_working=yes/' ./configure sed -i 's/pthreads_working=no/pthreads_working=yes/' ./configure
export LIBS="-lpthread -ldl" export LIBS="-lpthread -ldl"
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no"
fi fi
./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ RANLIB=$RANLIB ./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \
--exec-prefix="$DIR/bin/php5" \ --exec-prefix="$DIR/bin/php5" \
--with-curl="$HAVE_CURL" \ --with-curl="$HAVE_CURL" \
--with-zlib="$DIR/install_data/php/ext/zlib" \ --with-zlib="$DIR/bin/php5" \
--with-zlib-dir="$DIR/install_data/php/ext/zlib" \ --with-yaml="$DIR/bin/php5" \
--with-yaml="$DIR/install_data/php/ext/yaml" \
$HAVE_LIBEDIT \ $HAVE_LIBEDIT \
--disable-libxml \ --disable-libxml \
--disable-xml \ --disable-xml \
@ -356,33 +421,53 @@ fi
make -j $THREADS >> "$DIR/install.log" 2>&1 make -j $THREADS >> "$DIR/install.log" 2>&1
echo -n " installing..." echo -n " installing..."
make install >> "$DIR/install.log" 2>&1 make install >> "$DIR/install.log" 2>&1
echo " generating php.ini..."
if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then
set +e
install_name_tool -delete_rpath "$DIR/bin/php5/lib" "$DIR/bin/php5/bin/php" >> "$DIR/install.log" 2>&1
install_name_tool -change "$DIR/bin/php5/lib/libz.1.dylib" "@loader_path/../lib/libz.1.dylib" "$DIR/bin/php5/bin/php" >> "$DIR/install.log" 2>&1
install_name_tool -change "$DIR/bin/php5/lib/libyaml-0.2.dylib" "@loader_path/../lib/libyaml-0.2.dylib" "$DIR/bin/php5/bin/php" >> "$DIR/install.log" 2>&1
install_name_tool -change "$DIR/bin/php5/lib/libssl.1.0.0.dylib" "@loader_path/../lib/libssl.1.0.0.dylib" "$DIR/bin/php5/bin/php" >> "$DIR/install.log" 2>&1
install_name_tool -change "$DIR/bin/php5/lib/libcrypto.1.0.0.dylib" "@loader_path/../lib/libcrypto.1.0.0.dylib" "$DIR/bin/php5/bin/php" >> "$DIR/install.log" 2>&1
chmod 0777 "$DIR/bin/php5/lib/libssl.1.0.0.dylib" >> "$DIR/install.log" 2>&1
install_name_tool -change "$DIR/bin/php5/lib/libcrypto.1.0.0.dylib" "@loader_path/libcrypto.1.0.0.dylib" "$DIR/bin/php5/lib/libssl.1.0.0.dylib" >> "$DIR/install.log" 2>&1
chmod 0755 "$DIR/bin/php5/lib/libssl.1.0.0.dylib" >> "$DIR/install.log" 2>&1
set -e
fi
echo -n " generating php.ini..."
TIMEZONE=$(date +%Z) TIMEZONE=$(date +%Z)
touch "$DIR/bin/php5/lib/php.ini" echo "date.timezone=$TIMEZONE" > "$DIR/bin/php5/bin/php.ini"
echo "short_open_tag=0" >> "$DIR/bin/php5/bin/php.ini"
echo "asp_tags=0" >> "$DIR/bin/php5/bin/php.ini"
if [ "$1" != "crosscompile" ]; then if [ "$1" != "crosscompile" ]; then
OPCACHE_PATH=$(find "$DIR/bin/php5" -name opcache.so) echo "zend_extension=opcache.so" >> "$DIR/bin/php5/bin/php.ini"
echo "zend_extension=\"$OPCACHE_PATH\"" >> "$DIR/bin/php5/lib/php.ini" echo "opcache.enable=1" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "$DIR/bin/php5/lib/php.ini" echo "opcache.enable_cli=1" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "$DIR/bin/php5/lib/php.ini" echo "opcache.save_comments=0" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "$DIR/bin/php5/lib/php.ini" echo "opcache.fast_shutdown=1" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.fast_shutdown=1" >> "$DIR/bin/php5/lib/php.ini" echo "opcache.max_accelerated_files=4096" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.max_accelerated_files=4096" >> "$DIR/bin/php5/lib/php.ini" echo "opcache.interned_strings_buffer=8" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.interned_strings_buffer=8" >> "$DIR/bin/php5/lib/php.ini" echo "opcache.memory_consumption=128" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.memory_consumption=128" >> "$DIR/bin/php5/lib/php.ini" echo "opcache.optimization_level=0xffffffff" >> "$DIR/bin/php5/bin/php.ini"
echo "opcache.optimization_level=0xffffffff" >> "$DIR/bin/php5/lib/php.ini"
fi fi
if [ "$HAVE_CURL" == "shared,/usr" ]; then if [ "$HAVE_CURL" == "shared,/usr" ]; then
echo "extension=curl.so" >> "$DIR/bin/php5/lib/php.ini" echo "extension=curl.so" >> "$DIR/bin/php5/bin/php.ini"
fi fi
echo "date.timezone=$TIMEZONE" >> "$DIR/bin/php5/lib/php.ini"
echo "short_open_tag=0" >> "$DIR/bin/php5/lib/php.ini"
echo "asp_tags=0" >> "$DIR/bin/php5/lib/php.ini"
echo " done!" echo " done!"
cd "$DIR" cd "$DIR"
echo -n "[INFO] Cleaning up..." echo -n "[INFO] Cleaning up..."
rm -r -f install_data/ >> "$DIR/install.log" 2>&1 rm -r -f install_data/ >> "$DIR/install.log" 2>&1
rm -f bin/php5/bin/curl >> "$DIR/install.log" 2>&1
rm -f bin/php5/bin/curl-config >> "$DIR/install.log" 2>&1
rm -f bin/php5/bin/c_rehash >> "$DIR/install.log" 2>&1
rm -f bin/php5/bin/openssl >> "$DIR/install.log" 2>&1
rm -r -f bin/php5/man >> "$DIR/install.log" 2>&1
rm -r -f bin/php5/php >> "$DIR/install.log" 2>&1
rm -r -f bin/php5/share >> "$DIR/install.log" 2>&1
rm -r -f bin/php5/misc >> "$DIR/install.log" 2>&1
date >> "$DIR/install.log" 2>&1 date >> "$DIR/install.log" 2>&1
echo " done!" echo " done!"
echo "[PocketMine] You should start the server now using \"./start.sh.\"" echo "[PocketMine] You should start the server now using \"./start.sh.\""

View File

@ -1,10 +1,17 @@
#!/bin/bash #!/bin/bash
PMMP_VERSION="" PMMP_VERSION=""
MAC_BUILD="PHP_5.5.9_x86_MacOS" LINUX_32_BUILD="PHP_5.5.9_x86_Linux"
LINUX_64_BUILD="PHP_5.5.9_x86-64_Linux"
MAC_32_BUILD="PHP_5.5.9_x86_MacOS"
MAC_64_BUILD="PHP_5.5.9_x86-64_MacOS"
RPI_BUILD="PHP_5.5.9_ARM_Raspbian_hard" RPI_BUILD="PHP_5.5.9_ARM_Raspbian_hard"
# Temporal build
ODROID_BUILD="PHP_5.5.9_ARM_Raspbian_hard"
AND_BUILD="PHP_5.5.9_ARMv7_Android" AND_BUILD="PHP_5.5.9_ARMv7_Android"
IOS_BUILD="PHP_5.5.9_ARMv6_iOS" IOS_BUILD="PHP_5.5.9_ARMv6_iOS"
update=off update=off
forcecompile=off
alldone=no
#Needed to use aliases #Needed to use aliases
shopt -s expand_aliases shopt -s expand_aliases
@ -21,11 +28,14 @@ else
fi fi
while getopts "udv:" opt; do while getopts "ucdv:" opt; do
case $opt in case $opt in
u) u)
update=on update=on
;; ;;
c)
forcecompile=on
;;
d) d)
PMMP_VERSION="master" PMMP_VERSION="master"
;; ;;
@ -58,7 +68,6 @@ rm -f LICENSE
rm -f start.sh rm -f start.sh
rm -f start.bat rm -f start.bat
echo "[1/3] Downloading PocketMine-MP $PMMP_VERSION..." echo "[1/3] Downloading PocketMine-MP $PMMP_VERSION..."
set -e
download_file "https://github.com/PocketMine/PocketMine-MP/archive/$PMMP_VERSION.tar.gz" | tar -zx > /dev/null download_file "https://github.com/PocketMine/PocketMine-MP/archive/$PMMP_VERSION.tar.gz" | tar -zx > /dev/null
mv -f PocketMine-MP-$PMMP_VERSION/* ./ mv -f PocketMine-MP-$PMMP_VERSION/* ./
rm -f -r PocketMine-MP-$PMMP_VERSION/ rm -f -r PocketMine-MP-$PMMP_VERSION/
@ -70,67 +79,151 @@ if [ $update == on ]; then
else else
echo -n "[3/3] Obtaining PHP:" echo -n "[3/3] Obtaining PHP:"
echo " detecting if build is available..." echo " detecting if build is available..."
if [ "$(uname -s)" == "Darwin" ]; then if [ "$forcecompile" == "off" ] && [ "$(uname -s)" == "Darwin" ]; then
set +e set +e
UNAME_M=$(uname -m) UNAME_M=$(uname -m)
IS_IOS=$(expr match $UNAME_M 'iP[a-zA-Z0-9,]*') IS_IOS=$(expr match $UNAME_M 'iP[a-zA-Z0-9,]*' 2> /dev/null)
set -e set -e
if [ $IS_IOS -gt 0 ]; then if [[ $IS_IOS -gt 0 ]]; then
rm -r -f bin/ >> /dev/null 2>&1 rm -r -f bin/ >> /dev/null 2>&1
echo -n "[3/3] iOS PHP build available, downloading $IOS_BUILD.tar.gz..." echo -n "[3/3] iOS PHP build available, downloading $IOS_BUILD.tar.gz..."
download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1
chmod +x ./bin/php5/bin/* chmod +x ./bin/php5/bin/*
echo -n " checking..."
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
echo -n " regenerating php.ini..." echo -n " regenerating php.ini..."
echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini"
echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" echo "short_open_tag=0" >> "./bin/php5/bin/php.ini"
echo "asp_tags=0" >> "./bin/php5/lib/php.ini" echo "asp_tags=0" >> "./bin/php5/bin/php.ini"
echo " done" echo " done"
alldone=yes
else else
rm -r -f bin/ >> /dev/null 2>&1 echo " invalid build detected"
echo -n "[3/3] Mac OSX PHP build available, downloading $MAC_BUILD.tar.gz..." fi
download_file "http://sourceforge.net/projects/pocketmine/files/builds/$MAC_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 else
chmod +x ./bin/php5/bin/* rm -r -f bin/ >> /dev/null 2>&1
echo -n " regenerating php.ini..." if [ `getconf LONG_BIT` == "64" ]; then
OPCACHE_PATH=$(find "./bin/php5" -name opcache.so) echo -n "[3/3] MacOS 64-bit PHP build available, downloading $MAC_64_BUILD.tar.gz..."
echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/lib/php.ini" MAC_BUILD=$MAC_64_BUILD
echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" else
echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" echo -n "[3/3] MacOS 32-bit PHP build available, downloading $MAC_32_BUILD.tar.gz..."
echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" MAC_BUILD=$MAC_32_BUILD
echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" fi
echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" download_file "http://sourceforge.net/projects/pocketmine/files/builds/$MAC_BUILD.tar.gz" | tar -zx > /dev/null 2>&1
echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" chmod +x ./bin/php5/bin/*
echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" echo -n " checking..."
echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" echo -n " regenerating php.ini..."
echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
echo "asp_tags=0" >> "./bin/php5/lib/php.ini" echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/bin/php.ini"
echo " done" echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
echo "opcache.fast_shutdown=1" >> "./bin/php5/bin/php.ini"
echo "opcache.max_accelerated_files=4096" >> "./bin/php5/bin/php.ini"
echo "opcache.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini"
echo "opcache.memory_consumption=128" >> "./bin/php5/bin/php.ini"
echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini"
echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini"
echo "short_open_tag=0" >> "./bin/php5/bin/php.ini"
echo "asp_tags=0" >> "./bin/php5/bin/php.ini"
echo " done"
alldone=yes
else
echo " invalid build detected"
fi
fi fi
else else
set +e
grep -q BCM2708 /proc/cpuinfo > /dev/null 2>&1 grep -q BCM2708 /proc/cpuinfo > /dev/null 2>&1
if [ $? -eq 0 ]; then IS_RPI=$?
set -e grep -q ODROID /proc/cpuinfo > /dev/null 2>&1
IS_ODROID=$?
if [ $IS_RPI -eq 0 ] && [ "$forcecompile" == "off" ]; then
rm -r -f bin/ >> /dev/null 2>&1 rm -r -f bin/ >> /dev/null 2>&1
echo -n "[3/3] Raspberry Pi PHP build available, downloading $RPI_BUILD.tar.gz..." echo -n "[3/3] Raspberry Pi PHP build available, downloading $RPI_BUILD.tar.gz..."
download_file "http://sourceforge.net/projects/pocketmine/files/builds/$RPI_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 download_file "http://sourceforge.net/projects/pocketmine/files/builds/$RPI_BUILD.tar.gz" | tar -zx > /dev/null 2>&1
chmod +x ./bin/php5/bin/* chmod +x ./bin/php5/bin/*
echo -n " checking..."
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
echo -n " regenerating php.ini..." echo -n " regenerating php.ini..."
OPCACHE_PATH=$(find "./bin/php5" -name opcache.so) OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/lib/php.ini" echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" echo "opcache.fast_shutdown=1" >> "./bin/php5/bin/php.ini"
echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" echo "opcache.max_accelerated_files=4096" >> "./bin/php5/bin/php.ini"
echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" echo "opcache.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini"
echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" echo "opcache.memory_consumption=128" >> "./bin/php5/bin/php.ini"
echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini"
echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini"
echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" echo "short_open_tag=0" >> "./bin/php5/bin/php.ini"
echo "asp_tags=0" >> "./bin/php5/lib/php.ini" echo "asp_tags=0" >> "./bin/php5/bin/php.ini"
echo " done" echo " done"
alldone=yes
else else
echo " invalid build detected"
fi
elif [ $IS_ODROID -eq 0 ] && [ "$forcecompile" == "off" ]; then
rm -r -f bin/ >> /dev/null 2>&1
echo -n "[3/3] ODROID PHP build available, downloading $ODROID_BUILD.tar.gz..."
download_file "http://sourceforge.net/projects/pocketmine/files/builds/$ODROID_BUILD.tar.gz" | tar -zx > /dev/null 2>&1
chmod +x ./bin/php5/bin/*
echo -n " checking..."
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
echo -n " regenerating php.ini..."
OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
echo "opcache.fast_shutdown=1" >> "./bin/php5/bin/php.ini"
echo "opcache.max_accelerated_files=4096" >> "./bin/php5/bin/php.ini"
echo "opcache.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini"
echo "opcache.memory_consumption=128" >> "./bin/php5/bin/php.ini"
echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini"
echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini"
echo "short_open_tag=0" >> "./bin/php5/bin/php.ini"
echo "asp_tags=0" >> "./bin/php5/bin/php.ini"
echo " done"
alldone=yes
else
echo " invalid build detected"
fi
elif [ "$forcecompile" == "off" ] && [ "$(uname -s)" == "Linux" ]; then
rm -r -f bin/ >> /dev/null 2>&1
if [ `getconf LONG_BIT` = "64" ]; then
echo -n "[3/3] Linux 64-bit PHP build available, downloading $LINUX_64_BUILD.tar.gz..."
LINUX_BUILD=$LINUX_64_BUILD
else
echo -n "[3/3] Linux 32-bit PHP build available, downloading $LINUX_32_BUILD.tar.gz..."
LINUX_BUILD=$LINUX_32_BUILD
fi
download_file "http://sourceforge.net/projects/pocketmine/files/builds/$LINUX_BUILD.tar.gz" | tar -zx > /dev/null 2>&1
chmod +x ./bin/php5/bin/*
echo -n " checking..."
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
echo -n " regenerating php.ini..."
OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
echo "opcache.fast_shutdown=1" >> "./bin/php5/bin/php.ini"
echo "opcache.max_accelerated_files=4096" >> "./bin/php5/bin/php.ini"
echo "opcache.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini"
echo "opcache.memory_consumption=128" >> "./bin/php5/bin/php.ini"
echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini"
echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini"
echo "short_open_tag=0" >> "./bin/php5/bin/php.ini"
echo "asp_tags=0" >> "./bin/php5/bin/php.ini"
echo " done"
alldone=yes
else
echo " invalid build detected"
fi
fi
if [ "$alldone" == "no" ]; then
set -e set -e
echo "[3/3] no build found, compiling PHP" echo "[3/3] no build found, compiling PHP"
exec ./src/build/compile.sh exec ./src/build/compile.sh

View File

@ -1,6 +1,7 @@
#!/bin/bash -x #!/bin/bash -x
export PATH=/opt/arm-2013.05/bin:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/opt/arm-unknown-linux-uclibcgnueabi/bin:$PATH export PATH="/opt/arm-2013.05/bin:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/opt/arm-unknown-linux-uclibcgnueabi/bin:$PATH"
export THREADS=2 export THREADS=2
PHP_VERSION="5.5.9"
#Needed to use aliases #Needed to use aliases
shopt -s expand_aliases shopt -s expand_aliases
@ -31,9 +32,10 @@ then
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit
cd $COMPILEDIR/linux/32bit cd $COMPILEDIR/linux/32bit
CFLAGS=-m32 march=i686 mtune=generic $SCRIPT OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i386 mtune=none $SCRIPT linux openssl
cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ tar -czf PHP_${PHP_VERSION}_x86_Linux.tar.gz bin/
cp -r $COMPILEDIR/linux/32bit/{install.log,PHP_${PHP_VERSION}_x86_Linux.tar.gz,install_data/*} $ARCHIVE/linux/32bit/
if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -44,18 +46,19 @@ then
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit
cd $COMPILEDIR/linux/64bit cd $COMPILEDIR/linux/64bit
$SCRIPT OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=none $SCRIPT linux openssl
cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ tar -czf PHP_${PHP_VERSION}_x86-64_Linux.tar.gz bin/
cp -r $COMPILEDIR/linux/64bit/{install.log,PHP_${PHP_VERSION}_x86-64_Linux.tar.gz,install_data/*} $ARCHIVE/linux/64bit/
if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
fi fi
if [ "$COMPILE_MAC" = "true" ]; if [ "$COMPILE_MAC_32" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/mac mkdir -p {$COMPILEDIR,$ARCHIVE}/mac32
cd $COMPILEDIR/mac cd $COMPILEDIR/mac32
curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null
cd libtool-2.4.2 cd libtool-2.4.2
@ -68,8 +71,32 @@ then
export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize"
$SCRIPT mac curl $SCRIPT mac curl
cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/ tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/
if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then cp -r $COMPILEDIR/mac32/{install.log,PHP_${PHP_VERSION}_x86_MacOS.tar.gz,install_data/*} $ARCHIVE/mac32/
if [ ! -f $COMPILEDIR/mac32/bin/php5/bin/php ]; then
exit 1
fi
fi
if [ "$COMPILE_MAC_64" = "true" ];
then
mkdir -p {$COMPILEDIR,$ARCHIVE}/mac64
cd $COMPILEDIR/mac64
curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null
cd libtool-2.4.2
./configure --prefix="$COMPILEDIR/mac/libtool" > /dev/null
make > /dev/null
make install
cd ../
rm -rf libtool-2.4.2
export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool"
export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize"
$SCRIPT mac64 curl
tar -czf PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz bin/
cp -r $COMPILEDIR/mac64/{install.log,PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz,install_data/*} $ARCHIVE/mac64
if [ ! -f $COMPILEDIR/mac64/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
fi fi
@ -81,7 +108,8 @@ then
$SCRIPT rpi $SCRIPT rpi
cp -r $COMPILEDIR/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/rpi/ tar -czf PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz bin/
cp -r $COMPILEDIR/rpi/{install.log,PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz,install_data/*} $ARCHIVE/rpi/
if [ ! -f $COMPILEDIR/rpi/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/rpi/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -94,7 +122,8 @@ then
$SCRIPT crosscompile android-armv6 $SCRIPT crosscompile android-armv6
cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv6/ tar -czf PHP_${PHP_VERSION}_ARMv6_Android.tar.gz bin/
cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,PHP_${PHP_VERSION}_ARMv6_Android.tar.gz,install_data/*} $ARCHIVE/crosscompile/android-armv6/
if [ ! -f $COMPILEDIR/crosscompile/android-armv6/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/crosscompile/android-armv6/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -107,7 +136,8 @@ then
$SCRIPT crosscompile android-armv7 $SCRIPT crosscompile android-armv7
cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv7/ tar -czf PHP_${PHP_VERSION}_ARMv7_Android.tar.gz bin/
cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,PHP_${PHP_VERSION}_ARMv7_Android.tar.gz,install_data/*} $ARCHIVE/crosscompile/android-armv7/
if [ ! -f $COMPILEDIR/crosscompile/android-armv7/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/crosscompile/android-armv7/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -162,7 +192,8 @@ then
$SCRIPT crosscompile rpi $SCRIPT crosscompile rpi
cp -r $COMPILEDIR/crosscompile/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/rpi/ tar -czf PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz bin/
cp -r $COMPILEDIR/crosscompile/rpi/{install.log,PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz,install_data/*} $ARCHIVE/crosscompile/rpi/
if [ ! -f $COMPILEDIR/crosscompile/rpi/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/crosscompile/rpi/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi

View File

@ -22,7 +22,6 @@
abstract class EventHandler{ abstract class EventHandler{
public static function callEvent(BaseEvent $event){ public static function callEvent(BaseEvent $event){
$status = BaseEvent::NORMAL;
foreach($event::$handlerPriority as $priority => $handlerList){ foreach($event::$handlerPriority as $priority => $handlerList){
if(count($handlerList) > 0){ if(count($handlerList) > 0){
$event->setPrioritySlot($priority); $event->setPrioritySlot($priority);

View File

@ -139,7 +139,7 @@ function arguments ( $args ){
$args = array(); $args = array();
} }
array_shift( $args ); array_shift( $args );
$args = join( $args, ' ' ); $args = implode(' ', $args);
preg_match_all('/ (--[\w\-]+ (?:[= ] [^-\s]+ )? ) | (-\w+) | (\w+) /x', $args, $match ); preg_match_all('/ (--[\w\-]+ (?:[= ] [^-\s]+ )? ) | (-\w+) | (\w+) /x', $args, $match );
$args = array_shift( $match ); $args = array_shift( $match );
@ -157,7 +157,7 @@ function arguments ( $args ){
$value = preg_split( '/[= ]/', $arg, 2 ); $value = preg_split( '/[= ]/', $arg, 2 );
$com = substr( array_shift($value), 2 ); $com = substr( array_shift($value), 2 );
$value = join($value); $value = implode($value);
$ret['commands'][$com] = !empty($value) ? $value : true; $ret['commands'][$com] = !empty($value) ? $value : true;
continue; continue;

View File

@ -41,7 +41,7 @@ class SignPostBlock extends TransparentBlock{
return true; return true;
}else{ }else{
$this->meta = $faces[$face]; $this->meta = $faces[$face];
$this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta, true, false, true)); $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta), true, false, true);
return true; return true;
} }
} }

View File

@ -22,7 +22,7 @@
class TallGrassBlock extends FlowableBlock{ class TallGrassBlock extends FlowableBlock{
public function __construct($meta = 1){ public function __construct($meta = 1){
parent::__construct(TALL_GRASS, $meta, "Tall Grass"); parent::__construct(TALL_GRASS, $meta, "Tall Grass");
//$this->isReplaceable = true; $this->isReplaceable = true;
$names = array( $names = array(
0 => "Dead Shrub", 0 => "Dead Shrub",
1 => "Tall Grass", 1 => "Tall Grass",

View File

@ -43,7 +43,6 @@ class SpawnEggItem extends Item{
--$this->count; --$this->count;
} }
return true; return true;
break;
} }
return false; return false;
} }

View File

@ -30,7 +30,6 @@ class MinecraftInterface{
exit(1); exit(1);
} }
$this->bandwidth = array(0, 0, microtime(true)); $this->bandwidth = array(0, 0, microtime(true));
$this->start = microtime(true);
$this->packets = array(); $this->packets = array();
} }
@ -90,7 +89,7 @@ class MinecraftInterface{
if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){ if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){
return 0; return 0;
}elseif($packet instanceof RakNetPacket){ }elseif($packet instanceof RakNetPacket){
$codec = new RakNetCodec($packet); new RakNetCodec($packet);
} }
$write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port);
$this->bandwidth[1] += $write; $this->bandwidth[1] += $write;

View File

@ -22,7 +22,7 @@
class UDPSocket{ class UDPSocket{
public $connected, $sock, $server; public $connected, $sock, $server, $port;
function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){ function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){
$this->server = $server; $this->server = $server;
$this->port = $port; $this->port = $port;

View File

@ -21,6 +21,7 @@
class RakNetCodec{ class RakNetCodec{
public $packet; public $packet;
private $buffer;
public function __construct(RakNetPacket $packet){ public function __construct(RakNetPacket $packet){
$this->packet = $packet; $this->packet = $packet;
$this->buffer =& $this->packet->buffer; $this->buffer =& $this->packet->buffer;

View File

@ -76,8 +76,8 @@ abstract class RakNetDataPacket extends stdClass{
$this->buffer .= Utils::writeLong($v); $this->buffer .= Utils::writeLong($v);
} }
protected function getInt($unsigned = false){ protected function getInt(){
return Utils::readInt($this->get(4), $unsigned); return Utils::readInt($this->get(4));
} }
protected function putInt($v){ protected function putInt($v){

View File

@ -50,8 +50,8 @@ class RakNetParser{
return Utils::readLong($this->get(8), $unsigned); return Utils::readLong($this->get(8), $unsigned);
} }
private function getInt($unsigned = false){ private function getInt(){
return Utils::readInt($this->get(4), $unsigned); return Utils::readInt($this->get(4));
} }
private function getShort($unsigned = false){ private function getShort($unsigned = false){

View File

@ -95,7 +95,7 @@ class PMFLevel extends PMF{
} }
private function createBlank(){ private function createBlank(){
$this->saveData(false); $this->saveData();
@mkdir(dirname($this->file)."/chunks/", 0755); @mkdir(dirname($this->file)."/chunks/", 0755);
if(!file_exists(dirname($this->file)."/entities.yml")){ if(!file_exists(dirname($this->file)."/entities.yml")){
$entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML); $entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML);
@ -169,12 +169,12 @@ class PMFLevel extends PMF{
} }
public static function getIndex($X, $Z){ public static function getIndex($X, $Z){
return ($Z << 16) | ($X < 0 ? (~--$X & 0x7fff) | 0x1000 : $X & 0xFFFF); return ($Z << 16) | ($X < 0 ? (~--$X & 0x7fff) | 0x8000 : $X & 0x7fff);
} }
public static function getXZ($index, &$X = null, &$Z = null){ public static function getXZ($index, &$X = null, &$Z = null){
$Z = $index >> 16; $Z = $index >> 16;
$X = $index & 0xFFFF; $X = ($index & 0x8000) === 0x8000 ? -($index & 0x7fff) : $index & 0x7fff;
return array($X, $Z); return array($X, $Z);
} }
@ -218,20 +218,19 @@ class PMFLevel extends PMF{
} }
public function loadChunk($X, $Z){ public function loadChunk($X, $Z){
$X = (int) $X;
$Z = (int) $Z;
$index = self::getIndex($X, $Z);
if($this->isChunkLoaded($X, $Z)){ if($this->isChunkLoaded($X, $Z)){
return true; return true;
} }
$index = self::getIndex($X, $Z);
$path = $this->getChunkPath($X, $Z); $path = $this->getChunkPath($X, $Z);
if(!file_exists($path)){ if(!file_exists($path)){
if($this->generateChunk($X, $Z) === false){ if($this->generateChunk($X, $Z) === false){
return false; return false;
}elseif($this->isGenerating === 0){
$this->populateChunk($X, $Z);
return true;
} }
if($this->isGenerating === 0){
$this->populateChunk($X, $Z);
}
return true;
} }
$chunk = @gzopen($path, "rb"); $chunk = @gzopen($path, "rb");

View File

@ -76,7 +76,6 @@ class Config{
*/ */
public function __construct($file, $type = CONFIG_DETECT, $default = array(), &$correct = null){ public function __construct($file, $type = CONFIG_DETECT, $default = array(), &$correct = null){
$this->load($file, $type, $default); $this->load($file, $type, $default);
$correct = $this->check();
} }
public function reload(){ public function reload(){
@ -84,7 +83,6 @@ class Config{
unset($this->correct); unset($this->correct);
unset($this->type); unset($this->type);
$this->load($this->file); $this->load($this->file);
$correct = $this->check();
} }
public function fixYAMLIndexes($str){ public function fixYAMLIndexes($str){
@ -141,7 +139,6 @@ class Config{
default: default:
$this->correct = false; $this->correct = false;
return false; return false;
break;
} }
if(!is_array($this->config)){ if(!is_array($this->config)){
$this->config = $default; $this->config = $default;

View File

@ -107,7 +107,7 @@ class NBT{
} }
public function writeTAG_FLOAT($v){ public function writeTAG_FLOAT($v){
$this->binary .= Utils::writeLFloar($v); $this->binary .= Utils::writeLFloat($v);
} }
public function writeTAG_DOUBLE($v){ public function writeTAG_DOUBLE($v){

View File

@ -620,7 +620,7 @@ class Utils{
} }
public static function writeLLong($value){ public static function writeLLong($value){
return strrev(Utils::writeLong($str)); return strrev(Utils::writeLong($value));
} }

View File

@ -33,6 +33,7 @@ class VersionString{
private $release; private $release;
private $minor; private $minor;
private $development = false; private $development = false;
private $generation;
public function __construct($version = MAJOR_VERSION){ public function __construct($version = MAJOR_VERSION){
if(is_int($version)){ if(is_int($version)){
$this->minor = $version & 0x1F; $this->minor = $version & 0x1F;

View File

@ -87,7 +87,7 @@ class AsyncMultipleQueue extends Thread{
$d = array(); $d = array();
for($c = 0; $c < $cnt; ++$c){ for($c = 0; $c < $cnt; ++$c){
$key = $this->get(Utils::readShort($this->get(2), false)); $key = $this->get(Utils::readShort($this->get(2), false));
$d[$key] = $this->get(Utils::readInt($this->get(4), false)); $d[$key] = $this->get(Utils::readInt($this->get(4)));
} }
$res = (string) Utils::curl_post($url, $d, $timeout); $res = (string) Utils::curl_post($url, $d, $timeout);
$this->lock(); $this->lock();

View File

@ -77,6 +77,10 @@ class Level{
unset($this->usedChunks[$X.".".$Z][$player->CID]); unset($this->usedChunks[$X.".".$Z][$player->CID]);
} }
public function isChunkPopulated($X, $Z){
return $this->level->isPopulated($X, $Z);
}
public function checkTime(){ public function checkTime(){
if(!isset($this->level)){ if(!isset($this->level)){
return false; return false;
@ -138,8 +142,11 @@ class Level{
if(count($c) === 0){ if(count($c) === 0){
unset($this->usedChunks[$i]); unset($this->usedChunks[$i]);
$X = explode(".", $i); $X = explode(".", $i);
$Z = array_pop($X); $Z = (int) array_pop($X);
$this->level->unloadChunk((int) array_pop($X), (int) $Z, $this->server->saveEnabled); $X = (int) array_pop($X);
if(!$this->isSpawnChunk($X, $Z)){
$this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
}
} }
} }
$this->save(false, false); $this->save(false, false);
@ -408,14 +415,24 @@ class Level{
return $this->level->loadChunk($X, $Z); return $this->level->loadChunk($X, $Z);
} }
public function unloadChunk($X, $Z){ public function unloadChunk($X, $Z, $force = false){
if(!isset($this->level)){ if(!isset($this->level)){
return false; return false;
} }
if($force !== true and $this->isSpawnChunk($X, $Z)){
return false;
}
Cache::remove("world:{$this->name}:$X:$Z"); Cache::remove("world:{$this->name}:$X:$Z");
return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled); return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
} }
public function isSpawnChunk($X, $Z){
$spawnX = $this->level->getData("spawnX") >> 4;
$spawnZ = $this->level->getData("spawnZ") >> 4;
return abs($X - $spawnX) <= 1 and abs($Z - $spawnZ) <= 1;
}
public function getOrderedChunk($X, $Z, $Yndex){ public function getOrderedChunk($X, $Z, $Yndex){
if(!isset($this->level)){ if(!isset($this->level)){
return false; return false;

View File

@ -19,14 +19,19 @@
* *
*/ */
/**
* WARNING: This code is old, and only supports the file format partially (reverse engineering)
* It can break, lock, or hit you in the face in any moment.
*
*/
class PocketChunkParser{ class PocketChunkParser{
private $location, $raw = b"", $file; private $location, $raw = b"", $file;
var $sectorLength = 4096; //16 * 16 * 16 public $sectorLength = 4096; //16 * 16 * 16
var $chunkLength = 86016; //21 * $sectorLength public $chunkLength = 86016; //21 * $sectorLength
var $map; public $map = array();
function __construct(){ public function __construct(){
$map = array();
} }
private function loadLocationTable(){ private function loadLocationTable(){

View File

@ -31,6 +31,8 @@ class Tile extends Position{
public $attach; public $attach;
public $metadata; public $metadata;
public $closed; public $closed;
private $lastUpdate;
private $scheduledUpdate;
private $server; private $server;
function __construct(Level $level, $id, $class, $x, $y, $z, $data = array()){ function __construct(Level $level, $id, $class, $x, $y, $z, $data = array()){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();

View File

@ -80,6 +80,7 @@ class NormalGenerator implements LevelGenerator{
public function generateChunk($chunkX, $chunkZ){ public function generateChunk($chunkX, $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
$hills = array(); $hills = array();
$patches = array();
$patchesSmall = array(); $patchesSmall = array();
$base = array(); $base = array();
for($z = 0; $z < 16; ++$z){ for($z = 0; $z < 16; ++$z){

View File

@ -24,7 +24,7 @@ require_once("LevelGenerator.php");
/***REM_END***/ /***REM_END***/
class SuperflatGenerator implements LevelGenerator{ class SuperflatGenerator implements LevelGenerator{
private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = array(); private $level, $random, $structure, $chunks, $options, $floorLevel, $preset, $populators = array();
public function getSettings(){ public function getSettings(){
return $this->options; return $this->options;

View File

@ -20,7 +20,7 @@
*/ */
class WorldGenerator{ class WorldGenerator{
private $seed, $level, $path, $random, $generator, $width; private $seed, $level, $path, $random, $generator, $height;
public function __construct(LevelGenerator $generator, $name, $seed = false, $height = 8){ public function __construct(LevelGenerator $generator, $name, $seed = false, $height = 8){
$this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false)); $this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false));
$this->random = new Random($this->seed); $this->random = new Random($this->seed);
@ -50,7 +50,7 @@ class WorldGenerator{
//Generate 4 chunks for spawning players //Generate 4 chunks for spawning players
for($Z = 7; $Z <= 8; ++$Z){ for($Z = 7; $Z <= 8; ++$Z){
for($X = 7; $X <= 8; ++$X){ for($X = 7; $X <= 9; ++$X){
$this->level->level->loadChunk($X, $Z); $this->level->level->loadChunk($X, $Z);
} }
} }

View File

@ -1,108 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
abstract class OctaveGenerator{
protected $octaves;
protected $xScale = 1;
protected $yScale = 1;
protected $zScale = 1;
public function __construct(array $octaves){
$this->octaves = $octaves;
}
public function setScale($scale){
$this->setXScale($scale);
$this->setYScale($scale);
$this->setZScale($scale);
}
public function getXScale(){
return $this->xScale;
}
public function setXScale($scale){
$this->xScale = $scale;
}
public function getYScale(){
return $this->yScale;
}
public function setYScale($scale){
$this->yScale = $scale;
}
public function getZScale(){
return $this->zScale;
}
public function setZScale($scale){
$this->zScale = $scale;
}
public function getOctaves(){
$array = array();
foreach($this->octaves as $index => $value){
$array[$index] = clone $value;
}
return $array;
}
//1D-noise
public function noise1D($x, $frequency, $amplitude, $normalized = false){
return $this->noise3D($x, 0, 0, $frequency, $amplitude, $normalized);
}
//2D-noise
public function noise2D($x, $y, $frequency, $amplitude, $normalized = false){
return $this->noise3D($x, $y, 0, $frequency, $amplitude, $normalized);
}
//3D-noise
public function noise3D($x, $y, $z, $frequency, $amplitude, $normalized = false){
$result = 0;
$amp = 1;
$freq = 1;
$max = 0;
$x *= $this->xScale;
$y *= $this->yScale;
$z *= $this->zScale;
foreach($this->octaves as $noiseGenerator){
$result += $octave->noise($x * $freq, $y * $freq, $z * $freq) * $amp;
$max += $amp;
$freq *= $frequency;
$amp *= $amplitude;
}
if($normalized === true){
$result /= $max;
}
return $result;
}
/*public function generateNoiseOctaves($x, $y, $z, $frequency, $amplitude){
}*/
}

View File

@ -1,63 +0,0 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/***REM_START***/
require_once("OctaveGenerator.php");
/***REM_END***/
class PerlinOctaveGenerator extends OctaveGenerator{
public function __construct(Random $random, $octaves){
$this->octaves = array();
for($o = 0; $o < $octaves; ++$o){
$this->octaves[$o] = new NoiseGeneratorPerlin($random);
}
}
/*public function generateNoiseOctaves($x, $y, $z, $sizeX, $sizeY, $sizeZ, $fX, $fY, $fZ){
$adouble = array_fill(0, $sizeX * $sizeY * $sizeZ, 0.0);
$d3 = 1.0;
foreach($this->octaves as $octave){
$dX = $x * $d3 * $fX;
$dY = $y * $d3 * $fY;
$dZ = $x * $d3 * $fZ;
$x1 = NoiseGenerator::floor($dX);
$z1 = NoiseGenerator::floor($dZ);
$dX -= $x1;
$dZ -= $z1;
$x1 %= 16777216;
$z1 %= 16777216;
//$x1 &= 0xFFFFFF;
//$z1 &= 0xFFFFFF;
$dX += $x1;
$dZ += $z1;
$octave->populateNoiseArray($adouble, $dX, $dY, $dZ, $sizeX, $sizeY, $sizeZ, $fX * $d3, $fY * $d3, $fZ * $d3, $d3);
$d3 *= 0.5;
}
return $adouble;
}*/
}

View File

@ -55,7 +55,7 @@ class SpruceTreeObject extends TreeObject{
public function placeObject(Level $level, Vector3 $pos, Random $random){ public function placeObject(Level $level, Vector3 $pos, Random $random){
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) { if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
$this->findRandomLeavesSize(); $this->findRandomLeavesSize($random);
} }
$level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock()); $level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock());
$leavesRadius = 0; $leavesRadius = 0;

View File

@ -47,8 +47,8 @@ class TreeObject{
$tree = new SmallTreeObject(); $tree = new SmallTreeObject();
$tree->type = SaplingBlock::JUNGLE; $tree->type = SaplingBlock::JUNGLE;
break; break;
default:
case SaplingBlock::OAK: case SaplingBlock::OAK:
default:
/*if($random->nextRange(0, 9) === 0){ /*if($random->nextRange(0, 9) === 0){
$tree = new BigTreeObject(); $tree = new BigTreeObject();
}else{*/ }else{*/