From 8de39db59dad980cafd35d44ee0e0d694d0e4a71 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 9 Feb 2014 14:39:17 +0100 Subject: [PATCH 001/173] Updated chunk packet field names --- src/Player.php | 4 ++-- src/network/protocol/packet/ChunkDataPacket.php | 8 ++++---- src/network/protocol/packet/RequestChunkPacket.php | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Player.php b/src/Player.php index 87572c40e..c8c19b930 100644 --- a/src/Player.php +++ b/src/Player.php @@ -218,8 +218,8 @@ class Player{ } } $pk = new ChunkDataPacket; - $pk->x = $X; - $pk->z = $Z; + $pk->chunkX = $X; + $pk->chunkZ = $Z; $pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex); $cnt = $this->dataPacket($pk); if($cnt === false){ diff --git a/src/network/protocol/packet/ChunkDataPacket.php b/src/network/protocol/packet/ChunkDataPacket.php index 0546f55f8..05ccb67f1 100644 --- a/src/network/protocol/packet/ChunkDataPacket.php +++ b/src/network/protocol/packet/ChunkDataPacket.php @@ -20,8 +20,8 @@ */ class ChunkDataPacket extends RakNetDataPacket{ - public $x; - public $z; + public $chunkX; + public $chunkZ; public $data; public function pid(){ @@ -34,8 +34,8 @@ class ChunkDataPacket extends RakNetDataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->x); - $this->putInt($this->z); + $this->putInt($this->chunkX); + $this->putInt($this->chunkZ); $this->put($this->data); } diff --git a/src/network/protocol/packet/RequestChunkPacket.php b/src/network/protocol/packet/RequestChunkPacket.php index 8629e0519..f3f3b604c 100644 --- a/src/network/protocol/packet/RequestChunkPacket.php +++ b/src/network/protocol/packet/RequestChunkPacket.php @@ -20,16 +20,16 @@ */ class RequestChunkPacket extends RakNetDataPacket{ - public $x; - public $z; + public $chunkX; + public $chunkZ; public function pid(){ return ProtocolInfo::REQUEST_CHUNK_PACKET; } public function decode(){ - $this->x = $this->getInt(); - $this->z = $this->getInt(); + $this->chunkX = $this->getInt(); + $this->chunkZ = $this->getInt(); } public function encode(){ From 7e174eac5abfa193d82f3c0cf24b615a634cd4b6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 13:26:09 +0100 Subject: [PATCH 002/173] Decreased SO_SNDBUF --- src/network/UDPSocket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/UDPSocket.php b/src/network/UDPSocket.php index 72355beb6..ee9df38e0 100644 --- a/src/network/UDPSocket.php +++ b/src/network/UDPSocket.php @@ -34,7 +34,7 @@ class UDPSocket{ }else{ if(socket_bind($this->sock, $serverip, $port) === true){ socket_set_option($this->sock, SOL_SOCKET, SO_REUSEADDR, 0); - socket_set_option($this->sock, SOL_SOCKET, SO_SNDBUF, 1024 * 1024 * 8); //8MB + socket_set_option($this->sock, SOL_SOCKET, SO_SNDBUF, 1024 * 1024 * 2); //2MB socket_set_option($this->sock, SOL_SOCKET, SO_RCVBUF, 1024 * 1024); //1MB $this->unblock(); $this->connected = true; From d925640f03be4a3d228bf69c0693c092c87aaa93 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 13:28:54 +0100 Subject: [PATCH 003/173] Moved max-chunks-per-second to server.properties, increased to 8 --- src/API/ServerAPI.php | 4 ++++ src/constants/GeneralConstants.php | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 7ea988476..1f07c6ee4 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -134,8 +134,12 @@ class ServerAPI{ )); $this->parseProperties(); + + //Load advanced properties define("DEBUG", $this->getProperty("debug", 1)); define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); + define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s + if($this->getProperty("port") !== false){ $this->setProperty("server-port", $this->getProperty("port")); $this->config->remove("port"); diff --git a/src/constants/GeneralConstants.php b/src/constants/GeneralConstants.php index 9febec891..b60b45aca 100644 --- a/src/constants/GeneralConstants.php +++ b/src/constants/GeneralConstants.php @@ -31,7 +31,6 @@ define("VIEWER", 3); //Players -define("MAX_CHUNK_RATE", 20 / arg("max-chunks-per-second", 4)); //Default rate ~256 kB/s define("PLAYER_MAX_QUEUE", 1024); define("PLAYER_SURVIVAL_SLOTS", 36); From b9aa3a0e70fd87d763481946437866ce59010807 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 13:29:21 +0100 Subject: [PATCH 004/173] Removed old code for property migration --- src/API/ServerAPI.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 1f07c6ee4..4700ea2fb 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -139,12 +139,7 @@ class ServerAPI{ define("DEBUG", $this->getProperty("debug", 1)); define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s - - if($this->getProperty("port") !== false){ - $this->setProperty("server-port", $this->getProperty("port")); - $this->config->remove("port"); - $this->config->remove("invisible"); - } + $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"); $this->server->api = $this; self::$serverRequest = $this->server; From 7c12f6ce8a35fc1563dd6ecc9ee43e999794b3c6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 15:05:12 +0100 Subject: [PATCH 005/173] Implemented QueryPacket and QueryHandler --- src/API/ServerAPI.php | 21 ++++---- src/PocketMinecraftServer.php | 2 +- src/network/MinecraftInterface.php | 12 +++-- .../{Query.php => query/QueryHandler.php} | 51 ++++++++----------- src/network/query/QueryPacket.php | 41 +++++++++++++++ 5 files changed, 82 insertions(+), 45 deletions(-) rename src/network/{Query.php => query/QueryHandler.php} (74%) create mode 100644 src/network/query/QueryPacket.php diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 4700ea2fb..8a999a593 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -28,7 +28,8 @@ class ServerAPI{ private $apiList = array(); private $asyncCnt = 0; private $rcon; - private $query; + + public $query; //TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs. @@ -139,6 +140,13 @@ class ServerAPI{ define("DEBUG", $this->getProperty("debug", 1)); define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s + if(ADVANCED_CACHE == true){ + console("[INFO] Advanced cache enabled"); + } + if($this->getProperty("upnp-forwarding") == true){ + console("[INFO] [UPnP] Trying to port forward..."); + UPnP_PortForward($this->getProperty("server-port")); + } $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"); $this->server->api = $this; @@ -146,15 +154,6 @@ class ServerAPI{ console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.")", true, true, 0); console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0); - if(ADVANCED_CACHE == true){ - console("[INFO] Advanced cache enabled"); - } - - if($this->getProperty("upnp-forwarding") === true){ - console("[INFO] [UPnP] Trying to port forward..."); - UPnP_PortForward($this->getProperty("server-port")); - } - if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){ console("[INFO] Checking for new server version"); console("[INFO] Last check: ".FORMAT_AQUA.date("Y-m-d H:i:s", $this->getProperty("last-update"))."\x1b[0m"); @@ -348,7 +347,7 @@ class ServerAPI{ } if($this->getProperty("enable-query") === true){ - $this->query = new Query(); + $this->query = new QueryHandler(); } CraftingRecipes::init(); $this->server->init(); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 5a646e468..ac655f6cf 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -64,7 +64,7 @@ class PocketMinecraftServer{ $this->saveEnabled = true; $this->tickMeasure = array_fill(0, 40, 0); $this->setType("normal"); - $this->interface = new MinecraftInterface($this, "255.255.255.255", $this->port, true, false, $this->serverip); + $this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip); $this->stop = false; $this->ticks = 0; if(!defined("NO_THREADS")){ diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 1af83104d..dfa9c6b89 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -20,18 +20,16 @@ */ class MinecraftInterface{ - public $client; public $bandwidth; private $socket; private $packets; - function __construct($object, $server, $port = 25565, $listen = false, $client = false, $serverip = "0.0.0.0"){ - $this->socket = new UDPSocket($server, $port, (bool) $listen, $serverip); + function __construct($server, $port = 25565, $serverip = "0.0.0.0"){ + $this->socket = new UDPSocket($server, $port, true, $serverip); if($this->socket->connected === false){ console("[SEVERE] Couldn't bind to $serverip:".$port, true, true, 0); exit(1); } $this->bandwidth = array(0, 0, microtime(true)); - $this->client = (bool) $client; $this->start = microtime(true); $this->packets = array(); } @@ -65,6 +63,12 @@ class MinecraftInterface{ return $parser->packet; } return false; + }elseif($pid === 0xfe and $buffer{1} === "\xfd" and ServerAPI::request()->api->query instanceof QueryHandler){ + $packet = new QueryPacket; + $packet->ip = $source; + $packet->port = $port; + $packet->buffer = $buffer; + ServerAPI::request()->api->query->handle($packet); }else{ $packet = new Packet(); $packet->ip = $source; diff --git a/src/network/Query.php b/src/network/query/QueryHandler.php similarity index 74% rename from src/network/Query.php rename to src/network/query/QueryHandler.php index 3bfaab813..f300695bb 100644 --- a/src/network/Query.php +++ b/src/network/query/QueryHandler.php @@ -24,7 +24,7 @@ Implementation of the UT3 Query Protocol (GameSpot) Source: http://wiki.unrealadmin.org/UT3_query_protocol */ -class Query{ +class QueryHandler{ private $socket, $server, $lastToken, $token, $longData, $timeout; public function __construct(){ @@ -41,7 +41,7 @@ class Query{ Then, the Query class handles itself sending the packets in raw form, because packets can conflict with the MCPE ones. */ - $this->server->addHandler("server.unknownpacket.254", array($this, "packetHandler"), 50); + $this->server->schedule(20 * 30, array($this, "regenerateToken"), array(), true); $this->regenerateToken(); $this->lastToken = $this->token; @@ -94,48 +94,41 @@ class Query{ $this->token = Utils::readInt("\x00".Utils::getRandomBytes(3, false)); } - public function packetHandler($packet, $event){ - if($event !== "server.unknownpacket.254"){ - return; - } - $magic = substr($packet->buffer, 0, 2); - $offset = 2; - if($magic !== "\xfe\xfd"){ - return; - } - $type = ord($packet->buffer{2}); - ++$offset; - $sessionID = Utils::readInt(substr($packet->buffer, $offset, 4)); - $offset += 4; - $payload = substr($packet->buffer, $offset); - switch($type){ - case 9: //Handshake - $pk = new Packet; + public function handle(QueryPacket $packet){ + $packet->decode(); + switch($packet->packetType){ + case QueryPacket::HANDSHAKE: //Handshake + $pk = new QueryPacket; $pk->ip = $packet->ip; $pk->port = $packet->port; - $pk->buffer = chr(9).Utils::writeInt($sessionID).$this->token."\x00"; + $pk->packetType = QueryPacket::HANDSHAKE; + $pk->sessionID = $packet->sessionID; + $pk->payload = $this->token."\x00"; + $pk->encode(); $this->server->send($pk); break; - case 0: //Stat - $token = Utils::readInt(substr($payload, 0, 4)); + case QueryPacket::STATISTICS: //Stat + $token = Utils::readInt(substr($packet->payload, 0, 4)); if($token !== $this->token and $token !== $this->lastToken){ break; } - $pk = new Packet; + $pk = new QueryPacket; $pk->ip = $packet->ip; - $pk->port = $packet->port; - if(strlen($payload) === 8){ + $pk->port = $packet->port; + $pk->packetType = QueryPacket::STATISTICS; + $pk->sessionID = $packet->sessionID; + if(strlen($packet->payload) === 8){ if($this->timeout < microtime(true)){ $this->regenerateInfo(); } - $pk->buffer = chr(0).Utils::writeInt($sessionID).$this->longData; + $pk->payload = $this->longData; }else{ - $pk->buffer = chr(0).Utils::writeInt($sessionID).$this->server->name."\x00".(($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP")."\x00".$this->server->api->level->getDefault()->getName()."\x00".count($this->server->clients)."\x00".$this->server->maxClients."\x00".Utils::writeLShort($this->server->api->getProperty("server-port")).$this->server->api->getProperty("server-ip", "0.0.0.0")."\x00"; + $pk->payload = $this->server->name."\x00".(($this->server->gamemode & 0x01) === 0 ? "SMP":"CMP")."\x00".$this->server->api->level->getDefault()->getName()."\x00".count($this->server->clients)."\x00".$this->server->maxClients."\x00".Utils::writeLShort($this->server->api->getProperty("server-port")).$this->server->api->getProperty("server-ip", "0.0.0.0")."\x00"; } + $pk->encode(); $this->server->send($pk); break; } - return true; } -} +} \ No newline at end of file diff --git a/src/network/query/QueryPacket.php b/src/network/query/QueryPacket.php new file mode 100644 index 000000000..d0f0f148c --- /dev/null +++ b/src/network/query/QueryPacket.php @@ -0,0 +1,41 @@ +packetType = ord($this->buffer{2}); + $this->sessionID = Utils::readInt(substr($this->buffer, 3, 4)); + $this->payload = substr($this->buffer, 7); + } + + public function encode(){ + $this->buffer .= chr($this->packetType); + $this->buffer .= Utils::writeInt($this->sessionID); + $this->buffer .= $this->payload; + } +} \ No newline at end of file From 830530d868e22990e1f2b1f16d7727c9b2842d4a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 16:09:32 +0100 Subject: [PATCH 006/173] Basic Event types (extended from Bukkit) --- src/event/BaseEvent.php | 56 +++++++++++++++++++++++++ src/event/CancellableEvent.php | 30 +++++++++++++ src/event/EventPriority.php | 52 +++++++++++++++++++++++ src/event/MalleableCancellableEvent.php | 24 +++++++++++ src/event/MalleableEvent.php | 24 +++++++++++ 5 files changed, 186 insertions(+) create mode 100644 src/event/BaseEvent.php create mode 100644 src/event/CancellableEvent.php create mode 100644 src/event/EventPriority.php create mode 100644 src/event/MalleableCancellableEvent.php create mode 100644 src/event/MalleableEvent.php diff --git a/src/event/BaseEvent.php b/src/event/BaseEvent.php new file mode 100644 index 000000000..9a73cfeb5 --- /dev/null +++ b/src/event/BaseEvent.php @@ -0,0 +1,56 @@ +eventName !== null ? get_class($this) : $this->eventName; + } + + final public function setPrioritySlot($slot){ + $this->prioritySlot = (int) $slot; + } + + final public function getPrioritySlot(){ + return (int) $this->prioritySlot; + } + + + public function isAllowed(){ + return $this->status === BaseEvent::ALLOW; + } + + public function setAllowed($forceAllow = false){ + $this->status = BaseEvent::ALLOW & ($forceAllow === true ? BaseEvent::FORCE : 0); + } + + public function isForced(){ + return ($this->status & BaseEvent::FORCE) > 0; + } + +} \ No newline at end of file diff --git a/src/event/CancellableEvent.php b/src/event/CancellableEvent.php new file mode 100644 index 000000000..5d3fab8f0 --- /dev/null +++ b/src/event/CancellableEvent.php @@ -0,0 +1,30 @@ +status === BaseEvent::DENY; + } + + public function setCancelled($forceCancel = false){ + $this->status = BaseEvent::DENY & ($forceCancel === true ? BaseEvent::FORCE : 0); + } +} \ No newline at end of file diff --git a/src/event/EventPriority.php b/src/event/EventPriority.php new file mode 100644 index 000000000..f42e8d732 --- /dev/null +++ b/src/event/EventPriority.php @@ -0,0 +1,52 @@ + Date: Mon, 10 Feb 2014 17:23:35 +0100 Subject: [PATCH 007/173] Basic event system written --- src/API/ServerAPI.php | 9 +++++ src/event/BaseEvent.php | 70 +++++++++++++++++++++++++++++++++- src/event/CancellableEvent.php | 2 +- src/event/EventHandler.php | 50 ++++++++++++++++++++++++ src/utils/Utils.php | 8 ++++ 5 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/event/EventHandler.php diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 8a999a593..2126e4dca 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -98,6 +98,15 @@ class ServerAPI{ @mkdir(DATA_PATH."players/", 0755); @mkdir(DATA_PATH."worlds/", 0755); @mkdir(DATA_PATH."plugins/", 0755); + + //Init all the events + foreach(get_declared_classes() as $class){ + if(is_subclass_of($class, "BaseEvent") and property_exists($class, "handlers") and property_exists($class, "handlerPriority")){ + echo $class; + $class::unregisterAll(); + } + } + $version = new VersionString(); console("[INFO] Starting Minecraft PE server version ".FORMAT_AQUA.CURRENT_MINECRAFT_VERSION); diff --git a/src/event/BaseEvent.php b/src/event/BaseEvent.php index 9a73cfeb5..679739c43 100644 --- a/src/event/BaseEvent.php +++ b/src/event/BaseEvent.php @@ -25,8 +25,18 @@ abstract class BaseEvent{ const NORMAL = 2; const FORCE = 0x80000000; + /** + * Any callable event must declare the static variables + * + * private static $handlers; + * private static $handlerPriority; + * + * Not doing so will deny the proper event initialization + */ + protected $eventName = null; private $status = BaseEvent::NORMAL; + private $prioritySlot; final public function getEventName(){ return $this->eventName !== null ? get_class($this) : $this->eventName; @@ -42,15 +52,71 @@ abstract class BaseEvent{ public function isAllowed(){ - return $this->status === BaseEvent::ALLOW; + return ($this->status & 0x7FFFFFFF) === BaseEvent::ALLOW; } public function setAllowed($forceAllow = false){ $this->status = BaseEvent::ALLOW & ($forceAllow === true ? BaseEvent::FORCE : 0); } + public function isNormal(){ + return $this->status === BaseEvent::NORMAL; + } + + public function setNormal(){ + $this->status = BaseEvent::NORMAL; + } + public function isForced(){ return ($this->status & BaseEvent::FORCE) > 0; } - + + public static function getHandlerList(){ + return self::$handlers; + } + + public static function getPriorityList(){ + return self::$handlerPriority; + } + + public static function unregisterAll(){ + self::$handlers = array(); + self::$handlerPriority = array( + EventPriority::LOWEST => array(), + EventPriority::LOW => array(), + EventPriority::NORMAL => array(), + EventPriority::HIGH => array(), + EventPriority::HIGHEST => array(), + EventPriority::MONITOR => array() + ); + } + + public function register(callable $handler, $priority = EventPriority::NORMAL){ + $identifier = Utils::getCallableIdentifier($handler); + if(isset(self::$handlers[$identifier])){ //Already registered + return false; + }else{ + self::$handlers[$identifier] = $handler; + self::$handlerPriority[(int) $priority][$identifier] = $handler; + return true; + } + } + + public function unregister(callable $handler, $priority = EventPriority::NORMAL){ + $identifier = Utils::getCallableIdentifier($handler); + if(isset(self::$handlers[$identifier])){ + if(isset(self::$handlerPriority[(int) $priority][$identifier])){ + unset(self::$handlerPriority[(int) $priority][$identifier]); + }else{ + for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){ + unset(self::$handlerPriority[$priority][$identifier]); + } + } + unset(self::$handlers[$identifier]); + return true; + }else{ + return false; + } + } + } \ No newline at end of file diff --git a/src/event/CancellableEvent.php b/src/event/CancellableEvent.php index 5d3fab8f0..affb4132a 100644 --- a/src/event/CancellableEvent.php +++ b/src/event/CancellableEvent.php @@ -21,7 +21,7 @@ abstract class CancellableEvent extends BaseEvent{ public function isCancelled(){ - return $this->status === BaseEvent::DENY; + return ($this->status & 0x7FFFFFFF) === BaseEvent::DENY; } public function setCancelled($forceCancel = false){ diff --git a/src/event/EventHandler.php b/src/event/EventHandler.php new file mode 100644 index 000000000..50166b943 --- /dev/null +++ b/src/event/EventHandler.php @@ -0,0 +1,50 @@ + $handlerList){ + if(count($handlerList) > 0){ + $event->setPrioritySlot($priority); + foreach($handlerList as $handler){ + call_user_func($handler, $event); + } + if($event->isForced()){ + if($event instanceof CancellableEvent and $event->isCancelled()){ + return BaseEvent::DENY; + }else{ + return BaseEvent::ALLOW; + } + } + } + } + if($event instanceof CancellableEvent and $event->isCancelled()){ + return BaseEvent::DENY; + }elseif($event->isAllowed()){ + return BaseEvent::ALLOW; + }else{ + return BaseEvent::NORMAL; + } + } + +} \ No newline at end of file diff --git a/src/utils/Utils.php b/src/utils/Utils.php index c25597941..510337d81 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -31,6 +31,14 @@ class Utils{ return ((@fsockopen("8.8.8.8", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.linux.org", 80, $e = null, $n = null, 2) !== false or @fsockopen("www.php.net", 80, $e = null, $n = null, 2) !== false) ? true:false); } + public static function getCallableIdentifier(callable $variable){ + if(is_array($variable)){ + return sha1(strtolower(get_class($variable))."::".strtolower($variable[1])); + }else{ + return sha1(strtolower($variable)); + } + } + public static function getUniqueID($raw = false, $extra = ""){ $machine = php_uname("a"); $machine .= file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : ""; From a4cbb2f938a051aa1070a8e6782563a5b954bb74 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 17:33:12 +0100 Subject: [PATCH 008/173] Added PluginEvent --- src/event/BaseEvent.php | 20 +++++++++------- src/event/EventHandler.php | 2 ++ src/event/MalleableEvent.php | 24 ------------------- ...leCancellableEvent.php => PluginEvent.php} | 11 ++++++++- 4 files changed, 23 insertions(+), 34 deletions(-) delete mode 100644 src/event/MalleableEvent.php rename src/event/{MalleableCancellableEvent.php => PluginEvent.php} (78%) diff --git a/src/event/BaseEvent.php b/src/event/BaseEvent.php index 679739c43..e0744ea11 100644 --- a/src/event/BaseEvent.php +++ b/src/event/BaseEvent.php @@ -81,22 +81,21 @@ abstract class BaseEvent{ public static function unregisterAll(){ self::$handlers = array(); - self::$handlerPriority = array( - EventPriority::LOWEST => array(), - EventPriority::LOW => array(), - EventPriority::NORMAL => array(), - EventPriority::HIGH => array(), - EventPriority::HIGHEST => array(), - EventPriority::MONITOR => array() - ); + self::$handlerPriority = array(); } public function register(callable $handler, $priority = EventPriority::NORMAL){ + if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){ + return false; + } $identifier = Utils::getCallableIdentifier($handler); if(isset(self::$handlers[$identifier])){ //Already registered return false; }else{ self::$handlers[$identifier] = $handler; + if(!isset(self::$handlerPriority[(int) $priority])){ + self::$handlerPriority[(int) $priority] = array(); + } self::$handlerPriority[(int) $priority][$identifier] = $handler; return true; } @@ -110,8 +109,11 @@ abstract class BaseEvent{ }else{ for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){ unset(self::$handlerPriority[$priority][$identifier]); + if(count(self::$handlerPriority[$priority]) === 0){ + unset(self::$handlerPriority[$priority]); + } } - } + } unset(self::$handlers[$identifier]); return true; }else{ diff --git a/src/event/EventHandler.php b/src/event/EventHandler.php index 50166b943..9a2cf5019 100644 --- a/src/event/EventHandler.php +++ b/src/event/EventHandler.php @@ -38,6 +38,7 @@ abstract class EventHandler{ } } } + if($event instanceof CancellableEvent and $event->isCancelled()){ return BaseEvent::DENY; }elseif($event->isAllowed()){ @@ -45,6 +46,7 @@ abstract class EventHandler{ }else{ return BaseEvent::NORMAL; } + } } \ No newline at end of file diff --git a/src/event/MalleableEvent.php b/src/event/MalleableEvent.php deleted file mode 100644 index 90c1817ef..000000000 --- a/src/event/MalleableEvent.php +++ /dev/null @@ -1,24 +0,0 @@ - Date: Mon, 10 Feb 2014 18:08:25 +0100 Subject: [PATCH 009/173] Final structure with example events --- src/API/ServerAPI.php | 1 - src/event/BaseEvent.php | 47 ++++++++++++------- src/event/CancellableEvent.php | 14 +++--- src/event/EventHandler.php | 2 +- src/event/PluginEvent.php | 6 +-- src/event/ServerEvent.php | 24 ++++++++++ src/event/server/RakNetPacketReceiveEvent.php | 36 ++++++++++++++ src/event/server/RakNetPacketSendEvent.php | 36 ++++++++++++++ .../server/UnknownPacketReceiveEvent.php | 36 ++++++++++++++ src/event/server/UnknownPacketSendEvent.php | 36 ++++++++++++++ src/network/MinecraftInterface.php | 19 ++++++-- .../protocol/packet/ClientHandshakePacket.php | 4 +- 12 files changed, 221 insertions(+), 40 deletions(-) create mode 100644 src/event/ServerEvent.php create mode 100644 src/event/server/RakNetPacketReceiveEvent.php create mode 100644 src/event/server/RakNetPacketSendEvent.php create mode 100644 src/event/server/UnknownPacketReceiveEvent.php create mode 100644 src/event/server/UnknownPacketSendEvent.php diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 2126e4dca..9aa7c7289 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -102,7 +102,6 @@ class ServerAPI{ //Init all the events foreach(get_declared_classes() as $class){ if(is_subclass_of($class, "BaseEvent") and property_exists($class, "handlers") and property_exists($class, "handlerPriority")){ - echo $class; $class::unregisterAll(); } } diff --git a/src/event/BaseEvent.php b/src/event/BaseEvent.php index e0744ea11..fb65432f7 100644 --- a/src/event/BaseEvent.php +++ b/src/event/BaseEvent.php @@ -28,8 +28,8 @@ abstract class BaseEvent{ /** * Any callable event must declare the static variables * - * private static $handlers; - * private static $handlerPriority; + * public static $handlers; + * public static $handlerPriority; * * Not doing so will deny the proper event initialization */ @@ -59,6 +59,17 @@ abstract class BaseEvent{ $this->status = BaseEvent::ALLOW & ($forceAllow === true ? BaseEvent::FORCE : 0); } + public function isCancelled(){ + return ($this->status & 0x7FFFFFFF) === BaseEvent::DENY; + } + + public function setCancelled($forceCancel = false){ + if($this instanceof CancellableEvent){ + $this->status = BaseEvent::DENY & ($forceCancel === true ? BaseEvent::FORCE : 0); + } + return false; + } + public function isNormal(){ return $this->status === BaseEvent::NORMAL; } @@ -72,16 +83,16 @@ abstract class BaseEvent{ } public static function getHandlerList(){ - return self::$handlers; + return static::$handlers; } public static function getPriorityList(){ - return self::$handlerPriority; + return static::$handlerPriority; } public static function unregisterAll(){ - self::$handlers = array(); - self::$handlerPriority = array(); + static::$handlers = array(); + static::$handlerPriority = array(); } public function register(callable $handler, $priority = EventPriority::NORMAL){ @@ -89,32 +100,32 @@ abstract class BaseEvent{ return false; } $identifier = Utils::getCallableIdentifier($handler); - if(isset(self::$handlers[$identifier])){ //Already registered + if(isset(static::$handlers[$identifier])){ //Already registered return false; }else{ - self::$handlers[$identifier] = $handler; - if(!isset(self::$handlerPriority[(int) $priority])){ - self::$handlerPriority[(int) $priority] = array(); + static::$handlers[$identifier] = $handler; + if(!isset(static::$handlerPriority[(int) $priority])){ + static::$handlerPriority[(int) $priority] = array(); } - self::$handlerPriority[(int) $priority][$identifier] = $handler; + static::$handlerPriority[(int) $priority][$identifier] = $handler; return true; } } public function unregister(callable $handler, $priority = EventPriority::NORMAL){ $identifier = Utils::getCallableIdentifier($handler); - if(isset(self::$handlers[$identifier])){ - if(isset(self::$handlerPriority[(int) $priority][$identifier])){ - unset(self::$handlerPriority[(int) $priority][$identifier]); + if(isset(static::$handlers[$identifier])){ + if(isset(static::$handlerPriority[(int) $priority][$identifier])){ + unset(static::$handlerPriority[(int) $priority][$identifier]); }else{ for($priority = EventPriority::MONITOR; $priority <= EventPriority::LOWEST; ++$priority){ - unset(self::$handlerPriority[$priority][$identifier]); - if(count(self::$handlerPriority[$priority]) === 0){ - unset(self::$handlerPriority[$priority]); + unset(static::$handlerPriority[$priority][$identifier]); + if(count(static::$handlerPriority[$priority]) === 0){ + unset(static::$handlerPriority[$priority]); } } } - unset(self::$handlers[$identifier]); + unset(static::$handlers[$identifier]); return true; }else{ return false; diff --git a/src/event/CancellableEvent.php b/src/event/CancellableEvent.php index affb4132a..11b64cb22 100644 --- a/src/event/CancellableEvent.php +++ b/src/event/CancellableEvent.php @@ -19,12 +19,10 @@ * */ -abstract class CancellableEvent extends BaseEvent{ - public function isCancelled(){ - return ($this->status & 0x7FFFFFFF) === BaseEvent::DENY; - } - - public function setCancelled($forceCancel = false){ - $this->status = BaseEvent::DENY & ($forceCancel === true ? BaseEvent::FORCE : 0); - } +/** + * Events that can be cancelled must use the interface CancellableEvent + */ + +interface CancellableEvent{ + } \ No newline at end of file diff --git a/src/event/EventHandler.php b/src/event/EventHandler.php index 9a2cf5019..7498cfaff 100644 --- a/src/event/EventHandler.php +++ b/src/event/EventHandler.php @@ -23,7 +23,7 @@ abstract class EventHandler{ public static function callEvent(BaseEvent $event){ $status = BaseEvent::NORMAL; - foreach($event::getPriorityList() as $priority => $handlerList){ + foreach($event::$handlerPriority as $priority => $handlerList){ if(count($handlerList) > 0){ $event->setPrioritySlot($priority); foreach($handlerList as $handler){ diff --git a/src/event/PluginEvent.php b/src/event/PluginEvent.php index c98573f80..d7a483be3 100644 --- a/src/event/PluginEvent.php +++ b/src/event/PluginEvent.php @@ -21,13 +21,9 @@ /** - * Plugins that create events must use one of these classes as the base + * Plugins that create events must use this class as the base */ abstract class PluginEvent extends BaseEvent{ -} - -abstract class CancellablePluginEvent extends CancellableEvent{ - } \ No newline at end of file diff --git a/src/event/ServerEvent.php b/src/event/ServerEvent.php new file mode 100644 index 000000000..f99355828 --- /dev/null +++ b/src/event/ServerEvent.php @@ -0,0 +1,24 @@ +packet = $packet; + } + + public function getPacket(){ + return $this->packet; + } +} \ No newline at end of file diff --git a/src/event/server/RakNetPacketSendEvent.php b/src/event/server/RakNetPacketSendEvent.php new file mode 100644 index 000000000..ae3048087 --- /dev/null +++ b/src/event/server/RakNetPacketSendEvent.php @@ -0,0 +1,36 @@ +packet = $packet; + } + + public function getPacket(){ + return $this->packet; + } +} \ No newline at end of file diff --git a/src/event/server/UnknownPacketReceiveEvent.php b/src/event/server/UnknownPacketReceiveEvent.php new file mode 100644 index 000000000..322c6807f --- /dev/null +++ b/src/event/server/UnknownPacketReceiveEvent.php @@ -0,0 +1,36 @@ +packet = $packet; + } + + public function getPacket(){ + return $this->packet; + } +} \ No newline at end of file diff --git a/src/event/server/UnknownPacketSendEvent.php b/src/event/server/UnknownPacketSendEvent.php new file mode 100644 index 000000000..31820d881 --- /dev/null +++ b/src/event/server/UnknownPacketSendEvent.php @@ -0,0 +1,36 @@ +packet = $packet; + } + + public function getPacket(){ + return $this->packet; + } +} \ No newline at end of file diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index dfa9c6b89..1cd0cea6b 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -60,7 +60,9 @@ class MinecraftInterface{ if($parser->packet !== false){ $parser->packet->ip = $source; $parser->packet->port = $port; - return $parser->packet; + if(EventHandler::callEvent(new RakNetPacketReceiveEvent($parser->packet)) !== BaseEvent::DENY){ + return $parser->packet; + } } return false; }elseif($pid === 0xfe and $buffer{1} === "\xfd" and ServerAPI::request()->api->query instanceof QueryHandler){ @@ -74,16 +76,23 @@ class MinecraftInterface{ $packet->ip = $source; $packet->port = $port; $packet->buffer = $buffer; - if(ServerAPI::request()->api->dhandle("server.unknownpacket.$pid", $packet) !== true){ - console("[ERROR] Unknown Packet ID 0x".Utils::strToHex(chr($pid)), true, true, 2); - } + EventHandler::callEvent(new UnknownPacketReceiveEvent($packet)); return false; } } public function writePacket(Packet $packet){ if($packet instanceof RakNetPacket){ - $codec = new RakNetCodec($packet); + if(EventHandler::callEvent(new RakNetPacketSendEvent($packet)) === BaseEvent::DENY){ + return 0; + } + $codec = new RakNetCodec($packet); + }elseif($packet instanceof QueryPacket){ + + }else{ + if(EventHandler::callEvent(new UnknownPacketSendEvent($packet)) === BaseEvent::DENY){ + return 0; + } } $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); $this->bandwidth[1] += $write; diff --git a/src/network/protocol/packet/ClientHandshakePacket.php b/src/network/protocol/packet/ClientHandshakePacket.php index 2cac9e8d4..b718ebfc8 100644 --- a/src/network/protocol/packet/ClientHandshakePacket.php +++ b/src/network/protocol/packet/ClientHandshakePacket.php @@ -25,7 +25,7 @@ class ClientHandshakePacket extends RakNetDataPacket{ public $port; public $dataArray0; public $dataArray; - public $timespamp; + public $timestamp; public $session2; public $session; @@ -39,7 +39,7 @@ class ClientHandshakePacket extends RakNetDataPacket{ $this->port = $this->getShort(true); $this->dataArray0 = $this->get($this->getByte()); $this->dataArray = $this->getDataArray(9); - $this->timespamp = $this->get(2); + $this->timestamp = $this->get(2); $this->session2 = $this->getLong(); $this->session = $this->getLong(); } From a2ec9d6688e4530cb0c2ac755b7c12a2acdc8b06 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 18:10:51 +0100 Subject: [PATCH 010/173] Moved a file --- src/{event => }/BaseEvent.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{event => }/BaseEvent.php (100%) diff --git a/src/event/BaseEvent.php b/src/BaseEvent.php similarity index 100% rename from src/event/BaseEvent.php rename to src/BaseEvent.php From 0bf74d4139cdc4ae31155bd9cc70443e9fe9973f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 18:46:58 +0100 Subject: [PATCH 011/173] Two packet event types ;) --- src/Player.php | 17 ++++++++++++- ...ndEvent.php => DataPacketReceiveEvent.php} | 10 +++++--- ...ceiveEvent.php => DataPacketSendEvent.php} | 10 +++++--- ...etSendEvent.php => PacketReceiveEvent.php} | 2 +- ...etReceiveEvent.php => PacketSendEvent.php} | 2 +- src/network/MinecraftInterface.php | 24 +++++++++---------- 6 files changed, 43 insertions(+), 22 deletions(-) rename src/event/server/{RakNetPacketSendEvent.php => DataPacketReceiveEvent.php} (79%) rename src/event/server/{RakNetPacketReceiveEvent.php => DataPacketSendEvent.php} (79%) rename src/event/server/{UnknownPacketSendEvent.php => PacketReceiveEvent.php} (92%) rename src/event/server/{UnknownPacketReceiveEvent.php => PacketSendEvent.php} (91%) diff --git a/src/Player.php b/src/Player.php index c8c19b930..ae4f87d79 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1253,6 +1253,11 @@ class Player{ if($this->connected === false){ return; } + + if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){ + return; + } + switch($packet->pid()){ case 0x01: break; @@ -2315,7 +2320,7 @@ class Player{ $this->nextBuffer = microtime(true) + 0.1; } - public function directBigRawPacket(RakNetDataPacket $packet){ + private function directBigRawPacket(RakNetDataPacket $packet){ if($this->connected === false){ return false; } @@ -2355,6 +2360,11 @@ class Player{ if($this->connected === false){ return false; } + + if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ + return array(); + } + $packet->encode(); $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk->data[] = $packet; @@ -2378,6 +2388,11 @@ class Player{ if($this->connected === false){ return false; } + + if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ + return; + } + $packet->encode(); $len = strlen($packet->buffer) + 1; $MTU = $this->MTU - 24; diff --git a/src/event/server/RakNetPacketSendEvent.php b/src/event/server/DataPacketReceiveEvent.php similarity index 79% rename from src/event/server/RakNetPacketSendEvent.php rename to src/event/server/DataPacketReceiveEvent.php index ae3048087..1a3a0b67a 100644 --- a/src/event/server/RakNetPacketSendEvent.php +++ b/src/event/server/DataPacketReceiveEvent.php @@ -19,18 +19,22 @@ * */ -class RakNetPacketSendEvent extends ServerEvent implements CancellableEvent{ +class DataPacketReceiveEvent extends ServerEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; private $packet; + private $player; - - public function __construct(RakNetPacket $packet){ + public function __construct(Player $player, RakNetDataPacket $packet){ $this->packet = $packet; } public function getPacket(){ return $this->packet; } + + public function getPlayer(){ + return $this->player; + } } \ No newline at end of file diff --git a/src/event/server/RakNetPacketReceiveEvent.php b/src/event/server/DataPacketSendEvent.php similarity index 79% rename from src/event/server/RakNetPacketReceiveEvent.php rename to src/event/server/DataPacketSendEvent.php index 372821fda..a1935430d 100644 --- a/src/event/server/RakNetPacketReceiveEvent.php +++ b/src/event/server/DataPacketSendEvent.php @@ -19,18 +19,22 @@ * */ -class RakNetPacketReceiveEvent extends ServerEvent implements CancellableEvent{ +class DataPacketSendEvent extends ServerEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; private $packet; + private $player; - - public function __construct(RakNetPacket $packet){ + public function __construct(Player $player, RakNetDataPacket $packet){ $this->packet = $packet; } public function getPacket(){ return $this->packet; } + + public function getPlayer(){ + return $this->player; + } } \ No newline at end of file diff --git a/src/event/server/UnknownPacketSendEvent.php b/src/event/server/PacketReceiveEvent.php similarity index 92% rename from src/event/server/UnknownPacketSendEvent.php rename to src/event/server/PacketReceiveEvent.php index 31820d881..cb26cbf05 100644 --- a/src/event/server/UnknownPacketSendEvent.php +++ b/src/event/server/PacketReceiveEvent.php @@ -19,7 +19,7 @@ * */ -class UnknownPacketSendEvent extends ServerEvent implements CancellableEvent{ +class PacketReceiveEvent extends ServerEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; diff --git a/src/event/server/UnknownPacketReceiveEvent.php b/src/event/server/PacketSendEvent.php similarity index 91% rename from src/event/server/UnknownPacketReceiveEvent.php rename to src/event/server/PacketSendEvent.php index 322c6807f..becb15e48 100644 --- a/src/event/server/UnknownPacketReceiveEvent.php +++ b/src/event/server/PacketSendEvent.php @@ -19,7 +19,7 @@ * */ -class UnknownPacketReceiveEvent extends ServerEvent implements CancellableEvent{ +class PacketSendEvent extends ServerEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 1cd0cea6b..f7e149c04 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -55,14 +55,16 @@ class MinecraftInterface{ private function parsePacket($buffer, $source, $port){ $pid = ord($buffer{0}); + if(RakNetInfo::isValid($pid)){ $parser = new RakNetParser($buffer); if($parser->packet !== false){ $parser->packet->ip = $source; $parser->packet->port = $port; - if(EventHandler::callEvent(new RakNetPacketReceiveEvent($parser->packet)) !== BaseEvent::DENY){ - return $parser->packet; + if(EventHandler::callEvent(new PacketReceiveEvent($parser->packet)) === BaseEvent::DENY){ + return false; } + return $parser->packet; } return false; }elseif($pid === 0xfe and $buffer{1} === "\xfd" and ServerAPI::request()->api->query instanceof QueryHandler){ @@ -70,29 +72,25 @@ class MinecraftInterface{ $packet->ip = $source; $packet->port = $port; $packet->buffer = $buffer; + if(EventHandler::callEvent(new PacketReceiveEvent($packet)) === BaseEvent::DENY){ + return false; + } ServerAPI::request()->api->query->handle($packet); }else{ $packet = new Packet(); $packet->ip = $source; $packet->port = $port; $packet->buffer = $buffer; - EventHandler::callEvent(new UnknownPacketReceiveEvent($packet)); + EventHandler::callEvent(new PacketReceiveEvent($packet)); return false; } } public function writePacket(Packet $packet){ - if($packet instanceof RakNetPacket){ - if(EventHandler::callEvent(new RakNetPacketSendEvent($packet)) === BaseEvent::DENY){ - return 0; - } + if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){ + return 0; + }elseif($packet instanceof RakNetPacket){ $codec = new RakNetCodec($packet); - }elseif($packet instanceof QueryPacket){ - - }else{ - if(EventHandler::callEvent(new UnknownPacketSendEvent($packet)) === BaseEvent::DENY){ - return 0; - } } $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); $this->bandwidth[1] += $write; From 5057a3965e75a1dc1ca64ce792e5f432977a1963 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 20:46:47 +0100 Subject: [PATCH 012/173] Ooops, ;) --- src/BaseEvent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BaseEvent.php b/src/BaseEvent.php index fb65432f7..0929cb2bf 100644 --- a/src/BaseEvent.php +++ b/src/BaseEvent.php @@ -95,7 +95,7 @@ abstract class BaseEvent{ static::$handlerPriority = array(); } - public function register(callable $handler, $priority = EventPriority::NORMAL){ + public static function register(callable $handler, $priority = EventPriority::NORMAL){ if($priority < EventPriority::MONITOR or $priority > EventPriority::LOWEST){ return false; } @@ -112,7 +112,7 @@ abstract class BaseEvent{ } } - public function unregister(callable $handler, $priority = EventPriority::NORMAL){ + public static function unregister(callable $handler, $priority = EventPriority::NORMAL){ $identifier = Utils::getCallableIdentifier($handler); if(isset(static::$handlers[$identifier])){ if(isset(static::$handlerPriority[(int) $priority][$identifier])){ From b635a54b1397bf62ec0bbf22a4fd4d9b917a0aef Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 20:47:21 +0100 Subject: [PATCH 013/173] Oops x2 --- src/utils/Utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/Utils.php b/src/utils/Utils.php index a27a62ca7..fff7aa293 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -33,7 +33,7 @@ class Utils{ public static function getCallableIdentifier(callable $variable){ if(is_array($variable)){ - return sha1(strtolower(get_class($variable))."::".strtolower($variable[1])); + return sha1(strtolower(get_class($variable[0]))."::".strtolower($variable[1])); }else{ return sha1(strtolower($variable)); } From 94f2da1e38cbfbf61ef9d9ae83ac0794b0a5f080 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 20:52:10 +0100 Subject: [PATCH 014/173] Oops x3 --- src/event/server/DataPacketReceiveEvent.php | 1 + src/event/server/DataPacketSendEvent.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/event/server/DataPacketReceiveEvent.php b/src/event/server/DataPacketReceiveEvent.php index 1a3a0b67a..ee0faf394 100644 --- a/src/event/server/DataPacketReceiveEvent.php +++ b/src/event/server/DataPacketReceiveEvent.php @@ -28,6 +28,7 @@ class DataPacketReceiveEvent extends ServerEvent implements CancellableEvent{ public function __construct(Player $player, RakNetDataPacket $packet){ $this->packet = $packet; + $this->player = $player; } public function getPacket(){ diff --git a/src/event/server/DataPacketSendEvent.php b/src/event/server/DataPacketSendEvent.php index a1935430d..5e55a29b9 100644 --- a/src/event/server/DataPacketSendEvent.php +++ b/src/event/server/DataPacketSendEvent.php @@ -28,6 +28,7 @@ class DataPacketSendEvent extends ServerEvent implements CancellableEvent{ public function __construct(Player $player, RakNetDataPacket $packet){ $this->packet = $packet; + $this->player = $player; } public function getPacket(){ From 9cd5c1581bc97d1dda10229104b48ff90e8220b9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 10 Feb 2014 21:38:32 +0100 Subject: [PATCH 015/173] oops x4 --- src/BaseEvent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BaseEvent.php b/src/BaseEvent.php index 0929cb2bf..38b81c851 100644 --- a/src/BaseEvent.php +++ b/src/BaseEvent.php @@ -56,7 +56,7 @@ abstract class BaseEvent{ } public function setAllowed($forceAllow = false){ - $this->status = BaseEvent::ALLOW & ($forceAllow === true ? BaseEvent::FORCE : 0); + $this->status = BaseEvent::ALLOW | ($forceAllow === true ? BaseEvent::FORCE : 0); } public function isCancelled(){ @@ -65,7 +65,7 @@ abstract class BaseEvent{ public function setCancelled($forceCancel = false){ if($this instanceof CancellableEvent){ - $this->status = BaseEvent::DENY & ($forceCancel === true ? BaseEvent::FORCE : 0); + $this->status = BaseEvent::DENY | ($forceCancel === true ? BaseEvent::FORCE : 0); } return false; } From ad3bf0998f06783015c2266781f8eaf563c8d4d7 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 11 Feb 2014 01:41:04 +0100 Subject: [PATCH 016/173] Halt NBT parsing if end of data is found --- src/utils/NBT.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/NBT.php b/src/utils/NBT.php index b6e797424..f85f637bd 100644 --- a/src/utils/NBT.php +++ b/src/utils/NBT.php @@ -44,6 +44,10 @@ class NBT{ return substr($this->binary, $this->offset - $n, $n); } + private function feof(){ + return !isset($this->binary{$this->offset}); + } + public function write($bin){ $this->binary .= $bin; } @@ -119,7 +123,7 @@ class NBT{ } private function parseList(&$node, $tag, $cnt){ - for($i = 0; $i < $cnt; ++$i){ + for($i = 0; $i < $cnt and !$this->feof(); ++$i){ switch($tag){ case self::TAG_BYTE: $value = $this->readTAG_BYTE(); @@ -163,7 +167,7 @@ class NBT{ } private function parseTree(&$node){ - while(($tag = ord($this->read(1))) !== self::TAG_END){ + while(($tag = ord($this->read(1))) !== self::TAG_END and !$this->feof()){ $name = $this->readTAG_STRING(); switch($tag){ case self::TAG_BYTE: From 8b23568fe75954f244fcd9f7f3e5831c95c14fe7 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 11 Feb 2014 02:31:41 +0100 Subject: [PATCH 017/173] Changed codename to new scheme. Alpha_1.3.12 ready \o/ --- src/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.php b/src/config.php index b93bee79d..2b9c53afa 100644 --- a/src/config.php +++ b/src/config.php @@ -67,8 +67,8 @@ set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH); ini_set("memory_limit", "128M"); //Default define("LOG", true); define("START_TIME", microtime(true)); -define("MAJOR_VERSION", "Alpha_1.3.12dev"); -define("CODENAME", "変梃(Henteko)マインカート(Minecart)"); +define("MAJOR_VERSION", "Alpha_1.3.12"); +define("CODENAME", "甘い(Amai)ビートルート(Beetroot)"); define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha"); define("CURRENT_API_VERSION", 12); define("CURRENT_PHP_VERSION", "5.5"); From c09bc259fcc472df1a592ad471a9988ec6f4c3b5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 11 Feb 2014 10:27:53 +0100 Subject: [PATCH 018/173] Added #1142 OP players can bypass the player limit --- src/Player.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Player.php b/src/Player.php index ae4f87d79..966f9cf5b 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1291,8 +1291,10 @@ class Player{ if($this->loggedIn === true){ break; } + $this->username = $packet->username; + $this->iusername = strtolower($this->username); $this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData); - if(count($this->server->clients) > $this->server->maxClients){ + if(count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){ $this->close("server is full!", false); return; } @@ -1307,16 +1309,11 @@ class Player{ $this->directDataPacket($pk); } $this->close("Incorrect protocol #".$packet->protocol1, false); - break; + return; } - if(preg_match('#[^a-zA-Z0-9_]#', $packet->username) == 0 and $packet->username != ""){ - $this->username = $packet->username; - $this->iusername = strtolower($this->username); - }else{ - $this->username = $packet->username; - $this->iusername = strtolower($this->username); + if(preg_match('#[^a-zA-Z0-9_]#', $packet->username) > 0 or $packet->username === ""){ $this->close("Bad username", false); - break; + return; } if($this->server->api->handle("player.connect", $this) === false){ $this->close("Unknown reason", false); From 755cafa6003437399e582f041f9e19d91fa13c10 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 11 Feb 2014 12:47:18 +0100 Subject: [PATCH 019/173] Alpha_1.4dev --- src/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.php b/src/config.php index 2b9c53afa..760395a1d 100644 --- a/src/config.php +++ b/src/config.php @@ -67,8 +67,8 @@ set_include_path(get_include_path() . PATH_SEPARATOR . FILE_PATH); ini_set("memory_limit", "128M"); //Default define("LOG", true); define("START_TIME", microtime(true)); -define("MAJOR_VERSION", "Alpha_1.3.12"); -define("CODENAME", "甘い(Amai)ビートルート(Beetroot)"); +define("MAJOR_VERSION", "Alpha_1.4dev"); +define("CODENAME", "絶好(Zekkou)ケーキ(Cake)"); define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha"); define("CURRENT_API_VERSION", 12); define("CURRENT_PHP_VERSION", "5.5"); From 89a0e84404bc39036a13a2559d050a3fb91f1d17 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 11 Feb 2014 12:47:28 +0100 Subject: [PATCH 020/173] Fixed handlerPriority order --- src/BaseEvent.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BaseEvent.php b/src/BaseEvent.php index 38b81c851..294ab14ba 100644 --- a/src/BaseEvent.php +++ b/src/BaseEvent.php @@ -106,6 +106,7 @@ abstract class BaseEvent{ static::$handlers[$identifier] = $handler; if(!isset(static::$handlerPriority[(int) $priority])){ static::$handlerPriority[(int) $priority] = array(); + krsort(static::$handlerPriority); } static::$handlerPriority[(int) $priority][$identifier] = $handler; return true; From a373a581c5bf40383679d0ca47156aad869a2401 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 11 Feb 2014 16:57:45 +0100 Subject: [PATCH 021/173] Better fix for #1201 (case-insensitive) --- src/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Player.php b/src/Player.php index 966f9cf5b..35f392314 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1311,7 +1311,7 @@ class Player{ $this->close("Incorrect protocol #".$packet->protocol1, false); return; } - if(preg_match('#[^a-zA-Z0-9_]#', $packet->username) > 0 or $packet->username === ""){ + if(preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console"){ $this->close("Bad username", false); return; } From 4352fce82ddb1ee92ee042b0e3d12c19c43ee34f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=82=A4=EB=A6=AC=ED=86=A0?= Date: Wed, 12 Feb 2014 19:12:07 +0900 Subject: [PATCH 022/173] fixed disconnected message --- src/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Player.php b/src/Player.php index 35f392314..6bd62aa62 100644 --- a/src/Player.php +++ b/src/Player.php @@ -294,7 +294,6 @@ class Player{ $this->directDataPacket(new DisconnectPacket); $this->connected = false; $this->level->freeAllChunks($this); - $this->spawned = false; $this->loggedIn = false; $this->buffer = null; unset($this->buffer); @@ -306,6 +305,7 @@ class Player{ if($msg === true and $this->username != "" and $this->spawned !== false){ $this->server->api->chat->broadcast($this->username." left the game"); } + $this->spawned = false; console("[INFO] ".FORMAT_AQUA.$this->username.FORMAT_RESET."[/".$this->ip.":".$this->port."] logged out due to ".$reason); $this->windows = array(); $this->armor = array(); From ac505772550cb6e3238ac7ab99c06644b8650191 Mon Sep 17 00:00:00 2001 From: Intyre Date: Wed, 12 Feb 2014 19:28:33 +0100 Subject: [PATCH 023/173] Typo and fixed a filename --- src/network/protocol/packet/SendInventoryPacket.php | 2 +- .../packet/{TakeItemEntity.php => TakeItemEntityPacket.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/network/protocol/packet/{TakeItemEntity.php => TakeItemEntityPacket.php} (100%) diff --git a/src/network/protocol/packet/SendInventoryPacket.php b/src/network/protocol/packet/SendInventoryPacket.php index 250d3abce..b868c250b 100644 --- a/src/network/protocol/packet/SendInventoryPacket.php +++ b/src/network/protocol/packet/SendInventoryPacket.php @@ -36,7 +36,7 @@ class SendInventoryPacket extends RakNetDataPacket{ for($s = 0; $s < $count and !$this->feof(); ++$s){ $this->slots[$s] = $this->getSlot(); } - if($this->windowid === 1){ //Armir is sent + if($this->windowid === 1){ //Armor is sent for($s = 0; $s < 4; ++$s){ $this->armor[$s] = $this->getSlot(); } diff --git a/src/network/protocol/packet/TakeItemEntity.php b/src/network/protocol/packet/TakeItemEntityPacket.php similarity index 100% rename from src/network/protocol/packet/TakeItemEntity.php rename to src/network/protocol/packet/TakeItemEntityPacket.php From 3cbcb4871a12c14f6ad86215a58ed3b729ac4c6c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:13:55 +0100 Subject: [PATCH 024/173] Changed a few packet things --- src/network/MinecraftInterface.php | 4 +- src/network/protocol/ProtocolInfo.php | 59 +-------- src/network/raknet/RakNetInfo.php | 2 +- src/network/raknet/RakNetParser.php | 169 +++++++++++++++++++++++++- 4 files changed, 168 insertions(+), 66 deletions(-) diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index f7e149c04..587131a2d 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -71,7 +71,7 @@ class MinecraftInterface{ $packet = new QueryPacket; $packet->ip = $source; $packet->port = $port; - $packet->buffer = $buffer; + $packet->buffer =& $buffer; if(EventHandler::callEvent(new PacketReceiveEvent($packet)) === BaseEvent::DENY){ return false; } @@ -80,7 +80,7 @@ class MinecraftInterface{ $packet = new Packet(); $packet->ip = $source; $packet->port = $port; - $packet->buffer = $buffer; + $packet->buffer =& $buffer; EventHandler::callEvent(new PacketReceiveEvent($packet)); return false; } diff --git a/src/network/protocol/ProtocolInfo.php b/src/network/protocol/ProtocolInfo.php index b321c4c2c..45c100489 100644 --- a/src/network/protocol/ProtocolInfo.php +++ b/src/network/protocol/ProtocolInfo.php @@ -20,7 +20,7 @@ */ -class ProtocolInfo{ +abstract class ProtocolInfo{ const CURRENT_PROTOCOL = 14; @@ -95,63 +95,6 @@ class ProtocolInfo{ const ADVENTURE_SETTINGS_PACKET = 0xb7; const ENTITY_DATA_PACKET = 0xb8; //const PLAYER_INPUT_PACKET = 0xb9; - - public static $packets = array( - -1 => "UnknownPacket", - ProtocolInfo::PING_PACKET => "PingPacket", - ProtocolInfo::PONG_PACKET => "PongPacket", - ProtocolInfo::CLIENT_CONNECT_PACKET => "ClientConnectPacket", - ProtocolInfo::SERVER_HANDSHAKE_PACKET => "ServerHandshakePacket", - ProtocolInfo::DISCONNECT_PACKET => "DisconnectPacket", - ProtocolInfo::LOGIN_PACKET => "LoginPacket", - ProtocolInfo::LOGIN_STATUS_PACKET => "LoginStatusPacket", - ProtocolInfo::READY_PACKET => "ReadyPacket", - ProtocolInfo::MESSAGE_PACKET => "MessagePacket", - ProtocolInfo::SET_TIME_PACKET => "SetTimePacket", - ProtocolInfo::START_GAME_PACKET => "StartGamePacket", - ProtocolInfo::ADD_MOB_PACKET => "AddMobPacket", - ProtocolInfo::ADD_PLAYER_PACKET => "AddPlayerPacket", - ProtocolInfo::REMOVE_PLAYER_PACKET => "RemovePlayerPacket", - ProtocolInfo::ADD_ENTITY_PACKET => "AddEntityPacket", - ProtocolInfo::REMOVE_ENTITY_PACKET => "RemoveEntityPacket", - ProtocolInfo::ADD_ITEM_ENTITY_PACKET => "AddItemEntityPacket", - ProtocolInfo::TAKE_ITEM_ENTITY_PACKET => "TakeItemEntityPacket", - ProtocolInfo::MOVE_ENTITY_PACKET => "MoveEntityPacket", - ProtocolInfo::MOVE_ENTITY_PACKET_POSROT => "MoveEntityPacket_PosRot", - ProtocolInfo::ROTATE_HEAD_PACKET => "RotateHeadPacket", - ProtocolInfo::MOVE_PLAYER_PACKET => "MovePlayerPacket", - ProtocolInfo::REMOVE_BLOCK_PACKET => "RemoveBlockPacket", - ProtocolInfo::UPDATE_BLOCK_PACKET => "UpdateBlockPacket", - ProtocolInfo::ADD_PAINTING_PACKET => "AddPaintingPacket", - ProtocolInfo::EXPLODE_PACKET => "ExplodePacket", - ProtocolInfo::LEVEL_EVENT_PACKET => "LevelEventPacket", - ProtocolInfo::TILE_EVENT_PACKET => "TileEventPacket", - ProtocolInfo::ENTITY_EVENT_PACKET => "EntityEventPacket", - ProtocolInfo::REQUEST_CHUNK_PACKET => "RequestChunkPacket", - ProtocolInfo::CHUNK_DATA_PACKET => "ChunkDataPacket", - ProtocolInfo::PLAYER_EQUIPMENT_PACKET => "PlayerEquipmentPacket", - ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET => "PlayerArmorEquipmentPacket", - ProtocolInfo::INTERACT_PACKET => "InteractPacket", - ProtocolInfo::USE_ITEM_PACKET => "UseItemPacket", - ProtocolInfo::PLAYER_ACTION_PACKET => "PlayerActionPacket", - ProtocolInfo::HURT_ARMOR_PACKET => "HurtArmorPacket", - ProtocolInfo::SET_ENTITY_DATA_PACKET => "SetEntityDataPacket", - ProtocolInfo::SET_ENTITY_MOTION_PACKET => "SetEntityMotionPacket", - ProtocolInfo::SET_HEALTH_PACKET => "SetHealthPacket", - ProtocolInfo::SET_SPAWN_POSITION_PACKET => "SetSpawnPositionPacket", - ProtocolInfo::ANIMATE_PACKET => "AnimatePacket", - ProtocolInfo::RESPAWN_PACKET => "RespawnPacket", - ProtocolInfo::SEND_INVENTORY_PACKET => "SendInventoryPacket", - ProtocolInfo::DROP_ITEM_PACKET => "DropItemPacket", - ProtocolInfo::CONTAINER_OPEN_PACKET => "ContainerOpenPacket", - ProtocolInfo::CONTAINER_CLOSE_PACKET => "ContainerClosePacket", - ProtocolInfo::CONTAINER_SET_SLOT_PACKET => "ContainerSetSlotPacket", - ProtocolInfo::CONTAINER_SET_DATA_PACKET => "ContainerSetDataPacket", - ProtocolInfo::CONTAINER_SET_CONTENT_PACKET => "ContainerSetContentPacket", - ProtocolInfo::CHAT_PACKET => "ChatPacket", - ProtocolInfo::ADVENTURE_SETTINGS_PACKET => "AdventureSettingsPacket", - ProtocolInfo::ENTITY_DATA_PACKET => "EntityDataPacket", - ); } diff --git a/src/network/raknet/RakNetInfo.php b/src/network/raknet/RakNetInfo.php index 485f53973..2823ee433 100644 --- a/src/network/raknet/RakNetInfo.php +++ b/src/network/raknet/RakNetInfo.php @@ -19,7 +19,7 @@ * */ -class RakNetInfo{ +abstract class RakNetInfo{ const STRUCTURE = 5; const MAGIC = "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"; const UNCONNECTED_PING = 0x01; diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index fa2f6dca2..98699be9c 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -186,11 +186,170 @@ class RakNetParser{ if(strlen($buffer) < ($length - 1)){ return false; } - if(isset(ProtocolInfo::$packets[$pid])){ - $data = new ProtocolInfo::$packets[$pid]; - }else{ - $data = new UnknownPacket(); - $data->packetID = $pid; + switch($pid){ + case ProtocolInfo::PING_PACKET: + $data = new PingPacket; + break; + case ProtocolInfo::PONG_PACKET: + $data = new PongPacket; + break; + case ProtocolInfo::CLIENT_CONNECT_PACKET: + $data = new ClientConnectPacket; + break; + case ProtocolInfo::SERVER_HANDSHAKE_PACKET: + $data = new ServerHandshakePacket; + break; + case ProtocolInfo::DISCONNECT_PACKET: + $data = new DisconnectPacket; + break; + case ProtocolInfo::LOGIN_PACKET: + $data = new LoginPacket; + break; + case ProtocolInfo::LOGIN_STATUS_PACKET: + $data = new LoginStatusPacket; + break; + case ProtocolInfo::READY_PACKET: + $data = new ReadyPacket; + break; + case ProtocolInfo::MESSAGE_PACKET: + $data = new MessagePacket; + break; + case ProtocolInfo::SET_TIME_PACKET: + $data = new SetTimePacket; + break; + case ProtocolInfo::START_GAME_PACKET: + $data = new StartGamePacket; + break; + case ProtocolInfo::ADD_MOB_PACKET: + $data = new AddMobPacket; + break; + case ProtocolInfo::ADD_PLAYER_PACKET: + $data = new AddPlayerPacket; + break; + case ProtocolInfo::REMOVE_PLAYER_PACKET: + $data = new RemovePlayerPacket; + break; + case ProtocolInfo::ADD_ENTITY_PACKET: + $data = new AddEntityPacket; + break; + case ProtocolInfo::REMOVE_ENTITY_PACKET: + $data = new RemoveEntityPacket; + break; + case ProtocolInfo::ADD_ITEM_ENTITY_PACKET: + $data = new AddItemEntityPacket; + break; + case ProtocolInfo::TAKE_ITEM_ENTITY_PACKET: + $data = new TakeItemEntityPacket; + break; + case ProtocolInfo::MOVE_ENTITY_PACKET: + $data = new MoveEntityPacket; + break; + case ProtocolInfo::MOVE_ENTITY_PACKET_POSROT: + $data = new MoveEntityPacket_PosRot; + break; + case ProtocolInfo::ROTATE_HEAD_PACKET: + $data = new RotateHeadPacket; + break; + case ProtocolInfo::MOVE_PLAYER_PACKET: + $data = new MovePlayerPacket; + break; + case ProtocolInfo::REMOVE_BLOCK_PACKET: + $data = new RemoveBlockPacket; + break; + case ProtocolInfo::UPDATE_BLOCK_PACKET: + $data = new UpdateBlockPacket; + break; + case ProtocolInfo::ADD_PAINTING_PACKET: + $data = new AddPaintingPacket; + break; + case ProtocolInfo::EXPLODE_PACKET: + $data = new ExplodePacket; + break; + case ProtocolInfo::LEVEL_EVENT_PACKET: + $data = new LevelEventPacket; + break; + case ProtocolInfo::TILE_EVENT_PACKET: + $data = new TileEventPacket; + break; + case ProtocolInfo::ENTITY_EVENT_PACKET: + $data = new EntityEventPacket; + break; + case ProtocolInfo::REQUEST_CHUNK_PACKET: + $data = new RequestChunkPacket; + break; + case ProtocolInfo::CHUNK_DATA_PACKET: + $data = new ChunkDataPacket; + break; + case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: + $data = new PlayerEquipmentPacket; + break; + case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: + $data = new PlayerArmorEquipmentPacket; + break; + case ProtocolInfo::INTERACT_PACKET: + $data = new InteractPacket; + break; + case ProtocolInfo::USE_ITEM_PACKET: + $data = new UseItemPacket; + break; + case ProtocolInfo::PLAYER_ACTION_PACKET: + $data = new PlayerActionPacket; + break; + case ProtocolInfo::HURT_ARMOR_PACKET: + $data = new HurtArmorPacket; + break; + case ProtocolInfo::SET_ENTITY_DATA_PACKET: + $data = new SetEntityDataPacket; + break; + case ProtocolInfo::SET_ENTITY_MOTION_PACKET: + $data = new SetEntityMotionPacket; + break; + case ProtocolInfo::SET_HEALTH_PACKET: + $data = new SetHealthPacket; + break; + case ProtocolInfo::SET_SPAWN_POSITION_PACKET: + $data = new SetSpawnPositionPacket; + break; + case ProtocolInfo::ANIMATE_PACKET: + $data = new AnimatePacket; + break; + case ProtocolInfo::RESPAWN_PACKET: + $data = new RespawnPacket; + break; + case ProtocolInfo::SEND_INVENTORY_PACKET: + $data = new SendInventoryPacket; + break; + case ProtocolInfo::DROP_ITEM_PACKET: + $data = new DropItemPacket; + break; + case ProtocolInfo::CONTAINER_OPEN_PACKET: + $data = new ContainerOpenPacket; + break; + case ProtocolInfo::CONTAINER_CLOSE_PACKET: + $data = new ContainerClosePacket; + break; + case ProtocolInfo::CONTAINER_SET_SLOT_PACKET: + $data = new ContainerSetSlotPacket; + break; + case ProtocolInfo::CONTAINER_SET_DATA_PACKET: + $data = new ContainerSetDataPacket; + break; + case ProtocolInfo::CONTAINER_SET_CONTENT_PACKET: + $data = new ContainerSetContentPacket; + break; + case ProtocolInfo::CHAT_PACKET: + $data = new ChatPacket; + break; + case ProtocolInfo::ADVENTURE_SETTINGS_PACKET: + $data = new AdventureSettingsPacket; + break; + case ProtocolInfo::ENTITY_DATA_PACKET: + $data = new EntityDataPacket; + break; + default: + $data = new UnknownPacket(); + $data->packetID = $pid; + break; } $data->reliability = $reliability; $data->hasSplit = $hasSplit; From 26772082da273b1d1ae401add7463a3ac6e1a3e0 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 11 Feb 2014 22:28:53 +0100 Subject: [PATCH 025/173] Random generator with signed int/float methods --- src/utils/Random.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils/Random.php b/src/utils/Random.php index fd0273ecb..fbd00397f 100644 --- a/src/utils/Random.php +++ b/src/utils/Random.php @@ -47,10 +47,18 @@ class Random{ return Utils::readInt($this->nextBytes(4)) & 0x7FFFFFFF; } + public function nextSignedInt(){ + return Utils::readInt($this->nextBytes(4)); + } + public function nextFloat(){ return $this->nextInt() / 0x7FFFFFFF; } + public function nextSignedFloat(){ + return $this->nextSignedInt() / 0x7FFFFFFF; + } + public function nextBytes($byteCount){ $bytes = ""; for($i = 0; $i < $byteCount; ++$i){ From 1bc54dbc44cd6e05f435283c450ddd3581b813af Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 12 Feb 2014 09:45:38 +0100 Subject: [PATCH 026/173] Such noise --- src/API/LevelAPI.php | 2 +- src/utils/Random.php | 33 ++-- src/world/generator/NormalGenerator.php | 136 ++++++++++++++ src/world/generator/SuperflatGenerator.php | 2 +- src/world/generator/noise/NoiseGenerator.php | 43 +++++ .../generator/noise/NoiseGeneratorOctaves.php | 68 ------- .../generator/noise/NoiseGeneratorPerlin.php | 169 ------------------ src/world/generator/noise/OctaveGenerator.php | 108 +++++++++++ .../generator/noise/PerlinNoiseGenerator.php | 96 ++++++++++ .../generator/noise/PerlinOctaveGenerator.php | 35 ++++ 10 files changed, 430 insertions(+), 262 deletions(-) create mode 100644 src/world/generator/NormalGenerator.php delete mode 100644 src/world/generator/noise/NoiseGeneratorOctaves.php delete mode 100644 src/world/generator/noise/NoiseGeneratorPerlin.php create mode 100644 src/world/generator/noise/OctaveGenerator.php create mode 100644 src/world/generator/noise/PerlinNoiseGenerator.php create mode 100644 src/world/generator/noise/PerlinOctaveGenerator.php diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 07726c77f..56d96ec17 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -94,7 +94,7 @@ class LevelAPI{ if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){ $generator = new SuperflatGenerator($options); }else{ - $generator = new TemporalGenerator($options); + $generator = new NormalGenerator($options); } } $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)):(int) $seed); diff --git a/src/utils/Random.php b/src/utils/Random.php index fbd00397f..da7e9bf92 100644 --- a/src/utils/Random.php +++ b/src/utils/Random.php @@ -22,25 +22,15 @@ //Unsecure, not used for "Real Randomness" class Random{ - private $x, $y, $z, $w; + private $z, $w; public function __construct($seed = false){ $this->setSeed($seed); } public function setSeed($seed = false){ - $seed = $seed !== false ? Utils::writeInt((int) $seed):Utils::getRandomBytes(4, false); - $state = array(); - for($i = 0; $i < 256; ++$i){ - $state[] = $i; - } - for($i = $j = 0; $i < 256; ++$i){ - $j = ($j + ord($seed{$i & 0x03}) + $state[$i]) & 0xFF; - $state[$i] ^= $state[$j]; - $state[$j] ^= $state[$i]; - $state[$i] ^= $state[$j]; - } - $this->state = $state; - $this->i = $this->j = 0; + $seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false)); + $this->z = $seed ^ 0xdeadbeef; + $this->w = $seed ^ 0xc0de1337; } public function nextInt(){ @@ -61,19 +51,16 @@ class Random{ public function nextBytes($byteCount){ $bytes = ""; - for($i = 0; $i < $byteCount; ++$i){ - $this->i = ($this->i + 1) & 0xFF; - $this->j = ($this->j + $this->state[$this->i]) & 0xFF; - $this->state[$this->i] ^= $this->state[$this->j]; - $this->state[$this->j] ^= $this->state[$this->i]; - $this->state[$this->i] ^= $this->state[$this->j]; - $bytes .= chr($this->state[($this->state[$this->i] + $this->state[$this->j]) & 0xFF]); + while(strlen($bytes) < $byteCount){ + $this->z = 36969 * ($this->z & 65535) + ($this->z >> 16); + $this->w = 18000 * ($this->w & 65535) + ($this->w >> 16); + $bytes .= pack("N", ($this->z << 16) + $this->w); } - return $bytes; + return substr($bytes, 0, $byteCount); } public function nextBoolean(){ - return ($this->nextBytes(1) & 0x01) == 0; + return ($this->nextSignedInt() & 0x01) === 0; } public function nextRange($start = 0, $end = PHP_INT_MAX){ diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php new file mode 100644 index 000000000..9ea8967cb --- /dev/null +++ b/src/world/generator/NormalGenerator.php @@ -0,0 +1,136 @@ +noiseGen1 = new PerlinOctaveGenerator($rand, 16); + $this->noiseGen2 = new PerlinOctaveGenerator($rand, 16); + $this->noiseGen3 = new PerlinOctaveGenerator($rand, 8); + $this->noiseGen4 = new PerlinOctaveGenerator($rand, 4); + $this->noiseGen5 = new PerlinOctaveGenerator($rand, 10); + $this->noiseGen6 = new PerlinOctaveGenerator($rand, 16); + } + + public function init(Level $level, Random $random){ + $this->level = $level; + $this->random = $random; + $this->random->setSeed($this->level->getSeed()); + $perlin = new PerlinNoiseGenerator($this->random, array( + "frequency" => 1, + "octaves" => 8, + "persistence" => 0.3, + "scale" => 1, + )); + $this->deviations = $perlin->fillNoiseArray(256, 256); + + $ores = new OrePopulator(); + $ores->setOreTypes(array( + new OreType(new CoalOreBlock(), 20, 16, 0, 128), + new OreType(New IronOreBlock(), 20, 8, 0, 64), + new OreType(new RedstoneOreBlock(), 8, 7, 0, 16), + new OreType(new LapisOreBlock(), 1, 6, 0, 32), + new OreType(new GoldOreBlock(), 2, 8, 0, 32), + new OreType(new DiamondOreBlock(), 1, 7, 0, 16), + new OreType(new DirtBlock(), 20, 32, 0, 128), + new OreType(new GravelBlock(), 10, 16, 0, 128), + )); + $this->populators[] = $ores; + } + + public function generateChunk($chunkX, $chunkZ){ + //$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); + $byte0 = 4; + $this->noiseArray = $this->initializeNoiseArray($chunkX * $byte0, 0, $chunkZ * $byte0, $byte0 + 1, ($this->worldHeight / 8) + 1, $byte0 + 1); + + $chunks = array(); + for($chunkY = 0; $chunkY < 8; ++$chunkY){ + $chunk = ""; + $startY = $chunkY << 4; + $endY = $startY + 16; + for($z = 0; $z < 16; ++$z){ + for($x = 0; $x < 16; ++$x){ + $height = (int) ($this->baseHeight + $this->deviations[$z + ($chunkZ << 4)][$x + ($chunkX << 4)]); + for($y = $startY; $y < $endY; ++$y){ + $diff = $height - $y; + if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ + $chunk .= "\x07"; //bedrock + }elseif($diff > 3){ + $chunk .= "\x01"; //stone + }elseif($diff > 0){ + $chunk .= "\x03"; //dirt + }elseif($y <= $this->waterHeight){ + $chunk .= "\x09"; //still_water + }elseif($diff === 0){ + $chunk .= "\x02"; //grass + }else{ + $chunk .= "\x00"; + } + } + $chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; + } + } + $this->level->setMiniChunk($chunkX, $chunkZ, $chunkY, $chunk); + } + + } + + private function initializeNoiseArray($x, $y, $z, $sizeX, $sizeY, $sizeZ){ + $noiseArray = array_fill(0, $sizeX * $sizeY * $sizeZ, 0.0); + + $noise5 = $this->noiseGen5->generateNoiseOctaves($x, $y, $z); + + } + + public function populateChunk($chunkX, $chunkZ){ + foreach($this->populators as $populator){ + $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); + $populator->populate($this->level, $chunkX, $chunkZ, $this->random); + } + } + + public function populateLevel(){ + + } + + public function getSpawn(){ + return $this->level->getSafeSpawn(new Vector3(127.5, 128, 127.5)); + } + +} \ No newline at end of file diff --git a/src/world/generator/SuperflatGenerator.php b/src/world/generator/SuperflatGenerator.php index b7235694f..731c304df 100644 --- a/src/world/generator/SuperflatGenerator.php +++ b/src/world/generator/SuperflatGenerator.php @@ -127,7 +127,7 @@ class SuperflatGenerator implements LevelGenerator{ public function populateChunk($chunkX, $chunkZ){ foreach($this->populators as $populator){ - $this->random->setSeed((int) ($chunkX * 0xdead + $chunkZ * 0xbeef) ^ $this->level->getSeed()); + $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } } diff --git a/src/world/generator/noise/NoiseGenerator.php b/src/world/generator/noise/NoiseGenerator.php index b6d24472c..2bfbf1c8d 100644 --- a/src/world/generator/noise/NoiseGenerator.php +++ b/src/world/generator/noise/NoiseGenerator.php @@ -19,6 +19,49 @@ * */ + abstract class NoiseGenerator{ + protected $perm = array(); + protected $offsetX; + protected $offsetY; + protected $offsetZ; + public static function floor($x){ + return $x >= 0 ? (int) $x : (int) $x - 1; + } + + public static function fade($x){ + return $x * $x * $x * ($x * ($x * 6 - 15) + 10); + } + + public static function lerp($x, $y, $z){ + return $y + $x * ($z - $y); + } + + public static function grad($hash, $x, $y, $z){ + $hash &= 15; + $u = $hash < 8 ? $x : $y; + $v = $hash < 4 ? $y : (($hash === 12 or $hash === 14) ? $x : $z); + return (($hash & 1) === 0 ? $u : -$u) + (($hash & 2) === 0 ? $v : -$v); + } + + abstract public function noise($x, $y, $z); + + public function noise3D($x, $y, $z, $octaves, $frequency, $amplitude, $normalized = false){ + $result = 0; + $amp = 1; + $freq = 1; + $max = 0; + + for($i = 0; $i < $octaves; ++$i){ + $result += $this->noise($x * $freq, $y * $freq, $z * $freq) * $amp; + $max += $amp; + $freq *= $frequency; + $amp *= $amplitude; + } + if($normalized === true){ + $result /= $max; + } + + return $result; } \ No newline at end of file diff --git a/src/world/generator/noise/NoiseGeneratorOctaves.php b/src/world/generator/noise/NoiseGeneratorOctaves.php deleted file mode 100644 index ac5661432..000000000 --- a/src/world/generator/noise/NoiseGeneratorOctaves.php +++ /dev/null @@ -1,68 +0,0 @@ -generatorCollection = array(); - $this->octaves = (int) $octaves; - for($o = 0; $o < $this->octaves; ++$o){ - $this->generatorCollection[$o] = new NoiseGeneratorPerlin($random); - } - } - - public function generateNoiseOctaves($int1, $int2, $int3, $int4, $int5, $int6, $par1 = false, $par2 = false, $par3 = false){ - if($par1 === false or $par2 === false or $par3 === false){ - return $this->generateNoiseOctaves($int1, 10, $int2, $int3, 1, $int4, $int5, 1, $int6); - } - - $floats = array(); - $cnt = $int4 * $int5 * $int6; - for($i = 0; $i < $cnt; ++$i){ - $floats[$i] = 0; - } - - $d1 = 1; - - for($j = 0; $j < $this->octaves; ++$j){ - $d2 = $int1 * $d1 * $par1; - $d3 = $int2 * $d1 * $par2; - $d4 = $int3 * $d1 * $par3; - $l1 = floor($d2); - $l2 = floor($d4); - $d2 -= $l1; - $d4 -= $l2; - $l1 %= 16777216; - $l2 %= 16777216; - - $d2 += $l1; - $d4 += $l2; - $this->generatorCollection[$j]->populateNoiseArray($floats, $d2, $d3, $d4, $int4, $int5, $int6, $par1 * $d1, $par2 * $d1, $par3 * $d1, $d1); - $d1 /= 2; - } - return $floats; - } -} \ No newline at end of file diff --git a/src/world/generator/noise/NoiseGeneratorPerlin.php b/src/world/generator/noise/NoiseGeneratorPerlin.php deleted file mode 100644 index 079bda1f1..000000000 --- a/src/world/generator/noise/NoiseGeneratorPerlin.php +++ /dev/null @@ -1,169 +0,0 @@ -xCoord = $random->nextFloat() * 256; - $this->yCoord = $random->nextFloat() * 256; - $this->zCoord = $random->nextFloat() * 256; - - for($i = 0; $i < 512; ++$i){ - $this->permutations[$i] = 0; - } - for($i = 0; $i < 256; ++$i){ - $this->permutations[$i] = $i; - } - - for($i = 0; $i < 256; ++$i){ - $j = $random->nextRange(0, 256 - $i) + $i; - $k = $this->permutations[$i]; - $this->permutations[$i] = $this->permutations[$j]; - $this->permutations[$j] = $k; - $this->permutations[$i + 256] = $this->permutations[$i]; - } - - } - - public final function curve($par1, $par2, $par3){ - return $par2 + $par1 * ($par3 - $par2); - } - - public function grad2D($int, $par1, $par2){ - $i = $int & 0x0F; - $d1 = (1 - (($i & 0x08) >> 3)) * $par1; - $d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? 0:$par2); - - return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2); - } - - public function grad3D($int, $par1, $par2, $par3){ - $i = $int & 0x0F; - $d1 = $i < 8 ? $par1 : $par2; - $d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? $par2:$par3); - - return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2); - } - - public function populateNoiseArray(&$floats, $par1, $par2, $par3, $int1, $int2, $int3, $par4, $par5, $par6, $par7){ - if($int2 === 1){ - $n = 0; - $d3 = 1 / $par7; - for($i1 = 0; $i1 < $int1; ++$i1){ - $d4 = $par1 + $i1 * $par4 + $this->xCoord; - $i2 = (int) $d4; - if($d4 < $i2){ - --$i2; - } - $i3 = $i2 & 0xFF; - $d4 -= $i2; - $d5 = $d4 * $d4 * $d4 * ($d4 * ($d4 * 6 - 15) + 10); - - for($i4 = 0; $i4 < $int3; ++$i4){ - $d6 = $par3 + $i4 * $par6 + $this->zCoord; - $i5 = (int) $d6; - if($d6 < $i5){ - --$i5; - } - $i6 = $i5 & 0xFF; - $d6 -= $i5; - $d7 = $d6 * $d6 * $d6 * ($d6 * ($d6 * 6 - 15) + 10); - - $i = $this->permutations[$i3]; - $j = $this->permutations[$i] + $i6; - $k = $this->permutations[$i3 + 1]; - $m = $this->permutations[$k] + $i6; - $d1 = $this->curve($d5, $this->grad2D($this->permutations[$j], $d4, $d6), $this->grad3D($this->permutations[$m], $d4 - 1, 0, $d6)); - $d2 = $this->curve($d5, $this->grad3D($this->permutations[$j + 1], $d4, 0, $d6 - 1), $this->grad3D($this->permutations[$m + 1], $d4 - 1, 0, $d6 - 1)); - - $d8 = $this->curve($d7, $d1, $d2); - $floats[$n++] += $d8 * $d3; - } - } - return; - } - - $d9 = 1 / $par7; - $m = -1; - $n = 0; - $i = 0; - - for($i4 = 0; $i4 < $int1; ++$i4){ - $d6 = $par1 + $i4 * $par4 + $this->xCoord; - $i5 = (int) $d6; - if($d6 < $i5){ - --$i5; - } - $i6 = $i5 & 0xFF; - $d6 -= $i5; - $d7 = $d6 * $d6 * $d6 * ($d6 * ($d6 * 6 - 15) + 10); - - for($i12 = 0; $i12 < $int3; ++$i12){ - $d12 = $par3 + $i12 * $par6 + $this->zCoord; - $i13 = (int) $d12; - if($d12 < $i13){ - --$i13; - } - $i14 = $i13 & 0xFF; - $d12 -= $i13; - $d13 = $d12 * $d12 * $d12 * ($d12 * ($d12 * 6 - 15) + 10); - - for($i15 = 0; $i15 < $int2; ++$i15){ - $d14 = $par2 + $i15 * $par5 + $this->yCoord; - $i16 = (int) $d14; - if($d14 < $i16){ - --$i16; - } - $d14 -= $i16; - $d15 = $d14 * $d14 * $d14 * ($d14 * ($d14 * 6 - 15) + 10); - - if($i15 === 0 or $i17 !== $m){ - $m = $i17; - $i7 = $this->permutations[$i6] + $i17; - $i8 = $this->permutations[$i7] + $i14; - $i9 = $this->permutations[$i7 + 1] + $i14; - $i10 = $this->permutations[$i6 + 1] + $i17; - $n = $this->permutations[$i10] + $i14; - $i11 = $this->permutations[$i10 + 1] + $i14; - $d10 = $this->curve($d7, $this->grad3D($this->permutations[$i8], $d6, $d14, $d12), $this->grad3D($this->permutations[$n], $d6 - 1, $d14, $d12)); - $d4 = $this->curve($d7, $this->grad3D($this->permutations[$i9], $d6, $d14 - 1, $d12), $this->grad3D($this->permutations[$i11], $d6 - 1, $d14 - 1, $d12)); - $d11 = $this->curve($d7, $this->grad3D($this->permutations[$i8 + 1], $d6, $d14, $d12 - 1), $this->grad3D($this->permutations[$n + 1], $d6 - 1, $d14, $d12 - 1)); - $d5 = $this->curve($d7, $this->grad3D($this->permutations[$i9 + 1], $d6, $d14 - 1, $d12 - 1), $this->grad3D($this->permutations[$i11 + 1], $d6 - 1, $d14 - 1, $d12 - 1)); - } - - $d16 = $this->curve($d15, $d10, $d4); - $d17 = $this->curve($d15, $d11, $d5); - $d18 = $this->curve($d13, $d16, $d17); - $floats[$i++] += $d18 * $d9; - } - } - } - } -} \ No newline at end of file diff --git a/src/world/generator/noise/OctaveGenerator.php b/src/world/generator/noise/OctaveGenerator.php new file mode 100644 index 000000000..4bda3e720 --- /dev/null +++ b/src/world/generator/noise/OctaveGenerator.php @@ -0,0 +1,108 @@ +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){ + + } +} \ No newline at end of file diff --git a/src/world/generator/noise/PerlinNoiseGenerator.php b/src/world/generator/noise/PerlinNoiseGenerator.php new file mode 100644 index 000000000..640094aa1 --- /dev/null +++ b/src/world/generator/noise/PerlinNoiseGenerator.php @@ -0,0 +1,96 @@ +offsetX = $random->nextFloat() * 256; + $this->offsetY = $random->nextFloat() * 256; + $this->offsetZ = $random->nextFloat() * 256; + + for($i = 0; $i < 512; ++$i){ + $this->perm[$i} = 0; + } + + for($i = 0; $i < 256; ++$i){ + $this->perm[$i} = $random->nextRange(0, 255); + } + for($i = 0; $i < 256; ++$i)[ + $pos = $random->nextRange(0, 255 - $i) + $i; + $old = $this->perm[$i}; + + $this->perm[$i} = $this->perm[$pos}; + $this->perm[$pos} = $old; + $this->perm[$i + 256} = $this->perm[$i}; + } + + } + + public function noise($x, $y, $z){ + $x += $this->offsetX; + $y += $this->offsetY; + $z += $this->offsetZ; + + $floorX = self::floor($x); + $floorY = self::floor($y); + $floorZ = self::floor($z); + + $X = $floorX & 0xFF; + $Y = $floorY & 0xFF; + $Z = $floorZ & 0xFF; + + $x -= $floorX; + $y -= $floorY; + $z -= $floorZ; + + //Fade curves + $fX = self::fade($x); + $fY = self::fade($y); + $fZ = self::fade($z); + + //Cube corners + $A = $this->perm[$X] + $Y; + $AA = $this->perm[$A] + $Z; + $AB = $this->perm[$A + 1] + $Z; + $B = $this->perm[$X + 1] + $Y; + $BA = $this->perm[$B] + $Z; + $BB = $this->perm[$B + 1] + $Z; + + return self::lerp($fZ, self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA]), $x, $y, $z), + self::grad($this->perm[$BA], $x - 1, $y, $z), + self::lerp($fX, self::grad($this->perm[$AB], $x, $y - 1, $z), + self::grad($this->perm[$BB], $x - 1, $y - 1, $z))), + self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA + 1], $x, $y, $z - 1), + self::grad($this->perm[$BA + 1], $x - 1, $y, $z - 1)), + self::lerp($fX, self::grad($this->perm[$AB + 1], $x, $y - 1, $z - 1), + self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1)))); + } +} \ No newline at end of file diff --git a/src/world/generator/noise/PerlinOctaveGenerator.php b/src/world/generator/noise/PerlinOctaveGenerator.php new file mode 100644 index 000000000..857677285 --- /dev/null +++ b/src/world/generator/noise/PerlinOctaveGenerator.php @@ -0,0 +1,35 @@ +octaves = array(); + for($o = 0; $o < $octaves; ++$o){ + $this->octaves[$o] = new NoiseGeneratorPerlin($random); + } + } + + public function +} \ No newline at end of file From 4e820ab89f8c9b7951e5a024c69c2e3d6b219181 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 12 Feb 2014 13:25:40 +0100 Subject: [PATCH 027/173] Use single Perlin noise --- src/world/generator/NormalGenerator.php | 35 +++++++++---------- src/world/generator/noise/NoiseGenerator.php | 15 +++++--- ...Generator.php => NoiseGeneratorPerlin.php} | 21 +++++------ src/world/generator/noise/OctaveGenerator.php | 4 +-- .../generator/noise/PerlinOctaveGenerator.php | 30 +++++++++++++++- 5 files changed, 69 insertions(+), 36 deletions(-) rename src/world/generator/noise/{PerlinNoiseGenerator.php => NoiseGeneratorPerlin.php} (86%) diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index 9ea8967cb..3e37a38e3 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -38,28 +38,24 @@ class NormalGenerator implements LevelGenerator{ private $noiseGen5; private $noiseGen6; private $noiseArray = array(); + private $noise; public function __construct(array $options = array()){ - $this->noiseGen1 = new PerlinOctaveGenerator($rand, 16); - $this->noiseGen2 = new PerlinOctaveGenerator($rand, 16); - $this->noiseGen3 = new PerlinOctaveGenerator($rand, 8); - $this->noiseGen4 = new PerlinOctaveGenerator($rand, 4); - $this->noiseGen5 = new PerlinOctaveGenerator($rand, 10); - $this->noiseGen6 = new PerlinOctaveGenerator($rand, 16); + } public function init(Level $level, Random $random){ $this->level = $level; $this->random = $random; - $this->random->setSeed($this->level->getSeed()); - $perlin = new PerlinNoiseGenerator($this->random, array( - "frequency" => 1, - "octaves" => 8, - "persistence" => 0.3, - "scale" => 1, - )); - $this->deviations = $perlin->fillNoiseArray(256, 256); - + $this->random->setSeed($this->level->getSeed()); + $this->noise = new NoiseGeneratorPerlin($this->random); + $this->noiseGen1 = new PerlinOctaveGenerator($this->random, 16); + $this->noiseGen2 = new PerlinOctaveGenerator($this->random, 16); + $this->noiseGen3 = new PerlinOctaveGenerator($this->random, 8); + $this->noiseGen4 = new PerlinOctaveGenerator($this->random, 4); + $this->noiseGen5 = new PerlinOctaveGenerator($this->random, 10); + $this->noiseGen6 = new PerlinOctaveGenerator($this->random, 16); + $ores = new OrePopulator(); $ores->setOreTypes(array( new OreType(new CoalOreBlock(), 20, 16, 0, 128), @@ -75,9 +71,10 @@ class NormalGenerator implements LevelGenerator{ } public function generateChunk($chunkX, $chunkZ){ - //$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); - $byte0 = 4; - $this->noiseArray = $this->initializeNoiseArray($chunkX * $byte0, 0, $chunkZ * $byte0, $byte0 + 1, ($this->worldHeight / 8) + 1, $byte0 + 1); + $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); + + //$this->noiseArray = $this->initializeNoiseArray($chunkX * $byte0, 0, $chunkZ * $byte0, $byte0 + 1, ($this->worldHeight / 8) + 1, $byte0 + 1); + $chunks = array(); for($chunkY = 0; $chunkY < 8; ++$chunkY){ @@ -86,7 +83,7 @@ class NormalGenerator implements LevelGenerator{ $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ - $height = (int) ($this->baseHeight + $this->deviations[$z + ($chunkZ << 4)][$x + ($chunkX << 4)]); + $height = (int) ($this->worldHeight + $this->noise->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 4, 0.5, 24)); for($y = $startY; $y < $endY; ++$y){ $diff = $height - $y; if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ diff --git a/src/world/generator/noise/NoiseGenerator.php b/src/world/generator/noise/NoiseGenerator.php index 2bfbf1c8d..bb115ff65 100644 --- a/src/world/generator/noise/NoiseGenerator.php +++ b/src/world/generator/noise/NoiseGenerator.php @@ -22,12 +22,12 @@ abstract class NoiseGenerator{ protected $perm = array(); - protected $offsetX; - protected $offsetY; - protected $offsetZ; + protected $offsetX = 0; + protected $offsetY = 0; + protected $offsetZ = 0; public static function floor($x){ - return $x >= 0 ? (int) $x : (int) $x - 1; + return $x >= 0 ? (int) $x : (int) ($x - 1); } public static function fade($x){ @@ -64,4 +64,11 @@ abstract class NoiseGenerator{ } return $result; + } + + public function setOffset($x, $y, $z){ + $this->offsetX = $x; + $this->offsetY = $y; + $this->offsetZ = $z; + } } \ No newline at end of file diff --git a/src/world/generator/noise/PerlinNoiseGenerator.php b/src/world/generator/noise/NoiseGeneratorPerlin.php similarity index 86% rename from src/world/generator/noise/PerlinNoiseGenerator.php rename to src/world/generator/noise/NoiseGeneratorPerlin.php index 640094aa1..82886964e 100644 --- a/src/world/generator/noise/PerlinNoiseGenerator.php +++ b/src/world/generator/noise/NoiseGeneratorPerlin.php @@ -23,7 +23,7 @@ require_once("NoiseGenerator.php"); /***REM_END***/ -class NoiseGeneratorPerlin extends NoiseGenerator[ +class NoiseGeneratorPerlin extends NoiseGenerator{ public static $grad3 = [ [1, 1, 0], [-1, 1, 0], [1, -1, 0], [-1, -1, 0], [1, 0, 1], [-1, 0, 1], [1, 0, -1], [-1, 0, -1], @@ -37,19 +37,20 @@ class NoiseGeneratorPerlin extends NoiseGenerator[ $this->offsetZ = $random->nextFloat() * 256; for($i = 0; $i < 512; ++$i){ - $this->perm[$i} = 0; + $this->perm[$i] = 0; } for($i = 0; $i < 256; ++$i){ - $this->perm[$i} = $random->nextRange(0, 255); + $this->perm[$i] = $random->nextRange(0, 255); } - for($i = 0; $i < 256; ++$i)[ + + for($i = 0; $i < 256; ++$i){ $pos = $random->nextRange(0, 255 - $i) + $i; - $old = $this->perm[$i}; + $old = $this->perm[$i]; - $this->perm[$i} = $this->perm[$pos}; - $this->perm[$pos} = $old; - $this->perm[$i + 256} = $this->perm[$i}; + $this->perm[$i] = $this->perm[$pos]; + $this->perm[$pos] = $old; + $this->perm[$i + 256] = $this->perm[$i]; } } @@ -84,8 +85,8 @@ class NoiseGeneratorPerlin extends NoiseGenerator[ $BA = $this->perm[$B] + $Z; $BB = $this->perm[$B + 1] + $Z; - return self::lerp($fZ, self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA]), $x, $y, $z), - self::grad($this->perm[$BA], $x - 1, $y, $z), + return self::lerp($fZ, self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA], $x, $y, $z), + self::grad($this->perm[$BA], $x - 1, $y, $z)), self::lerp($fX, self::grad($this->perm[$AB], $x, $y - 1, $z), self::grad($this->perm[$BB], $x - 1, $y - 1, $z))), self::lerp($fY, self::lerp($fX, self::grad($this->perm[$AA + 1], $x, $y, $z - 1), diff --git a/src/world/generator/noise/OctaveGenerator.php b/src/world/generator/noise/OctaveGenerator.php index 4bda3e720..962801bec 100644 --- a/src/world/generator/noise/OctaveGenerator.php +++ b/src/world/generator/noise/OctaveGenerator.php @@ -102,7 +102,7 @@ abstract class OctaveGenerator{ return $result; } - public function generateNoiseOctaves($x, $y, $z, $frequency, $amplitude){ + /*public function generateNoiseOctaves($x, $y, $z, $frequency, $amplitude){ - } + }*/ } \ No newline at end of file diff --git a/src/world/generator/noise/PerlinOctaveGenerator.php b/src/world/generator/noise/PerlinOctaveGenerator.php index 857677285..53a79884c 100644 --- a/src/world/generator/noise/PerlinOctaveGenerator.php +++ b/src/world/generator/noise/PerlinOctaveGenerator.php @@ -31,5 +31,33 @@ class PerlinOctaveGenerator extends OctaveGenerator{ } } - public function + /*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; + }*/ } \ No newline at end of file From 2d887390057a1e8b28cbbe222086e2d8e5ef0b88 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 12 Feb 2014 13:28:18 +0100 Subject: [PATCH 028/173] normalize --- src/world/generator/NormalGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index 3e37a38e3..8c08d4c49 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -83,7 +83,7 @@ class NormalGenerator implements LevelGenerator{ $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ - $height = (int) ($this->worldHeight + $this->noise->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 4, 0.5, 24)); + $height = (int) ($this->worldHeight + $this->noise->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 4, 0.5, 24, true)); for($y = $startY; $y < $endY; ++$y){ $diff = $height - $y; if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ From f91e2a5cfe39fed9de75acc5c64718dc8515460d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 12 Feb 2014 16:06:43 +0100 Subject: [PATCH 029/173] Better parameters ^^ --- src/world/generator/NormalGenerator.php | 19 +++-------- src/world/generator/noise/NoiseGenerator.php | 32 ++++++++++++++++--- .../generator/noise/NoiseGeneratorPerlin.php | 9 ++++-- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index 8c08d4c49..c88e24d7f 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -30,15 +30,12 @@ class NormalGenerator implements LevelGenerator{ private $random; private $worldHeight = 64; private $waterHeight = 60; - private $blockLevels = array(); private $noiseGen1; private $noiseGen2; private $noiseGen3; private $noiseGen4; private $noiseGen5; private $noiseGen6; - private $noiseArray = array(); - private $noise; public function __construct(array $options = array()){ @@ -48,13 +45,8 @@ class NormalGenerator implements LevelGenerator{ $this->level = $level; $this->random = $random; $this->random->setSeed($this->level->getSeed()); - $this->noise = new NoiseGeneratorPerlin($this->random); - $this->noiseGen1 = new PerlinOctaveGenerator($this->random, 16); - $this->noiseGen2 = new PerlinOctaveGenerator($this->random, 16); - $this->noiseGen3 = new PerlinOctaveGenerator($this->random, 8); - $this->noiseGen4 = new PerlinOctaveGenerator($this->random, 4); - $this->noiseGen5 = new PerlinOctaveGenerator($this->random, 10); - $this->noiseGen6 = new PerlinOctaveGenerator($this->random, 16); + $this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 16); + $this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4); $ores = new OrePopulator(); $ores->setOreTypes(array( @@ -73,17 +65,14 @@ class NormalGenerator implements LevelGenerator{ public function generateChunk($chunkX, $chunkZ){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); - //$this->noiseArray = $this->initializeNoiseArray($chunkX * $byte0, 0, $chunkZ * $byte0, $byte0 + 1, ($this->worldHeight / 8) + 1, $byte0 + 1); - - - $chunks = array(); + $baseHeight = $this->worldHeight;// + $this->noiseGen1->noise2D($chunkX, $chunkZ, 2, 1/4, true) * 35; for($chunkY = 0; $chunkY < 8; ++$chunkY){ $chunk = ""; $startY = $chunkY << 4; $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ - $height = (int) ($this->worldHeight + $this->noise->noise3D($x + ($chunkX << 4), 0, $z + ($chunkZ << 4), 4, 0.5, 24, true)); + $height = (int) ($baseHeight + $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.3, 32, true) * 15); for($y = $startY; $y < $endY; ++$y){ $diff = $height - $y; if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ diff --git a/src/world/generator/noise/NoiseGenerator.php b/src/world/generator/noise/NoiseGenerator.php index bb115ff65..ca0b655a8 100644 --- a/src/world/generator/noise/NoiseGenerator.php +++ b/src/world/generator/noise/NoiseGenerator.php @@ -25,6 +25,7 @@ abstract class NoiseGenerator{ protected $offsetX = 0; protected $offsetY = 0; protected $offsetZ = 0; + protected $octaves = 8; public static function floor($x){ return $x >= 0 ? (int) $x : (int) ($x - 1); @@ -44,17 +45,38 @@ abstract class NoiseGenerator{ $v = $hash < 4 ? $y : (($hash === 12 or $hash === 14) ? $x : $z); return (($hash & 1) === 0 ? $u : -$u) + (($hash & 2) === 0 ? $v : -$v); } + + abstract public function getNoise2D($x, $z); - abstract public function noise($x, $y, $z); - - public function noise3D($x, $y, $z, $octaves, $frequency, $amplitude, $normalized = false){ + abstract public function getNoise3D($x, $y, $z); + + public function noise2D($x, $z, $frequency, $amplitude, $normalized = false){ $result = 0; $amp = 1; $freq = 1; $max = 0; - for($i = 0; $i < $octaves; ++$i){ - $result += $this->noise($x * $freq, $y * $freq, $z * $freq) * $amp; + for($i = 0; $i < $this->octaves; ++$i){ + $result += $this->getNoise2D($x * $freq, $z * $freq) * $amp; + $max += $amp; + $freq *= $frequency; + $amp *= $amplitude; + } + if($normalized === true){ + $result /= $max; + } + + return $result; + } + + public function noise3D($x, $y, $z, $frequency, $amplitude, $normalized = false){ + $result = 0; + $amp = 1; + $freq = 1; + $max = 0; + + for($i = 0; $i < $this->octaves; ++$i){ + $result += $this->getNoise3D($x * $freq, $y * $freq, $z * $freq) * $amp; $max += $amp; $freq *= $frequency; $amp *= $amplitude; diff --git a/src/world/generator/noise/NoiseGeneratorPerlin.php b/src/world/generator/noise/NoiseGeneratorPerlin.php index 82886964e..83341c094 100644 --- a/src/world/generator/noise/NoiseGeneratorPerlin.php +++ b/src/world/generator/noise/NoiseGeneratorPerlin.php @@ -31,7 +31,8 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ ]; - public function __construct(Random $random){ + public function __construct(Random $random, $octaves){ + $this->octaves = $octaves; $this->offsetX = $random->nextFloat() * 256; $this->offsetY = $random->nextFloat() * 256; $this->offsetZ = $random->nextFloat() * 256; @@ -55,7 +56,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ } - public function noise($x, $y, $z){ + public function getNoise3D($x, $y, $z){ $x += $this->offsetX; $y += $this->offsetY; $z += $this->offsetZ; @@ -94,4 +95,8 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ self::lerp($fX, self::grad($this->perm[$AB + 1], $x, $y - 1, $z - 1), self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1)))); } + + public function getNoise2D($x, $z){ + return $this->getNoise3D($x, 0, $z); + } } \ No newline at end of file From 8377416f48330a3b096f60a0c903dc752e539a7d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 12 Feb 2014 16:35:17 +0100 Subject: [PATCH 030/173] Nice generation :D --- src/world/generator/NormalGenerator.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index c88e24d7f..ac6c3aa18 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -45,8 +45,9 @@ class NormalGenerator implements LevelGenerator{ $this->level = $level; $this->random = $random; $this->random->setSeed($this->level->getSeed()); - $this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 16); + $this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 4); $this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4); + $this->noiseGen3 = new NoiseGeneratorPerlin($this->random, 4); $ores = new OrePopulator(); $ores->setOreTypes(array( @@ -65,14 +66,17 @@ class NormalGenerator implements LevelGenerator{ public function generateChunk($chunkX, $chunkZ){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); - $baseHeight = $this->worldHeight;// + $this->noiseGen1->noise2D($chunkX, $chunkZ, 2, 1/4, true) * 35; + $baseHeight = $this->worldHeight;// + * 35; for($chunkY = 0; $chunkY < 8; ++$chunkY){ $chunk = ""; $startY = $chunkY << 4; $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ - $height = (int) ($baseHeight + $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.3, 32, true) * 15); + $noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.6, 32, true) * 2; + $noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.35, 64, true) * 15; + $noise3 = $this->noiseGen3->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.1, 64, true) * 45; + $height = (int) ($baseHeight + $noise1 + $noise2); for($y = $startY; $y < $endY; ++$y){ $diff = $height - $y; if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ @@ -82,7 +86,11 @@ class NormalGenerator implements LevelGenerator{ }elseif($diff > 0){ $chunk .= "\x03"; //dirt }elseif($y <= $this->waterHeight){ - $chunk .= "\x09"; //still_water + if($diff === 0){ + $chunk .= "\x0c"; //sand + }else{ + $chunk .= "\x09"; //still_water + } }elseif($diff === 0){ $chunk .= "\x02"; //grass }else{ From f7b8ad0e37fd419e670f2192504e82adfbf7fa8b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 00:01:32 +0100 Subject: [PATCH 031/173] Infinite generation, in-place chunk creation working. New PMF Format --- src/pmf/{Level.php => PMFLevel.php} | 252 +++++----- src/pmf/{Plugin.php => PMFPlugin.php} | 0 src/world/Level.php | 21 +- src/world/generator/LevelGenerator.php | 7 +- src/world/generator/NormalGenerator.php | 37 +- src/world/generator/SuperflatGenerator.php | 4 + src/world/generator/TemporalGenerator.php | 95 ---- src/world/generator/WorldGenerator.php | 36 +- .../generator/noise/NoiseGeneratorPerlin.php | 4 +- .../generator/noise/NoiseGeneratorSimplex.php | 437 ++++++++++++++++++ 10 files changed, 641 insertions(+), 252 deletions(-) rename src/pmf/{Level.php => PMFLevel.php} (68%) rename src/pmf/{Plugin.php => PMFPlugin.php} (100%) delete mode 100644 src/world/generator/TemporalGenerator.php create mode 100644 src/world/generator/noise/NoiseGeneratorSimplex.php diff --git a/src/pmf/Level.php b/src/pmf/PMFLevel.php similarity index 68% rename from src/pmf/Level.php rename to src/pmf/PMFLevel.php index e4c8824fd..657019b09 100644 --- a/src/pmf/Level.php +++ b/src/pmf/PMFLevel.php @@ -19,16 +19,17 @@ * */ -define("PMF_CURRENT_LEVEL_VERSION", 0x00); - class PMFLevel extends PMF{ - private $levelData = array(); - private $locationTable = array(); + const VERSION = 0x01; + const DEFLATE_LEVEL = 9; + + public $level; + public $levelData = array(); public $isLoaded = true; - private $log = 4; - private $payloadOffset = 0; private $chunks = array(); private $chunkChange = array(); + private $chunkInfo = array(); + public $isGenerating = false; public function getData($index){ if(!isset($this->levelData[$index])){ @@ -46,8 +47,8 @@ class PMFLevel extends PMF{ } public function close(){ - $chunks = null; - unset($chunks, $chunkChange, $locationTable); + $this->chunks = null; + unset($this->chunks, $this->chunkChange, $this->chunkInfo, $this->level); parent::close(); } @@ -57,7 +58,6 @@ class PMFLevel extends PMF{ $this->levelData = $blank; $this->createBlank(); $this->isLoaded = true; - $this->log = (int) ((string) log($this->levelData["width"], 2)); }else{ if($this->load($file) !== false){ $this->parseInfo(); @@ -65,7 +65,6 @@ class PMFLevel extends PMF{ $this->isLoaded = false; }else{ $this->isLoaded = true; - $this->log = (int) ((string) log($this->levelData["width"], 2)); } }else{ $this->isLoaded = false; @@ -73,8 +72,8 @@ class PMFLevel extends PMF{ } } - public function saveData($locationTable = true){ - $this->levelData["version"] = PMF_CURRENT_LEVEL_VERSION; + public function saveData(){ + $this->levelData["version"] = PMFLevel::VERSION; @ftruncate($this->fp, 5); $this->seek(5); $this->write(chr($this->levelData["version"])); @@ -84,33 +83,17 @@ class PMFLevel extends PMF{ $this->write(Utils::writeFloat($this->levelData["spawnX"])); $this->write(Utils::writeFloat($this->levelData["spawnY"])); $this->write(Utils::writeFloat($this->levelData["spawnZ"])); - $this->write(chr($this->levelData["width"])); $this->write(chr($this->levelData["height"])); - $extra = gzdeflate($this->levelData["extra"], PMF_LEVEL_DEFLATE_LEVEL); + $this->write(Utils::writeShort(strlen($this->levelData["generator"])).$this->levelData["generator"]); + $settings = serialize($this->levelData["generatorSettings"]); + $this->write(Utils::writeShort(strlen($settings)).$settings); + $extra = gzdeflate($this->levelData["extra"], PMFLevel::DEFLATE_LEVEL); $this->write(Utils::writeShort(strlen($extra)).$extra); - $this->payloadOffset = ftell($this->fp); - - if($locationTable !== false){ - $this->writeLocationTable(); - } } private function createBlank(){ $this->saveData(false); - $this->locationTable = array(); - $cnt = pow($this->levelData["width"], 2); @mkdir(dirname($this->file)."/chunks/", 0755); - for($index = 0; $index < $cnt; ++$index){ - $this->chunks[$index] = false; - $this->chunkChange[$index] = false; - $this->locationTable[$index] = array( - 0 => 0, - ); - $this->write(Utils::writeShort(0)); - $X = $Z = null; - $this->getXZ($index, $X, $Z); - @file_put_contents($this->getChunkPath($X, $Z), gzdeflate("", PMF_LEVEL_DEFLATE_LEVEL)); - } if(!file_exists(dirname($this->file)."/entities.yml")){ $entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML); $entities->save(); @@ -127,7 +110,7 @@ class PMFLevel extends PMF{ } $this->seek(5); $this->levelData["version"] = ord($this->read(1)); - if($this->levelData["version"] > PMF_CURRENT_LEVEL_VERSION){ + if($this->levelData["version"] > PMFLevel::VERSION){ return false; } $this->levelData["name"] = $this->read(Utils::readShort($this->read(2), false)); @@ -136,90 +119,81 @@ class PMFLevel extends PMF{ $this->levelData["spawnX"] = Utils::readFloat($this->read(4)); $this->levelData["spawnY"] = Utils::readFloat($this->read(4)); $this->levelData["spawnZ"] = Utils::readFloat($this->read(4)); - $this->levelData["width"] = ord($this->read(1)); $this->levelData["height"] = ord($this->read(1)); - if(($this->levelData["width"] !== 16 and $this->levelData["width"] !== 32) or $this->levelData["height"] !== 8){ + if($this->levelData["height"] !== 8){ return false; } - $lastseek = ftell($this->fp); - if(($len = $this->read(2)) === false or ($this->levelData["extra"] = @gzinflate($this->read(Utils::readShort($len, false)))) === false){ //Corruption protection - console("[NOTICE] Empty/corrupt location table detected, forcing recovery"); - fseek($this->fp, $lastseek); - $c = gzdeflate(""); - $this->write(Utils::writeShort(strlen($c)).$c); - $this->payloadOffset = ftell($this->fp); - $this->levelData["extra"] = ""; - $cnt = pow($this->levelData["width"], 2); - for($index = 0; $index < $cnt; ++$index){ - $this->write("\x00\xFF"); //Force index recreation - } - fseek($this->fp, $this->payloadOffset); + if($this->levelData["version"] === 0){ + $this->read(1); }else{ - $this->payloadOffset = ftell($this->fp); + $this->levelData["generator"] = $this->read(Utils::readShort($this->read(2), false)); + $this->levelData["generatorSettings"] = unserialize($this->read(Utils::readShort($this->read(2), false))); + } + $this->levelData["extra"] = @gzinflate($this->read(Utils::readShort($this->read(2), false))); + + if($this->levelData["version"] === 0){ + $this->upgrade_From0_To1(); } - return $this->readLocationTable(); } - public function getIndex($X, $Z){ - $X = (int) $X; - $Z = (int) $Z; - return ($Z << $this->log) + $X; - } - - public function getXZ($index, &$X = null, &$Z = null){ - $X = $index >> $this->log; - $Z = $index & (pow($this->log, 2) - 1); - return array($X, $Z); - } - - private function readLocationTable(){ - $this->locationTable = array(); - $cnt = pow($this->levelData["width"], 2); - $this->seek($this->payloadOffset); + private function upgrade_From0_To1(){ for($index = 0; $index < $cnt; ++$index){ $this->chunks[$index] = false; $this->chunkChange[$index] = false; - $this->locationTable[$index] = array( + $locationTable[$index] = array( 0 => Utils::readShort($this->read(2)), //16 bit flags ); } - return true; } - private function writeLocationTable(){ - $cnt = pow($this->levelData["width"], 2); - @ftruncate($this->fp, $this->payloadOffset); - $this->seek($this->payloadOffset); - for($index = 0; $index < $cnt; ++$index){ - $this->write(Utils::writeShort($this->locationTable[$index][0])); - } + public static function getIndex($X, $Z){ + return ($Z << 16) + $X; + } + + public static function getXZ($index, &$X = null, &$Z = null){ + $Z = $index >> 16; + $X = $index & 0xFFFF; + return array($X, $Z); } private function getChunkPath($X, $Z){ - return dirname($this->file)."/chunks/".$Z.".".$X.".pmc"; + return dirname($this->file)."/chunks/".(($X ^ $Z) & 0xff)."/".$Z.".".$X.".pmc"; + } + + public function generateChunk($X, $Z){ + $path = $this->getChunkPath($X, $Z); + if(!file_exists(dirname($path))){ + @mkdir(dirname($path), 0755); + } + $this->isGenerating = true; + $ret = $this->level->generateChunk($X, $Z); + $this->isGenerating = false; + return $ret; } public function loadChunk($X, $Z){ $X = (int) $X; $Z = (int) $Z; - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); if($this->isChunkLoaded($X, $Z)){ return true; - }elseif(!isset($this->locationTable[$index])){ + } + $path = $this->getChunkPath($X, $Z); + if(!file_exists($path) and $this->generateChunk($X, $Z) === false){ return false; } - $info = $this->locationTable[$index]; - $this->seek($info[0]); - - $chunk = @gzopen($this->getChunkPath($X, $Z), "rb"); + $chunk = @gzopen($path, "rb"); if($chunk === false){ return false; } + $this->chunkInfo[$index] = array( + 0 => ord(gzread($chunk, 1)), + ); $this->chunks[$index] = array(); $this->chunkChange[$index] = array(-1 => false); - for($Y = 0; $Y < $this->levelData["height"]; ++$Y){ + for($Y = 0; $Y < $this->chunkInfo[$index][0]; ++$Y){ $t = 1 << $Y; - if(($info[0] & $t) === $t){ + if(($this->chunkInfo[$index][0] & $t) === $t){ // 4096 + 2048 + 2048, Block Data, Meta, Light if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){ console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents"); @@ -241,15 +215,16 @@ class PMFLevel extends PMF{ }elseif($save !== false){ $this->saveChunk($X, $Z); } - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); $this->chunks[$index] = null; $this->chunkChange[$index] = null; - unset($this->chunks[$index], $this->chunkChange[$index]); + $this->chunkInfo[$index] = null; + unset($this->chunks[$index], $this->chunkChange[$index], $this->chunkInfo[$index]); return true; } public function isChunkLoaded($X, $Z){ - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ return false; } @@ -257,7 +232,7 @@ class PMFLevel extends PMF{ } protected function isMiniChunkEmpty($X, $Z, $Y){ - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); if($this->chunks[$index][$Y] !== false){ if(substr_count($this->chunks[$index][$Y], "\x00") < 8192){ return false; @@ -270,11 +245,11 @@ class PMFLevel extends PMF{ if($this->isChunkLoaded($X, $Z) === false){ return false; } - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); $this->chunks[$index][$Y] = str_repeat("\x00", 8192); $this->chunkChange[$index][-1] = true; $this->chunkChange[$index][$Y] = 8192; - $this->locationTable[$index][0] |= 1 << $Y; + $this->chunkInfo[$index][0] |= 1 << $Y; return true; } @@ -282,36 +257,61 @@ class PMFLevel extends PMF{ if($this->loadChunk($X, $Z) === false){ return str_repeat("\x00", 8192); } - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); if(!isset($this->chunks[$index][$Y]) or $this->chunks[$index][$Y] === false){ return str_repeat("\x00", 8192); } return $this->chunks[$index][$Y]; } + public function initCleanChunk($X, $Z){ + $index = self::getIndex($X, $Z); + if(!isset($this->chunks[$index])){ + $this->chunks[$index] = array( + 0 => false, + 1 => false, + 2 => false, + 3 => false, + 4 => false, + 5 => false, + 6 => false, + 7 => false, + ); + $this->chunkChange[$index] = array(-1 => false); + $this->chunkInfo[$index] = array( + 0 => 0, + ); + } + } + public function setMiniChunk($X, $Z, $Y, $data){ - if($this->isChunkLoaded($X, $Z) === false){ + if($this->isGenerating === true){ + $this->initCleanChunk($X, $Z); + }elseif($this->isChunkLoaded($X, $Z) === false){ $this->loadChunk($X, $Z); } if(strlen($data) !== 8192){ return false; } - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); $this->chunks[$index][$Y] = (string) $data; $this->chunkChange[$index][-1] = true; $this->chunkChange[$index][$Y] = 8192; - $this->locationTable[$index][0] |= 1 << $Y; + $this->chunkInfo[$index][0] |= 1 << $Y; return true; } public function getBlockID($x, $y, $z){ - if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){ + if($y > 127 or $y < 0){ return 0; } $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); + if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + return 0; + } $aX = $x - ($X << 4); $aZ = $z - ($Z << 4); $aY = $y - ($Y << 4); @@ -320,17 +320,17 @@ class PMFLevel extends PMF{ } public function setBlockID($x, $y, $z, $block){ - if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){ + if($y > 127 or $y < 0){ return false; } $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; $block &= 0xFF; - if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){ + $index = self::getIndex($X, $Z); + if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ return false; } - $index = $this->getIndex($X, $Z); $aX = $x - ($X << 4); $aZ = $z - ($Z << 4); $aY = $y - ($Y << 4); @@ -345,13 +345,16 @@ class PMFLevel extends PMF{ } public function getBlockDamage($x, $y, $z){ - if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){ + if($y > 127 or $y < 0){ return 0; } $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); + if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + return 0; + } $aX = $x - ($X << 4); $aZ = $z - ($Z << 4); $aY = $y - ($Y << 4); @@ -365,17 +368,17 @@ class PMFLevel extends PMF{ } public function setBlockDamage($x, $y, $z, $damage){ - if($y > 127 or $y < 0 or $x < 0 or $z < 0 or $x > 255 or $z > 255){ + if($y > 127 or $y < 0){ return false; } $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; $damage &= 0x0F; - if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){ + $index = self::getIndex($X, $Z); + if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ return false; } - $index = $this->getIndex($X, $Z); $aX = $x - ($X << 4); $aZ = $z - ($Z << 4); $aY = $y - ($Y << 4); @@ -404,10 +407,10 @@ class PMFLevel extends PMF{ $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; - if($x < 0 or $z < 0 or $X >= $this->levelData["width"] or $Z >= $this->levelData["width"] or $Y >= $this->levelData["height"] or $y < 0){ + if($y < 0 or $y > 127){ return array(AIR, 0); } - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ if($this->loadChunk($X, $Z) === false){ return array(AIR, 0); @@ -429,15 +432,15 @@ class PMFLevel extends PMF{ } public function setBlock($x, $y, $z, $block, $meta = 0){ + if($y > 127 or $y < 0){ + return false; + } $X = $x >> 4; $Z = $z >> 4; $Y = $y >> 4; $block &= 0xFF; $meta &= 0x0F; - if($X >= 32 or $Z >= 32 or $Y >= $this->levelData["height"] or $y < 0){ - return false; - } - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ if($this->loadChunk($X, $Z) === false){ return false; @@ -486,35 +489,46 @@ class PMFLevel extends PMF{ public function saveChunk($X, $Z){ $X = (int) $X; $Z = (int) $Z; - if(!$this->isChunkLoaded($X, $Z)){ + if($this->isGenerating === true){ + $this->initCleanChunk($X, $Z); + }elseif(!$this->isChunkLoaded($X, $Z)){ return false; } - $index = $this->getIndex($X, $Z); + $index = self::getIndex($X, $Z); if(!isset($this->chunkChange[$index]) or $this->chunkChange[$index][-1] === false){//No changes in chunk return true; } - $chunk = @gzopen($this->getChunkPath($X, $Z), "wb".PMF_LEVEL_DEFLATE_LEVEL); + $path = $this->getChunkPath($X, $Z); + if(!file_exists(dirname($path))){ + @mkdir(dirname($path), 0755); + } $bitmap = 0; - for($Y = 0; $Y < $this->levelData["height"]; ++$Y){ + for($Y = 0; $Y < 8; ++$Y){ if($this->chunks[$index][$Y] !== false and ((isset($this->chunkChange[$index][$Y]) and $this->chunkChange[$index][$Y] === 0) or !$this->isMiniChunkEmpty($X, $Z, $Y))){ - gzwrite($chunk, $this->chunks[$index][$Y]); $bitmap |= 1 << $Y; }else{ $this->chunks[$index][$Y] = false; } $this->chunkChange[$index][$Y] = 0; } + $chunk = @gzopen($path, "wb".PMFLevel::DEFLATE_LEVEL); + gzwrite($chunk, chr($bitmap)); + for($Y = 0; $Y < 8; ++$Y){ + $t = 1 << $Y; + if(($bitmap & $t) === $t){ + gzwrite($chunk, $this->chunks[$index][$Y]); + } + } + gzclose($chunk); $this->chunkChange[$index][-1] = false; - $this->locationTable[$index][0] = $bitmap; - $this->seek($this->payloadOffset + ($index << 1)); - $this->write(Utils::writeShort($this->locationTable[$index][0])); + $this->chunkInfo[$index][0] = $bitmap; return true; } public function doSaveRound(){ foreach($this->chunks as $index => $chunk){ - $this->getXZ($index, $X, $Z); + self::getXZ($index, $X, $Z); $this->saveChunk($X, $Z); } } diff --git a/src/pmf/Plugin.php b/src/pmf/PMFPlugin.php similarity index 100% rename from src/pmf/Plugin.php rename to src/pmf/PMFPlugin.php diff --git a/src/world/Level.php b/src/world/Level.php index 84ff983be..05414e943 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -21,11 +21,12 @@ class Level{ public $entities, $tiles, $blockUpdates, $nextSave, $players = array(), $level; - private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime; + private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime, $generator; public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ $this->server = ServerAPI::request(); $this->level = $level; + $level->level = $this; $this->level->level = $this; $this->entities = $entities; $this->tiles = $tiles; @@ -40,6 +41,17 @@ class Level{ $this->usedChunks = array(); $this->changedBlocks = array(); $this->changedCount = array(); + if(class_exists($this->level->levelData["generator"])){ + $gen = $this->level->levelData["generator"]; + $this->generator = new $gen((array) $this->level->levelData["generatorSettings"]); + }else{ + if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){ + $this->generator = new SuperflatGenerator(); + }else{ + $this->generator = new NormalGenerator(); + } + } + $this->generator->init($this, new Random($this->level->levelData["seed"])); } public function close(){ @@ -136,6 +148,13 @@ class Level{ } } + public function generateChunk($X, $Z){ + $this->level->initCleanChunk($X, $Z); + $this->generator->generateChunk($X, $Z); + $this->generator->populateChunk($X, $Z); + $this->level->saveChunk($X, $Z); + } + public function __destruct(){ if(isset($this->level)){ $this->save(false, false); diff --git a/src/world/generator/LevelGenerator.php b/src/world/generator/LevelGenerator.php index 5da986456..939d356f3 100644 --- a/src/world/generator/LevelGenerator.php +++ b/src/world/generator/LevelGenerator.php @@ -20,7 +20,8 @@ */ interface LevelGenerator{ - public function __construct(array $options = array()); + + public function __construct(array $settings = array()); public function init(Level $level, Random $random); @@ -28,7 +29,9 @@ interface LevelGenerator{ public function populateChunk($chunkX, $chunkZ); - public function populateLevel(); + public function getSettings(); + + //public function populateLevel(); public function getSpawn(); } \ No newline at end of file diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index ac6c3aa18..462154051 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -28,8 +28,9 @@ class NormalGenerator implements LevelGenerator{ private $populators = array(); private $level; private $random; - private $worldHeight = 64; - private $waterHeight = 60; + private $worldHeight = 65; + private $waterHeight = 62; + private $noiseGenBase; private $noiseGen1; private $noiseGen2; private $noiseGen3; @@ -41,13 +42,17 @@ class NormalGenerator implements LevelGenerator{ } + public function getSettings(){ + return array(); + } + public function init(Level $level, Random $random){ $this->level = $level; $this->random = $random; $this->random->setSeed($this->level->getSeed()); - $this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 4); - $this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4); - $this->noiseGen3 = new NoiseGeneratorPerlin($this->random, 4); + $this->noiseGenBase = new NoiseGeneratorSimplex($this->random, 4); + $this->noiseGen1 = new NoiseGeneratorSimplex($this->random, 8); + //$this->noiseGen2 = new NoiseGeneratorSimplex($this->random, 8); $ores = new OrePopulator(); $ores->setOreTypes(array( @@ -66,17 +71,18 @@ class NormalGenerator implements LevelGenerator{ public function generateChunk($chunkX, $chunkZ){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); - $baseHeight = $this->worldHeight;// + * 35; for($chunkY = 0; $chunkY < 8; ++$chunkY){ $chunk = ""; $startY = $chunkY << 4; $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ - $noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.6, 32, true) * 2; - $noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.35, 64, true) * 15; - $noise3 = $this->noiseGen3->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.1, 64, true) * 45; - $height = (int) ($baseHeight + $noise1 + $noise2); + $noiseBase = $this->noiseGenBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 1/5, 16, true); + $noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 25, true); + //$noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.8, 1); + //$height = $this->worldHeight + $noiseBase + $noise1 /*+ $noise2*/; + $height = $this->worldHeight + $noiseBase;//$height = (int) ($height + ($height * 0.15 * $noiseBase)); + $height = (int) $height; for($y = $startY; $y < $endY; ++$y){ $diff = $height - $y; if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ @@ -86,13 +92,13 @@ class NormalGenerator implements LevelGenerator{ }elseif($diff > 0){ $chunk .= "\x03"; //dirt }elseif($y <= $this->waterHeight){ - if($diff === 0){ + if($y === $this->waterHeight and $diff === 0){ $chunk .= "\x0c"; //sand }else{ $chunk .= "\x09"; //still_water } }elseif($diff === 0){ - $chunk .= "\x02"; //grass + $chunk .= $noise1 > 0 ? "\x02":"\x01"; //grass }else{ $chunk .= "\x00"; } @@ -105,13 +111,6 @@ class NormalGenerator implements LevelGenerator{ } - private function initializeNoiseArray($x, $y, $z, $sizeX, $sizeY, $sizeZ){ - $noiseArray = array_fill(0, $sizeX * $sizeY * $sizeZ, 0.0); - - $noise5 = $this->noiseGen5->generateNoiseOctaves($x, $y, $z); - - } - public function populateChunk($chunkX, $chunkZ){ foreach($this->populators as $populator){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); diff --git a/src/world/generator/SuperflatGenerator.php b/src/world/generator/SuperflatGenerator.php index 731c304df..2ac111337 100644 --- a/src/world/generator/SuperflatGenerator.php +++ b/src/world/generator/SuperflatGenerator.php @@ -26,6 +26,10 @@ require_once("LevelGenerator.php"); class SuperflatGenerator implements LevelGenerator{ private $level, $random, $structure, $chunks, $options, $floorLevel, $populators = array(); + public function getSettings(){ + return $this->options; + } + public function __construct(array $options = array()){ $this->preset = "2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)"; $this->options = $options; diff --git a/src/world/generator/TemporalGenerator.php b/src/world/generator/TemporalGenerator.php deleted file mode 100644 index d03fde3db..000000000 --- a/src/world/generator/TemporalGenerator.php +++ /dev/null @@ -1,95 +0,0 @@ -level = $level; - $this->random = $random; - $this->index = mt_rand(0, count(TemporalGenerator::$levels) - 1); - $this->world = new PocketChunkParser(); - $this->world->loadRaw(gzinflate(gzinflate(base64_decode(TemporalGenerator::$levels[$this->index][4]))), ""); - $this->world->loadMap(); - $this->level->setSeed(TemporalGenerator::$levels[$this->index][0]); - } - - public function generateChunk($chunkX, $chunkZ){ - - } - - public function populateChunk($chunkX, $chunkZ){ - - } - - public function populateLevel(){ - for($Z = 0; $Z < 16; ++$Z){ - for($X = 0; $X < 16; ++$X){ - $chunk = array( - 0 => "", - 1 => "", - 2 => "", - 3 => "", - 4 => "", - 5 => "", - 6 => "", - 7 => "" - ); - for($z = 0; $z < 16; ++$z){ - for($x = 0; $x < 16; ++$x){ - $block = $this->world->getChunkColumn($X, $Z, $x, $z, 0); - $meta = $this->world->getChunkColumn($X, $Z, $x, $z, 1); - for($Y = 0; $Y < 8; ++$Y){ - $chunk[$Y] .= substr($block, $Y << 4, 16); - $chunk[$Y] .= substr($meta, $Y << 3, 8); - $chunk[$Y] .= "\x00\x00\x00\x00\x00\x00\x00\x00"; - } - } - } - foreach($chunk as $Y => $data){ - $this->level->setMiniChunk($X, $Z, $Y, $data); - } - } - console("[NOTICE] Importing level ".ceil(($Z + 1)/0.16)."%"); - } - $this->level->save(true, true); - $this->world->map = null; - $this->world = null; - } - - public function getSpawn(){ - return new Vector3(TemporalGenerator::$levels[$this->index][1], TemporalGenerator::$levels[$this->index][2], TemporalGenerator::$levels[$this->index][3]); - } -} \ No newline at end of file diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index 4b79bf8fb..cfca09041 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -21,10 +21,9 @@ class WorldGenerator{ private $seed, $level, $path, $random, $generator, $width; - public function __construct(LevelGenerator $generator, $name, $seed = false, $width = 16, $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->random = new Random($this->seed); - $this->width = (int) $width; $this->height = (int) $height; $this->path = DATA_PATH."worlds/".$name."/"; $this->generator = $generator; @@ -35,9 +34,10 @@ class WorldGenerator{ "spawnX" => 128, "spawnY" => 128, "spawnZ" => 128, - "extra" => "", - "width" => $this->width, - "height" => $this->height + "height" => $this->height, + "generator" => get_class($this->generator), + "generatorSettings" => $this->generator->getSettings(), + "extra" => "" )); $entities = new Config($this->path."entities.yml", CONFIG_YAML); $tiles = new Config($this->path."tiles.yml", CONFIG_YAML); @@ -45,25 +45,33 @@ class WorldGenerator{ $this->level = new Level($level, $entities, $tiles, $blockUpdates, $name); } - public function generate(){ + public function generate(){ + $this->level->level->isGenerating = true; $this->generator->init($this->level, $this->random); - for($Z = 0; $Z < $this->width; ++$Z){ - for($X = 0; $X < $this->width; ++$X){ + + $i = 0; + for($Z = 6; $Z <= 10; ++$Z){ + for($X = 6; $X <= 10; ++$X){ $this->generator->generateChunk($X, $Z); } - console("[NOTICE] Generating level ".ceil((($Z + 1)/$this->width) * 100)."%"); + console("[NOTICE] Generating level".str_repeat(".", $i)); + ++$i; } - console("[NOTICE] Populating level"); - $this->generator->populateLevel(); - for($Z = 0; $Z < $this->width; ++$Z){ - for($X = 0; $X < $this->width; ++$X){ + //console("[NOTICE] Populating level"); + //$this->generator->populateLevel(); + + $i = 0; + for($Z = 6; $Z <= 10; ++$Z){ + for($X = 6; $X <= 10; ++$X){ $this->generator->populateChunk($X, $Z); } - console("[NOTICE] Populating level ".ceil((($Z + 1)/$this->width) * 100)."%"); + console("[NOTICE] Populating level".str_repeat(".", $i)); + ++$i; } $this->level->setSpawn($this->generator->getSpawn()); $this->level->save(true, true); + $this->level->level->isGenerating = false; } public function close(){ diff --git a/src/world/generator/noise/NoiseGeneratorPerlin.php b/src/world/generator/noise/NoiseGeneratorPerlin.php index 83341c094..8fcf6a34c 100644 --- a/src/world/generator/noise/NoiseGeneratorPerlin.php +++ b/src/world/generator/noise/NoiseGeneratorPerlin.php @@ -96,7 +96,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{ self::grad($this->perm[$BB + 1], $x - 1, $y - 1, $z - 1)))); } - public function getNoise2D($x, $z){ - return $this->getNoise3D($x, 0, $z); + public function getNoise2D($x, $y){ + return $this->getNoise3D($x, $y, 0); } } \ No newline at end of file diff --git a/src/world/generator/noise/NoiseGeneratorSimplex.php b/src/world/generator/noise/NoiseGeneratorSimplex.php new file mode 100644 index 000000000..f01f108b4 --- /dev/null +++ b/src/world/generator/noise/NoiseGeneratorSimplex.php @@ -0,0 +1,437 @@ + + * This is a modified version of the freely published version in the paper by + * Stefan Gustavson at + * + * http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf + */ +class NoiseGeneratorSimplex extends NoiseGeneratorPerlin{ + protected static $SQRT_3; + protected static $SQRT_5; + protected static $F2; + protected static $G2; + protected static $G22; + protected static $F3; + protected static $G3; + protected static $F4; + protected static $G4; + protected static $G42; + protected static $G43; + protected static $G44; + protected static $grad4 = [[0, 1, 1, 1],[0, 1, 1, -1],[0, 1, -1, 1],[0, 1, -1, -1], + [0, -1, 1, 1],[0, -1, 1, -1],[0, -1, -1, 1],[0, -1, -1, -1], + [1, 0, 1, 1],[1, 0, 1, -1],[1, 0, -1, 1],[1, 0, -1, -1], + [-1, 0, 1, 1],[-1, 0, 1, -1],[-1, 0, -1, 1],[-1, 0, -1, -1], + [1, 1, 0, 1],[1, 1, 0, -1],[1, -1, 0, 1],[1, -1, 0, -1], + [-1, 1, 0, 1],[-1, 1, 0, -1],[-1, -1, 0, 1],[-1, -1, 0, -1], + [1, 1, 1, 0],[1, 1, -1, 0],[1, -1, 1, 0],[1, -1, -1, 0], + [-1, 1, 1, 0],[-1, 1, -1, 0],[-1, -1, 1, 0],[-1, -1, -1, 0]]; + protected static $simplex = [ + [0, 1, 2, 3],[0, 1, 3, 2],[0, 0, 0, 0],[0, 2, 3, 1],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[1, 2, 3, 0], + [0, 2, 1, 3],[0, 0, 0, 0],[0, 3, 1, 2],[0, 3, 2, 1],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[1, 3, 2, 0], + [0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0], + [1, 2, 0, 3],[0, 0, 0, 0],[1, 3, 0, 2],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[2, 3, 0, 1],[2, 3, 1, 0], + [1, 0, 2, 3],[1, 0, 3, 2],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[2, 0, 3, 1],[0, 0, 0, 0],[2, 1, 3, 0], + [0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0], + [2, 0, 1, 3],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[3, 0, 1, 2],[3, 0, 2, 1],[0, 0, 0, 0],[3, 1, 2, 0], + [2, 1, 0, 3],[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 0, 0],[3, 1, 0, 2],[0, 0, 0, 0],[3, 2, 0, 1],[3, 2, 1, 0]]; + protected $offsetW; + + public function __construct(Random $random, $octaves){ + parent::__construct($random, $octaves); + $this->offsetW = $random->nextFloat() * 256; + self::$SQRT_3 = sqrt(3); + self::$SQRT_5 = sqrt(5); + self::$F2 = 0.5 * (self::$SQRT_3 - 1); + self::$G2 = (3 - self::$SQRT_3) / 6; + self::$G22 = self::$G2 * 2.0 - 1; + self::$F3 = 1.0 / 3.0; + self::$G3 = 1.0 / 6.0; + self::$F4 = (self::$SQRT_5 - 1.0) / 4.0; + self::$G4 = (5.0 - self::$SQRT_5) / 20.0; + self::$G42 = self::$G4 * 2.0; + self::$G43 = self::$G4 * 3.0; + self::$G44 = self::$G4 * 4.0 - 1.0; + } + + protected static function dot2D($g, $x, $y){ + return $g[0] * $x + $g[1] * $y; + } + + protected static function dot3D($g, $x, $y, $z){ + return $g[0] * $x + $g[1] * $y + $g[2] * $z; + } + + protected static function dot4D($g, $x, $y, $z, $w){ + return $g[0] * $x + $g[1] * $y + $g[2] * $z + $g[3] * $w; + } + + public function getNoise3D($x, $y, $z){ + $x += $this->offsetX; + $y += $this->offsetY; + $z += $this->offsetZ; + + // Skew the input space to determine which simplex cell we're in + $s = ($x + $y + $z) * self::$F3; // Very nice and simple skew factor for 3D + $i = self::floor($x + $s); + $j = self::floor($y + $s); + $k = self::floor($z + $s); + $t = ($i + $j + $k) * self::$G3; + $X0 = $i - $t; // Unskew the cell origin back to (x,y,z) space + $Y0 = $j - $t; + $Z0 = $k - $t; + $x0 = $x - $X0; // The x,y,z distances from the cell origin + $y0 = $y - $Y0; + $z0 = $z - $Z0; + + // For the 3D case, the simplex shape is a slightly irregular tetrahedron. + + // Determine which simplex we are in. + if($x0 >= $y0){ + if($y0 >= $z0){ + $i1 = 1; + $j1 = 0; + $k1 = 0; + $i2 = 1; + $j2 = 1; + $k2 = 0; + }// X Y Z order + elseif($x0 >= $z0){ + $i1 = 1; + $j1 = 0; + $k1 = 0; + $i2 = 1; + $j2 = 0; + $k2 = 1; + }// X Z Y order + else{ + $i1 = 0; + $j1 = 0; + $k1 = 1; + $i2 = 1; + $j2 = 0; + $k2 = 1; + }// Z X Y order + }else{ // x0perm[$ii + $this->perm[$jj + $this->perm[$kk]]] % 12; + $gi1 = $this->perm[$ii + $i1 + $this->perm[$jj + $j1 + $this->perm[$kk + $k1]]] % 12; + $gi2 = $this->perm[$ii + $i2 + $this->perm[$jj + $j2 + $this->perm[$kk + $k2]]] % 12; + $gi3 = $this->perm[$ii + 1 + $this->perm[$jj + 1 + $this->perm[$kk + 1]]] % 12; + + // Calculate the contribution from the four corners + $t0 = 0.6 - $x0 * $x0 - $y0 * $y0 - $z0 * $z0; + if($t0 < 0){ + $n0 = 0.0; + }else{ + $t0 *= $t0; + $n0 = $t0 * $t0 * self::dot3D(self::$grad3[$gi0], $x0, $y0, $z0); + } + + $t1 = 0.6 - $x1 * $x1 - $y1 * $y1 - $z1 * $z1; + if($t1 < 0){ + $n1 = 0.0; + }else{ + $t1 *= $t1; + $n1 = $t1 * $t1 * self::dot3D(self::$grad3[$gi1], $x1, $y1, $z1); + } + + $t2 = 0.6 - $x2 * $x2 - $y2 * $y2 - $z2 * $z2; + if($t2 < 0){ + $n2 = 0.0; + }else{ + $t2 *= $t2; + $n2 = $t2 * $t2 * self::dot3D(self::$grad3[$gi2], $x2, $y2, $z2); + } + + $t3 = 0.6 - $x3 * $x3 - $y3 * $y3 - $z3 * $z3; + if($t3 < 0){ + $n3 = 0.0; + }else{ + $t3 *= $t3; + $n3 = $t3 * $t3 * self::dot3D(self::$grad3[$gi3], $x3, $y3, $z3); + } + + // Add contributions from each corner to get the noise value. + // The result is scaled to stay just inside [-1,1] + return 32.0 * ($n0 + $n1 + $n2 + $n3); + } + + public function getNoise2D($x, $y){ + $x += $this->offsetX; + $y += $this->offsetY; + + // Skew the input space to determine which simplex cell we're in + $s = ($x + $y) * self::$F2; // Hairy factor for 2D + $i = self::floor($x + $s); + $j = self::floor($y + $s); + $t = ($i + $j) * self::$G2; + $X0 = $i - $t; // Unskew the cell origin back to (x,y) space + $Y0 = $j - $t; + $x0 = $x - $X0; // The x,y distances from the cell origin + $y0 = $y - $Y0; + + // For the 2D case, the simplex shape is an equilateral triangle. + + // Determine which simplex we are in. + if($x0 > $y0){ + $i1 = 1; + $j1 = 0; + }// lower triangle, XY order: (0,0)->(1,0)->(1,1) + else{ + $i1 = 0; + $j1 = 1; + }// upper triangle, YX order: (0,0)->(0,1)->(1,1) + + // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and + // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where + // c = (3-sqrt(3))/6 + + $x1 = $x0 - $i1 + self::$G2; // Offsets for middle corner in (x,y) unskewed coords + $y1 = $y0 - $j1 + self::$G2; + $x2 = $x0 + self::$G22; // Offsets for last corner in (x,y) unskewed coords + $y2 = $y0 + self::$G22; + + // Work out the hashed gradient indices of the three simplex corners + $ii = $i & 255; + $jj = $j & 255; + $gi0 = $this->perm[$ii + $this->perm[$jj]] % 12; + $gi1 = $this->perm[$ii + $i1 + $this->perm[$jj + $j1]] % 12; + $gi2 = $this->perm[$ii + 1 + $this->perm[$jj + 1]] % 12; + + // Calculate the contribution from the three corners + $t0 = 0.5 - $x0 * $x0 - $y0 * $y0; + if($t0 < 0){ + $n0 = 0.0; + }else{ + $t0 *= $t0; + $n0 = $t0 * $t0 * self::dot2D(self::$grad3[$gi0], $x0, $y0); // (x,y) of grad3 used for 2D gradient + } + + $t1 = 0.5 - $x1 * $x1 - $y1 * $y1; + if($t1 < 0){ + $n1 = 0.0; + }else{ + $t1 *= $t1; + $n1 = $t1 * $t1 * self::dot2D(self::$grad3[$gi1], $x1, $y1); + } + + $t2 = 0.5 - $x2 * $x2 - $y2 * $y2; + if($t2 < 0){ + $n2 = 0.0; + }else{ + $t2 *= $t2; + $n2 = $t2 * $t2 * self::dot2D(self::$grad3[$gi2], $x2, $y2); + } + + // Add contributions from each corner to get the noise value. + // The result is scaled to return values in the interval [-1,1]. + return 70.0 * ($n0 + $n1 + $n2); + } + + /** + * Computes and returns the 4D simplex noise for the given coordinates in + * 4D space + * + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @param w W coordinate + * @return Noise at given location, from range -1 to 1 + */ + /*public function getNoise4D(x, y, z, w){ + x += offsetX; + y += offsetY; + z += offsetZ; + w += offsetW; + + n0, n1, n2, n3, n4; // Noise contributions from the five corners + + // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in + s = (x + y + z + w) * self::$F4; // Factor for 4D skewing + i = floor(x + s); + j = floor(y + s); + k = floor(z + s); + l = floor(w + s); + + t = (i + j + k + l) * self::$G4; // Factor for 4D unskewing + X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space + Y0 = j - t; + Z0 = k - t; + W0 = l - t; + x0 = x - X0; // The x,y,z,w distances from the cell origin + y0 = y - Y0; + z0 = z - Z0; + w0 = w - W0; + + // For the 4D case, the simplex is a 4D shape I won't even try to describe. + // To find out which of the 24 possible simplices we're in, we need to + // determine the magnitude ordering of x0, y0, z0 and w0. + // The method below is a good way of finding the ordering of x,y,z,w and + // then find the correct traversal order for the simplex we’re in. + // First, six pair-wise comparisons are performed between each possible pair + // of the four coordinates, and the results are used to add up binary bits + // for an integer index. + c1 = (x0 > y0) ? 32 : 0; + c2 = (x0 > z0) ? 16 : 0; + c3 = (y0 > z0) ? 8 : 0; + c4 = (x0 > w0) ? 4 : 0; + c5 = (y0 > w0) ? 2 : 0; + c6 = (z0 > w0) ? 1 : 0; + c = c1 + c2 + c3 + c4 + c5 + c6; + i1, j1, k1, l1; // The integer offsets for the second simplex corner + i2, j2, k2, l2; // The integer offsets for the third simplex corner + i3, j3, k3, l3; // The integer offsets for the fourth simplex corner + + // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order. + // Many values of c will never occur, since e.g. x>y>z>w makes x= 3 ? 1 : 0; + j1 = simplex[c][1] >= 3 ? 1 : 0; + k1 = simplex[c][2] >= 3 ? 1 : 0; + l1 = simplex[c][3] >= 3 ? 1 : 0; + + // The number 2 in the "simplex" array is at the second largest coordinate. + i2 = simplex[c][0] >= 2 ? 1 : 0; + j2 = simplex[c][1] >= 2 ? 1 : 0; + k2 = simplex[c][2] >= 2 ? 1 : 0; + l2 = simplex[c][3] >= 2 ? 1 : 0; + + // The number 1 in the "simplex" array is at the second smallest coordinate. + i3 = simplex[c][0] >= 1 ? 1 : 0; + j3 = simplex[c][1] >= 1 ? 1 : 0; + k3 = simplex[c][2] >= 1 ? 1 : 0; + l3 = simplex[c][3] >= 1 ? 1 : 0; + + // The fifth corner has all coordinate offsets = 1, so no need to look that up. + + x1 = x0 - i1 + self::$G4; // Offsets for second corner in (x,y,z,w) coords + y1 = y0 - j1 + self::$G4; + z1 = z0 - k1 + self::$G4; + w1 = w0 - l1 + self::$G4; + + x2 = x0 - i2 + self::$G42; // Offsets for third corner in (x,y,z,w) coords + y2 = y0 - j2 + self::$G42; + z2 = z0 - k2 + self::$G42; + w2 = w0 - l2 + self::$G42; + + x3 = x0 - i3 + self::$G43; // Offsets for fourth corner in (x,y,z,w) coords + y3 = y0 - j3 + self::$G43; + z3 = z0 - k3 + self::$G43; + w3 = w0 - l3 + self::$G43; + + x4 = x0 + self::$G44; // Offsets for last corner in (x,y,z,w) coords + y4 = y0 + self::$G44; + z4 = z0 + self::$G44; + w4 = w0 + self::$G44; + + // Work out the hashed gradient indices of the five simplex corners + ii = i & 255; + jj = j & 255; + kk = k & 255; + ll = l & 255; + + gi0 = $this->perm[ii + $this->perm[jj + $this->perm[kk + $this->perm[ll]]]] % 32; + gi1 = $this->perm[ii + i1 + $this->perm[jj + j1 + $this->perm[kk + k1 + $this->perm[ll + l1]]]] % 32; + gi2 = $this->perm[ii + i2 + $this->perm[jj + j2 + $this->perm[kk + k2 + $this->perm[ll + l2]]]] % 32; + gi3 = $this->perm[ii + i3 + $this->perm[jj + j3 + $this->perm[kk + k3 + $this->perm[ll + l3]]]] % 32; + gi4 = $this->perm[ii + 1 + $this->perm[jj + 1 + $this->perm[kk + 1 + $this->perm[ll + 1]]]] % 32; + + // Calculate the contribution from the five corners + t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0; + if(t0 < 0){ + n0 = 0.0; + }else{ + t0 *= t0; + n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0); + } + + t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1; + if(t1 < 0){ + n1 = 0.0; + }else{ + t1 *= t1; + n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1); + } + + t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2; + if(t2 < 0){ + n2 = 0.0; + }else{ + t2 *= t2; + n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2); + } + + t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3; + if(t3 < 0){ + n3 = 0.0; + }else{ + t3 *= t3; + n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3); + } + + t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4; + if(t4 < 0){ + n4 = 0.0; + }else{ + t4 *= t4; + n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4); + } + + // Sum up and scale the result to cover the range [-1,1] + return 27.0 * (n0 + n1 + n2 + n3 + n4); + }*/ +} \ No newline at end of file From b7ed2f765c8e629728619d8c54d420e7286597d9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 00:37:23 +0100 Subject: [PATCH 032/173] Added PMFLevel upgrade --- src/pmf/PMFLevel.php | 74 +++++++++++++++++++--- src/world/Level.php | 5 +- src/world/generator/NormalGenerator.php | 2 + src/world/generator/SuperflatGenerator.php | 1 + 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 657019b09..e92499c5a 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -137,13 +137,29 @@ class PMFLevel extends PMF{ } private function upgrade_From0_To1(){ - for($index = 0; $index < $cnt; ++$index){ + for($index = 0; $index < 256; ++$index){ + $X = $index & 0xFF; + $Z = $index >> 8; + $this->chunks[$index] = false; $this->chunkChange[$index] = false; - $locationTable[$index] = array( - 0 => Utils::readShort($this->read(2)), //16 bit flags - ); + $bitflags = $this->read(2); + $oldPath = dirname($this->file)."/chunks/".$Z.".".$X.".pmc"; + $chunkOld = @gzopen($oldPath, "rb"); + $newPath = dirname($this->file)."/chunks/".(($X ^ $Z) & 0xff)."/".$Z.".".$X.".pmc"; + @mkdir(dirname($newPath)); + $chunkNew = @gzopen($path, "wb".PMFLevel::DEFLATE_LEVEL); + gzwrite($chunkNew, $chunkFlags . "\x00\x00\x00\x00"); + while(gzeof($chunkOld) === false){ + gzwrite($chunkNew, gzread($chunkOld, 65535)); + } + gzclose($chunkNew); + gzclose($chunkOld); + @unlink($oldPath); } + $this->levelData["version"] = 0x01; + $this->levelData["generator"] = "NormalGenerator"; + $this->levelData["generatorSettings"] = ""; } public static function getIndex($X, $Z){ @@ -165,8 +181,11 @@ class PMFLevel extends PMF{ if(!file_exists(dirname($path))){ @mkdir(dirname($path), 0755); } - $this->isGenerating = true; - $ret = $this->level->generateChunk($X, $Z); + $this->isGenerating = true; + $this->initCleanChunk($X, $Z); + $ret = $this->level->generateChunk($X, $Z); + $ret = $ret and $this->level->populateChunk($X, $Z); + $this->saveChunk($X, $Z); $this->isGenerating = false; return $ret; } @@ -179,15 +198,28 @@ class PMFLevel extends PMF{ return true; } $path = $this->getChunkPath($X, $Z); - if(!file_exists($path) and $this->generateChunk($X, $Z) === false){ - return false; + if(!file_exists($path)){ + if($this->isGenerating === true){ + $this->level->generateChunk($X, $Z); + $this->saveChunk($X, $Z); + }elseif($this->generateChunk($X, $Z) === false){ + return false; + } } + + if($this->isGenerating === false and !$this->isPopulated($X, $Z)){ + $this->isGenerating = true; + $ret = $this->level->populateChunk($X, $Z); + $this->isGenerating = false; + } + $chunk = @gzopen($path, "rb"); if($chunk === false){ return false; } $this->chunkInfo[$index] = array( 0 => ord(gzread($chunk, 1)), + 1 => Utils::readInt(gzread($chunk, 4)), ); $this->chunks[$index] = array(); $this->chunkChange[$index] = array(-1 => false); @@ -280,6 +312,7 @@ class PMFLevel extends PMF{ $this->chunkChange[$index] = array(-1 => false); $this->chunkInfo[$index] = array( 0 => 0, + 1 => 0, ); } } @@ -514,6 +547,7 @@ class PMFLevel extends PMF{ } $chunk = @gzopen($path, "wb".PMFLevel::DEFLATE_LEVEL); gzwrite($chunk, chr($bitmap)); + gzwrite($chunk, Utils::writeInt($this->chunkInfo[$index][0])); for($Y = 0; $Y < 8; ++$Y){ $t = 1 << $Y; if(($bitmap & $t) === $t){ @@ -526,6 +560,30 @@ class PMFLevel extends PMF{ return true; } + public function setPopulated($X, $Z){ + if(!$this->isChunkLoaded($X, $Z)){ + return false; + } + $index = self::getIndex($X, $Z); + $this->chunkInfo[$index][1] |= 0b00000000000000000000000000000001; + } + + public function unsetPopulated($X, $Z){ + if(!$this->isChunkLoaded($X, $Z)){ + return false; + } + $index = self::getIndex($X, $Z); + $this->chunkInfo[$index][1] &= ~0b00000000000000000000000000000001; + } + + public function isPopulated($X, $Z){ + if(!$this->isChunkLoaded($X, $Z)){ + return false; + } + $index = self::getIndex($X, $Z); + return ($this->chunkInfo[$index][1] & 0b00000000000000000000000000000001) > 0; + } + public function doSaveRound(){ foreach($this->chunks as $index => $chunk){ self::getXZ($index, $X, $Z); diff --git a/src/world/Level.php b/src/world/Level.php index 05414e943..97d25a64b 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -149,10 +149,11 @@ class Level{ } public function generateChunk($X, $Z){ - $this->level->initCleanChunk($X, $Z); $this->generator->generateChunk($X, $Z); + } + + public function populateChunk($X, $Z){ $this->generator->populateChunk($X, $Z); - $this->level->saveChunk($X, $Z); } public function __destruct(){ diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index 462154051..3860ad263 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -116,6 +116,8 @@ class NormalGenerator implements LevelGenerator{ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } + + $this->level->level->setPopulated($chunkX, $chunkZ); } public function populateLevel(){ diff --git a/src/world/generator/SuperflatGenerator.php b/src/world/generator/SuperflatGenerator.php index 2ac111337..95162d42b 100644 --- a/src/world/generator/SuperflatGenerator.php +++ b/src/world/generator/SuperflatGenerator.php @@ -134,6 +134,7 @@ class SuperflatGenerator implements LevelGenerator{ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } + $this->level->level->setPopulated($chunkX, $chunkZ); } public function populateLevel(){ From 1ab90b14094eedf65a51ea58557fd1c17c76d84b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 00:49:44 +0100 Subject: [PATCH 033/173] PMFLevel upgrade tested --- src/pmf/PMFLevel.php | 25 +++++++++++++++---------- src/world/LevelImport.php | 7 ++++--- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index e92499c5a..e8e2ecfc7 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -110,7 +110,9 @@ class PMFLevel extends PMF{ } $this->seek(5); $this->levelData["version"] = ord($this->read(1)); + var_dump($this->levelData["version"]); if($this->levelData["version"] > PMFLevel::VERSION){ + console("[ERROR] New unsupported PMF Level format version #".$this->levelData["version"].", current version is #".PMFLevel::VERSION); return false; } $this->levelData["name"] = $this->read(Utils::readShort($this->read(2), false)); @@ -119,15 +121,17 @@ class PMFLevel extends PMF{ $this->levelData["spawnX"] = Utils::readFloat($this->read(4)); $this->levelData["spawnY"] = Utils::readFloat($this->read(4)); $this->levelData["spawnZ"] = Utils::readFloat($this->read(4)); - $this->levelData["height"] = ord($this->read(1)); - if($this->levelData["height"] !== 8){ - return false; - } if($this->levelData["version"] === 0){ $this->read(1); + $this->levelData["height"] = ord($this->read(1)); }else{ + $this->levelData["height"] = ord($this->read(1)); + if($this->levelData["height"] !== 8){ + return false; + } $this->levelData["generator"] = $this->read(Utils::readShort($this->read(2), false)); $this->levelData["generatorSettings"] = unserialize($this->read(Utils::readShort($this->read(2), false))); + } $this->levelData["extra"] = @gzinflate($this->read(Utils::readShort($this->read(2), false))); @@ -137,19 +141,20 @@ class PMFLevel extends PMF{ } private function upgrade_From0_To1(){ + console("[NOTICE] Old PMF Level format version #0 detected, upgrading to version #1"); for($index = 0; $index < 256; ++$index){ - $X = $index & 0xFF; - $Z = $index >> 8; + $X = $index & 0x0F; + $Z = $index >> 4; $this->chunks[$index] = false; $this->chunkChange[$index] = false; - $bitflags = $this->read(2); + $bitflags = Utils::readShort($this->read(2)); $oldPath = dirname($this->file)."/chunks/".$Z.".".$X.".pmc"; - $chunkOld = @gzopen($oldPath, "rb"); + $chunkOld = gzopen($oldPath, "rb"); $newPath = dirname($this->file)."/chunks/".(($X ^ $Z) & 0xff)."/".$Z.".".$X.".pmc"; @mkdir(dirname($newPath)); - $chunkNew = @gzopen($path, "wb".PMFLevel::DEFLATE_LEVEL); - gzwrite($chunkNew, $chunkFlags . "\x00\x00\x00\x00"); + $chunkNew = gzopen($newPath, "wb".PMFLevel::DEFLATE_LEVEL); + gzwrite($chunkNew, chr($bitflags) . "\x00\x00\x00\x01"); while(gzeof($chunkOld) === false){ gzwrite($chunkNew, gzread($chunkOld, 65535)); } diff --git a/src/world/LevelImport.php b/src/world/LevelImport.php index 39676d2ff..b2af2f7ab 100644 --- a/src/world/LevelImport.php +++ b/src/world/LevelImport.php @@ -64,9 +64,10 @@ class LevelImport{ "spawnX" => $level["SpawnX"], "spawnY" => $level["SpawnY"], "spawnZ" => $level["SpawnZ"], - "extra" => "", - "width" => 16, - "height" => 8 + "height" => 8, + "generator" => "NormalGenerator", + "generatorSettings" => "", + "extra" => "" )); $chunks = new PocketChunkParser(); $chunks->loadFile($this->path."chunks.dat"); From 7f86746cbe79c1802d3e364932c559a611ae3ced Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 00:58:55 +0100 Subject: [PATCH 034/173] woo :D --- src/world/generator/NormalGenerator.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index 3860ad263..0f0cc025a 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -29,8 +29,8 @@ class NormalGenerator implements LevelGenerator{ private $level; private $random; private $worldHeight = 65; - private $waterHeight = 62; - private $noiseGenBase; + private $waterHeight = 63; + private $noiseBase; private $noiseGen1; private $noiseGen2; private $noiseGen3; @@ -50,9 +50,10 @@ class NormalGenerator implements LevelGenerator{ $this->level = $level; $this->random = $random; $this->random->setSeed($this->level->getSeed()); - $this->noiseGenBase = new NoiseGeneratorSimplex($this->random, 4); - $this->noiseGen1 = new NoiseGeneratorSimplex($this->random, 8); - //$this->noiseGen2 = new NoiseGeneratorSimplex($this->random, 8); + $this->noiseBase = new NoiseGeneratorSimplex($this->random, 4); + $this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 4); + $this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4); + $ores = new OrePopulator(); $ores->setOreTypes(array( @@ -77,12 +78,11 @@ class NormalGenerator implements LevelGenerator{ $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ - $noiseBase = $this->noiseGenBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 1/5, 16, true); - $noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 25, true); - //$noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.8, 1); - //$height = $this->worldHeight + $noiseBase + $noise1 /*+ $noise2*/; - $height = $this->worldHeight + $noiseBase;//$height = (int) ($height + ($height * 0.15 * $noiseBase)); - $height = (int) $height; + $noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.6, 32, true) * 2; + $noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.35, 64, true) * 15; + $noiseBase = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 1/5, 16, true) * 3; + $height = (int) ($this->worldHeight + $noise1 + $noise2 + $noiseBase); + for($y = $startY; $y < $endY; ++$y){ $diff = $height - $y; if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ @@ -98,7 +98,7 @@ class NormalGenerator implements LevelGenerator{ $chunk .= "\x09"; //still_water } }elseif($diff === 0){ - $chunk .= $noise1 > 0 ? "\x02":"\x01"; //grass + $chunk .= "\x02"; //grass }else{ $chunk .= "\x00"; } From 3e68972253064072310339725016bff78869be53 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:02:44 +0100 Subject: [PATCH 035/173] fix an include --- src/world/generator/noise/NoiseGeneratorSimplex.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/world/generator/noise/NoiseGeneratorSimplex.php b/src/world/generator/noise/NoiseGeneratorSimplex.php index f01f108b4..2989ba718 100644 --- a/src/world/generator/noise/NoiseGeneratorSimplex.php +++ b/src/world/generator/noise/NoiseGeneratorSimplex.php @@ -2,6 +2,7 @@ /***REM_START***/ require_once("NoiseGenerator.php"); +require_once("NoiseGeneratorPerlin.php"); /***REM_END***/ /** From e83e424671c403a829c2560ca77c680769937728 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:04:50 +0100 Subject: [PATCH 036/173] Removed entity limits --- src/world/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/Entity.php b/src/world/Entity.php index e96703152..11e3e81f8 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -296,7 +296,7 @@ class Entity extends Position{ } } - if($this->class !== ENTITY_PLAYER and ($this->x <= 0 or $this->z <= 0 or $this->x >= 256 or $this->z >= 256 or $this->y >= 128 or $this->y <= 0)){ + if($this->class !== ENTITY_PLAYER and ($this->y >= 128 or $this->y <= 0)){ $this->close(); return false; } From 268e8c1164e9a5e32319471eab7d3cb01c45ed01 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:20:43 +0100 Subject: [PATCH 037/173] Force PMF save on PMF Level upgrade --- src/pmf/PMFLevel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index e8e2ecfc7..b98f357ac 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -165,6 +165,7 @@ class PMFLevel extends PMF{ $this->levelData["version"] = 0x01; $this->levelData["generator"] = "NormalGenerator"; $this->levelData["generatorSettings"] = ""; + $this->saveData(); } public static function getIndex($X, $Z){ From c9a2a0ea50229bbf9989c638b91f8c2fb9ec8e16 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:33:30 +0100 Subject: [PATCH 038/173] Updated API version --- src/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.php b/src/config.php index 760395a1d..d908f7a2f 100644 --- a/src/config.php +++ b/src/config.php @@ -70,7 +70,7 @@ define("START_TIME", microtime(true)); define("MAJOR_VERSION", "Alpha_1.4dev"); define("CODENAME", "絶好(Zekkou)ケーキ(Cake)"); define("CURRENT_MINECRAFT_VERSION", "v0.8.1 alpha"); -define("CURRENT_API_VERSION", 12); +define("CURRENT_API_VERSION", 13); define("CURRENT_PHP_VERSION", "5.5"); $gitsha1 = false; if(file_exists(FILE_PATH.".git/refs/heads/master")){ //Found Git information! From e4c814268198af18f3d57a0c05dce9a6cd928e8f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:41:40 +0100 Subject: [PATCH 039/173] Removed var_dump() --- src/pmf/PMFLevel.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index b98f357ac..74de7391d 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -110,7 +110,6 @@ class PMFLevel extends PMF{ } $this->seek(5); $this->levelData["version"] = ord($this->read(1)); - var_dump($this->levelData["version"]); if($this->levelData["version"] > PMFLevel::VERSION){ console("[ERROR] New unsupported PMF Level format version #".$this->levelData["version"].", current version is #".PMFLevel::VERSION); return false; From bd73cced6e40a5a116721bf8fa4af761b5a2221c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:47:18 +0100 Subject: [PATCH 040/173] Do not send block changes during chunk generation --- src/world/Level.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/Level.php b/src/world/Level.php index 97d25a64b..f20c09068 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -105,7 +105,7 @@ class Level{ $now = microtime(true); $this->players = $this->server->api->player->getAll($this); - if(count($this->changedCount) > 0){ + if($this->level->isGenerating === false and count($this->changedCount) > 0){ arsort($this->changedCount); $resendChunks = array(); foreach($this->changedCount as $index => $count){ From 4523b159915c6f61d51c8b86380a4248a24b11ab Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:53:30 +0100 Subject: [PATCH 041/173] do not send chunk updates on chunk generation --- src/pmf/PMFLevel.php | 29 ++++++++++++++++++++--------- src/world/Level.php | 1 - 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 74de7391d..a64d64f93 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -186,12 +186,19 @@ class PMFLevel extends PMF{ if(!file_exists(dirname($path))){ @mkdir(dirname($path), 0755); } - $this->isGenerating = true; - $this->initCleanChunk($X, $Z); - $ret = $this->level->generateChunk($X, $Z); - $ret = $ret and $this->level->populateChunk($X, $Z); - $this->saveChunk($X, $Z); - $this->isGenerating = false; + if($this->isGenerating === false){ + $this->isGenerating = true; + $this->initCleanChunk($X, $Z); + $ret = $this->level->generateChunk($X, $Z); + $ret = $ret and $this->level->populateChunk($X, $Z); + $this->saveChunk($X, $Z); + $this->isGenerating = false; + }else{ + $this->initCleanChunk($X, $Z); + $ret = $this->level->generateChunk($X, $Z); + $ret = $ret and $this->level->populateChunk($X, $Z); + $this->saveChunk($X, $Z); + } return $ret; } @@ -213,9 +220,13 @@ class PMFLevel extends PMF{ } if($this->isGenerating === false and !$this->isPopulated($X, $Z)){ - $this->isGenerating = true; - $ret = $this->level->populateChunk($X, $Z); - $this->isGenerating = false; + if($this->isGenerating === false){ + $this->isGenerating = true; + $this->level->populateChunk($X, $Z); + $this->isGenerating = false; + }else{ + $this->level->populateChunk($X, $Z); + } } $chunk = @gzopen($path, "rb"); diff --git a/src/world/Level.php b/src/world/Level.php index f20c09068..fb6beb6a8 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -107,7 +107,6 @@ class Level{ if($this->level->isGenerating === false and count($this->changedCount) > 0){ arsort($this->changedCount); - $resendChunks = array(); foreach($this->changedCount as $index => $count){ if($count < 582){//Optimal value, calculated using the relation between minichunks and single packets break; From d0af3673951208b78ba1c21d228b8b214a4f19f4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 01:59:08 +0100 Subject: [PATCH 042/173] Use integers instead of booleans --- src/pmf/PMFLevel.php | 39 ++++++++++++++------------------------- src/world/Level.php | 2 +- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index a64d64f93..3b3707029 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -29,7 +29,7 @@ class PMFLevel extends PMF{ private $chunks = array(); private $chunkChange = array(); private $chunkInfo = array(); - public $isGenerating = false; + public $isGenerating = 0; public function getData($index){ if(!isset($this->levelData[$index])){ @@ -186,19 +186,12 @@ class PMFLevel extends PMF{ if(!file_exists(dirname($path))){ @mkdir(dirname($path), 0755); } - if($this->isGenerating === false){ - $this->isGenerating = true; - $this->initCleanChunk($X, $Z); - $ret = $this->level->generateChunk($X, $Z); - $ret = $ret and $this->level->populateChunk($X, $Z); - $this->saveChunk($X, $Z); - $this->isGenerating = false; - }else{ - $this->initCleanChunk($X, $Z); - $ret = $this->level->generateChunk($X, $Z); - $ret = $ret and $this->level->populateChunk($X, $Z); - $this->saveChunk($X, $Z); - } + ++$this->isGenerating; + $this->initCleanChunk($X, $Z); + $ret = $this->level->generateChunk($X, $Z); + $ret = $ret and $this->level->populateChunk($X, $Z); + $this->saveChunk($X, $Z); + --$this->isGenerating; return $ret; } @@ -211,7 +204,7 @@ class PMFLevel extends PMF{ } $path = $this->getChunkPath($X, $Z); if(!file_exists($path)){ - if($this->isGenerating === true){ + if($this->isGenerating > 0){ $this->level->generateChunk($X, $Z); $this->saveChunk($X, $Z); }elseif($this->generateChunk($X, $Z) === false){ @@ -219,14 +212,10 @@ class PMFLevel extends PMF{ } } - if($this->isGenerating === false and !$this->isPopulated($X, $Z)){ - if($this->isGenerating === false){ - $this->isGenerating = true; - $this->level->populateChunk($X, $Z); - $this->isGenerating = false; - }else{ - $this->level->populateChunk($X, $Z); - } + if($this->isGenerating === 0 and !$this->isPopulated($X, $Z)){ + ++$this->isGenerating; + $this->level->populateChunk($X, $Z); + --$this->isGenerating; } $chunk = @gzopen($path, "rb"); @@ -334,7 +323,7 @@ class PMFLevel extends PMF{ } public function setMiniChunk($X, $Z, $Y, $data){ - if($this->isGenerating === true){ + if($this->isGenerating > 0){ $this->initCleanChunk($X, $Z); }elseif($this->isChunkLoaded($X, $Z) === false){ $this->loadChunk($X, $Z); @@ -538,7 +527,7 @@ class PMFLevel extends PMF{ public function saveChunk($X, $Z){ $X = (int) $X; $Z = (int) $Z; - if($this->isGenerating === true){ + if($this->isGenerating > 0){ $this->initCleanChunk($X, $Z); }elseif(!$this->isChunkLoaded($X, $Z)){ return false; diff --git a/src/world/Level.php b/src/world/Level.php index fb6beb6a8..05e9ce4c0 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -105,7 +105,7 @@ class Level{ $now = microtime(true); $this->players = $this->server->api->player->getAll($this); - if($this->level->isGenerating === false and count($this->changedCount) > 0){ + if($this->level->isGenerating === 0 and count($this->changedCount) > 0){ arsort($this->changedCount); foreach($this->changedCount as $index => $count){ if($count < 582){//Optimal value, calculated using the relation between minichunks and single packets From ab5c6341fedf085fd4578f5845bbbf47804857de Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 08:37:54 +0100 Subject: [PATCH 043/173] Added /plugins and /version --- src/API/PluginAPI.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 1f1ff514f..d4dce81d2 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -26,6 +26,30 @@ class PluginAPI extends stdClass{ public function __construct(){ $this->server = ServerAPI::request(); $this->randomNonce = Utils::getRandomBytes(16, false); + $this->server->api->console->register("plugins", "", array($this, "commandHandler")); + $this->server->api->console->register("version", "", array($this, "commandHandler")); + $this->server->api->ban->cmdWhitelist("version"); + } + + public function commandHandler($cmd, $params, $issuer, $alias){ + $output = ""; + switch($cmd){ + case "plugins": + $output = "Plugins: "; + foreach($this->getList() as $plugin){ + $output .= $plugin["name"] . ": ".$plugin["version"] .", "; + } + $output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2)."\n"; + break; + case "version": + $output = "PocketMine-MP ".MAJOR_VERSION." 「".CODENAME."」 API #".CURRENT_API_VERSION." for Minecraft: PE ".CURRENT_MINECRAFT_VERSION; + if(GIT_COMMIT !== str_repeat("00", 20)){ + $output .= " (git ".GIT_COMMIT.")"; + } + $output .= "\n"; + break; + } + return $output; } public function __destruct(){ From 89e556755d7eadcaa5a5c010ce878290aa69d143 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 08:38:23 +0100 Subject: [PATCH 044/173] Updated WorldGenerator to use correct generation variables --- src/world/generator/WorldGenerator.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index cfca09041..af62c0559 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -46,23 +46,20 @@ class WorldGenerator{ } public function generate(){ - $this->level->level->isGenerating = true; + ++$this->level->level->isGenerating; $this->generator->init($this->level, $this->random); $i = 0; - for($Z = 6; $Z <= 10; ++$Z){ - for($X = 6; $X <= 10; ++$X){ + for($Z = 7; $Z <= 9; ++$Z){ + for($X = 7; $X <= 9; ++$X){ $this->generator->generateChunk($X, $Z); } - console("[NOTICE] Generating level".str_repeat(".", $i)); ++$i; } - //console("[NOTICE] Populating level"); - //$this->generator->populateLevel(); $i = 0; - for($Z = 6; $Z <= 10; ++$Z){ - for($X = 6; $X <= 10; ++$X){ + for($Z = 7; $Z <= 9; ++$Z){ + for($X = 7; $X <= 9; ++$X){ $this->generator->populateChunk($X, $Z); } console("[NOTICE] Populating level".str_repeat(".", $i)); @@ -71,7 +68,7 @@ class WorldGenerator{ $this->level->setSpawn($this->generator->getSpawn()); $this->level->save(true, true); - $this->level->level->isGenerating = false; + --$this->level->level->isGenerating; } public function close(){ From c3a6149b29e8ddc8f57050a8abc8ce277a4c88fd Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 08:52:27 +0100 Subject: [PATCH 045/173] added protocol number to /version --- src/API/PluginAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index d4dce81d2..7581e263a 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -42,7 +42,7 @@ class PluginAPI extends stdClass{ $output = $output === "Plugins: " ? "No plugins installed.\n" : substr($output, 0, -2)."\n"; break; case "version": - $output = "PocketMine-MP ".MAJOR_VERSION." 「".CODENAME."」 API #".CURRENT_API_VERSION." for Minecraft: PE ".CURRENT_MINECRAFT_VERSION; + $output = "PocketMine-MP ".MAJOR_VERSION." 「".CODENAME."」 API #".CURRENT_API_VERSION." for Minecraft: PE ".CURRENT_MINECRAFT_VERSION." protocol #".ProtocolInfo::CURRENT_PROTOCOL; if(GIT_COMMIT !== str_repeat("00", 20)){ $output .= " (git ".GIT_COMMIT.")"; } From 4d1adb98a8dea4d3c0df0d5b2faa8862eaed62b9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 09:29:50 +0100 Subject: [PATCH 046/173] Removed $i on WorldGenerator --- src/world/generator/WorldGenerator.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index af62c0559..7dc4519e6 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -49,21 +49,16 @@ class WorldGenerator{ ++$this->level->level->isGenerating; $this->generator->init($this->level, $this->random); - $i = 0; for($Z = 7; $Z <= 9; ++$Z){ for($X = 7; $X <= 9; ++$X){ $this->generator->generateChunk($X, $Z); } - ++$i; } - $i = 0; for($Z = 7; $Z <= 9; ++$Z){ for($X = 7; $X <= 9; ++$X){ $this->generator->populateChunk($X, $Z); } - console("[NOTICE] Populating level".str_repeat(".", $i)); - ++$i; } $this->level->setSpawn($this->generator->getSpawn()); From 1bbf211a372be00f2a89f013877d7f4ded65ed0a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 09:47:30 +0100 Subject: [PATCH 047/173] Set a world spawnpoint using /spawnpoint w:WORLD x y z --- src/API/PlayerAPI.php | 860 +++++++++++++++++++++--------------------- 1 file changed, 439 insertions(+), 421 deletions(-) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 2a3a2bb1a..272439ec4 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -20,301 +20,319 @@ */ class PlayerAPI{ - private $server; - function __construct(){ - $this->server = ServerAPI::request(); - } + private $server; + function __construct(){ + $this->server = ServerAPI::request(); + } - public function init(){ - $this->server->schedule(20 * 15, array($this, "handle"), 1, true, "server.regeneration"); - $this->server->addHandler("player.death", array($this, "handle"), 1); - $this->server->api->console->register("list", "", array($this, "commandHandler")); - $this->server->api->console->register("kill", "", array($this, "commandHandler")); - $this->server->api->console->register("gamemode", " [player]", array($this, "commandHandler")); - $this->server->api->console->register("tp", "[target player] OR /tp [target player] ", array($this, "commandHandler")); - $this->server->api->console->register("spawnpoint", "[player] [x] [y] [z]", array($this, "commandHandler")); - $this->server->api->console->register("spawn", "", array($this, "commandHandler")); - $this->server->api->console->register("ping", "", array($this, "commandHandler")); - $this->server->api->console->alias("lag", "ping"); - $this->server->api->console->alias("suicide", "kill"); - $this->server->api->console->alias("tppos", "tp"); - $this->server->api->ban->cmdWhitelist("list"); - $this->server->api->ban->cmdWhitelist("ping"); - $this->server->api->ban->cmdWhitelist("spawn"); - $this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = ".ENTITY_PLAYER." AND health < 20;"); - } + public function init(){ + $this->server->schedule(20 * 15, array($this, "handle"), 1, true, "server.regeneration"); + $this->server->addHandler("player.death", array($this, "handle"), 1); + $this->server->api->console->register("list", "", array($this, "commandHandler")); + $this->server->api->console->register("kill", "", array($this, "commandHandler")); + $this->server->api->console->register("gamemode", " [player]", array($this, "commandHandler")); + $this->server->api->console->register("tp", "[target player] OR /tp [target player] ", array($this, "commandHandler")); + $this->server->api->console->register("spawnpoint", "[player | w:world] [x] [y] [z]", array($this, "commandHandler")); + $this->server->api->console->register("spawn", "", array($this, "commandHandler")); + $this->server->api->console->register("ping", "", array($this, "commandHandler")); + $this->server->api->console->alias("lag", "ping"); + $this->server->api->console->alias("suicide", "kill"); + $this->server->api->console->alias("tppos", "tp"); + $this->server->api->ban->cmdWhitelist("list"); + $this->server->api->ban->cmdWhitelist("ping"); + $this->server->api->ban->cmdWhitelist("spawn"); + $this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = ".ENTITY_PLAYER." AND health < 20;"); + } - public function handle($data, $event){ - switch($event){ - case "server.regeneration": - if($this->server->difficulty === 0){ - $result = $this->server->preparedSQL->selectPlayersToHeal->execute(); - if($result !== false){ - while(($player = $result->fetchArray()) !== false){ - if(($player = $this->server->api->entity->get($player["EID"])) !== false){ - if($player->getHealth() <= 0){ - continue; - } - $player->setHealth(min(20, $player->getHealth() + $data), "regeneration"); - } - } - return true; - } - } - break; - case "player.death": - if(is_numeric($data["cause"])){ - $e = $this->server->api->entity->get($data["cause"]); - if($e instanceof Entity){ - switch($e->class){ - case ENTITY_PLAYER: - $message = " was killed by ".$e->name; - break; - default: - $message = " was killed"; - break; - } - } - }else{ - switch($data["cause"]){ - case "cactus": - $message = " was pricked to death"; - break; - case "lava": - $message = " tried to swim in lava"; - break; - case "fire": - $message = " went up in flames"; - break; - case "burning": - $message = " burned to death"; - break; - case "suffocation": - $message = " suffocated in a wall"; - break; - case "water": - $message = " drowned"; - break; - case "void": - $message = " fell out of the world"; - break; - case "fall": - $message = " hit the ground too hard"; - break; - case "explosion": - $message = " blew up"; - break; - default: - $message = " died"; - break; - } - } - $this->server->api->chat->broadcast($data["player"]->username . $message); - return true; - break; - } - } + public function handle($data, $event){ + switch($event){ + case "server.regeneration": + if($this->server->difficulty === 0){ + $result = $this->server->preparedSQL->selectPlayersToHeal->execute(); + if($result !== false){ + while(($player = $result->fetchArray()) !== false){ + if(($player = $this->server->api->entity->get($player["EID"])) !== false){ + if($player->getHealth() <= 0){ + continue; + } + $player->setHealth(min(20, $player->getHealth() + $data), "regeneration"); + } + } + return true; + } + } + break; + case "player.death": + if(is_numeric($data["cause"])){ + $e = $this->server->api->entity->get($data["cause"]); + if($e instanceof Entity){ + switch($e->class){ + case ENTITY_PLAYER: + $message = " was killed by ".$e->name; + break; + default: + $message = " was killed"; + break; + } + } + }else{ + switch($data["cause"]){ + case "cactus": + $message = " was pricked to death"; + break; + case "lava": + $message = " tried to swim in lava"; + break; + case "fire": + $message = " went up in flames"; + break; + case "burning": + $message = " burned to death"; + break; + case "suffocation": + $message = " suffocated in a wall"; + break; + case "water": + $message = " drowned"; + break; + case "void": + $message = " fell out of the world"; + break; + case "fall": + $message = " hit the ground too hard"; + break; + case "explosion": + $message = " blew up"; + break; + default: + $message = " died"; + break; + } + } + $this->server->api->chat->broadcast($data["player"]->username . $message); + return true; + break; + } + } - public function commandHandler($cmd, $params, $issuer, $alias){ - $output = ""; - switch($cmd){ - case "spawnpoint": - if(!($issuer instanceof Player)){ - $output .= "Please run this command in-game.\n"; - break; - } + public function commandHandler($cmd, $params, $issuer, $alias){ + $output = ""; + switch($cmd){ + case "spawnpoint": + if(count($params) === 0){ + $output .= "Usage: /$cmd [player | w:world] [x] [y] [z]\n"; + break; + } + if(!($issuer instanceof Player) and count($params) < 4){ + $output .= "Please run this command in-game.\n"; + break; + } - if(count($params) === 1 or count($params) === 4){ - $target = $this->server->api->player->get(array_shift($params)); - }else{ - $target = $issuer; - } + if(count($params) === 1 or count($params) === 4){ + $tg = array_shift($params); + if(count($params) === 3 and substr($tg, 0, 2) === "w:"){ + $target = $this->server->api->level->get(substr($tg, 2)); + }else{ + $target = $this->server->api->player->get($tg); + } + }else{ + $target = $issuer; + } - if(!($target instanceof Player)){ - $output .= "That player cannot be found.\n"; - break; - } + if(!($target instanceof Player) and !($target instanceof Level)){ + $output .= "That player cannot be found.\n"; + break; + } - if(count($params) === 3){ - $spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level); - }else{ - $spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level); - } + if(count($params) === 3){ + if($target instanceof Level){ + $spawn = new Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params))); + }else{ + $spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level); + } + }else{ + $spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level); + } - $target->setSpawn($spawn); + $target->setSpawn($spawn); + if($target instanceof Level){ + $output .= "Spawnpoint of world ".$target->getName()." set correctly!\n"; + }elseif($target !== $issuer){ + $output .= "Spawnpoint of ".$target->username." set correctly!\n"; + }else{ + $output .= "Spawnpoint set correctly!\n"; + } + break; + case "spawn": + if(!($issuer instanceof Player)){ + $output .= "Please run this command in-game.\n"; + break; + } + $issuer->teleport($this->server->spawn); + break; + case "ping": + if(!($issuer instanceof Player)){ + $output .= "Please run this command in-game.\n"; + break; + } + $output .= "ping ".round($issuer->getLag(), 2)."ms, packet loss ".round($issuer->getPacketLoss() * 100, 2)."%, ".round($issuer->getBandwidth() / 1024, 2)." KB/s\n"; + break; + case "gamemode": + $player = false; + $setgm = false; + $gms = array( + "0" => SURVIVAL, + "survival" => SURVIVAL, + "s" => SURVIVAL, + "1" => CREATIVE, + "creative" => CREATIVE, + "c" => CREATIVE, + "2" => ADVENTURE, + "adventure" => ADVENTURE, + "a" => ADVENTURE, + "3" => VIEW, + "view" => VIEW, + "viewer" => VIEW, + "spectator" => VIEW, + "v" => VIEW, + ); + if($issuer instanceof Player){ + $player = $issuer; + } + if(isset($params[1])){ + if($this->server->api->player->get($params[1]) instanceof Player){ + $player = $this->server->api->player->get($params[1]); + $setgm = $params[0]; + }elseif($this->server->api->player->get($params[0]) instanceof Player){ + $player = $this->server->api->player->get($params[0]); + $setgm = $params[1]; + }else{ + $output .= "Usage: /$cmd [player] or /$cmd [player] \n"; + break; + } + } + if(!($player instanceof Player) or !isset($gms[strtolower($setgm)])){ + $output .= "Usage: /$cmd [player] or /$cmd [player] \n"; + break; + } + if($player->setGamemode($gms[strtolower($setgm)])){ + $output .= "Gamemode of ".$player->username." changed to ".$player->getGamemode()."\n"; + } + break; + case "tp": + if(count($params) <= 2 or substr($params[0], 0, 2) === "w:" or substr($params[1], 0, 2) === "w:"){ + if((!isset($params[1]) or substr($params[0], 0, 2) === "w:") and isset($params[0]) and ($issuer instanceof Player)){ + $name = $issuer->username; + $target = implode(" ", $params); + }elseif(isset($params[1]) and isset($params[0])){ + $name = array_shift($params); + $target = implode(" ", $params); + }else{ + $output .= "Usage: /$cmd [target player] \n"; + break; + } + if($this->teleport($name, $target) !== false){ + $output .= "\"$name\" teleported to \"$target\"\n"; + }else{ + $output .= "Couldn't teleport.\n"; + } + }else{ + if(!isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){ + $name = $issuer->username; + $x = $params[0]; + $y = $params[1]; + $z = $params[2]; + }elseif(isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0])){ + $name = $params[0]; + $x = $params[1]; + $y = $params[2]; + $z = $params[3]; + }else{ + $output .= "Usage: /$cmd [player] \n"; + break; + } + if($this->tppos($name, $x, $y, $z)){ + $output .= "\"$name\" teleported to ($x, $y, $z)\n"; + }else{ + $output .= "Couldn't teleport.\n"; + } + } + break; + case "kill": + case "suicide": + if(!isset($params[0]) and ($issuer instanceof Player)){ + $player = $issuer; + }else{ + $player = $this->get($params[0]); + } + if($player instanceof Player){ + $player->entity->harm(1000, "console", true); + $player->sendChat("Ouch. That looks like it hurt.\n"); + }else{ + $output .= "Usage: /$cmd [player]\n"; + } + break; + case "list": + $output .= "There are ".count($this->server->clients)."/".$this->server->maxClients." players online:\n"; + if(count($this->server->clients) == 0){ + break; + } + foreach($this->server->clients as $c){ + $output .= $c->username.", "; + } + $output = substr($output, 0, -2)."\n"; + break; + } + return $output; + } - $output .= "Spawnpoint set correctly!\n"; - break; - case "spawn": - if(!($issuer instanceof Player)){ - $output .= "Please run this command in-game.\n"; - break; - } - $issuer->teleport($this->server->spawn); - break; - case "ping": - if(!($issuer instanceof Player)){ - $output .= "Please run this command in-game.\n"; - break; - } - $output .= "ping ".round($issuer->getLag(), 2)."ms, packet loss ".round($issuer->getPacketLoss() * 100, 2)."%, ".round($issuer->getBandwidth() / 1024, 2)." KB/s\n"; - break; - case "gamemode": - $player = false; - $setgm = false; - $gms = array( - "0" => SURVIVAL, - "survival" => SURVIVAL, - "s" => SURVIVAL, - "1" => CREATIVE, - "creative" => CREATIVE, - "c" => CREATIVE, - "2" => ADVENTURE, - "adventure" => ADVENTURE, - "a" => ADVENTURE, - "3" => VIEW, - "view" => VIEW, - "viewer" => VIEW, - "spectator" => VIEW, - "v" => VIEW, - ); - if($issuer instanceof Player){ - $player = $issuer; - } - if(isset($params[1])){ - if($this->server->api->player->get($params[1]) instanceof Player){ - $player = $this->server->api->player->get($params[1]); - $setgm = $params[0]; - }elseif($this->server->api->player->get($params[0]) instanceof Player){ - $player = $this->server->api->player->get($params[0]); - $setgm = $params[1]; - }else{ - $output .= "Usage: /$cmd [player] or /$cmd [player] \n"; - break; - } - } - if(!($player instanceof Player) or !isset($gms[strtolower($setgm)])){ - $output .= "Usage: /$cmd [player] or /$cmd [player] \n"; - break; - } - if($player->setGamemode($gms[strtolower($setgm)])){ - $output .= "Gamemode of ".$player->username." changed to ".$player->getGamemode()."\n"; - } - break; - case "tp": - if(count($params) <= 2 or substr($params[0], 0, 2) === "w:" or substr($params[1], 0, 2) === "w:"){ - if((!isset($params[1]) or substr($params[0], 0, 2) === "w:") and isset($params[0]) and ($issuer instanceof Player)){ - $name = $issuer->username; - $target = implode(" ", $params); - }elseif(isset($params[1]) and isset($params[0])){ - $name = array_shift($params); - $target = implode(" ", $params); - }else{ - $output .= "Usage: /$cmd [target player] \n"; - break; - } - if($this->teleport($name, $target) !== false){ - $output .= "\"$name\" teleported to \"$target\"\n"; - }else{ - $output .= "Couldn't teleport.\n"; - } - }else{ - if(!isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){ - $name = $issuer->username; - $x = $params[0]; - $y = $params[1]; - $z = $params[2]; - }elseif(isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0])){ - $name = $params[0]; - $x = $params[1]; - $y = $params[2]; - $z = $params[3]; - }else{ - $output .= "Usage: /$cmd [player] \n"; - break; - } - if($this->tppos($name, $x, $y, $z)){ - $output .= "\"$name\" teleported to ($x, $y, $z)\n"; - }else{ - $output .= "Couldn't teleport.\n"; - } - } - break; - case "kill": - case "suicide": - if(!isset($params[0]) and ($issuer instanceof Player)){ - $player = $issuer; - }else{ - $player = $this->get($params[0]); - } - if($player instanceof Player){ - $player->entity->harm(1000, "console", true); - $player->sendChat("Ouch. That looks like it hurt.\n"); - }else{ - $output .= "Usage: /$cmd [player]\n"; - } - break; - case "list": - $output .= "There are ".count($this->server->clients)."/".$this->server->maxClients." players online:\n"; - if(count($this->server->clients) == 0){ - break; - } - foreach($this->server->clients as $c){ - $output .= $c->username.", "; - } - $output = substr($output, 0, -2)."\n"; - break; - } - return $output; - } + public function teleport(&$name, &$target){ + if(substr($target, 0, 2) === "w:"){ + $lv = $this->server->api->level->get(substr($target, 2)); + if($lv instanceof Level){ + $origin = $this->get($name); + if($origin instanceof Player){ + $name = $origin->username; + return $origin->teleport($lv->getSafeSpawn()); + } + }else{ + return false; + } + } + $player = $this->get($target); + if(($player instanceof Player) and ($player->entity instanceof Entity)){ + $target = $player->username; + $origin = $this->get($name); + if($origin instanceof Player){ + $name = $origin->username; + return $origin->teleport($player->entity); + } + } + return false; + } - public function teleport(&$name, &$target){ - if(substr($target, 0, 2) === "w:"){ - $lv = $this->server->api->level->get(substr($target, 2)); - if($lv instanceof Level){ - $origin = $this->get($name); - if($origin instanceof Player){ - $name = $origin->username; - return $origin->teleport($lv->getSafeSpawn()); - } - }else{ - return false; - } - } - $player = $this->get($target); - if(($player instanceof Player) and ($player->entity instanceof Entity)){ - $target = $player->username; - $origin = $this->get($name); - if($origin instanceof Player){ - $name = $origin->username; - return $origin->teleport($player->entity); - } - } - return false; - } + public function tppos(&$name, &$x, &$y, &$z){ + $player = $this->get($name); + if(($player instanceof Player) and ($player->entity instanceof Entity)){ + $name = $player->username; + $x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x); + $y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y); + $z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)):floatval($z); + $player->teleport(new Vector3($x, $y, $z)); + return true; + } + return false; + } - public function tppos(&$name, &$x, &$y, &$z){ - $player = $this->get($name); - if(($player instanceof Player) and ($player->entity instanceof Entity)){ - $name = $player->username; - $x = $x{0} === "~" ? $player->entity->x + floatval(substr($x, 1)):floatval($x); - $y = $y{0} === "~" ? $player->entity->y + floatval(substr($y, 1)):floatval($y); - $z = $z{0} === "~" ? $player->entity->z + floatval(substr($z, 1)):floatval($z); - $player->teleport(new Vector3($x, $y, $z)); - return true; - } - return false; - } - - public function get($name, $alike = true, $multiple = false){ - $name = trim(strtolower($name)); - if($name === ""){ - return false; - } - $query = $this->server->query("SELECT ip,port,name FROM players WHERE name ".($alike === true ? "LIKE '%".$name."%'":"= '".$name."'").";"); + public function get($name, $alike = true, $multiple = false){ + $name = trim(strtolower($name)); + if($name === ""){ + return false; + } + $query = $this->server->query("SELECT ip,port,name FROM players WHERE name ".($alike === true ? "LIKE '%".$name."%'":"= '".$name."'").";"); $players = array(); - if($query !== false and $query !== true){ - while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){ + if($query !== false and $query !== true){ + while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){ $CID = PocketMinecraftServer::clientID($d["ip"], $d["port"]); if(isset($this->server->clients[$CID])){ $players[$CID] = $this->server->clients[$CID]; @@ -322,7 +340,7 @@ class PlayerAPI{ return $players[$CID]; } } - } + } } if($multiple === false){ @@ -334,74 +352,74 @@ class PlayerAPI{ }else{ return $players; } - } + } - public function getAll($level = null){ - if($level instanceof Level){ - $clients = array(); - $l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."' AND class = '".ENTITY_PLAYER."';"); - if($l !== false and $l !== true){ - while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ - $e = $this->getByEID($e["EID"]); - if($e instanceof Player){ - $clients[$e->CID] = $e; - } - } - } - return $clients; - } - return $this->server->clients; - } + public function getAll($level = null){ + if($level instanceof Level){ + $clients = array(); + $l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."' AND class = '".ENTITY_PLAYER."';"); + if($l !== false and $l !== true){ + while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ + $e = $this->getByEID($e["EID"]); + if($e instanceof Player){ + $clients[$e->CID] = $e; + } + } + } + return $clients; + } + return $this->server->clients; + } - public function broadcastPacket(array $players, RakNetDataPacket $packet){ - foreach($players as $p){ - $p->dataPacket(clone $packet); - } - } + public function broadcastPacket(array $players, RakNetDataPacket $packet){ + foreach($players as $p){ + $p->dataPacket(clone $packet); + } + } - public function getByEID($eid){ - $eid = (int) $eid; - $CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true); - $CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]); - if(isset($this->server->clients[$CID])){ - return $this->server->clients[$CID]; - } - return false; - } + public function getByEID($eid){ + $eid = (int) $eid; + $CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true); + $CID = PocketMinecraftServer::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 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]; - $player->data = $this->getOffline($player->username); - $player->gamemode = $player->data->get("gamemode"); - if(($player->level = $this->server->api->level->get($player->data->get("position")["level"])) === false){ - $player->level = $this->server->api->level->getDefault(); - $player->data->set("position", array( - "level" => $player->level->getName(), - "x" => $player->level->getSpawn()->x, - "y" => $player->level->getSpawn()->y, - "z" => $player->level->getSpawn()->z, - )); - } - $this->server->query("INSERT OR REPLACE INTO players (CID, ip, port, name) VALUES (".$player->CID.", '".$player->ip."', ".$player->port.", '".strtolower($player->username)."');"); - } - } + public function add($CID){ + if(isset($this->server->clients[$CID])){ + $player = $this->server->clients[$CID]; + $player->data = $this->getOffline($player->username); + $player->gamemode = $player->data->get("gamemode"); + if(($player->level = $this->server->api->level->get($player->data->get("position")["level"])) === false){ + $player->level = $this->server->api->level->getDefault(); + $player->data->set("position", array( + "level" => $player->level->getName(), + "x" => $player->level->getSpawn()->x, + "y" => $player->level->getSpawn()->y, + "z" => $player->level->getSpawn()->z, + )); + } + $this->server->query("INSERT OR REPLACE INTO players (CID, ip, port, name) VALUES (".$player->CID.", '".$player->ip."', ".$player->port.", '".strtolower($player->username)."');"); + } + } - public function spawnAllPlayers(Player $player){ - foreach($this->getAll() as $p){ - if($p !== $player and ($p->entity instanceof Entity)){ - $p->entity->spawn($player); - if($p->level !== $player->level){ + public function spawnAllPlayers(Player $player){ + foreach($this->getAll() as $p){ + if($p !== $player and ($p->entity instanceof Entity)){ + $p->entity->spawn($player); + if($p->level !== $player->level){ $pk = new MoveEntityPacket_PosRot; $pk->eid = $p->entity->eid; $pk->x = -256; @@ -409,17 +427,17 @@ class PlayerAPI{ $pk->z = -256; $pk->yaw = 0; $pk->pitch = 0; - $player->dataPacket($pk); - } - } - } - } + $player->dataPacket($pk); + } + } + } + } - public function spawnToAllPlayers(Player $player){ - foreach($this->getAll() as $p){ - if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){ - $player->entity->spawn($p); - if($p->level !== $player->level){ + public function spawnToAllPlayers(Player $player){ + foreach($this->getAll() as $p){ + if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){ + $player->entity->spawn($p); + if($p->level !== $player->level){ $pk = new MoveEntityPacket_PosRot; $pk->eid = $player->entity->eid; $pk->x = -256; @@ -427,74 +445,74 @@ class PlayerAPI{ $pk->z = -256; $pk->yaw = 0; $pk->pitch = 0; - $p->dataPacket($pk); - } - } - } - } + $p->dataPacket($pk); + } + } + } + } - public function remove($CID){ - if(isset($this->server->clients[$CID])){ - $player = $this->server->clients[$CID]; - unset($this->server->clients[$CID]); - $player->close(); - if($player->username != "" and ($player->data instanceof Config)){ - $this->saveOffline($player->data); - } - $this->server->query("DELETE FROM players WHERE name = '".$player->username."';"); - if($player->entity instanceof Entity){ - unset($player->entity->player); - //unset($player->entity); - } - $this->server->api->entity->remove($player->eid); - $player = null; - unset($player); - } - } + public function remove($CID){ + if(isset($this->server->clients[$CID])){ + $player = $this->server->clients[$CID]; + unset($this->server->clients[$CID]); + $player->close(); + if($player->username != "" and ($player->data instanceof Config)){ + $this->saveOffline($player->data); + } + $this->server->query("DELETE FROM players WHERE name = '".$player->username."';"); + if($player->entity instanceof Entity){ + unset($player->entity->player); + //unset($player->entity); + } + $this->server->api->entity->remove($player->eid); + $player = null; + unset($player); + } + } - public function getOffline($name){ - $iname = strtolower($name); - $default = array( - "caseusername" => $name, - "position" => array( - "level" => $this->server->spawn->level->getName(), - "x" => $this->server->spawn->x, - "y" => $this->server->spawn->y, - "z" => $this->server->spawn->z, - ), - "spawn" => array( - "level" => $this->server->spawn->level->getName(), - "x" => $this->server->spawn->x, - "y" => $this->server->spawn->y, - "z" => $this->server->spawn->z, - ), - "inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, array(AIR, 0, 0)), + public function getOffline($name){ + $iname = strtolower($name); + $default = array( + "caseusername" => $name, + "position" => array( + "level" => $this->server->spawn->level->getName(), + "x" => $this->server->spawn->x, + "y" => $this->server->spawn->y, + "z" => $this->server->spawn->z, + ), + "spawn" => array( + "level" => $this->server->spawn->level->getName(), + "x" => $this->server->spawn->x, + "y" => $this->server->spawn->y, + "z" => $this->server->spawn->z, + ), + "inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, array(AIR, 0, 0)), "hotbar" => array(0, -1, -1, -1, -1, -1, -1, -1, -1), - "armor" => array_fill(0, 4, array(AIR, 0)), - "gamemode" => $this->server->gamemode, - "health" => 20, - "lastIP" => "", - "lastID" => 0, - "achievements" => array(), - ); + "armor" => array_fill(0, 4, array(AIR, 0)), + "gamemode" => $this->server->gamemode, + "health" => 20, + "lastIP" => "", + "lastID" => 0, + "achievements" => array(), + ); - if(!file_exists(DATA_PATH."players/".$iname.".yml")){ - console("[NOTICE] Player data not found for \"".$iname."\", creating new profile"); - $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); - $data->save(); - }else{ - $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); - } + if(!file_exists(DATA_PATH."players/".$iname.".yml")){ + console("[NOTICE] Player data not found for \"".$iname."\", creating new profile"); + $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); + $data->save(); + }else{ + $data = new Config(DATA_PATH."players/".$iname.".yml", CONFIG_YAML, $default); + } - if(($data->get("gamemode") & 0x01) === 1){ - $data->set("health", 20); - } - $this->server->handle("player.offline.get", $data); - return $data; - } + if(($data->get("gamemode") & 0x01) === 1){ + $data->set("health", 20); + } + $this->server->handle("player.offline.get", $data); + return $data; + } - public function saveOffline(Config $data){ - $this->server->handle("player.offline.save", $data); - $data->save(); - } + public function saveOffline(Config $data){ + $this->server->handle("player.offline.save", $data); + $data->save(); + } } From 4eebbba5bf13015284ada5be9e6b02d3391a7296 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 11:06:55 +0100 Subject: [PATCH 048/173] PHP 5.4, PHP 5.5 and PHP 5.6 on Travis CI --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index b2032b9dc..02e9f8d89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ language: php php: + - 5.4 - 5.5 + - 5.6 before_script: - pecl install channel://pecl.php.net/pthreads-0.1.0 From 5929b510d52998e4ad67f239ee55e2e79a5b54c6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 20:44:15 +0100 Subject: [PATCH 049/173] Better, faster world generation. Needs more things --- src/API/ServerAPI.php | 2 +- src/pmf/PMFLevel.php | 2 +- src/world/generator/NormalGenerator.php | 59 +++++++++++++++++-------- src/world/generator/WorldGenerator.php | 11 ++--- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 9aa7c7289..996d9f05e 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -147,7 +147,7 @@ class ServerAPI{ //Load advanced properties define("DEBUG", $this->getProperty("debug", 1)); define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); - define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s + define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 6)); //Default rate ~384 kB/s if(ADVANCED_CACHE == true){ console("[INFO] Advanced cache enabled"); } diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 3b3707029..4f685176a 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -233,7 +233,7 @@ class PMFLevel extends PMF{ if(($this->chunkInfo[$index][0] & $t) === $t){ // 4096 + 2048 + 2048, Block Data, Meta, Light if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){ - console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents"); + console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2); $this->fillMiniChunk($X, $Z, $Y); } }else{ diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index 0f0cc025a..1aba17c3b 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -30,13 +30,9 @@ class NormalGenerator implements LevelGenerator{ private $random; private $worldHeight = 65; private $waterHeight = 63; + private $noiseHills; + private $noisePatches; private $noiseBase; - private $noiseGen1; - private $noiseGen2; - private $noiseGen3; - private $noiseGen4; - private $noiseGen5; - private $noiseGen6; public function __construct(array $options = array()){ @@ -50,9 +46,9 @@ class NormalGenerator implements LevelGenerator{ $this->level = $level; $this->random = $random; $this->random->setSeed($this->level->getSeed()); - $this->noiseBase = new NoiseGeneratorSimplex($this->random, 4); - $this->noiseGen1 = new NoiseGeneratorPerlin($this->random, 4); - $this->noiseGen2 = new NoiseGeneratorPerlin($this->random, 4); + $this->noiseHills = new NoiseGeneratorSimplex($this->random, 3); + $this->noisePatches = new NoiseGeneratorSimplex($this->random, 2); + $this->noiseBase = new NoiseGeneratorSimplex($this->random, 8); $ores = new OrePopulator(); @@ -71,34 +67,59 @@ class NormalGenerator implements LevelGenerator{ public function generateChunk($chunkX, $chunkZ){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); - + $hills = array(); + $patches = array(); + $base = array(); + for($z = 0; $z < 16; ++$z){ + for($x = 0; $x < 16; ++$x){ + $i = ($z << 4) + $x; + $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.11, 12, true); + $patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true); + $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true); + if($base[$i] < 0){ + $base[$i] *= 0.5; + } + } + } + for($chunkY = 0; $chunkY < 8; ++$chunkY){ $chunk = ""; $startY = $chunkY << 4; - $endY = $startY + 16; + $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ - $noise1 = $this->noiseGen1->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.6, 32, true) * 2; - $noise2 = $this->noiseGen2->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.35, 64, true) * 15; - $noiseBase = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 1/5, 16, true) * 3; - $height = (int) ($this->worldHeight + $noise1 + $noise2 + $noiseBase); + $i = ($z << 4) + $x; + $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 4; + $height = (int) $height; for($y = $startY; $y < $endY; ++$y){ $diff = $height - $y; if($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)){ $chunk .= "\x07"; //bedrock - }elseif($diff > 3){ + }elseif($diff > 2){ $chunk .= "\x01"; //stone }elseif($diff > 0){ - $chunk .= "\x03"; //dirt + if($patches[$i] > 0.7){ + $chunk .= "\x01"; //stone + }elseif($patches[$i] < -0.8){ + $chunk .= "\x0d"; //gravel + }else{ + $chunk .= "\x03"; //dirt + } }elseif($y <= $this->waterHeight){ - if($y === $this->waterHeight and $diff === 0){ + if(($this->waterHeight - $y) <= 1 and $diff === 0){ $chunk .= "\x0c"; //sand }else{ $chunk .= "\x09"; //still_water } }elseif($diff === 0){ - $chunk .= "\x02"; //grass + if($patches[$i] > 0.7){ + $chunk .= "\x01"; //stone + }elseif($patches[$i] < -0.8){ + $chunk .= "\x0d"; //gravel + }else{ + $chunk .= "\x02"; //grass + } }else{ $chunk .= "\x00"; } diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index 7dc4519e6..d5a6f174a 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -45,18 +45,19 @@ class WorldGenerator{ $this->level = new Level($level, $entities, $tiles, $blockUpdates, $name); } - public function generate(){ + public function generate(){ ++$this->level->level->isGenerating; $this->generator->init($this->level, $this->random); - for($Z = 7; $Z <= 9; ++$Z){ - for($X = 7; $X <= 9; ++$X){ + //Generate 4 chunks for spawning players + for($Z = 7; $Z <= 8; ++$Z){ + for($X = 7; $X <= 8; ++$X){ $this->generator->generateChunk($X, $Z); } } - for($Z = 7; $Z <= 9; ++$Z){ - for($X = 7; $X <= 9; ++$X){ + for($Z = 7; $Z <= 8; ++$Z){ + for($X = 7; $X <= 8; ++$X){ $this->generator->populateChunk($X, $Z); } } From 9600d614548e8b734c61e99f003920ba524af068 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 20:48:50 +0100 Subject: [PATCH 050/173] Modified max-chunks-per-second default value --- src/API/ServerAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 996d9f05e..53f6ed6a7 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -147,7 +147,7 @@ class ServerAPI{ //Load advanced properties define("DEBUG", $this->getProperty("debug", 1)); define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); - define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 6)); //Default rate ~384 kB/s + define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 7)); //Default rate ~448 kB/s if(ADVANCED_CACHE == true){ console("[INFO] Advanced cache enabled"); } From 4fecbc2dbc6d1864cb067cf45e98a95d87490151 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 22:05:50 +0100 Subject: [PATCH 051/173] Added water sand and gravel --- src/world/generator/NormalGenerator.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index 1aba17c3b..df447767d 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -32,6 +32,7 @@ class NormalGenerator implements LevelGenerator{ private $waterHeight = 63; private $noiseHills; private $noisePatches; + private $noisePatchesSmall; private $noiseBase; public function __construct(array $options = array()){ @@ -48,7 +49,8 @@ class NormalGenerator implements LevelGenerator{ $this->random->setSeed($this->level->getSeed()); $this->noiseHills = new NoiseGeneratorSimplex($this->random, 3); $this->noisePatches = new NoiseGeneratorSimplex($this->random, 2); - $this->noiseBase = new NoiseGeneratorSimplex($this->random, 8); + $this->noisePatchesSmall = new NoiseGeneratorSimplex($this->random, 2); + $this->noiseBase = new NoiseGeneratorSimplex($this->random, 16); $ores = new OrePopulator(); @@ -68,17 +70,15 @@ class NormalGenerator implements LevelGenerator{ public function generateChunk($chunkX, $chunkZ){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $hills = array(); - $patches = array(); + $patchesSmall = array(); $base = array(); for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ $i = ($z << 4) + $x; $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.11, 12, true); $patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true); - $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true); - if($base[$i] < 0){ - $base[$i] *= 0.5; - } + $patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true); + $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 16, true); } } @@ -89,7 +89,7 @@ class NormalGenerator implements LevelGenerator{ for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ $i = ($z << 4) + $x; - $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 4; + $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 7; $height = (int) $height; for($y = $startY; $y < $endY; ++$y){ @@ -109,6 +109,14 @@ class NormalGenerator implements LevelGenerator{ }elseif($y <= $this->waterHeight){ if(($this->waterHeight - $y) <= 1 and $diff === 0){ $chunk .= "\x0c"; //sand + }elseif($diff === 0){ + if($patchesSmall[$i] > 0.3){ + $chunk .= "\x0d"; //gravel + }elseif($patches[$i] < -0.45){ + $chunk .= "\x0c"; //sand + }else{ + $chunk .= "\x03"; //dirt + } }else{ $chunk .= "\x09"; //still_water } From 5d7198396d2875597c79f9abe8f2030c9db41ae5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Feb 2014 22:39:53 +0100 Subject: [PATCH 052/173] Added TallGrassPopulator --- src/world/generator/NormalGenerator.php | 8 +++ .../generator/populator/OrePopulator.php | 4 +- .../populator/TallGrassPopulator.php | 70 +++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/world/generator/populator/TallGrassPopulator.php diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index df447767d..a0cd73e6b 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -65,6 +65,10 @@ class NormalGenerator implements LevelGenerator{ new OreType(new GravelBlock(), 10, 16, 0, 128), )); $this->populators[] = $ores; + $tallGrass = new TallGrassPopulator(); + $tallGrass->setBaseAmount(5); + $tallGrass->setRandomAmount(1); + $this->populators[] = $tallGrass; } public function generateChunk($chunkX, $chunkZ){ @@ -79,6 +83,10 @@ class NormalGenerator implements LevelGenerator{ $patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.03, 16, true); $patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.5, 4, true); $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), 0.7, 16, true); + + if($base[$i] < 0){ + $base[$i] *= 0.5; + } } } diff --git a/src/world/generator/populator/OrePopulator.php b/src/world/generator/populator/OrePopulator.php index 390cbcba7..5ae016ad9 100644 --- a/src/world/generator/populator/OrePopulator.php +++ b/src/world/generator/populator/OrePopulator.php @@ -25,9 +25,9 @@ class OrePopulator extends Populator{ foreach($this->oreTypes as $type){ $ore = new OreObject($random, $type); for($i = 0; $i < $ore->type->clusterCount; ++$i){ - $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16); + $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight); - $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16); + $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); if($ore->canPlaceObject($level, $x, $y, $z)){ $ore->placeObject($level, new Vector3($x, $y, $z)); } diff --git a/src/world/generator/populator/TallGrassPopulator.php b/src/world/generator/populator/TallGrassPopulator.php new file mode 100644 index 000000000..ba37bf59d --- /dev/null +++ b/src/world/generator/populator/TallGrassPopulator.php @@ -0,0 +1,70 @@ +randomAmount = $amount; + } + + public function setBaseAmount($amount){ + $this->baseAmount = $amount; + } + + public function populate(Level $level, $chunkX, $chunkZ, Random $random){ + $this->level = $level; + $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; + for($i = 0; $i < $amount; ++$i){ + $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); + $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); + for($size = 30; $size > 0; --$size){ + $xx = $x - 7 + $random->nextRange(0, 15); + $zz = $z - 7 + $random->nextRange(0, 15); + $yy = $this->getHighestWorkableBlock($xx, $zz); + $vector = new Vector3($xx, $yy, $zz); + if($yy !== -1 and $this->canTallGrassStay($this->level->getBlockRaw($vector))){ + $this->level->setBlockRaw($vector, new TallGrassBlock(1)); + } + } + } + } + + private function canTallGrassStay(Block $block){ + return $block->getID() === AIR and $block->getSide(0)->getID() === GRASS; + } + + private function getHighestWorkableBlock($x, $z){ + for($y = 128; $y > 0; --$y){ + $b = $this->level->getBlockRaw(new Vector3($x, $y, $z)); + if($b->getID() === AIR or $b->getID() === LEAVES){ + if(--$y <= 0){ + return -1; + } + }else{ + break; + } + } + return ++$y; + } +} \ No newline at end of file From 715e51b7c5ff97680d0a0d23326e3102787f3e23 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 00:19:26 +0100 Subject: [PATCH 053/173] Automatic population on side loading --- src/pmf/PMFLevel.php | 74 +++++++++++++------ src/world/Level.php | 5 +- src/world/generator/NormalGenerator.php | 25 ++++--- src/world/generator/SuperflatGenerator.php | 5 +- src/world/generator/WorldGenerator.php | 10 +-- .../generator/populator/TreePopulator.php | 67 +++++++++++++++++ 6 files changed, 139 insertions(+), 47 deletions(-) create mode 100644 src/world/generator/populator/TreePopulator.php diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 4f685176a..17a3e233d 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -144,9 +144,7 @@ class PMFLevel extends PMF{ for($index = 0; $index < 256; ++$index){ $X = $index & 0x0F; $Z = $index >> 4; - - $this->chunks[$index] = false; - $this->chunkChange[$index] = false; + $bitflags = Utils::readShort($this->read(2)); $oldPath = dirname($this->file)."/chunks/".$Z.".".$X.".pmc"; $chunkOld = gzopen($oldPath, "rb"); @@ -186,15 +184,36 @@ class PMFLevel extends PMF{ if(!file_exists(dirname($path))){ @mkdir(dirname($path), 0755); } - ++$this->isGenerating; $this->initCleanChunk($X, $Z); - $ret = $this->level->generateChunk($X, $Z); - $ret = $ret and $this->level->populateChunk($X, $Z); + $ret = $this->level->generateChunk($X, $Z); $this->saveChunk($X, $Z); - --$this->isGenerating; + $this->populateChunk($X - 1, $Z); + $this->populateChunk($X + 1, $Z); + $this->populateChunk($X, $Z - 1); + $this->populateChunk($X, $Z + 1); + $this->populateChunk($X + 1, $Z + 1); + $this->populateChunk($X + 1, $Z - 1); + $this->populateChunk($X - 1, $Z - 1); + $this->populateChunk($X - 1, $Z + 1); return $ret; } + public function populateChunk($X, $Z){ + if($this->isGenerating === 0 and + !$this->isPopulated($X, $Z) and + $this->isGenerated($X - 1, $Z) and + $this->isGenerated($X, $Z - 1) and + $this->isGenerated($X + 1, $Z) and + $this->isGenerated($X, $Z + 1) and + $this->isGenerated($X + 1, $Z + 1) and + $this->isGenerated($X - 1, $Z - 1) and + $this->isGenerated($X + 1, $Z - 1) and + $this->isGenerated($X - 1, $Z + 1)){ + $this->level->populateChunk($X, $Z); + $this->saveChunk($X, $Z); + } + } + public function loadChunk($X, $Z){ $X = (int) $X; $Z = (int) $Z; @@ -206,16 +225,13 @@ class PMFLevel extends PMF{ if(!file_exists($path)){ if($this->isGenerating > 0){ $this->level->generateChunk($X, $Z); - $this->saveChunk($X, $Z); }elseif($this->generateChunk($X, $Z) === false){ return false; } } if($this->isGenerating === 0 and !$this->isPopulated($X, $Z)){ - ++$this->isGenerating; - $this->level->populateChunk($X, $Z); - --$this->isGenerating; + $this->populateChunk($X, $Z); } $chunk = @gzopen($path, "rb"); @@ -262,15 +278,15 @@ class PMFLevel extends PMF{ public function isChunkLoaded($X, $Z){ $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + if(!isset($this->chunks[$index])){ return false; } return true; } - protected function isMiniChunkEmpty($X, $Z, $Y){ + public function isMiniChunkEmpty($X, $Z, $Y){ $index = self::getIndex($X, $Z); - if($this->chunks[$index][$Y] !== false){ + if(isset($this->chunks[$index]) and $this->chunks[$index][$Y] !== false){ if(substr_count($this->chunks[$index][$Y], "\x00") < 8192){ return false; } @@ -314,7 +330,17 @@ class PMFLevel extends PMF{ 6 => false, 7 => false, ); - $this->chunkChange[$index] = array(-1 => false); + $this->chunkChange[$index] = array( + -1 => true, + 0 => 8192, + 1 => 8192, + 2 => 8192, + 3 => 8192, + 4 => 8192, + 5 => 8192, + 6 => 8192, + 7 => 8192, + ); $this->chunkInfo[$index] = array( 0 => 0, 1 => 0, @@ -347,7 +373,7 @@ class PMFLevel extends PMF{ $Z = $z >> 4; $Y = $y >> 4; $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + if(!isset($this->chunks[$index])){ return 0; } $aX = $x - ($X << 4); @@ -366,7 +392,7 @@ class PMFLevel extends PMF{ $Y = $y >> 4; $block &= 0xFF; $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + if(!isset($this->chunks[$index])){ return false; } $aX = $x - ($X << 4); @@ -390,7 +416,7 @@ class PMFLevel extends PMF{ $Z = $z >> 4; $Y = $y >> 4; $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + if(!isset($this->chunks[$index])){ return 0; } $aX = $x - ($X << 4); @@ -414,7 +440,7 @@ class PMFLevel extends PMF{ $Y = $y >> 4; $damage &= 0x0F; $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + if(!isset($this->chunks[$index])){ return false; } $aX = $x - ($X << 4); @@ -449,7 +475,7 @@ class PMFLevel extends PMF{ return array(AIR, 0); } $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + if(!isset($this->chunks[$index])){ if($this->loadChunk($X, $Z) === false){ return array(AIR, 0); } @@ -479,7 +505,7 @@ class PMFLevel extends PMF{ $block &= 0xFF; $meta &= 0x0F; $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index]) or $this->chunks[$index] === false){ + if(!isset($this->chunks[$index])){ if($this->loadChunk($X, $Z) === false){ return false; } @@ -552,7 +578,7 @@ class PMFLevel extends PMF{ } $chunk = @gzopen($path, "wb".PMFLevel::DEFLATE_LEVEL); gzwrite($chunk, chr($bitmap)); - gzwrite($chunk, Utils::writeInt($this->chunkInfo[$index][0])); + gzwrite($chunk, Utils::writeInt($this->chunkInfo[$index][1])); for($Y = 0; $Y < 8; ++$Y){ $t = 1 << $Y; if(($bitmap & $t) === $t){ @@ -589,6 +615,10 @@ class PMFLevel extends PMF{ return ($this->chunkInfo[$index][1] & 0b00000000000000000000000000000001) > 0; } + public function isGenerated($X, $Z){ + return file_exists($this->getChunkPath($X, $Z)); + } + public function doSaveRound(){ foreach($this->chunks as $index => $chunk){ self::getXZ($index, $X, $Z); diff --git a/src/world/Level.php b/src/world/Level.php index 05e9ce4c0..d63d2c54e 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -148,11 +148,14 @@ class Level{ } public function generateChunk($X, $Z){ + ++$this->level->isGenerating; $this->generator->generateChunk($X, $Z); + --$this->level->isGenerating; } public function populateChunk($X, $Z){ - $this->generator->populateChunk($X, $Z); + $this->generator->populateChunk($X, $Z); + $this->level->setPopulated($X, $Z); } public function __destruct(){ diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index a0cd73e6b..bf24d7649 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -65,10 +65,16 @@ class NormalGenerator implements LevelGenerator{ new OreType(new GravelBlock(), 10, 16, 0, 128), )); $this->populators[] = $ores; + + $trees = new TreePopulator(); + $trees->setBaseAmount(3); + $trees->setRandomAmount(0); + $this->populators[] = $trees; + $tallGrass = new TallGrassPopulator(); $tallGrass->setBaseAmount(5); - $tallGrass->setRandomAmount(1); - $this->populators[] = $tallGrass; + $tallGrass->setRandomAmount(0); + $this->populators[] = $tallGrass; } public function generateChunk($chunkX, $chunkZ){ @@ -89,11 +95,11 @@ class NormalGenerator implements LevelGenerator{ } } } - + for($chunkY = 0; $chunkY < 8; ++$chunkY){ $chunk = ""; $startY = $chunkY << 4; - $endY = $startY + 16; + $endY = $startY + 16; for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ $i = ($z << 4) + $x; @@ -120,7 +126,7 @@ class NormalGenerator implements LevelGenerator{ }elseif($diff === 0){ if($patchesSmall[$i] > 0.3){ $chunk .= "\x0d"; //gravel - }elseif($patches[$i] < -0.45){ + }elseif($patchesSmall[$i] < -0.45){ $chunk .= "\x0c"; //sand }else{ $chunk .= "\x03"; //dirt @@ -148,17 +154,12 @@ class NormalGenerator implements LevelGenerator{ } - public function populateChunk($chunkX, $chunkZ){ + public function populateChunk($chunkX, $chunkZ){ + $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); foreach($this->populators as $populator){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } - - $this->level->level->setPopulated($chunkX, $chunkZ); - } - - public function populateLevel(){ - } public function getSpawn(){ diff --git a/src/world/generator/SuperflatGenerator.php b/src/world/generator/SuperflatGenerator.php index 95162d42b..d57874456 100644 --- a/src/world/generator/SuperflatGenerator.php +++ b/src/world/generator/SuperflatGenerator.php @@ -129,12 +129,11 @@ class SuperflatGenerator implements LevelGenerator{ } } - public function populateChunk($chunkX, $chunkZ){ + public function populateChunk($chunkX, $chunkZ){ + $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); foreach($this->populators as $populator){ - $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } - $this->level->level->setPopulated($chunkX, $chunkZ); } public function populateLevel(){ diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index d5a6f174a..aac73c0ce 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -46,25 +46,17 @@ class WorldGenerator{ } public function generate(){ - ++$this->level->level->isGenerating; $this->generator->init($this->level, $this->random); //Generate 4 chunks for spawning players for($Z = 7; $Z <= 8; ++$Z){ for($X = 7; $X <= 8; ++$X){ - $this->generator->generateChunk($X, $Z); - } - } - - for($Z = 7; $Z <= 8; ++$Z){ - for($X = 7; $X <= 8; ++$X){ - $this->generator->populateChunk($X, $Z); + $this->level->level->generateChunk($X, $Z); } } $this->level->setSpawn($this->generator->getSpawn()); $this->level->save(true, true); - --$this->level->level->isGenerating; } public function close(){ diff --git a/src/world/generator/populator/TreePopulator.php b/src/world/generator/populator/TreePopulator.php new file mode 100644 index 000000000..635b813eb --- /dev/null +++ b/src/world/generator/populator/TreePopulator.php @@ -0,0 +1,67 @@ +randomAmount = $amount; + } + + public function setBaseAmount($amount){ + $this->baseAmount = $amount; + } + + public function populate(Level $level, $chunkX, $chunkZ, Random $random){ + $this->level = $level; + $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; + for($i = 0; $i < $amount; ++$i){ + $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); + $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); + $y = $this->getHighestWorkableBlock($x, $z); + if($y === -1){ + continue; + } + if($random->nextFloat() > 0.75){ + $meta = 1; + }else{ + $meta = 0; + } + TreeObject::growTree($this->level, new Vector3($x, $y, $z), $random, $meta); + } + } + + private function getHighestWorkableBlock($x, $z){ + for($y = 128; $y > 0; --$y){ + $b = $this->level->getBlockRaw(new Vector3($x, $y, $z)); + if($b->getID() !== DIRT and $b->getID() !== GRASS){ + if(--$y <= 0){ + return -1; + } + }else{ + break; + } + } + return ++$y; + } +} \ No newline at end of file From da554fbf23c878f9cc10125db6b9926254b47057 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 00:25:44 +0100 Subject: [PATCH 054/173] Fixed Trees --- src/world/generator/object/tree/TreeObject.php | 2 ++ src/world/generator/populator/TreePopulator.php | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/world/generator/object/tree/TreeObject.php b/src/world/generator/object/tree/TreeObject.php index 86677c8c7..109702334 100644 --- a/src/world/generator/object/tree/TreeObject.php +++ b/src/world/generator/object/tree/TreeObject.php @@ -23,6 +23,8 @@ class TreeObject{ public $overridable = array( 0 => true, + 2 => true, + 3 => true, 6 => true, 17 => true, 18 => true, diff --git a/src/world/generator/populator/TreePopulator.php b/src/world/generator/populator/TreePopulator.php index 635b813eb..7b6a2be31 100644 --- a/src/world/generator/populator/TreePopulator.php +++ b/src/world/generator/populator/TreePopulator.php @@ -43,9 +43,9 @@ class TreePopulator extends Populator{ continue; } if($random->nextFloat() > 0.75){ - $meta = 1; + $meta = SaplingBlock::BIRCH; }else{ - $meta = 0; + $meta = SaplingBlock::OAK; } TreeObject::growTree($this->level, new Vector3($x, $y, $z), $random, $meta); } @@ -57,7 +57,7 @@ class TreePopulator extends Populator{ if($b->getID() !== DIRT and $b->getID() !== GRASS){ if(--$y <= 0){ return -1; - } + } }else{ break; } From c1251a25bdddbff887156832dd2f307855a8c310 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 01:36:10 +0100 Subject: [PATCH 055/173] Removed water PMFLevel update that caused locks --- src/pmf/PMFLevel.php | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 17a3e233d..5dc9305c5 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -534,17 +534,6 @@ class PMFLevel extends PMF{ ++$this->chunkChange[$index][$Y]; } $this->chunkChange[$index][-1] = true; - if($old_b instanceof LiquidBlock){ - $pos = new Position($x, $y, $z, $this->level); - for($side = 0; $side <= 5; ++$side){ - $b = $pos->getSide($side); - if($b instanceof LavaBlock){ - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); - }else{ - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); - } - } - } return true; } return false; @@ -553,10 +542,12 @@ class PMFLevel extends PMF{ public function saveChunk($X, $Z){ $X = (int) $X; $Z = (int) $Z; - if($this->isGenerating > 0){ - $this->initCleanChunk($X, $Z); - }elseif(!$this->isChunkLoaded($X, $Z)){ - return false; + if(!$this->isChunkLoaded($X, $Z)){ + if($this->isGenerating > 0){ + $this->initCleanChunk($X, $Z); + }else{ + return false; + } } $index = self::getIndex($X, $Z); if(!isset($this->chunkChange[$index]) or $this->chunkChange[$index][-1] === false){//No changes in chunk From 63f4f87d373309fd621c2afb3771095424a61c78 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 13:17:05 +0100 Subject: [PATCH 056/173] Fixed PMFLevel bugs, crashes and weird methods --- src/API/LevelAPI.php | 18 +++--------- src/pmf/PMFLevel.php | 38 ++++++++++++-------------- src/world/Level.php | 7 +++-- src/world/generator/WorldGenerator.php | 3 +- 4 files changed, 26 insertions(+), 40 deletions(-) diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 56d96ec17..e93e6df31 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -151,6 +151,10 @@ class LevelAPI{ $path = DATA_PATH."worlds/".$name."/"; console("[INFO] Preparing level \"".$name."\""); $level = new PMFLevel($path."level.pmf"); + if(!$level->isLoaded){ + console("[ERROR] Could not load level \"".$name."\""); + return false; + } $entities = new Config($path."entities.yml", CONFIG_YAML); if(file_exists($path."tileEntities.yml")){ @rename($path."tileEntities.yml", $path."tiles.yml"); @@ -223,20 +227,6 @@ class LevelAPI{ return $this->server->spawn; } - public function loadMap(){ - if($this->mapName !== false and trim($this->mapName) !== ""){ - if(!file_exists($this->mapDir."level.pmf")){ - $level = new LevelImport($this->mapDir); - $level->import(); - } - $this->level = new PMFLevel($this->mapDir."level.pmf"); - console("[INFO] Preparing level \"".$this->level->getData("name")."\""); - $this->time = (int) $this->level->getData("time"); - $this->seed = (int) $this->level->getData("seed"); - $this->spawn = $this->level->getSpawn(); - } - } - public function getAll(){ return $this->levels; } diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 5dc9305c5..f4babf92e 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -46,13 +46,16 @@ class PMFLevel extends PMF{ return true; } - public function close(){ + public function closeLevel(){ $this->chunks = null; unset($this->chunks, $this->chunkChange, $this->chunkInfo, $this->level); - parent::close(); + $this->close(); } public function __construct($file, $blank = false){ + $this->chunks = array(); + $this->chunkChange = array(); + $this->chunkInfo = array(); if(is_array($blank)){ $this->create($file, 0); $this->levelData = $blank; @@ -166,7 +169,7 @@ class PMFLevel extends PMF{ } public static function getIndex($X, $Z){ - return ($Z << 16) + $X; + return ($Z << 16) | ($X < 0 ? (~--$X & 0x7fff) | 0x1000 : $X & 0xFFFF); } public static function getXZ($index, &$X = null, &$Z = null){ @@ -223,10 +226,11 @@ class PMFLevel extends PMF{ } $path = $this->getChunkPath($X, $Z); if(!file_exists($path)){ - if($this->isGenerating > 0){ - $this->level->generateChunk($X, $Z); - }elseif($this->generateChunk($X, $Z) === false){ + if($this->generateChunk($X, $Z) === false){ return false; + }else{ + $this->populateChunk($X, $Z); + return true; } } @@ -307,7 +311,7 @@ class PMFLevel extends PMF{ } public function getMiniChunk($X, $Z, $Y){ - if($this->loadChunk($X, $Z) === false){ + if($this->isChunkLoaded($X, $Z) === false and $this->loadChunk($X, $Z) === false){ return str_repeat("\x00", 8192); } $index = self::getIndex($X, $Z); @@ -475,11 +479,9 @@ class PMFLevel extends PMF{ return array(AIR, 0); } $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index])){ - if($this->loadChunk($X, $Z) === false){ - return array(AIR, 0); - } - }elseif($this->chunks[$index][$Y] === false){ + if(!isset($this->chunks[$index]) and $this->loadChunk($X, $Z) === false){ + return array(AIR, 0); + }elseif($this->chunks[$index][$Y] === false){ return array(AIR, 0); } $aX = $x - ($X << 4); @@ -505,10 +507,8 @@ class PMFLevel extends PMF{ $block &= 0xFF; $meta &= 0x0F; $index = self::getIndex($X, $Z); - if(!isset($this->chunks[$index])){ - if($this->loadChunk($X, $Z) === false){ - return false; - } + if(!isset($this->chunks[$index]) and $this->loadChunk($X, $Z) === false){ + return false; }elseif($this->chunks[$index][$Y] === false){ $this->fillMiniChunk($X, $Z, $Y); } @@ -543,11 +543,7 @@ class PMFLevel extends PMF{ $X = (int) $X; $Z = (int) $Z; if(!$this->isChunkLoaded($X, $Z)){ - if($this->isGenerating > 0){ - $this->initCleanChunk($X, $Z); - }else{ - return false; - } + return false; } $index = self::getIndex($X, $Z); if(!isset($this->chunkChange[$index]) or $this->chunkChange[$index][-1] === false){//No changes in chunk diff --git a/src/world/Level.php b/src/world/Level.php index d63d2c54e..5def8ab8b 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -26,7 +26,6 @@ class Level{ public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ $this->server = ServerAPI::request(); $this->level = $level; - $level->level = $this; $this->level->level = $this; $this->entities = $entities; $this->tiles = $tiles; @@ -151,17 +150,19 @@ class Level{ ++$this->level->isGenerating; $this->generator->generateChunk($X, $Z); --$this->level->isGenerating; + return true; } public function populateChunk($X, $Z){ - $this->generator->populateChunk($X, $Z); $this->level->setPopulated($X, $Z); + $this->generator->populateChunk($X, $Z); + return true; } public function __destruct(){ if(isset($this->level)){ $this->save(false, false); - $this->level->close(); + $this->level->closeLevel(); unset($this->level); } } diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index aac73c0ce..b9b842d53 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -51,12 +51,11 @@ class WorldGenerator{ //Generate 4 chunks for spawning players for($Z = 7; $Z <= 8; ++$Z){ for($X = 7; $X <= 8; ++$X){ - $this->level->level->generateChunk($X, $Z); + $this->level->level->loadChunk($X, $Z); } } $this->level->setSpawn($this->generator->getSpawn()); - $this->level->save(true, true); } public function close(){ From 47893ed765da4d8ae9ec2e946bed2f31cb59a10b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 14:21:13 +0100 Subject: [PATCH 057/173] Generate backtrace on error/crash --- src/PocketMinecraftServer.php | 5 +++++ src/functions.php | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index ac655f6cf..32afc47d2 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -420,6 +420,11 @@ class PocketMinecraftServer{ $dump .= "[".($l + 1)."] ".@$file[$l]."\r\n"; } $dump .= "\r\n\r\n"; + $dump .= "Backtrace: \r\n"; + foreach(getTrace() as $line){ + $dump .= "$line\r\n"; + } + $dump .= "\r\n\r\n"; $version = new VersionString(); $dump .= "PocketMine-MP version: ".$version." #".$version->getNumber()." [Protocol ".ProtocolInfo::CURRENT_PROTOCOL."; API ".CURRENT_API_VERSION."]\r\n"; $dump .= "Git commit: ".GIT_COMMIT."\r\n"; diff --git a/src/functions.php b/src/functions.php index 720d8062c..6fcdcf891 100644 --- a/src/functions.php +++ b/src/functions.php @@ -218,6 +218,21 @@ function console($message, $EOL = true, $log = true, $level = 1){ } } +function getTrace($start = 1){ + $e = new Exception(); + $trace = $e->getTrace(); + $messages = array(); + $j = 0; + for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){ + $params = ""; + foreach($trace[$i]["args"] as $name => $value){ + $params .= (is_object($value) ? get_class($value)." ".(method_exists($value, "__toString") ? $value->__toString() : "object"):gettype($value)." ".@strval($value)).", "; + } + $messages[] = "#$j ".(isset($trace[$i]["file"]) ? $trace[$i]["file"]:"")."(".(isset($trace[$i]["line"]) ? $trace[$i]["line"]:"")."): ".(isset($trace[$i]["class"]) ? $trace[$i]["class"].$trace[$i]["type"]:"").$trace[$i]["function"]."(".substr($params, 0, -2).")"; + } + return $messages; +} + function error_handler($errno, $errstr, $errfile, $errline){ if(error_reporting() === 0){ //@ error-control return false; @@ -241,6 +256,9 @@ function error_handler($errno, $errstr, $errfile, $errline){ ); $errno = isset($errorConversion[$errno]) ? $errorConversion[$errno]:$errno; console("[ERROR] A ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0); + foreach(getTrace() as $i => $line){ + console("[TRACE] $line"); + } return true; } From cbe07a1fa0f54c3255e3cd1068be112236fe6f29 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 14:21:28 +0100 Subject: [PATCH 058/173] Fixed PMFLevel infinite loop --- src/pmf/PMFLevel.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index f4babf92e..20d50e7ff 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -228,15 +228,11 @@ class PMFLevel extends PMF{ if(!file_exists($path)){ if($this->generateChunk($X, $Z) === false){ return false; - }else{ + }elseif($this->isGenerating === 0){ $this->populateChunk($X, $Z); return true; } } - - if($this->isGenerating === 0 and !$this->isPopulated($X, $Z)){ - $this->populateChunk($X, $Z); - } $chunk = @gzopen($path, "rb"); if($chunk === false){ @@ -261,6 +257,9 @@ class PMFLevel extends PMF{ } } @gzclose($chunk); + if($this->isGenerating === 0 and !$this->isPopulated($X, $Z)){ + $this->populateChunk($X, $Z); + } return true; } From 4acb4541ab91aa2805e3a9c8e99eaf8a3061721b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 17:59:34 +0100 Subject: [PATCH 059/173] Infinite player chunk sending (not yet visible :( ) --- src/Player.php | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/Player.php b/src/Player.php index 6bd62aa62..38ee6d611 100644 --- a/src/Player.php +++ b/src/Player.php @@ -63,6 +63,7 @@ class Player{ public $blocked = true; public $achievements = array(); public $chunksLoaded = array(); + private $viewDistance; private $chunksOrder = array(); private $lastMeasure = 0; private $bandwidthRaw = 0; @@ -112,6 +113,7 @@ class Player{ $this->armor = array(); $this->gamemode = $this->server->gamemode; $this->level = $this->server->api->level->getDefault(); + $this->viewDistance = (int) $this->server->api->getProperty("view-distance"); $this->slot = 0; $this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1); $this->packetStats = array(0,0); @@ -148,22 +150,35 @@ class Player{ if(!($this->entity instanceof Entity) or $this->connected === false){ return false; } - $X = ($this->entity->x - 0.5) / 16; - $Z = ($this->entity->z - 0.5) / 16; - $v = new Vector2($X, $Z); - $this->chunksOrder = array(); - for($x = 0; $x < 16; ++$x){ - for($z = 0; $z < 16; ++$z){ - $dist = $v->distance(new Vector2($x, $z)); - for($y = 0; $y < 8; ++$y){ - $d = $x.":".$y.":".$z; - if(!isset($this->chunksLoaded[$d])){ - $this->chunksOrder[$d] = $dist; + + $newOrder = array(); + $lastLoaded = $this->chunksLoaded; + $centerX = intval(($this->entity->x - 0.5) / 16); + $centerZ = intval(($this->entity->z - 0.5) / 16); + $startX = $centerX - $this->viewDistance; + $startZ = $centerZ - $this->viewDistance; + $finalX = $centerX + $this->viewDistance; + $finalZ = $centerZ + $this->viewDistance; + for($X = $startX; $X <= $finalX; ++$X){ + 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(){ @@ -195,7 +210,7 @@ class Player{ $c = key($this->chunksOrder); $d = @$this->chunksOrder[$c]; - if($c === null or $d > $this->server->api->getProperty("view-distance")){ + if($c === null){ $this->server->schedule(50, array($this, "getNextChunk")); return false; } @@ -1468,7 +1483,7 @@ class Player{ } $this->sendInventory(); $this->sendSettings(); - $this->server->schedule(50, array($this, "orderChunks"), array(), true); + $this->server->schedule(30, array($this, "orderChunks"), array(), true); $this->blocked = false; $pk = new SetTimePacket; From f0ff4206593571e02f59a2906043ae6403194471 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 18:25:06 +0100 Subject: [PATCH 060/173] Fixed negative chunk indexes on PMFLevel --- src/pmf/PMFLevel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 20d50e7ff..61bb92e44 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -169,12 +169,12 @@ class PMFLevel extends PMF{ } 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){ $Z = $index >> 16; - $X = $index & 0xFFFF; + $X = ($index & 0x8000) === 0x8000 ? -($index & 0x7fff) : $index & 0x7fff; return array($X, $Z); } From fdf519398a66dae2f4cad220752f468b7ad773b1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 19:37:39 +0100 Subject: [PATCH 061/173] Do not unload spawn chunks --- src/Player.php | 18 ++++++++++-------- src/world/Level.php | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Player.php b/src/Player.php index 38ee6d611..b1a5b08a8 100644 --- a/src/Player.php +++ b/src/Player.php @@ -2322,14 +2322,16 @@ class Player{ } public function sendBuffer(){ - if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket){ - $this->buffer->seqNumber = $this->counter[0]++; - $this->send($this->buffer); + if($this->connected === true){ + if($this->bufferLen > 0 and $this->buffer instanceof RakNetPacket){ + $this->buffer->seqNumber = $this->counter[0]++; + $this->send($this->buffer); + } + $this->bufferLen = 0; + $this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0); + $this->buffer->data = array(); + $this->nextBuffer = microtime(true) + 0.1; } - $this->bufferLen = 0; - $this->buffer = new RakNetPacket(RakNetInfo::DATA_PACKET_0); - $this->buffer->data = array(); - $this->nextBuffer = microtime(true) + 0.1; } private function directBigRawPacket(RakNetDataPacket $packet){ @@ -2418,7 +2420,7 @@ class Player{ $packet->messageIndex = $this->counter[3]++; $packet->reliability = 2; - $this->buffer->data[] = $packet; + @$this->buffer->data[] = $packet; $this->bufferLen += 6 + $len; return array(); } diff --git a/src/world/Level.php b/src/world/Level.php index 5def8ab8b..dc8a8bff3 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -138,8 +138,11 @@ class Level{ if(count($c) === 0){ unset($this->usedChunks[$i]); $X = explode(".", $i); - $Z = array_pop($X); - $this->level->unloadChunk((int) array_pop($X), (int) $Z, $this->server->saveEnabled); + $Z = (int) array_pop($X); + $X = (int) array_pop($X); + if(!$this->isSpawnChunk($X, $Z)){ + $this->level->unloadChunk($X, $Z, $this->server->saveEnabled); + } } } $this->save(false, false); @@ -408,13 +411,23 @@ class Level{ return $this->level->loadChunk($X, $Z); } - public function unloadChunk($X, $Z){ + public function unloadChunk($X, $Z, $force = false){ if(!isset($this->level)){ return false; } + + if($force !== true and $this->isSpawnChunk($X, $Z)){ + return false; + } Cache::remove("world:{$this->name}:$X:$Z"); 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){ if(!isset($this->level)){ From daf3198136e59d7f28b58e10eb2ab3b2123f5f11 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 19:37:57 +0100 Subject: [PATCH 062/173] Tall Grass can be replaced --- src/material/block/plant/TallGrass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/material/block/plant/TallGrass.php b/src/material/block/plant/TallGrass.php index ec0068e50..afe385289 100644 --- a/src/material/block/plant/TallGrass.php +++ b/src/material/block/plant/TallGrass.php @@ -22,7 +22,7 @@ class TallGrassBlock extends FlowableBlock{ public function __construct($meta = 1){ parent::__construct(TALL_GRASS, $meta, "Tall Grass"); - //$this->isReplaceable = true; + $this->isReplaceable = true; $names = array( 0 => "Dead Shrub", 1 => "Tall Grass", From 2b15c440ee0c5c2763adafb7975487404ff36147 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 19:54:14 +0100 Subject: [PATCH 063/173] Send inventory on invalid crafting/invalid movement of item --- src/API/BlockAPI.php | 2 +- src/Player.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index e162ac1fe..4ee73014a 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -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){ return $this->cancelAction($target, $player, false); } diff --git a/src/Player.php b/src/Player.php index b1a5b08a8..95dc81c5c 100644 --- a/src/Player.php +++ b/src/Player.php @@ -2170,6 +2170,7 @@ class Player{ if($item->getID() !== AIR and $slot->getID() == $item->getID()){ if($slot->count < $item->count){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ + $this->sendInventory(); break; } }elseif($slot->count > $item->count){ @@ -2177,6 +2178,7 @@ class Player{ } }else{ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){ + $this->sendInventory(); break; } $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); @@ -2216,6 +2218,7 @@ class Player{ if($item->getID() !== AIR and $slot->getID() == $item->getID()){ if($slot->count < $item->count){ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count - $slot->count, false) === false){ + $this->sendInventory(); break; } }elseif($slot->count > $item->count){ @@ -2223,6 +2226,7 @@ class Player{ } }else{ if($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false){ + $this->sendInventory(); break; } $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); From dfe726901919a9daee484dcb4dc5dc2754fb4169 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 20:53:15 +0100 Subject: [PATCH 064/173] Fixed #1193 using #1194 --- src/API/PlayerAPI.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 272439ec4..788d6bbd1 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -196,9 +196,6 @@ class PlayerAPI{ "spectator" => VIEW, "v" => VIEW, ); - if($issuer instanceof Player){ - $player = $issuer; - } if(isset($params[1])){ if($this->server->api->player->get($params[1]) instanceof Player){ $player = $this->server->api->player->get($params[1]); @@ -210,7 +207,15 @@ class PlayerAPI{ $output .= "Usage: /$cmd [player] or /$cmd [player] \n"; 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)])){ $output .= "Usage: /$cmd [player] or /$cmd [player] \n"; break; From 08149fa4b34599a80eace04e10f581990db1310f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 20:56:00 +0100 Subject: [PATCH 065/173] Fixed #1229 --- src/world/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/Entity.php b/src/world/Entity.php index 11e3e81f8..372185a2b 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -164,7 +164,7 @@ class Entity extends Position{ } public function getDrops(){ - if($this->class === ENTITY_PLAYER and ($this->player->gamemode & 0x01) === 0){ + if($this->class === ENTITY_PLAYER and $this->player instanceof Player ($this->player->gamemode & 0x01) === 0){ $inv = array(); for($i = 0; $i < PLAYER_SURVIVAL_SLOTS; ++$i){ $slot = $this->player->getSlot($i); From 5d1c79379b7a8d5ca2384d709b7680639515dff6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 21:49:26 +0100 Subject: [PATCH 066/173] *and --- src/world/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/Entity.php b/src/world/Entity.php index 372185a2b..a8bb3d26d 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -164,7 +164,7 @@ class Entity extends Position{ } public function getDrops(){ - if($this->class === ENTITY_PLAYER and $this->player instanceof Player ($this->player->gamemode & 0x01) === 0){ + if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){ $inv = array(); for($i = 0; $i < PLAYER_SURVIVAL_SLOTS; ++$i){ $slot = $this->player->getSlot($i); From 12141fe2b12486e8cb4c7ee4f11ca28976f2c924 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 22:41:50 +0100 Subject: [PATCH 067/173] Updated jenkins.sh --- src/build/jenkins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 006158610..c22f512fb 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -31,7 +31,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - CFLAGS=-m32 march=i686 mtune=generic $SCRIPT + CFLAGS=-m32 march=i686 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then @@ -44,7 +44,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit cd $COMPILEDIR/linux/64bit - $SCRIPT + CFLAGS=-m64 march=x86-64 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then From 9301c04e1f8da243df54ee60a5377d9d82d0219f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 14 Feb 2014 23:09:29 +0100 Subject: [PATCH 068/173] Added pre-compiled Linux binaries to installer --- src/build/installer.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/build/installer.sh b/src/build/installer.sh index 4cba6bcde..e97aee552 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -1,5 +1,7 @@ #!/bin/bash PMMP_VERSION="" +LINUX_32_BUILD="PHP_5.5.9_x86_Linux" +LINUX_64_BUILD="PHP_5.5.9_x86-64_Linux" MAC_BUILD="PHP_5.5.9_x86_MacOS" RPI_BUILD="PHP_5.5.9_ARM_Raspbian_hard" AND_BUILD="PHP_5.5.9_ARMv7_Android" @@ -130,6 +132,32 @@ else echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" echo "asp_tags=0" >> "./bin/php5/lib/php.ini" echo " done" + elif [ "$(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 " regenerating php.ini..." + OPCACHE_PATH=$(find "./bin/php5" -name opcache.so) + echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/lib/php.ini" + echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" + echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" + echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" + echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" + echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" + echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" + echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" else set -e echo "[3/3] no build found, compiling PHP" From d699a97bb79e0a31c9f8fd388fb1a2eddabb70a1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 15 Feb 2014 01:39:37 +0100 Subject: [PATCH 069/173] small things --- src/Player.php | 4 ++-- src/pmf/PMFLevel.php | 13 ++++++------- src/world/Level.php | 4 ++++ src/world/generator/WorldGenerator.php | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Player.php b/src/Player.php index 95dc81c5c..4819c0dc5 100644 --- a/src/Player.php +++ b/src/Player.php @@ -210,8 +210,8 @@ class Player{ $c = key($this->chunksOrder); $d = @$this->chunksOrder[$c]; - if($c === null){ - $this->server->schedule(50, array($this, "getNextChunk")); + if($c === null or $d === null){ + $this->server->schedule(40, array($this, "getNextChunk")); return false; } unset($this->chunksOrder[$c]); diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 61bb92e44..46f6bb98d 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -212,26 +212,25 @@ class PMFLevel extends PMF{ $this->isGenerated($X - 1, $Z - 1) and $this->isGenerated($X + 1, $Z - 1) and $this->isGenerated($X - 1, $Z + 1)){ - $this->level->populateChunk($X, $Z); + $this->level->populateChunk($X, $Z); $this->saveChunk($X, $Z); } } public function loadChunk($X, $Z){ - $X = (int) $X; - $Z = (int) $Z; - $index = self::getIndex($X, $Z); if($this->isChunkLoaded($X, $Z)){ return true; } + $index = self::getIndex($X, $Z); $path = $this->getChunkPath($X, $Z); if(!file_exists($path)){ if($this->generateChunk($X, $Z) === 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"); diff --git a/src/world/Level.php b/src/world/Level.php index dc8a8bff3..01a256dde 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -77,6 +77,10 @@ class Level{ unset($this->usedChunks[$X.".".$Z][$player->CID]); } + public function isChunkPopulated($X, $Z){ + return $this->level->isPopulated($X, $Z); + } + public function checkTime(){ if(!isset($this->level)){ return false; diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index b9b842d53..9825adea5 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -50,7 +50,7 @@ class WorldGenerator{ //Generate 4 chunks for spawning players for($Z = 7; $Z <= 8; ++$Z){ - for($X = 7; $X <= 8; ++$X){ + for($X = 7; $X <= 9; ++$X){ $this->level->level->loadChunk($X, $Z); } } From b6ad8890578ba113becb5cbbdfa1d0927c6fe2c3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 12:46:26 +0100 Subject: [PATCH 070/173] Trying to fix libssl.so.10 error, re-added libedit --- src/build/compile.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 885898db7..6f5af08c2 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -1,17 +1,16 @@ #!/bin/bash -COMPILER_VERSION="0.16" - PHP_VERSION="5.5.9" ZEND_VM="GOTO" -LIBEDIT_VERSION="0.3" ZLIB_VERSION="1.2.8" +GNUTLS_VERSION="3.2.11" +CURL_VERSION="curl-7_35_0" +LIBEDIT_VERSION="0.3" PTHREADS_VERSION="0.1.0" PHPYAML_VERSION="1.1.1" YAML_VERSION="0.1.4" -CURL_VERSION="curl-7_35_0" -echo "[PocketMine] PHP installer and compiler for Linux & Mac" +echo "[PocketMine] PHP installer and compiler for Linux and Mac" DIR="$(pwd)" date > "$DIR/install.log" 2>&1 uname -a >> "$DIR/install.log" 2>&1 @@ -168,7 +167,7 @@ download_file "http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror" | ta mv php-$PHP_VERSION php echo " done!" -if [ 1 ] || [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ]; then +if [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ]; then HAVE_LIBEDIT="--without-libedit" else #libedit @@ -176,15 +175,18 @@ else download_file "http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 echo -n " checking..." cd libedit - ./configure --prefix="$DIR/install_data/php/ext/libedit" --enable-static >> "$DIR/install.log" 2>&1 + ./configure --prefix="$DIR/install_data/php/ext/libedit" \ + --enable-shared=no \ + --enable-static=yes \ + $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." if make -j $THREADS >> "$DIR/install.log" 2>&1; then echo -n " installing..." make install >> "$DIR/install.log" 2>&1 - HAVE_LIBEDIT="--with-libedit=\"$DIR/install_data/php/ext/libedit\"" + HAVE_LIBEDIT="--without-readline --with-libedit=\"$DIR/install_data/php/ext/libedit\"" else echo -n " disabling..." - HAVE_LIBEDIT="--without-libedit" + HAVE_LIBEDIT="--without-readline --without-libedit" fi echo -n " cleaning..." cd .. @@ -199,7 +201,8 @@ mv zlib-$ZLIB_VERSION zlib echo -n " checking..." cd zlib RANLIB=$RANLIB ./configure --prefix="$DIR/install_data/php/ext/zlib" \ ---static >> "$DIR/install.log" 2>&1 +--static \ +$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." @@ -238,6 +241,8 @@ else --disable-ldap \ --disable-ldaps \ --without-libidn \ + --with-ssl="/usr/lib" \ + --with-axtls="$DIR/install_data/axTLS" \ --enable-threaded-resolver \ --prefix="$DIR/install_data/php/ext/curl" \ --disable-shared \ From e740124b437ab88826d236062a044be607939bf1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 13:03:31 +0100 Subject: [PATCH 071/173] Update jenkins.sh --- src/build/jenkins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index c22f512fb..cff26fb89 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -31,7 +31,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - CFLAGS=-m32 march=i686 mtune=none $SCRIPT + CFLAGS="-m32 -static" march=i686 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then @@ -44,7 +44,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit cd $COMPILEDIR/linux/64bit - CFLAGS=-m64 march=x86-64 mtune=none $SCRIPT + CFLAGS="-m64 -static" march=x86-64 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then From 0915e751c4e7bf9ca9055411e1011dd6d461148f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 13:11:15 +0100 Subject: [PATCH 072/173] Update jenkins.sh --- src/build/jenkins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index cff26fb89..cd2b29321 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -31,7 +31,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - CFLAGS="-m32 -static" march=i686 mtune=none $SCRIPT + CFLAGS="-m32 -static -ldl" march=i686 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then @@ -44,7 +44,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit cd $COMPILEDIR/linux/64bit - CFLAGS="-m64 -static" march=x86-64 mtune=none $SCRIPT + CFLAGS="-m64 -static -ldl" march=x86-64 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then From 878c3a3e3a2b1d282f377fc6ab2130a3a99db889 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 13:27:29 +0100 Subject: [PATCH 073/173] Update compile.sh --- src/build/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 6f5af08c2..ee5a31bae 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -241,7 +241,7 @@ else --disable-ldap \ --disable-ldaps \ --without-libidn \ - --with-ssl="/usr/lib" \ + --with-ssl \ --with-axtls="$DIR/install_data/axTLS" \ --enable-threaded-resolver \ --prefix="$DIR/install_data/php/ext/curl" \ From e7565e41833a13074cea239d18b0c8461a813f4d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 13:34:41 +0100 Subject: [PATCH 074/173] Update jenkins.sh --- src/build/jenkins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index cd2b29321..2f9267a38 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -31,7 +31,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - CFLAGS="-m32 -static -ldl" march=i686 mtune=none $SCRIPT + CFLAGS="-m32 -static" LDFLAGS="-ldl" march=i686 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then @@ -44,7 +44,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit cd $COMPILEDIR/linux/64bit - CFLAGS="-m64 -static -ldl" march=x86-64 mtune=none $SCRIPT + CFLAGS="-m64 -static" LDFLAGS="-ldl" march=x86-64 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then From 5725b5a1a89f5dbef26cb23bd3b1b86ccd886df9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 13:36:13 +0100 Subject: [PATCH 075/173] Update compile.sh --- src/build/compile.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index ee5a31bae..d6d356c93 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -242,7 +242,6 @@ else --disable-ldaps \ --without-libidn \ --with-ssl \ - --with-axtls="$DIR/install_data/axTLS" \ --enable-threaded-resolver \ --prefix="$DIR/install_data/php/ext/curl" \ --disable-shared \ From e22b70296f34e06f82556099599c677f50689041 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 13:52:10 +0100 Subject: [PATCH 076/173] Update compile.sh --- src/build/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index d6d356c93..57724235b 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -3,7 +3,6 @@ PHP_VERSION="5.5.9" ZEND_VM="GOTO" ZLIB_VERSION="1.2.8" -GNUTLS_VERSION="3.2.11" CURL_VERSION="curl-7_35_0" LIBEDIT_VERSION="0.3" PTHREADS_VERSION="0.1.0" @@ -241,6 +240,7 @@ else --disable-ldap \ --disable-ldaps \ --without-libidn \ + --with-zlib="$DIR/install_data/php/ext/zlib" \ --with-ssl \ --enable-threaded-resolver \ --prefix="$DIR/install_data/php/ext/curl" \ From 9847f38a9f4a31cdd04fc34adb05fb1018ab3803 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 16:10:05 +0100 Subject: [PATCH 077/173] Include OpenSSL in builds --- src/build/compile.sh | 41 ++++++++++++++++++++++++++++++++++++++--- src/build/jenkins.sh | 4 ++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 57724235b..219ac541b 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -3,6 +3,7 @@ PHP_VERSION="5.5.9" ZEND_VM="GOTO" ZLIB_VERSION="1.2.8" +OPENSSL_VERSION="1.0.1f" CURL_VERSION="curl-7_35_0" LIBEDIT_VERSION="0.3" PTHREADS_VERSION="0.1.0" @@ -44,16 +45,19 @@ if [ "$1" == "rpi" ]; then [ -z "$march" ] && march=armv6zk; [ -z "$mtune" ] && mtune=arm1176jzf-s; [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; + OPENSSL_TARGET="linux-armv4" echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float" elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-fomit-frame-pointer"; + OPENSSL_TARGET="darwin64-x86_64-cc" echo "[INFO] Compiling for Intel MacOS" elif [ "$1" == "ios" ]; then [ -z "$march" ] && march=armv6; [ -z "$mtune" ] && mtune=cortex-a8; echo "[INFO] Compiling for iOS ARMv6" + OPENSSL_TARGET="linux-armv4" elif [ "$1" == "crosscompile" ]; then HAVE_MYSQLI="--without-mysqli" if [ "$2" == "android" ] || [ "$2" == "android-armv6" ]; then @@ -66,6 +70,7 @@ elif [ "$1" == "crosscompile" ]; then CFLAGS="-uclibc --static $CFLAGS"; LDFLAGS="--static" echo "[INFO] Cross-compiling for Android ARMv6" + OPENSSL_TARGET="linux-armv4" elif [ "$2" == "android-armv7" ]; then COMPILE_FOR_ANDROID=yes [ -z "$march" ] && march=armv7-a; @@ -76,6 +81,7 @@ elif [ "$1" == "crosscompile" ]; then CFLAGS="-uclibc --static $CFLAGS"; LDFLAGS="--static" echo "[INFO] Cross-compiling for Android ARMv7" + OPENSSL_TARGET="linux-armv4" elif [ "$2" == "rpi" ]; then TOOLCHAIN_PREFIX="arm-linux-gnueabihf" [ -z "$march" ] && march=armv6zk; @@ -84,6 +90,7 @@ elif [ "$1" == "crosscompile" ]; then export CC="$TOOLCHAIN_PREFIX-gcc" CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" [ -z "$CFLAGS" ] && CFLAGS="-uclibc"; + OPENSSL_TARGET="linux-armv4" echo "[INFO] Cross-compiling for Raspberry Pi ARMv6zk hard float" elif [ "$2" == "mac" ]; then [ -z "$march" ] && march=prescott; @@ -94,15 +101,18 @@ elif [ "$1" == "crosscompile" ]; then CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" #zlib doesn't use the correct ranlib RANLIB=$TOOLCHAIN_PREFIX-ranlib + OPENSSL_TARGET="darwin64-x86_64-cc" echo "[INFO] Cross-compiling for Intel MacOS" elif [ "$2" == "ios" ] || [ "$2" == "ios-armv6" ]; then [ -z "$march" ] && march=armv6; [ -z "$mtune" ] && mtune=generic-armv6; CONFIGURE_FLAGS="--target=arm-apple-darwin10" + OPENSSL_TARGET="linux-armv4" elif [ "$2" == "ios-armv7" ]; then [ -z "$march" ] && march=armv7-a; [ -z "$mtune" ] && mtune=generic-armv7-a; CONFIGURE_FLAGS="--target=arm-apple-darwin10" + OPENSSL_TARGET="linux-armv4" else echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile" exit 1 @@ -111,9 +121,11 @@ elif [ -z "$CFLAGS" ]; then if [ `getconf LONG_BIT` = "64" ]; then echo "[INFO] Compiling for current machine using 64-bit" CFLAGS="-m64 $CFLAGS" + OPENSSL_TARGET="linux-x86_64" else echo "[INFO] Compiling for current machine using 32-bit" CFLAGS="-m32 $CFLAGS" + OPENSSL_TARGET="linux-generic32" fi fi @@ -211,6 +223,29 @@ cd .. rm -r -f ./zlib echo " done!" +#OpenSSL +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/install_data/php/ext/openssl" \ +no-zlib \ +no-shared \ +no-asm \ +no-hw \ +no-engines \ +$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 +echo -n " compiling..." +make -j $THREADS >> "$DIR/install.log" 2>&1 +echo -n " installing..." +make install >> "$DIR/install.log" 2>&1 +mv "$DIR/install_data/php/ext/openssl/include/openssl/"* "$DIR/install_data/php/ext/openssl/include/" +cd .. +echo " done!" + if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then HAVE_CURL="shared,/usr" else @@ -223,7 +258,7 @@ else if [ ! -f ./configure ]; then ./buildconf --force >> "$DIR/install.log" 2>&1 fi - ./configure --disable-dependency-tracking \ + PKG_CONFIG_PATH="$DIR/install_data/php/ext/openssl/lib/pkgconfig" ./configure --disable-dependency-tracking \ --enable-ipv6 \ --enable-optimize \ --enable-http \ @@ -241,7 +276,7 @@ else --disable-ldaps \ --without-libidn \ --with-zlib="$DIR/install_data/php/ext/zlib" \ - --with-ssl \ + --with-ssl="$DIR/install_data/php/ext/openssl" \ --enable-threaded-resolver \ --prefix="$DIR/install_data/php/ext/curl" \ --disable-shared \ @@ -314,7 +349,6 @@ if [ "$1" == "crosscompile" ]; then sed -i 's/pthreads_working=no/pthreads_working=yes/' ./configure export LIBS="-lpthread -ldl" CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" - fi ./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ --exec-prefix="$DIR/bin/php5" \ @@ -322,6 +356,7 @@ fi --with-zlib="$DIR/install_data/php/ext/zlib" \ --with-zlib-dir="$DIR/install_data/php/ext/zlib" \ --with-yaml="$DIR/install_data/php/ext/yaml" \ +--with-openssl="$DIR/install_data/php/ext/openssl" \ $HAVE_LIBEDIT \ --disable-libxml \ --disable-xml \ diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 2f9267a38..7f41fec3c 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -31,7 +31,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - CFLAGS="-m32 -static" LDFLAGS="-ldl" march=i686 mtune=none $SCRIPT + OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i686 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then @@ -44,7 +44,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit cd $COMPILEDIR/linux/64bit - CFLAGS="-m64 -static" LDFLAGS="-ldl" march=x86-64 mtune=none $SCRIPT + OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then From 65940719c2e7c0e7364a0d80284c977e96ae0e1f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 16:44:07 +0100 Subject: [PATCH 078/173] OpenSSL + cURL --- src/build/compile.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 219ac541b..87c9c7c7d 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -242,8 +242,9 @@ echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." make install >> "$DIR/install.log" 2>&1 -mv "$DIR/install_data/php/ext/openssl/include/openssl/"* "$DIR/install_data/php/ext/openssl/include/" +echo -n " cleaning..." cd .. +rm -r -f ./openssh echo " done!" if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then @@ -258,7 +259,7 @@ else if [ ! -f ./configure ]; then ./buildconf --force >> "$DIR/install.log" 2>&1 fi - PKG_CONFIG_PATH="$DIR/install_data/php/ext/openssl/lib/pkgconfig" ./configure --disable-dependency-tracking \ + ./configure --disable-dependency-tracking \ --enable-ipv6 \ --enable-optimize \ --enable-http \ @@ -276,7 +277,7 @@ else --disable-ldaps \ --without-libidn \ --with-zlib="$DIR/install_data/php/ext/zlib" \ - --with-ssl="$DIR/install_data/php/ext/openssl" \ + --with-ssl="static,$DIR/install_data/php/ext/openssl" \ --enable-threaded-resolver \ --prefix="$DIR/install_data/php/ext/curl" \ --disable-shared \ From d0c5f27ed38390d453b47bfcf8fd6fca2441387d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 16:54:48 +0100 Subject: [PATCH 079/173] OpenSSL make depend :S --- src/build/compile.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/build/compile.sh b/src/build/compile.sh index 87c9c7c7d..c871e192f 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -239,6 +239,7 @@ no-hw \ no-engines \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." +make depend -j $THREADS >> "$DIR/install.log" 2>&1 make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." make install >> "$DIR/install.log" 2>&1 From 7497e320424f381762dbd9b28bf7cc3be3916518 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 16:56:19 +0100 Subject: [PATCH 080/173] Update jenkins.sh --- src/build/jenkins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 7f41fec3c..3b1f6fd6b 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -31,7 +31,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i686 mtune=none $SCRIPT + OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i386 mtune=none $SCRIPT cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then From 1a7cdc5ceacbf5c38282e20d75aa7fde2d5a9676 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 17:03:36 +0100 Subject: [PATCH 081/173] No OpenSSL for PHP :( --- src/build/compile.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index c871e192f..e505c0206 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -358,7 +358,6 @@ fi --with-zlib="$DIR/install_data/php/ext/zlib" \ --with-zlib-dir="$DIR/install_data/php/ext/zlib" \ --with-yaml="$DIR/install_data/php/ext/yaml" \ ---with-openssl="$DIR/install_data/php/ext/openssl" \ $HAVE_LIBEDIT \ --disable-libxml \ --disable-xml \ From bab5a36d39e5fb07b68c45c69da4a5ca65e1bb8d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 17:10:04 +0100 Subject: [PATCH 082/173] Well, I found what broke everything --- src/build/compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index e505c0206..d46bbbd89 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -239,8 +239,8 @@ no-hw \ no-engines \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." -make depend -j $THREADS >> "$DIR/install.log" 2>&1 -make -j $THREADS >> "$DIR/install.log" 2>&1 +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..." From e999de22d5705beb48fa77ca1c5916bf0f50d4d4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 18:16:17 +0100 Subject: [PATCH 083/173] oh my god. well, this should do. works for 32 and 64 bit FINALLY --- src/build/compile.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/build/compile.sh b/src/build/compile.sh index d46bbbd89..88386214e 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -232,6 +232,7 @@ cd openssl RANLIB=$RANLIB ./Configure \ $OPENSSL_TARGET \ --prefix="$DIR/install_data/php/ext/openssl" \ +--openssldir="$DIR/install_data/php/ext/openssl" \ no-zlib \ no-shared \ no-asm \ @@ -284,6 +285,35 @@ else --disable-shared \ --enable-static \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Solaris/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Win32/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Win32/cygwin/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Linux/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Linux/RPM/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/vms/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/AIX/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/AIX/RPM/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/EPM/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" config.status + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" ltmain.sh + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" lib/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" docs/examples/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" docs/examples/Makefile.netware + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" docs/libcurl/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" docs/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/data/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/certs/scripts/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/certs/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/unit/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/libtest/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/server/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" src/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" include/curl/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" include/Makefile + sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" curl-config echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." From bb680e6e679b72152926926305b759555937d7ed Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 18:52:55 +0100 Subject: [PATCH 084/173] Fix compile.sh things --- src/build/compile.sh | 65 ++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 88386214e..6166e21eb 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -178,10 +178,11 @@ download_file "http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror" | ta mv php-$PHP_VERSION php echo " done!" -if [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ]; then +if [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ] || [ "$1" == "mac" ]; then HAVE_LIBEDIT="--without-libedit" else #libedit + set +e 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 echo -n " checking..." @@ -203,6 +204,7 @@ else cd .. rm -r -f ./libedit echo " done!" + set -e fi #zlib @@ -212,8 +214,7 @@ mv zlib-$ZLIB_VERSION zlib echo -n " checking..." cd zlib RANLIB=$RANLIB ./configure --prefix="$DIR/install_data/php/ext/zlib" \ ---static \ -$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 +--static >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." @@ -285,35 +286,35 @@ else --disable-shared \ --enable-static \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Solaris/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Win32/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Win32/cygwin/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Linux/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Linux/RPM/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/vms/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/AIX/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/AIX/RPM/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" packages/EPM/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" config.status - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" ltmain.sh - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" lib/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" docs/examples/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" docs/examples/Makefile.netware - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" docs/libcurl/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" docs/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/data/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/certs/scripts/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/certs/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/unit/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/libtest/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" tests/server/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" src/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" include/curl/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" include/Makefile - sed -i "s#static,$DIR/install_data/php/ext/openssl#$DIR/install_data/php/ext/openssl#g" curl-config + sed -i "s#static,$DIR#$DIR#g" Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Solaris/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Win32/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Win32/cygwin/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Linux/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Linux/RPM/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/vms/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/AIX/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/AIX/RPM/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/EPM/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" config.status >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" ltmain.sh >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" lib/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" docs/examples/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" docs/examples/Makefile.netware >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" docs/libcurl/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" docs/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/data/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/certs/scripts/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/certs/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/unit/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/libtest/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/server/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" src/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" include/curl/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" include/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" curl-config >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." From b0a6631b8e4b9db3b630b0c7c7b3b92751f3b24a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 19:45:09 +0100 Subject: [PATCH 085/173] Update jenkins.sh --- src/build/jenkins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 3b1f6fd6b..8b47d1e07 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -1,5 +1,5 @@ #!/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 #Needed to use aliases From 7e979f40cb63baea402eee482a988f4f1ca8acbe Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 20:05:21 +0100 Subject: [PATCH 086/173] Use full path on compile.sh --- src/build/compile.sh | 58 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 6166e21eb..fec0f3783 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -286,35 +286,35 @@ else --disable-shared \ --enable-static \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Solaris/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Win32/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Win32/cygwin/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Linux/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Linux/RPM/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/vms/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/AIX/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/AIX/RPM/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/EPM/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" config.status >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" ltmain.sh >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" lib/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" docs/examples/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" docs/examples/Makefile.netware >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" docs/libcurl/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" docs/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/data/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/certs/scripts/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/certs/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/unit/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/libtest/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/server/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" src/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" include/curl/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" include/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" curl-config >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Solaris/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Win32/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Win32/cygwin/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Linux/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Linux/RPM/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/vms/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/AIX/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/AIX/RPM/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/EPM/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/config.status" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/ltmain.sh" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/lib/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/docs/examples/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/docs/examples/Makefile.netware" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/docs/libcurl/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/docs/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/data/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/certs/scripts/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/certs/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/unit/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/libtest/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/server/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/src/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/include/curl/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/include/Makefile" >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/curl-config" >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." From 696792cd2a2e651b3ce393bc6bd4b1c45d746a87 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 20:21:42 +0100 Subject: [PATCH 087/173] Pre-sed --- src/build/compile.sh | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index fec0f3783..ba57e4609 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -261,7 +261,8 @@ else cd curl if [ ! -f ./configure ]; then ./buildconf --force >> "$DIR/install.log" 2>&1 - fi + fi + sed -i 's#LIB_OPENSSL="$PREFIX_OPENSSL/lib$libsuff"#LIB_OPENSSL="$PREFIX_OPENSSL/lib$libsuff"; PREFIX_OPENSSL="static,$PREFIX_OPENSSL"#g' ./configure >> "$DIR/install.log" 2>&1 ./configure --disable-dependency-tracking \ --enable-ipv6 \ --enable-optimize \ @@ -286,35 +287,6 @@ else --disable-shared \ --enable-static \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Solaris/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Win32/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Win32/cygwin/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Linux/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Linux/RPM/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/vms/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/AIX/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/AIX/RPM/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/packages/EPM/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/config.status" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/ltmain.sh" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/lib/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/docs/examples/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/docs/examples/Makefile.netware" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/docs/libcurl/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/docs/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/data/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/certs/scripts/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/certs/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/unit/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/libtest/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/tests/server/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/src/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/include/curl/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/include/Makefile" >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" "$DIR/install_data/curl/curl-config" >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." From 5f6c9b7fad856eae5854b0cd6a54dff684604a5b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 20:47:32 +0100 Subject: [PATCH 088/173] Normal compile.sh --- src/build/compile.sh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index ba57e4609..9ea601f95 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -261,9 +261,8 @@ else cd curl if [ ! -f ./configure ]; then ./buildconf --force >> "$DIR/install.log" 2>&1 - fi - sed -i 's#LIB_OPENSSL="$PREFIX_OPENSSL/lib$libsuff"#LIB_OPENSSL="$PREFIX_OPENSSL/lib$libsuff"; PREFIX_OPENSSL="static,$PREFIX_OPENSSL"#g' ./configure >> "$DIR/install.log" 2>&1 - ./configure --disable-dependency-tracking \ + fi + RANLIB=$RANLIB ./configure --disable-dependency-tracking \ --enable-ipv6 \ --enable-optimize \ --enable-http \ @@ -287,6 +286,35 @@ else --disable-shared \ --enable-static \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Solaris/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Win32/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Win32/cygwin/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Linux/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Linux/RPM/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/vms/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/AIX/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/AIX/RPM/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" packages/EPM/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" config.status >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" ltmain.sh >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" lib/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" docs/examples/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" docs/examples/Makefile.netware >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" docs/libcurl/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" docs/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/data/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/certs/scripts/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/certs/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/unit/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/libtest/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" tests/server/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" src/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" include/curl/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" include/Makefile >> "$DIR/install.log" 2>&1 + sed -i "s#static,$DIR#$DIR#g" curl-config >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." @@ -355,7 +383,7 @@ if [ "$1" == "crosscompile" ]; then export LIBS="-lpthread -ldl" CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" fi -./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ +RANLIB=$RANLIB ./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ --exec-prefix="$DIR/bin/php5" \ --with-curl="$HAVE_CURL" \ --with-zlib="$DIR/install_data/php/ext/zlib" \ From 6b2bca10a3137eacd5e269cdb897ecb6d0c2268c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 16 Feb 2014 22:51:25 +0100 Subject: [PATCH 089/173] Added PHP check on installer.sh --- src/build/installer.sh | 140 ++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 58 deletions(-) diff --git a/src/build/installer.sh b/src/build/installer.sh index e97aee552..1a5dbc561 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -7,6 +7,8 @@ RPI_BUILD="PHP_5.5.9_ARM_Raspbian_hard" AND_BUILD="PHP_5.5.9_ARMv7_Android" IOS_BUILD="PHP_5.5.9_ARMv6_iOS" update=off +forcecompile=off +alldone=no #Needed to use aliases shopt -s expand_aliases @@ -23,11 +25,14 @@ else fi -while getopts "udv:" opt; do +while getopts "ucdv:" opt; do case $opt in u) update=on ;; + c) + forcecompile=on + ;; d) PMMP_VERSION="master" ;; @@ -60,7 +65,6 @@ rm -f LICENSE rm -f start.sh rm -f start.bat echo "[1/3] Downloading PocketMine-MP $PMMP_VERSION..." -set -e download_file "https://github.com/PocketMine/PocketMine-MP/archive/$PMMP_VERSION.tar.gz" | tar -zx > /dev/null mv -f PocketMine-MP-$PMMP_VERSION/* ./ rm -f -r PocketMine-MP-$PMMP_VERSION/ @@ -72,7 +76,7 @@ if [ $update == on ]; then else echo -n "[3/3] Obtaining PHP:" echo " detecting if build is available..." - if [ "$(uname -s)" == "Darwin" ]; then + if [ "$forcecompile" == "off" ] && [ "$(uname -s)" == "Darwin" ]; then set +e UNAME_M=$(uname -m) IS_IOS=$(expr match $UNAME_M 'iP[a-zA-Z0-9,]*') @@ -82,57 +86,71 @@ else echo -n "[3/3] iOS PHP build available, downloading $IOS_BUILD.tar.gz..." download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 chmod +x ./bin/php5/bin/* - echo -n " regenerating php.ini..." - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" - echo " done" + echo -n " checking..." + if [ $(./bin/php5/bin/php -r 'echo "yes";') == "yes" ]; then + echo -n " regenerating php.ini..." + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" + alldone=yes + else + echo " invalid build detected" + fi else rm -r -f bin/ >> /dev/null 2>&1 echo -n "[3/3] Mac OSX PHP build available, downloading $MAC_BUILD.tar.gz..." download_file "http://sourceforge.net/projects/pocketmine/files/builds/$MAC_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 chmod +x ./bin/php5/bin/* - echo -n " regenerating php.ini..." - OPCACHE_PATH=$(find "./bin/php5" -name opcache.so) - echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/lib/php.ini" - echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" - echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" - echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" - echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" - echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" - echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" - echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" - echo " done" + echo -n " checking..." + if [ $(./bin/php5/bin/php -r 'echo "yes";') == "yes" ]; then + echo -n " regenerating php.ini..." + echo "zend_extension=opcache.so" > "./bin/php5/lib/php.ini" + echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" + echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" + echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" + echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" + echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" + echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" + echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" + alldone=yes + else + echo " invalid build detected" + fi fi else - set +e grep -q BCM2708 /proc/cpuinfo > /dev/null 2>&1 - if [ $? -eq 0 ]; then - set -e + if [ $? -eq 0 ] && [ "$forcecompile" == "off" ]; then rm -r -f bin/ >> /dev/null 2>&1 echo -n "[3/3] Raspberry Pi PHP build available, downloading $RPI_BUILD.tar.gz..." download_file "http://sourceforge.net/projects/pocketmine/files/builds/$RPI_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 chmod +x ./bin/php5/bin/* - echo -n " regenerating php.ini..." - OPCACHE_PATH=$(find "./bin/php5" -name opcache.so) - echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/lib/php.ini" - echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" - echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" - echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" - echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" - echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" - echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" - echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" - echo " done" - elif [ "$(uname -s)" == "Linux" ]; then + echo -n " checking..." + if [ $(./bin/php5/bin/php -r 'echo "yes";') == "yes" ]; then + echo -n " regenerating php.ini..." + echo "zend_extension=opcache.so" > "./bin/php5/lib/php.ini" + echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" + echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" + echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" + echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" + echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" + echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" + echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" + 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..." @@ -143,22 +161,28 @@ else 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 " regenerating php.ini..." - OPCACHE_PATH=$(find "./bin/php5" -name opcache.so) - echo "zend_extension=\"$OPCACHE_PATH\"" > "./bin/php5/lib/php.ini" - echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" - echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" - echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" - echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" - echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" - echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" - echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" - echo " done" - else + echo -n " checking..." + if [ $(./bin/php5/bin/php -r 'echo "yes";') == "yes" ]; then + echo -n " regenerating php.ini..." + echo "zend_extension=opcache.so" > "./bin/php5/lib/php.ini" + echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" + echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" + echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" + echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" + echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" + echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" + echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" + alldone=yes + else + echo " invalid build detected" + fi + fi + if [ "$alldone" == "no" ]; then set -e echo "[3/3] no build found, compiling PHP" exec ./src/build/compile.sh From 98c50f9a9c5d778810a5c2f74b7d66750d0a94ef Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 01:46:28 +0100 Subject: [PATCH 090/173] OpenSSL is now not enforced compile.sh --- src/build/compile.sh | 57 ++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 9ea601f95..4b0cf4d43 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -224,31 +224,36 @@ cd .. rm -r -f ./zlib echo " done!" -#OpenSSL -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/install_data/php/ext/openssl" \ ---openssldir="$DIR/install_data/php/ext/openssl" \ -no-zlib \ -no-shared \ -no-asm \ -no-hw \ -no-engines \ -$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!" +if [ "$2" == "openssl" ]; then + #OpenSSL + WITH_OPENSSL="--with-ssl=$DIR/install_data/php/ext/openssl" + 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/install_data/php/ext/openssl" \ + --openssldir="$DIR/install_data/php/ext/openssl" \ + no-zlib \ + no-shared \ + no-asm \ + no-hw \ + no-engines \ + $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_OPENSSL="--with-ssl" +fi if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then HAVE_CURL="shared,/usr" @@ -280,7 +285,7 @@ else --disable-ldaps \ --without-libidn \ --with-zlib="$DIR/install_data/php/ext/zlib" \ - --with-ssl="static,$DIR/install_data/php/ext/openssl" \ + $WITH_OPENSSL \ --enable-threaded-resolver \ --prefix="$DIR/install_data/php/ext/curl" \ --disable-shared \ From 5f3772d14ab852c2df08e11f8c101b8d0ab84848 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 02:13:35 +0100 Subject: [PATCH 091/173] fixed cURL SSL for Darwin --- src/build/compile.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/build/compile.sh b/src/build/compile.sh index 4b0cf4d43..258fc900d 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -253,6 +253,9 @@ if [ "$2" == "openssl" ]; then echo " done!" else WITH_OPENSSL="--with-ssl" + if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then + WITH_OPENSSL="--with-darwinssl" + fi fi if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then From 8b4abcc55884bb000efbe3d5d64cb0f7f997cfb5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 03:09:58 +0100 Subject: [PATCH 092/173] Generate OpenSSL shared binaries --- src/build/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 258fc900d..8924cdd8a 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -237,7 +237,7 @@ if [ "$2" == "openssl" ]; then --prefix="$DIR/install_data/php/ext/openssl" \ --openssldir="$DIR/install_data/php/ext/openssl" \ no-zlib \ - no-shared \ + shared \ no-asm \ no-hw \ no-engines \ From 109f97ae0019c6fdd3926fb7651682aeeff706d4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 13:20:28 +0100 Subject: [PATCH 093/173] Added ODROID detection to installer.sh --- src/build/installer.sh | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/build/installer.sh b/src/build/installer.sh index 1a5dbc561..3b9d5e6f9 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -4,6 +4,8 @@ LINUX_32_BUILD="PHP_5.5.9_x86_Linux" LINUX_64_BUILD="PHP_5.5.9_x86-64_Linux" MAC_BUILD="PHP_5.5.9_x86_MacOS" 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" IOS_BUILD="PHP_5.5.9_ARMv6_iOS" update=off @@ -125,7 +127,10 @@ else fi else grep -q BCM2708 /proc/cpuinfo > /dev/null 2>&1 - if [ $? -eq 0 ] && [ "$forcecompile" == "off" ]; then + IS_RPI=$? + 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 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 @@ -150,6 +155,30 @@ 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";') == "yes" ]; then + echo -n " regenerating php.ini..." + echo "zend_extension=opcache.so" > "./bin/php5/lib/php.ini" + echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" + echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" + echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" + echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" + echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" + echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" + echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" + echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" + echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" + echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo " done" + alldone=yes + else + echo " invalid build detected" elif [ "$forcecompile" == "off" ] && [ "$(uname -s)" == "Linux" ]; then rm -r -f bin/ >> /dev/null 2>&1 if [ `getconf LONG_BIT` = "64" ]; then From 0e39131e76069e90bd9987278d5cc711a0f80804 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 13:26:51 +0100 Subject: [PATCH 094/173] *fix --- src/build/installer.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/build/installer.sh b/src/build/installer.sh index 3b9d5e6f9..80837ae5d 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -179,6 +179,7 @@ else 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 From 5b5dcd6d77a0c4732fd67cc9bfbb4b9496456a32 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 14:43:58 +0100 Subject: [PATCH 095/173] Removed not used code in compile.sh --- src/build/compile.sh | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 8924cdd8a..be073e65e 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -294,35 +294,6 @@ else --disable-shared \ --enable-static \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Solaris/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Win32/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Win32/cygwin/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Linux/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Linux/RPM/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/vms/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/AIX/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/AIX/RPM/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" packages/EPM/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" config.status >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" ltmain.sh >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" lib/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" docs/examples/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" docs/examples/Makefile.netware >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" docs/libcurl/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" docs/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/data/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/certs/scripts/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/certs/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/unit/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/libtest/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" tests/server/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" src/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" include/curl/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" include/Makefile >> "$DIR/install.log" 2>&1 - sed -i "s#static,$DIR#$DIR#g" curl-config >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." From 697d96e60c0721a4abfaef5f71327d40ed10ba66 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 18:30:18 +0100 Subject: [PATCH 096/173] Updated compile script to handle shared libraries --- src/build/compile.sh | 86 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index be073e65e..e95d22ab5 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -143,7 +143,7 @@ type $CC >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"$CC\ [ -z "$march" ] && march=native; [ -z "$mtune" ] && mtune=native; [ -z "$CFLAGS" ] && CFLAGS=""; -[ -z "$LDFLAGS" ] && LDFLAGS=""; +[ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib'"; [ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS=""; @@ -159,16 +159,16 @@ else fi fi -rm test >> "$DIR/install.log" 2>&1 -rm test.c >> "$DIR/install.log" 2>&1 +rm test.* >> "$DIR/install.log" 2>&1 export CFLAGS="-O2 $CFLAGS" export LDFLAGS="$LDFLAGS" rm -r -f install_data/ >> "$DIR/install.log" 2>&1 rm -r -f bin/ >> "$DIR/install.log" 2>&1 -mkdir -m 0777 install_data >> "$DIR/install.log" 2>&1 -mkdir -m 0777 bin >> "$DIR/install.log" 2>&1 +mkdir -m 0755 install_data >> "$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 set -e @@ -179,7 +179,7 @@ mv php-$PHP_VERSION php echo " done!" if [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ] || [ "$1" == "mac" ]; then - HAVE_LIBEDIT="--without-libedit" + HAVE_LIBEDIT="--without-readline --without-libedit" else #libedit set +e @@ -187,15 +187,15 @@ else download_file "http://download.sourceforge.net/project/libedit/libedit/libedit-$LIBEDIT_VERSION/libedit-$LIBEDIT_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 echo -n " checking..." cd libedit - ./configure --prefix="$DIR/install_data/php/ext/libedit" \ - --enable-shared=no \ - --enable-static=yes \ + ./configure --prefix="$DIR/bin/php5" \ + --enable-shared=yes \ + --enable-static=no \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." if make -j $THREADS >> "$DIR/install.log" 2>&1; then echo -n " installing..." make install >> "$DIR/install.log" 2>&1 - HAVE_LIBEDIT="--without-readline --with-libedit=\"$DIR/install_data/php/ext/libedit\"" + HAVE_LIBEDIT="--without-readline --with-libedit=\"$DIR/bin/php5\"" else echo -n " disabling..." HAVE_LIBEDIT="--without-readline --without-libedit" @@ -213,8 +213,8 @@ download_file "http://zlib.net/zlib-$ZLIB_VERSION.tar.gz" | tar -zx >> "$DIR/ins mv zlib-$ZLIB_VERSION zlib echo -n " checking..." cd zlib -RANLIB=$RANLIB ./configure --prefix="$DIR/install_data/php/ext/zlib" \ ---static >> "$DIR/install.log" 2>&1 +RANLIB=$RANLIB ./configure --prefix="$DIR/bin/php5" \ +--shared >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." @@ -226,7 +226,8 @@ echo " done!" if [ "$2" == "openssl" ]; then #OpenSSL - WITH_OPENSSL="--with-ssl=$DIR/install_data/php/ext/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 @@ -234,13 +235,14 @@ if [ "$2" == "openssl" ]; then cd openssl RANLIB=$RANLIB ./Configure \ $OPENSSL_TARGET \ - --prefix="$DIR/install_data/php/ext/openssl" \ - --openssldir="$DIR/install_data/php/ext/openssl" \ + --prefix="$DIR/bin/php5" \ + --openssldir="$DIR/bin/php5" \ no-zlib \ 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 @@ -252,9 +254,10 @@ if [ "$2" == "openssl" ]; then rm -r -f ./openssh echo " done!" else - WITH_OPENSSL="--with-ssl" + WITH_SSL="--with-ssl" + WITH_OPENSSL="--without-ssl" if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then - WITH_OPENSSL="--with-darwinssl" + WITH_SSL="--with-darwinssl" fi fi @@ -277,6 +280,7 @@ else --enable-ftp \ --disable-dict \ --enable-file \ + --without-librtmp \ --disable-gopher \ --disable-imap \ --disable-pop3 \ @@ -287,10 +291,10 @@ else --disable-ldap \ --disable-ldaps \ --without-libidn \ - --with-zlib="$DIR/install_data/php/ext/zlib" \ - $WITH_OPENSSL \ + --with-zlib="$DIR/bin/php5" \ + $WITH_SSL \ --enable-threaded-resolver \ - --prefix="$DIR/install_data/php/ext/curl" \ + --prefix="$DIR/bin/php5" \ --disable-shared \ --enable-static \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 @@ -302,7 +306,7 @@ else cd .. rm -r -f ./curl echo " done!" - HAVE_CURL="$DIR/install_data/php/ext/curl" + HAVE_CURL="$DIR/bin/php5" fi #pthreads @@ -324,9 +328,9 @@ mv yaml-$YAML_VERSION yaml echo -n " checking..." cd yaml RANLIB=$RANLIB ./configure \ ---prefix="$DIR/install_data/php/ext/yaml" \ ---enable-static \ ---disable-shared \ +--prefix="$DIR/bin/php5" \ +--disable-static \ +--enable-shared \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." make -j $THREADS >> "$DIR/install.log" 2>&1 @@ -365,9 +369,9 @@ fi RANLIB=$RANLIB ./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ --exec-prefix="$DIR/bin/php5" \ --with-curl="$HAVE_CURL" \ ---with-zlib="$DIR/install_data/php/ext/zlib" \ ---with-zlib-dir="$DIR/install_data/php/ext/zlib" \ ---with-yaml="$DIR/install_data/php/ext/yaml" \ +--with-zlib="$DIR/bin/php5" \ +--with-yaml="$DIR/bin/php5" \ +$WITH_OPENSSL \ $HAVE_LIBEDIT \ --disable-libxml \ --disable-xml \ @@ -409,25 +413,23 @@ make install >> "$DIR/install.log" 2>&1 echo " generating php.ini..." 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 - OPCACHE_PATH=$(find "$DIR/bin/php5" -name opcache.so) - echo "zend_extension=\"$OPCACHE_PATH\"" >> "$DIR/bin/php5/lib/php.ini" - echo "opcache.enable=1" >> "$DIR/bin/php5/lib/php.ini" - echo "opcache.enable_cli=1" >> "$DIR/bin/php5/lib/php.ini" - echo "opcache.save_comments=0" >> "$DIR/bin/php5/lib/php.ini" - echo "opcache.fast_shutdown=1" >> "$DIR/bin/php5/lib/php.ini" - echo "opcache.max_accelerated_files=4096" >> "$DIR/bin/php5/lib/php.ini" - echo "opcache.interned_strings_buffer=8" >> "$DIR/bin/php5/lib/php.ini" - echo "opcache.memory_consumption=128" >> "$DIR/bin/php5/lib/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "$DIR/bin/php5/lib/php.ini" + echo "zend_extension=opcache.so" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.enable=1" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.enable_cli=1" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.save_comments=0" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.fast_shutdown=1" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.max_accelerated_files=4096" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.interned_strings_buffer=8" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.memory_consumption=128" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "$DIR/bin/php5/bin/php.ini" fi 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 -echo "date.timezone=$TIMEZONE" >> "$DIR/bin/php5/lib/php.ini" -echo "short_open_tag=0" >> "$DIR/bin/php5/lib/php.ini" -echo "asp_tags=0" >> "$DIR/bin/php5/lib/php.ini" echo " done!" cd "$DIR" From 42e7467dba22b133b14331cb28140bb66fd432f6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 18:32:02 +0100 Subject: [PATCH 097/173] Added OpenSSL to Jenkins --- src/build/jenkins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 8b47d1e07..b41692b43 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -31,7 +31,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i386 mtune=none $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/ if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then @@ -44,7 +44,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit cd $COMPILEDIR/linux/64bit - OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=none $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/ if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then From 943e038772c57cacc627b58b3f19147042bc2ff1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 18:37:37 +0100 Subject: [PATCH 098/173] Remove OpenSSL from PHP build :P --- src/build/compile.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index e95d22ab5..5dd48f786 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -371,7 +371,6 @@ RANLIB=$RANLIB ./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ --with-curl="$HAVE_CURL" \ --with-zlib="$DIR/bin/php5" \ --with-yaml="$DIR/bin/php5" \ -$WITH_OPENSSL \ $HAVE_LIBEDIT \ --disable-libxml \ --disable-xml \ From 747223851090fb449c8046f40e845e377dacebc2 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 17 Feb 2014 19:10:28 +0100 Subject: [PATCH 099/173] Updated installer to handle full paths right and discard warnings on PHP checking --- src/build/installer.sh | 116 +++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/src/build/installer.sh b/src/build/installer.sh index 80837ae5d..1e7f4ab5f 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -89,11 +89,11 @@ else download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 chmod +x ./bin/php5/bin/* echo -n " checking..." - if [ $(./bin/php5/bin/php -r 'echo "yes";') == "yes" ]; then + if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then echo -n " regenerating php.ini..." - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + echo "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 @@ -105,20 +105,21 @@ else download_file "http://sourceforge.net/projects/pocketmine/files/builds/$MAC_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 chmod +x ./bin/php5/bin/* echo -n " checking..." - if [ $(./bin/php5/bin/php -r 'echo "yes";') == "yes" ]; then + if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then echo -n " regenerating php.ini..." - echo "zend_extension=opcache.so" > "./bin/php5/lib/php.ini" - echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" - echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" - echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" - echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" - echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" - echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" - echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + 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 @@ -136,20 +137,21 @@ else download_file "http://sourceforge.net/projects/pocketmine/files/builds/$RPI_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 chmod +x ./bin/php5/bin/* echo -n " checking..." - if [ $(./bin/php5/bin/php -r 'echo "yes";') == "yes" ]; then + if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then echo -n " regenerating php.ini..." - echo "zend_extension=opcache.so" > "./bin/php5/lib/php.ini" - echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" - echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" - echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" - echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" - echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" - echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" - echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + 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 @@ -161,20 +163,21 @@ else 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";') == "yes" ]; then + if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then echo -n " regenerating php.ini..." - echo "zend_extension=opcache.so" > "./bin/php5/lib/php.ini" - echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" - echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" - echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" - echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" - echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" - echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" - echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + 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 @@ -192,20 +195,21 @@ else 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";') == "yes" ]; then + if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then echo -n " regenerating php.ini..." - echo "zend_extension=opcache.so" > "./bin/php5/lib/php.ini" - echo "opcache.enable=1" >> "./bin/php5/lib/php.ini" - echo "opcache.enable_cli=1" >> "./bin/php5/lib/php.ini" - echo "opcache.save_comments=0" >> "./bin/php5/lib/php.ini" - echo "opcache.fast_shutdown=1" >> "./bin/php5/lib/php.ini" - echo "opcache.max_accelerated_files=4096" >> "./bin/php5/lib/php.ini" - echo "opcache.interned_strings_buffer=8" >> "./bin/php5/lib/php.ini" - echo "opcache.memory_consumption=128" >> "./bin/php5/lib/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/lib/php.ini" - echo "date.timezone=$TIMEZONE" >> "./bin/php5/lib/php.ini" - echo "short_open_tag=0" >> "./bin/php5/lib/php.ini" - echo "asp_tags=0" >> "./bin/php5/lib/php.ini" + 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 From aae66930b6cb0b8f9c6a1d446337eea82626a5b9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 10:27:32 +0100 Subject: [PATCH 100/173] Update compile.sh to remove unused data --- src/build/compile.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/build/compile.sh b/src/build/compile.sh index 5dd48f786..0d94ac72e 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -434,6 +434,10 @@ echo " done!" cd "$DIR" echo -n "[INFO] Cleaning up..." rm -r -f install_data/ >> "$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 echo " done!" echo "[PocketMine] You should start the server now using \"./start.sh.\"" From 2e2990fe333b3d6bdd445e66b5c56f5aa3e70593 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 11:25:01 +0100 Subject: [PATCH 101/173] Update compile.sh --- src/build/compile.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 0d94ac72e..4fa7f254e 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -67,8 +67,7 @@ elif [ "$1" == "crosscompile" ]; then TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" export CC="$TOOLCHAIN_PREFIX-gcc" CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" - CFLAGS="-uclibc --static $CFLAGS"; - LDFLAGS="--static" + CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" echo "[INFO] Cross-compiling for Android ARMv6" OPENSSL_TARGET="linux-armv4" elif [ "$2" == "android-armv7" ]; then @@ -78,8 +77,7 @@ elif [ "$1" == "crosscompile" ]; then TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" export CC="$TOOLCHAIN_PREFIX-gcc" CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" - CFLAGS="-uclibc --static $CFLAGS"; - LDFLAGS="--static" + CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" echo "[INFO] Cross-compiling for Android ARMv7" OPENSSL_TARGET="linux-armv4" elif [ "$2" == "rpi" ]; then From daf27f46be5459c703ef294bce31d72300b090db Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 11:54:33 +0100 Subject: [PATCH 102/173] Update installer.sh --- src/build/installer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/installer.sh b/src/build/installer.sh index 1e7f4ab5f..e19ccbc0e 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -2,7 +2,7 @@ PMMP_VERSION="" LINUX_32_BUILD="PHP_5.5.9_x86_Linux" LINUX_64_BUILD="PHP_5.5.9_x86-64_Linux" -MAC_BUILD="PHP_5.5.9_x86_MacOS" +MAC_BUILD="PHP_5.5.9_x86-64_MacOS" RPI_BUILD="PHP_5.5.9_ARM_Raspbian_hard" # Temporal build ODROID_BUILD="PHP_5.5.9_ARM_Raspbian_hard" From d38ae3c230770681b754ff4cfc7d31bcccd3c7f3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 11:58:34 +0100 Subject: [PATCH 103/173] Added tar.gz files to jenkins.sh --- src/build/jenkins.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index b41692b43..7fea13753 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -1,6 +1,7 @@ #!/bin/bash -x export PATH="/opt/arm-2013.05/bin:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/opt/arm-unknown-linux-uclibcgnueabi/bin:$PATH" export THREADS=2 +PHP_VERSION="5.5.9" #Needed to use aliases shopt -s expand_aliases @@ -33,7 +34,8 @@ then 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 exit 1 fi @@ -46,7 +48,8 @@ then 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 exit 1 fi @@ -68,7 +71,8 @@ then export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" $SCRIPT mac curl - cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/ + tar -czf PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz ./bin + cp -r $COMPILEDIR/mac/{install.log,PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz,install_data/*} $ARCHIVE/mac/ if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then exit 1 fi @@ -81,7 +85,8 @@ then $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 exit 1 fi @@ -94,7 +99,8 @@ then $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 exit 1 fi @@ -107,7 +113,8 @@ then $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 exit 1 fi @@ -162,7 +169,8 @@ then $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 exit 1 fi From 0245ebe9f63c9e2dba886a6f1c3cd925b40691e4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 13:00:33 +0100 Subject: [PATCH 104/173] Update jenkins.sh --- src/build/jenkins.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 7fea13753..7ac250ce5 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -34,7 +34,7 @@ then OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i386 mtune=none $SCRIPT linux openssl - tar -czf PHP_${PHP_VERSION}_x86_Linux.tar.gz ./bin + 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 exit 1 @@ -48,7 +48,7 @@ then OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=none $SCRIPT linux openssl - tar -czf PHP_${PHP_VERSION}_x86-64_Linux.tar.gz ./bin + 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 exit 1 @@ -71,7 +71,7 @@ then export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" $SCRIPT mac curl - tar -czf PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz ./bin + tar -czf PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz bin/ cp -r $COMPILEDIR/mac/{install.log,PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz,install_data/*} $ARCHIVE/mac/ if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then exit 1 @@ -85,7 +85,7 @@ then $SCRIPT rpi - tar -czf PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz ./bin + 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 exit 1 @@ -99,7 +99,7 @@ then $SCRIPT crosscompile android-armv6 - tar -czf PHP_${PHP_VERSION}_ARMv6_Android.tar.gz ./bin + 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 exit 1 @@ -113,7 +113,7 @@ then $SCRIPT crosscompile android-armv7 - tar -czf PHP_${PHP_VERSION}_ARMv7_Android.tar.gz ./bin + 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 exit 1 @@ -169,7 +169,7 @@ then $SCRIPT crosscompile rpi - tar -czf PHP_${PHP_VERSION}_ARM_Raspbian_hard.tar.gz ./bin + 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 exit 1 From ea2fc1fb03d4897b264bb9bd09d8959905b62a0c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 14:37:56 +0100 Subject: [PATCH 105/173] MacOS 32-bit compilation --- src/build/compile.sh | 14 ++++++++++++-- src/build/jenkins.sh | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 4fa7f254e..861dec3d9 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -50,9 +50,19 @@ if [ "$1" == "rpi" ]; then elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; - [ -z "$CFLAGS" ] && CFLAGS="-fomit-frame-pointer"; + [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; + [ -z "$LDFLAGS" ] && LDFLAGS=" "; + export RPATH="@executable_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"; + [ -z "$LDFLAGS" ] && LDFLAGS=" "; + export RPATH="@executable_path/../lib" OPENSSL_TARGET="darwin64-x86_64-cc" - echo "[INFO] Compiling for Intel MacOS" + echo "[INFO] Compiling for Intel MacOS x86_64" elif [ "$1" == "ios" ]; then [ -z "$march" ] && march=armv6; [ -z "$mtune" ] && mtune=cortex-a8; diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 7ac250ce5..a3e2fbfc7 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -71,6 +71,29 @@ then export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" $SCRIPT mac curl + tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/ + cp -r $COMPILEDIR/mac/{install.log,PHP_${PHP_VERSION}_x86_MacOS.tar.gz,install_data/*} $ARCHIVE/mac/ + if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$COMPILE_MAC_64" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/mac + cd $COMPILEDIR/mac + + curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null + cd libtool-2.4.2 + ./configure --prefix="$COMPILEDIR/mac/libtool" > /dev/null + make > /dev/null + make install + cd ../ + rm -rf libtool-2.4.2 + export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" + export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" + $SCRIPT mac64 curl + tar -czf PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz bin/ cp -r $COMPILEDIR/mac/{install.log,PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz,install_data/*} $ARCHIVE/mac/ if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then From 4573389840d59bc8cc8151d3a0ad23a8d38aee20 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 14:48:51 +0100 Subject: [PATCH 106/173] Use Github URL for zlib --- src/build/compile.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 861dec3d9..caa682cca 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -10,7 +10,7 @@ PTHREADS_VERSION="0.1.0" PHPYAML_VERSION="1.1.1" YAML_VERSION="0.1.4" -echo "[PocketMine] PHP installer and compiler for Linux and Mac" +echo "[PocketMine] PHP compiler for Linux, MacOS and Android" DIR="$(pwd)" date > "$DIR/install.log" 2>&1 uname -a >> "$DIR/install.log" 2>&1 @@ -139,8 +139,9 @@ fi cat > test.c <<'CTEST' #include -main(){ +int main(void){ printf("Hello world\n"); + return 0; } CTEST @@ -168,6 +169,7 @@ else fi rm test.* >> "$DIR/install.log" 2>&1 +rm test >> "$DIR/install.log" 2>&1 export CFLAGS="-O2 $CFLAGS" export LDFLAGS="$LDFLAGS" @@ -216,8 +218,8 @@ else fi #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..." -download_file "http://zlib.net/zlib-$ZLIB_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 mv zlib-$ZLIB_VERSION zlib echo -n " checking..." cd zlib From c7acc3f22197f3eae7f3b146fced4531cff2e67e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 15:00:29 +0100 Subject: [PATCH 107/173] Updated -rpath for MacOS --- src/build/compile.sh | 5 ++--- src/build/installer.sh | 11 +++++++++-- src/build/jenkins.sh | 18 +++++++++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index caa682cca..aa4d7273a 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -51,7 +51,7 @@ elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS=" "; + [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; export RPATH="@executable_path/../lib" OPENSSL_TARGET="darwin-i386-cc" echo "[INFO] Compiling for Intel MacOS x86" @@ -59,8 +59,7 @@ elif [ "$1" == "mac64" ]; then [ -z "$march" ] && march=core2; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS=" "; - export RPATH="@executable_path/../lib" + [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; OPENSSL_TARGET="darwin64-x86_64-cc" echo "[INFO] Compiling for Intel MacOS x86_64" elif [ "$1" == "ios" ]; then diff --git a/src/build/installer.sh b/src/build/installer.sh index e19ccbc0e..b1844d413 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -2,7 +2,8 @@ PMMP_VERSION="" LINUX_32_BUILD="PHP_5.5.9_x86_Linux" LINUX_64_BUILD="PHP_5.5.9_x86-64_Linux" -MAC_BUILD="PHP_5.5.9_x86-64_MacOS" +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" # Temporal build ODROID_BUILD="PHP_5.5.9_ARM_Raspbian_hard" @@ -101,7 +102,13 @@ else fi else rm -r -f bin/ >> /dev/null 2>&1 - echo -n "[3/3] Mac OSX PHP build available, downloading $MAC_BUILD.tar.gz..." + if [ `getconf LONG_BIT` = "64" ]; then + echo -n "[3/3] MacOS 64-bit PHP build available, downloading $MAC_64_BUILD.tar.gz..." + MAC_BUILD=$MAC_64_BUILD + else + echo -n "[3/3] MacOS 32-bit PHP build available, downloading $MAC_32_BUILD.tar.gz..." + MAC_BUILD=$MAC_32_BUILD + fi download_file "http://sourceforge.net/projects/pocketmine/files/builds/$MAC_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 chmod +x ./bin/php5/bin/* echo -n " checking..." diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index a3e2fbfc7..fc09ae46a 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -55,10 +55,10 @@ then fi fi -if [ "$COMPILE_MAC" = "true" ]; +if [ "$COMPILE_MAC_32" = "true" ]; then - mkdir -p {$COMPILEDIR,$ARCHIVE}/mac - cd $COMPILEDIR/mac + mkdir -p {$COMPILEDIR,$ARCHIVE}/mac32 + cd $COMPILEDIR/mac32 curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null cd libtool-2.4.2 @@ -72,16 +72,16 @@ then $SCRIPT mac curl tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/ - cp -r $COMPILEDIR/mac/{install.log,PHP_${PHP_VERSION}_x86_MacOS.tar.gz,install_data/*} $ARCHIVE/mac/ - 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}/mac - cd $COMPILEDIR/mac + 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 @@ -95,8 +95,8 @@ then $SCRIPT mac64 curl tar -czf PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz bin/ - cp -r $COMPILEDIR/mac/{install.log,PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz,install_data/*} $ARCHIVE/mac/ - if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then + cp -r $COMPILEDIR/mac64/{install.log,PHP_${PHP_VERSION}_x86-64_MacOS.tar.gz,install_data/*} $ARCHIVE/mac/64 + if [ ! -f $COMPILEDIR/mac64/bin/php5/bin/php ]; then exit 1 fi fi From 2ee76182ad531c5dcb4f56be6d76ac7bbbf7e48b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 15:16:10 +0100 Subject: [PATCH 108/173] Compile OpenSSL on MacOS --- src/build/compile.sh | 4 ++-- src/build/installer.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index aa4d7273a..ee6d6c7c1 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -233,7 +233,7 @@ cd .. rm -r -f ./zlib echo " done!" -if [ "$2" == "openssl" ]; then +if [ "$2" == "openssl" ] || [ "$2" == "curl" ] && [ "$1" != "crosscompile" ]; then #OpenSSL WITH_SSL="--with-ssl=$DIR/bin/php5" WITH_OPENSSL="--with-openssl=$DIR/bin/php5" @@ -357,7 +357,7 @@ if which free >/dev/null; then else MAX_MEMORY=$(top -l 1 | grep PhysMem: | awk '{print $10}' | tr -d 'a-zA-Z') fi -if [ $MAX_MEMORY -gt 512 ] && [ "$1" != "crosscompile" ]; then +if [ $MAX_MEMORY -gt 512 2>> /dev/null ] && [ "$1" != "crosscompile" ]; then echo -n " enabling optimizations..." OPTIMIZATION="--enable-inline-optimization " else diff --git a/src/build/installer.sh b/src/build/installer.sh index b1844d413..c8068bf4c 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -84,7 +84,7 @@ else UNAME_M=$(uname -m) IS_IOS=$(expr match $UNAME_M 'iP[a-zA-Z0-9,]*') set -e - if [ $IS_IOS -gt 0 ]; then + if [ $IS_IOS -gt 0 2>> /dev/null ]; then rm -r -f bin/ >> /dev/null 2>&1 echo -n "[3/3] iOS PHP build available, downloading $IOS_BUILD.tar.gz..." download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 From f384dfc40afee89f4a17ebde1463fb20333d2795 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 15:33:32 +0100 Subject: [PATCH 109/173] Changed @loader_path to @executable_path on MacOS --- src/build/compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index ee6d6c7c1..15a82a5ca 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -51,7 +51,7 @@ elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; + [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@executable_path/../lib"; export RPATH="@executable_path/../lib" OPENSSL_TARGET="darwin-i386-cc" echo "[INFO] Compiling for Intel MacOS x86" @@ -59,7 +59,7 @@ elif [ "$1" == "mac64" ]; then [ -z "$march" ] && march=core2; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; + [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@executable_path/../lib"; OPENSSL_TARGET="darwin64-x86_64-cc" echo "[INFO] Compiling for Intel MacOS x86_64" elif [ "$1" == "ios" ]; then From bd3544e917d7e12b40300124e99177fdaa87721b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 16:28:30 +0100 Subject: [PATCH 110/173] Added DYLD_LIBRARY_PATH --- src/build/compile.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 15a82a5ca..b53709d66 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -51,15 +51,16 @@ elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@executable_path/../lib"; - export RPATH="@executable_path/../lib" + [ -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"; - [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@executable_path/../lib"; + [ -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 @@ -418,6 +419,11 @@ fi make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." make install >> "$DIR/install.log" 2>&1 + +if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then + install_name_tool -change "$DIR/bin/php5/lib" "@loader_path/../lib" "$DIR/bin/php5/bin/php" +fi + echo " generating php.ini..." TIMEZONE=$(date +%Z) @@ -443,6 +449,10 @@ echo " done!" cd "$DIR" echo -n "[INFO] Cleaning up..." 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 From 9006e5afad8063daee0e993ad6e5b7bb0ec73230 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 17:13:36 +0100 Subject: [PATCH 111/173] Added custom zlib to OpenSSL --- src/build/compile.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index b53709d66..b194c9c06 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -247,7 +247,9 @@ if [ "$2" == "openssl" ] || [ "$2" == "curl" ] && [ "$1" != "crosscompile" ]; th $OPENSSL_TARGET \ --prefix="$DIR/bin/php5" \ --openssldir="$DIR/bin/php5" \ - no-zlib \ + --with-zlib-lib="$DIR/bin/php5/lib" \ + --with-zlib-include="$DIR/bin/php5/include" \ + zlib-dynamic \ shared \ no-asm \ no-hw \ @@ -421,7 +423,13 @@ echo -n " installing..." make install >> "$DIR/install.log" 2>&1 if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then - install_name_tool -change "$DIR/bin/php5/lib" "@loader_path/../lib" "$DIR/bin/php5/bin/php" + 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/install.log" 2>&1 + install_name_tool -change "$DIR/bin/php5/lib/libyaml-0.2.dylib" "@loader_path/../lib/libyaml-0.2.dylib" >> "$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/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/install.log" 2>&1 + set -e fi echo " generating php.ini..." From 0e5c532f5e72af84cd2d67485d8c4593bb22607a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 17:24:46 +0100 Subject: [PATCH 112/173] Changed Android OpenSSL target --- src/build/compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index b194c9c06..de4909783 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -79,7 +79,7 @@ elif [ "$1" == "crosscompile" ]; then CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" echo "[INFO] Cross-compiling for Android ARMv6" - OPENSSL_TARGET="linux-armv4" + OPENSSL_TARGET="android" elif [ "$2" == "android-armv7" ]; then COMPILE_FOR_ANDROID=yes [ -z "$march" ] && march=armv7-a; @@ -89,7 +89,7 @@ elif [ "$1" == "crosscompile" ]; then CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" echo "[INFO] Cross-compiling for Android ARMv7" - OPENSSL_TARGET="linux-armv4" + OPENSSL_TARGET="android-armv7" elif [ "$2" == "rpi" ]; then TOOLCHAIN_PREFIX="arm-linux-gnueabihf" [ -z "$march" ] && march=armv6zk; From c290b0738294759a0c38db18688000212301e169 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 17:26:36 +0100 Subject: [PATCH 113/173] Added $WITH_OPENSSL again to PHP --- src/build/compile.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index de4909783..d2f9fa2d6 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -133,7 +133,7 @@ elif [ -z "$CFLAGS" ]; then else echo "[INFO] Compiling for current machine using 32-bit" CFLAGS="-m32 $CFLAGS" - OPENSSL_TARGET="linux-generic32" + OPENSSL_TARGET="linux-elf" fi fi @@ -383,6 +383,7 @@ RANLIB=$RANLIB ./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ --with-curl="$HAVE_CURL" \ --with-zlib="$DIR/bin/php5" \ --with-yaml="$DIR/bin/php5" \ +$WITH_OPENSSL \ $HAVE_LIBEDIT \ --disable-libxml \ --disable-xml \ From 2c9337f200c28eefa99acf8e5844b27c8183f93d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 17:31:12 +0100 Subject: [PATCH 114/173] Revert "Added $WITH_OPENSSL again to PHP" This reverts commit c290b0738294759a0c38db18688000212301e169. --- src/build/compile.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index d2f9fa2d6..de4909783 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -133,7 +133,7 @@ elif [ -z "$CFLAGS" ]; then else echo "[INFO] Compiling for current machine using 32-bit" CFLAGS="-m32 $CFLAGS" - OPENSSL_TARGET="linux-elf" + OPENSSL_TARGET="linux-generic32" fi fi @@ -383,7 +383,6 @@ RANLIB=$RANLIB ./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ --with-curl="$HAVE_CURL" \ --with-zlib="$DIR/bin/php5" \ --with-yaml="$DIR/bin/php5" \ -$WITH_OPENSSL \ $HAVE_LIBEDIT \ --disable-libxml \ --disable-xml \ From f8dc01ccb3c2f9e6b30e8eb0f4063c1c592b03d1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 17:47:40 +0100 Subject: [PATCH 115/173] Fixed things compile.sh --- src/build/compile.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index de4909783..82ac84baa 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -425,10 +425,10 @@ make install >> "$DIR/install.log" 2>&1 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/install.log" 2>&1 - install_name_tool -change "$DIR/bin/php5/lib/libyaml-0.2.dylib" "@loader_path/../lib/libyaml-0.2.dylib" >> "$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/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/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 set -e fi From 60cf2c824fc1809ed8e0a404876b5afe516d3c25 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 18:22:27 +0100 Subject: [PATCH 116/173] This should do for MacOS x86 --- src/build/compile.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 82ac84baa..1bc7abbe4 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -429,10 +429,13 @@ if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then 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 " generating php.ini..." +echo -n " generating php.ini..." TIMEZONE=$(date +%Z) echo "date.timezone=$TIMEZONE" > "$DIR/bin/php5/bin/php.ini" From 0cfb5aa720835ed16e2d9750e309ab62ba7c0c46 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 18:42:41 +0100 Subject: [PATCH 117/173] fixed typo --- src/build/jenkins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index fc09ae46a..064649b5d 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -95,7 +95,7 @@ then $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/mac/64 + 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 fi From 08c1dbe3a7d8a0aad0c5a78fcf74bcd4af382539 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 18:52:27 +0100 Subject: [PATCH 118/173] fix fix* --- src/build/installer.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/build/installer.sh b/src/build/installer.sh index c8068bf4c..cc6755976 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -81,10 +81,10 @@ else echo " detecting if build is available..." if [ "$forcecompile" == "off" ] && [ "$(uname -s)" == "Darwin" ]; then set +e - UNAME_M=$(uname -m) - IS_IOS=$(expr match $UNAME_M 'iP[a-zA-Z0-9,]*') + UNAME_M=`uname -m` + IS_IOS=`expr match $UNAME_M 'iP[a-zA-Z0-9,]*'` set -e - if [ $IS_IOS -gt 0 2>> /dev/null ]; then + if [ $IS_IOS -gt 0 2> /dev/null ]; then rm -r -f bin/ >> /dev/null 2>&1 echo -n "[3/3] iOS PHP build available, downloading $IOS_BUILD.tar.gz..." download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 @@ -102,7 +102,7 @@ else fi else rm -r -f bin/ >> /dev/null 2>&1 - if [ `getconf LONG_BIT` = "64" ]; then + if [ `getconf LONG_BIT` == "64" ]; then echo -n "[3/3] MacOS 64-bit PHP build available, downloading $MAC_64_BUILD.tar.gz..." MAC_BUILD=$MAC_64_BUILD else From 80e2a7e486da2983e0896d34568cdeb74a2c5be4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 19:46:39 +0100 Subject: [PATCH 119/173] Update installer.sh --- src/build/installer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/build/installer.sh b/src/build/installer.sh index cc6755976..1bf0a9804 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -81,10 +81,10 @@ else echo " detecting if build is available..." if [ "$forcecompile" == "off" ] && [ "$(uname -s)" == "Darwin" ]; then set +e - UNAME_M=`uname -m` - IS_IOS=`expr match $UNAME_M 'iP[a-zA-Z0-9,]*'` + UNAME_M=$(uname -m) + IS_IOS=$(expr match $UNAME_M 'iP[a-zA-Z0-9,]*' 2> /dev/null) set -e - if [ $IS_IOS -gt 0 2> /dev/null ]; then + if [[ $IS_IOS -gt 0 ]]; then rm -r -f bin/ >> /dev/null 2>&1 echo -n "[3/3] iOS PHP build available, downloading $IOS_BUILD.tar.gz..." download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 From 15881d328d67f81137fa1c9dea11b0848f76509b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 20:41:54 +0100 Subject: [PATCH 120/173] Added -weak-lSystem to MacOS x86_64 --- src/build/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 1bc7abbe4..fc9af7ed4 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -59,7 +59,7 @@ elif [ "$1" == "mac64" ]; then [ -z "$march" ] && march=core2; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; + [ -z "$LDFLAGS" ] && LDFLAGS="-weak-lSystem -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" From 1961e82645b4896eeef4d33ec2470b1bf00b408f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 21:31:04 +0100 Subject: [PATCH 121/173] Downgrade OpenSSL to 0.9.8y --- src/build/compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index fc9af7ed4..cabcc1a12 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -3,7 +3,7 @@ PHP_VERSION="5.5.9" ZEND_VM="GOTO" ZLIB_VERSION="1.2.8" -OPENSSL_VERSION="1.0.1f" +OPENSSL_VERSION="0.9.8y" CURL_VERSION="curl-7_35_0" LIBEDIT_VERSION="0.3" PTHREADS_VERSION="0.1.0" @@ -59,7 +59,7 @@ elif [ "$1" == "mac64" ]; then [ -z "$march" ] && march=core2; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-weak-lSystem -Wl,-rpath,@loader_path/../lib"; + [ -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" From a1b2cf4b341694dea5c60af269821371bad37af9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 18 Feb 2014 21:36:52 +0100 Subject: [PATCH 122/173] Added -undefined dynamic_lookup --- src/build/compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index cabcc1a12..7744230a8 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -51,7 +51,7 @@ elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; + [ -z "$LDFLAGS" ] && LDFLAGS="-undefined dynamic_lookup -Wl,-rpath,@loader_path/../lib"; export DYLD_LIBRARY_PATH="@loader_path/../lib" OPENSSL_TARGET="darwin-i386-cc" echo "[INFO] Compiling for Intel MacOS x86" @@ -59,7 +59,7 @@ elif [ "$1" == "mac64" ]; then [ -z "$march" ] && march=core2; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath,@loader_path/../lib"; + [ -z "$LDFLAGS" ] && LDFLAGS="-undefined dynamic_lookup -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" From 3d3111fef6d97b932dd36dc4513434f2b483df64 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 19 Feb 2014 00:48:54 +0100 Subject: [PATCH 123/173] Changed preg_match() code in Player username handling --- src/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Player.php b/src/Player.php index 4819c0dc5..82589d8e6 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1326,7 +1326,7 @@ class Player{ $this->close("Incorrect protocol #".$packet->protocol1, false); 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); return; } From f1b5f83fd4fd928fbfd3e4d3d022ae3027ccafa6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 19 Feb 2014 01:55:42 +0100 Subject: [PATCH 124/173] Lots of typos fixed, undefined variables, unused code --- src/API/BanAPI.php | 6 +- src/API/BlockAPI.php | 8 +- src/API/ConsoleAPI.php | 5 +- src/API/LevelAPI.php | 1 - src/API/PlayerAPI.php | 1 - src/API/PluginAPI.php | 13 --- src/Player.php | 14 +-- src/PocketMinecraftServer.php | 11 +- src/build/compile.sh | 4 +- src/event/EventHandler.php | 1 - src/functions.php | 4 +- src/material/block/attachable/SignPost.php | 2 +- src/material/item/generic/SpawnEgg.php | 1 - src/network/MinecraftInterface.php | 3 +- src/network/UDPSocket.php | 2 +- src/network/raknet/RakNetCodec.php | 1 + src/network/raknet/RakNetDataPacket.php | 4 +- src/network/raknet/RakNetParser.php | 4 +- src/pmf/PMFLevel.php | 2 +- src/utils/Config.php | 3 - src/utils/NBT.php | 2 +- src/utils/Utils.php | 2 +- src/utils/VersionString.php | 1 + src/utils/pthreads.php | 2 +- src/{installer => wizard}/Installer.php | 0 src/world/Entity.php | 20 +++- src/world/PocketChunkParser.php | 15 ++- src/world/Tile.php | 2 + src/world/generator/NormalGenerator.php | 1 + src/world/generator/SuperflatGenerator.php | 2 +- src/world/generator/WorldGenerator.php | 2 +- src/world/generator/noise/OctaveGenerator.php | 108 ------------------ .../generator/noise/PerlinOctaveGenerator.php | 63 ---------- .../object/tree/SpruceTreeObject.php | 2 +- .../generator/object/tree/TreeObject.php | 2 +- 35 files changed, 63 insertions(+), 251 deletions(-) rename src/{installer => wizard}/Installer.php (100%) delete mode 100644 src/world/generator/noise/OctaveGenerator.php delete mode 100644 src/world/generator/noise/PerlinOctaveGenerator.php diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 0c5d6f3ea..9353e9c01 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -32,7 +32,7 @@ class BanAPI{ private $ops; /** @var Config */ private $bannedIPs; - private $cmdWL = array();//Command WhiteList + private $cmdWhitelist = array();//Command WhiteList function __construct(){ $this->server = ServerAPI::request(); } @@ -104,7 +104,6 @@ class BanAPI{ } } return; - break; case "console.command"://Checks if a command is allowed with the current user permissions. if(isset($this->cmdWhitelist[$data["cmd"]])){ return; @@ -118,7 +117,6 @@ class BanAPI{ return; } return false; - break; } } @@ -152,7 +150,7 @@ class BanAPI{ $player = $this->server->api->player->get($user); if(!($player instanceof Player)){ $this->ops->set($user); - $this->ops->save($user); + $this->ops->save(); $output .= $user." is now op\n"; break; } diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 4ee73014a..5abdf9fb4 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -516,13 +516,9 @@ class BlockAPI{ public function nextRandomUpdate(Position $pos){ 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); - $i = 0; $offset = 0; - while(true){ + do{ $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).";"); if($update instanceof SQLite3Result){ @@ -534,7 +530,7 @@ class BlockAPI{ break; } $offset += mt_rand(25, 75); - } + }while(true); $this->scheduleBlockUpdate($pos, $t / 0.05, BLOCK_UPDATE_RANDOM); } } diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 0ac1583e6..0dfb688f3 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -26,7 +26,6 @@ class ConsoleAPI{ $this->cmds = array(); $this->alias = array(); $this->server = ServerAPI::request(); - $this->last = microtime(true); } 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 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"; - }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])){ $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){ @@ -326,7 +325,7 @@ class ConsoleLoop extends Thread{ } if(!extension_loaded("readline")){ - @fclose($fp); + @fclose($this->fp); } exit(0); } diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index e93e6df31..d5d92929f 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -198,7 +198,6 @@ class LevelAPI{ $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){ $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"]); } diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 788d6bbd1..4468ca2c7 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -111,7 +111,6 @@ class PlayerAPI{ } $this->server->api->chat->broadcast($data["player"]->username . $message); return true; - break; } } diff --git a/src/API/PluginAPI.php b/src/API/PluginAPI.php index 7581e263a..65a7dcd73 100644 --- a/src/API/PluginAPI.php +++ b/src/API/PluginAPI.php @@ -196,19 +196,6 @@ class PluginAPI extends stdClass{ 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 yaml_parse(preg_replace("#^([ ]*)([a-zA-Z_]{1}[^\:]*)\:#m", "$1\"$2\":", file_get_contents($file))); } diff --git a/src/Player.php b/src/Player.php index 82589d8e6..e1f4a8e2c 100644 --- a/src/Player.php +++ b/src/Player.php @@ -222,7 +222,6 @@ class Player{ $Y = $id[1]; $x = $X << 4; $z = $Z << 4; - $y = $Y << 4; $this->level->useChunk($X, $Z, $this); $Yndex = 1 << $Y; for($iY = 0; $iY < 8; ++$iY){ @@ -328,7 +327,7 @@ class Player{ $this->chunksLoaded = array(); $this->chunksOrder = array(); $this->chunkCount = array(); - $this->cratingItems = array(); + $this->craftingItems = array(); $this->received = array(); } } @@ -698,11 +697,10 @@ class Player{ return; }else{ $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{ - $message = (string) $data; - $this->sendChat(preg_replace('/\x1b\[[0-9;]*m/', "", (string) $data)); //Remove ANSI codes from chat + $this->sendChat((string) $data); } break; } @@ -1377,8 +1375,8 @@ class Player{ $inv[] = array($item[0], $item[1], 1); } } + $this->data->set("inventory", $inv); } - $this->data->set("inventory", $inv); } $this->achievements = $this->data->get("achievements"); $this->data->set("caseusername", $this->username); @@ -2007,6 +2005,7 @@ class Player{ $packet->item = $this->getSlot($this->slot); $this->craftingItems = array(); $this->toCraft = array(); + $data = array(); $data["eid"] = $packet->eid; $data["unknown"] = $packet->unknown; $data["item"] = $packet->item; @@ -2374,7 +2373,7 @@ class Player{ return $cnts; } - public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $recover = true){ + public function directDataPacket(RakNetDataPacket $packet, $recover = true){ if($this->connected === false){ return false; } @@ -2382,7 +2381,6 @@ class Player{ if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ return array(); } - $packet->encode(); $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk->data[] = $packet; diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 32afc47d2..408c4a1c2 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -21,8 +21,8 @@ class PocketMinecraftServer{ public $tCnt; - public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; - private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $ticks, $memoryStats, $async = array(), $asyncID = 0; + public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $spawn, $seed, $stop, $gamemode, $difficulty$name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; + private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $doTick, $ticks, $memoryStats, $schedule, $asyncThread, $async = array(), $asyncID = 0; /** * @var ServerAPI @@ -45,10 +45,7 @@ class PocketMinecraftServer{ $this->eventsID = array(); $this->handlers = array(); $this->invisible = false; - $this->levelData = false; $this->difficulty = 1; - $this->tiles = array(); - $this->entities = array(); $this->custom = array(); $this->evCnt = 1; $this->handCnt = 1; @@ -57,7 +54,6 @@ class PocketMinecraftServer{ $this->schedule = array(); $this->scheduleCnt = 1; $this->description = ""; - $this->whitelist = false; $this->memoryStats = array(); $this->clients = array(); $this->spawn = false; @@ -129,7 +125,7 @@ class PocketMinecraftServer{ public function startDatabase(){ $this->preparedSQL = 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 encoding = \"UTF-8\";"); $this->query("PRAGMA secure_delete = OFF;"); @@ -316,7 +312,6 @@ class PocketMinecraftServer{ $handlers->finalize(); foreach($call as $hnid => $boolean){ if($result !== false and $result !== true){ - $called[$hnid] = true; $handler = $this->handlers[$hnid]; if(is_array($handler)){ $method = $handler[1]; diff --git a/src/build/compile.sh b/src/build/compile.sh index 7744230a8..cabcc1a12 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -51,7 +51,7 @@ elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-undefined dynamic_lookup -Wl,-rpath,@loader_path/../lib"; + [ -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" @@ -59,7 +59,7 @@ elif [ "$1" == "mac64" ]; then [ -z "$march" ] && march=core2; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; - [ -z "$LDFLAGS" ] && LDFLAGS="-undefined dynamic_lookup -Wl,-rpath,@loader_path/../lib"; + [ -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" diff --git a/src/event/EventHandler.php b/src/event/EventHandler.php index 7498cfaff..2a9b1becd 100644 --- a/src/event/EventHandler.php +++ b/src/event/EventHandler.php @@ -22,7 +22,6 @@ abstract class EventHandler{ public static function callEvent(BaseEvent $event){ - $status = BaseEvent::NORMAL; foreach($event::$handlerPriority as $priority => $handlerList){ if(count($handlerList) > 0){ $event->setPrioritySlot($priority); diff --git a/src/functions.php b/src/functions.php index 6fcdcf891..75ed19015 100644 --- a/src/functions.php +++ b/src/functions.php @@ -140,7 +140,7 @@ function arguments ( $args ){ $args = array(); } array_shift( $args ); - $args = join( $args, ' ' ); + $args = implode( $args, ' ' ); preg_match_all('/ (--[\w\-]+ (?:[= ] [^-\s]+ )? ) | (-\w+) | (\w+) /x', $args, $match ); $args = array_shift( $match ); @@ -158,7 +158,7 @@ function arguments ( $args ){ $value = preg_split( '/[= ]/', $arg, 2 ); $com = substr( array_shift($value), 2 ); - $value = join($value); + $value = implode($value); $ret['commands'][$com] = !empty($value) ? $value : true; continue; diff --git a/src/material/block/attachable/SignPost.php b/src/material/block/attachable/SignPost.php index 743d35adc..948476b3b 100644 --- a/src/material/block/attachable/SignPost.php +++ b/src/material/block/attachable/SignPost.php @@ -41,7 +41,7 @@ class SignPostBlock extends TransparentBlock{ return true; }else{ $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; } } diff --git a/src/material/item/generic/SpawnEgg.php b/src/material/item/generic/SpawnEgg.php index 2c9d1329f..8c78182e0 100644 --- a/src/material/item/generic/SpawnEgg.php +++ b/src/material/item/generic/SpawnEgg.php @@ -43,7 +43,6 @@ class SpawnEggItem extends Item{ --$this->count; } return true; - break; } return false; } diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 587131a2d..7a4266266 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -30,7 +30,6 @@ class MinecraftInterface{ exit(1); } $this->bandwidth = array(0, 0, microtime(true)); - $this->start = microtime(true); $this->packets = array(); } @@ -90,7 +89,7 @@ class MinecraftInterface{ if(EventHandler::callEvent(new PacketSendEvent($packet)) === BaseEvent::DENY){ return 0; }elseif($packet instanceof RakNetPacket){ - $codec = new RakNetCodec($packet); + new RakNetCodec($packet); } $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); $this->bandwidth[1] += $write; diff --git a/src/network/UDPSocket.php b/src/network/UDPSocket.php index ee9df38e0..8dc30c717 100644 --- a/src/network/UDPSocket.php +++ b/src/network/UDPSocket.php @@ -22,7 +22,7 @@ class UDPSocket{ - public $connected, $sock, $server; + public $connected, $sock, $server, $port; function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){ $this->server = $server; $this->port = $port; diff --git a/src/network/raknet/RakNetCodec.php b/src/network/raknet/RakNetCodec.php index a009f63d2..c0c908760 100644 --- a/src/network/raknet/RakNetCodec.php +++ b/src/network/raknet/RakNetCodec.php @@ -21,6 +21,7 @@ class RakNetCodec{ public $packet; + private $buffer; public function __construct(RakNetPacket $packet){ $this->packet = $packet; $this->buffer =& $this->packet->buffer; diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php index 75ebc44b7..b2452f77c 100644 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -76,8 +76,8 @@ abstract class RakNetDataPacket extends stdClass{ $this->buffer .= Utils::writeLong($v); } - protected function getInt($unsigned = false){ - return Utils::readInt($this->get(4), $unsigned); + protected function getInt(){ + return Utils::readInt($this->get(4)); } protected function putInt($v){ diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index 98699be9c..a8d99a2ca 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -50,8 +50,8 @@ class RakNetParser{ return Utils::readLong($this->get(8), $unsigned); } - private function getInt($unsigned = false){ - return Utils::readInt($this->get(4), $unsigned); + private function getInt(){ + return Utils::readInt($this->get(4)); } private function getShort($unsigned = false){ diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 46f6bb98d..acb8776cf 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -95,7 +95,7 @@ class PMFLevel extends PMF{ } private function createBlank(){ - $this->saveData(false); + $this->saveData(); @mkdir(dirname($this->file)."/chunks/", 0755); if(!file_exists(dirname($this->file)."/entities.yml")){ $entities = new Config(dirname($this->file)."/entities.yml", CONFIG_YAML); diff --git a/src/utils/Config.php b/src/utils/Config.php index ace15d218..f491e9a52 100644 --- a/src/utils/Config.php +++ b/src/utils/Config.php @@ -76,7 +76,6 @@ class Config{ */ public function __construct($file, $type = CONFIG_DETECT, $default = array(), &$correct = null){ $this->load($file, $type, $default); - $correct = $this->check(); } public function reload(){ @@ -84,7 +83,6 @@ class Config{ unset($this->correct); unset($this->type); $this->load($this->file); - $correct = $this->check(); } public function fixYAMLIndexes($str){ @@ -141,7 +139,6 @@ class Config{ default: $this->correct = false; return false; - break; } if(!is_array($this->config)){ $this->config = $default; diff --git a/src/utils/NBT.php b/src/utils/NBT.php index f85f637bd..daa6b3932 100644 --- a/src/utils/NBT.php +++ b/src/utils/NBT.php @@ -107,7 +107,7 @@ class NBT{ } public function writeTAG_FLOAT($v){ - $this->binary .= Utils::writeLFloar($v); + $this->binary .= Utils::writeLFloat($v); } public function writeTAG_DOUBLE($v){ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index fff7aa293..761e76a05 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -620,7 +620,7 @@ class Utils{ } public static function writeLLong($value){ - return strrev(Utils::writeLong($str)); + return strrev(Utils::writeLong($value)); } diff --git a/src/utils/VersionString.php b/src/utils/VersionString.php index 7fccc28b2..f0a398ab8 100644 --- a/src/utils/VersionString.php +++ b/src/utils/VersionString.php @@ -33,6 +33,7 @@ class VersionString{ private $release; private $minor; private $development = false; + private $generation; public function __construct($version = MAJOR_VERSION){ if(is_int($version)){ $this->minor = $version & 0x1F; diff --git a/src/utils/pthreads.php b/src/utils/pthreads.php index 134fd3f3a..d4a3faaf0 100644 --- a/src/utils/pthreads.php +++ b/src/utils/pthreads.php @@ -87,7 +87,7 @@ class AsyncMultipleQueue extends Thread{ $d = array(); for($c = 0; $c < $cnt; ++$c){ $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); $this->lock(); diff --git a/src/installer/Installer.php b/src/wizard/Installer.php similarity index 100% rename from src/installer/Installer.php rename to src/wizard/Installer.php diff --git a/src/world/Entity.php b/src/world/Entity.php index a8bb3d26d..b93775abc 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -43,8 +43,16 @@ class Entity extends Position{ public $attach; public $closed; public $player; + public $status; public $fallY; + public $health; + public $fire; + public $crouched; + public $invincible; public $fallStart; + public $stack; + public $meta; + private $position; private $tickCounter; private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0); private $server; @@ -526,8 +534,8 @@ class Entity extends Position{ } }elseif($this->fallY !== false){ //Fall damage! if($y < $this->fallY){ - $d = $this->level->getBlock(new Vector3($x, $y + 1, $z)); - $d2 = $this->level->getBlock(new Vector3($x, $y + 2, $z)); + $d = $this->level->getBlock(new Vector3($this->x, $y + 1, $this->z)); + $d2 = $this->level->getBlock(new Vector3($this->x, $y + 2, $this->z)); $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){ $this->harm($dmg, "fall"); @@ -562,10 +570,10 @@ class Entity 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->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){ 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]); }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{ $this->updateLast(); @@ -593,7 +601,7 @@ class Entity extends Position{ } } }else{ - $this->updatePosition($this->x, $this->y, $this->z, $this->yaw, $this->pitch); + $this->updatePosition(); } } $this->lastUpdate = $now; @@ -658,7 +666,7 @@ class Entity extends Position{ } switch($this->class){ 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; } diff --git a/src/world/PocketChunkParser.php b/src/world/PocketChunkParser.php index 589ece0e2..333f40fed 100644 --- a/src/world/PocketChunkParser.php +++ b/src/world/PocketChunkParser.php @@ -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{ private $location, $raw = b"", $file; - var $sectorLength = 4096; //16 * 16 * 16 - var $chunkLength = 86016; //21 * $sectorLength - var $map; + public $sectorLength = 4096; //16 * 16 * 16 + public $chunkLength = 86016; //21 * $sectorLength + public $map = array(); - function __construct(){ - $map = array(); + public function __construct(){ } private function loadLocationTable(){ diff --git a/src/world/Tile.php b/src/world/Tile.php index b7ccd4283..c2b89fbef 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -31,6 +31,8 @@ class Tile extends Position{ public $attach; public $metadata; public $closed; + private $lastUpdate; + private $scheduledUpdate; private $server; function __construct(Level $level, $id, $class, $x, $y, $z, $data = array()){ $this->server = ServerAPI::request(); diff --git a/src/world/generator/NormalGenerator.php b/src/world/generator/NormalGenerator.php index bf24d7649..1b65e3c85 100644 --- a/src/world/generator/NormalGenerator.php +++ b/src/world/generator/NormalGenerator.php @@ -80,6 +80,7 @@ class NormalGenerator implements LevelGenerator{ public function generateChunk($chunkX, $chunkZ){ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed()); $hills = array(); + $patches = array(); $patchesSmall = array(); $base = array(); for($z = 0; $z < 16; ++$z){ diff --git a/src/world/generator/SuperflatGenerator.php b/src/world/generator/SuperflatGenerator.php index d57874456..5de375ed4 100644 --- a/src/world/generator/SuperflatGenerator.php +++ b/src/world/generator/SuperflatGenerator.php @@ -24,7 +24,7 @@ require_once("LevelGenerator.php"); /***REM_END***/ 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(){ return $this->options; diff --git a/src/world/generator/WorldGenerator.php b/src/world/generator/WorldGenerator.php index 9825adea5..9e7d52393 100644 --- a/src/world/generator/WorldGenerator.php +++ b/src/world/generator/WorldGenerator.php @@ -20,7 +20,7 @@ */ 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){ $this->seed = $seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false)); $this->random = new Random($this->seed); diff --git a/src/world/generator/noise/OctaveGenerator.php b/src/world/generator/noise/OctaveGenerator.php deleted file mode 100644 index 962801bec..000000000 --- a/src/world/generator/noise/OctaveGenerator.php +++ /dev/null @@ -1,108 +0,0 @@ -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){ - - }*/ -} \ No newline at end of file diff --git a/src/world/generator/noise/PerlinOctaveGenerator.php b/src/world/generator/noise/PerlinOctaveGenerator.php deleted file mode 100644 index 53a79884c..000000000 --- a/src/world/generator/noise/PerlinOctaveGenerator.php +++ /dev/null @@ -1,63 +0,0 @@ -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; - }*/ -} \ No newline at end of file diff --git a/src/world/generator/object/tree/SpruceTreeObject.php b/src/world/generator/object/tree/SpruceTreeObject.php index e705764df..0f78ac2a5 100644 --- a/src/world/generator/object/tree/SpruceTreeObject.php +++ b/src/world/generator/object/tree/SpruceTreeObject.php @@ -55,7 +55,7 @@ class SpruceTreeObject extends TreeObject{ public function placeObject(Level $level, Vector3 $pos, Random $random){ 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()); $leavesRadius = 0; diff --git a/src/world/generator/object/tree/TreeObject.php b/src/world/generator/object/tree/TreeObject.php index 109702334..9a1638f44 100644 --- a/src/world/generator/object/tree/TreeObject.php +++ b/src/world/generator/object/tree/TreeObject.php @@ -47,8 +47,8 @@ class TreeObject{ $tree = new SmallTreeObject(); $tree->type = SaplingBlock::JUNGLE; break; - default: case SaplingBlock::OAK: + default: /*if($random->nextRange(0, 9) === 0){ $tree = new BigTreeObject(); }else{*/ From b4c6a0bf226ba407dc935375b3cfc53f6e4e79dc Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 19 Feb 2014 01:56:25 +0100 Subject: [PATCH 125/173] oops, typo --- src/PocketMinecraftServer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 408c4a1c2..6a907678e 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -21,7 +21,7 @@ class PocketMinecraftServer{ public $tCnt; - public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $spawn, $seed, $stop, $gamemode, $difficulty$name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; + public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $spawn, $seed, $stop, $gamemode, $difficulty, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $doTick, $ticks, $memoryStats, $schedule, $asyncThread, $async = array(), $asyncID = 0; /** From dd177b689b643f4499422b4938b11650501efffa Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 19 Feb 2014 02:09:02 +0100 Subject: [PATCH 126/173] Added -mmacosx-version-min=10.5 to compile.sh --- src/build/compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index cabcc1a12..baeda7204 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -50,7 +50,7 @@ if [ "$1" == "rpi" ]; then elif [ "$1" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; - [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer"; + [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -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="darwin-i386-cc" @@ -58,7 +58,7 @@ elif [ "$1" == "mac" ]; then elif [ "$1" == "mac64" ]; then [ -z "$march" ] && march=core2; [ -z "$mtune" ] && mtune=generic; - [ -z "$CFLAGS" ] && CFLAGS="-m64 -arch x86_64 -fomit-frame-pointer"; + [ -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" From d12ce8fd6cbe2c5ae5acb687c1943334fba91166 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 19 Feb 2014 02:23:45 +0100 Subject: [PATCH 127/173] small fixes --- src/Player.php | 2 +- src/PocketMinecraftServer.php | 3 ++- src/build/compile.sh | 2 +- src/functions.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Player.php b/src/Player.php index e1f4a8e2c..40ede5726 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1658,7 +1658,7 @@ class Player{ $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)){ $this->sendInventorySlot($this->slot); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 6a907678e..3c6b29a28 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -21,7 +21,7 @@ class PocketMinecraftServer{ public $tCnt; - public $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $spawn, $seed, $stop, $gamemode, $difficulty, $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, $doTick, $ticks, $memoryStats, $schedule, $asyncThread, $async = array(), $asyncID = 0; /** @@ -58,6 +58,7 @@ class PocketMinecraftServer{ $this->clients = array(); $this->spawn = false; $this->saveEnabled = true; + $this->whitelist = false; $this->tickMeasure = array_fill(0, 40, 0); $this->setType("normal"); $this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip); diff --git a/src/build/compile.sh b/src/build/compile.sh index baeda7204..08ab28930 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -126,7 +126,7 @@ elif [ "$1" == "crosscompile" ]; then exit 1 fi 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" CFLAGS="-m64 $CFLAGS" OPENSSL_TARGET="linux-x86_64" diff --git a/src/functions.php b/src/functions.php index 75ed19015..1784f992e 100644 --- a/src/functions.php +++ b/src/functions.php @@ -140,7 +140,7 @@ function arguments ( $args ){ $args = array(); } array_shift( $args ); - $args = implode( $args, ' ' ); + $args = implode(' ', $args); preg_match_all('/ (--[\w\-]+ (?:[= ] [^-\s]+ )? ) | (-\w+) | (\w+) /x', $args, $match ); $args = array_shift( $match ); From 772fa2b9e38cebb759467ffda5810e92492c36f3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 20 Feb 2014 09:00:17 +0100 Subject: [PATCH 128/173] Query token now depends on the source IP --- src/network/query/QueryHandler.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/network/query/QueryHandler.php b/src/network/query/QueryHandler.php index f300695bb..bc7286443 100644 --- a/src/network/query/QueryHandler.php +++ b/src/network/query/QueryHandler.php @@ -91,7 +91,11 @@ class QueryHandler{ public function regenerateToken(){ $this->lastToken = $this->token; - $this->token = Utils::readInt("\x00".Utils::getRandomBytes(3, false)); + $this->token = Utils::getRandomBytes(16, false); + } + + public static function getTokenString($token, $salt){ + return Utils::readInt(substr(hash("sha512", $salt . ":". $token, true), 7, 4)); } public function handle(QueryPacket $packet){ @@ -103,13 +107,13 @@ class QueryHandler{ $pk->port = $packet->port; $pk->packetType = QueryPacket::HANDSHAKE; $pk->sessionID = $packet->sessionID; - $pk->payload = $this->token."\x00"; + $pk->payload = self::getTokenString($this->token, $packet->ip)."\x00"; $pk->encode(); $this->server->send($pk); break; case QueryPacket::STATISTICS: //Stat $token = Utils::readInt(substr($packet->payload, 0, 4)); - if($token !== $this->token and $token !== $this->lastToken){ + if($token !== self::getTokenString($this->token, $packet->ip) and $token !== self::getTokenString($this->lastToken, $packet->ip)){ break; } $pk = new QueryPacket; @@ -131,4 +135,4 @@ class QueryHandler{ } } -} \ No newline at end of file +} From eb40c34547fba4eb6e988c302b1174409d6d7b5e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 20 Feb 2014 10:57:00 +0100 Subject: [PATCH 129/173] Fix error dump not dumped on memory problems --- src/PocketMinecraftServer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 3c6b29a28..7cfb2ee31 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -384,6 +384,7 @@ class PocketMinecraftServer{ if($this->stop === true){ return; } + ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems console("[SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump"); $dump = "```\r\n# PocketMine-MP Error Dump ".date("D M j H:i:s T Y")."\r\n"; $er = error_get_last(); From 9bc69f4c177a371031e7e0007341a682acdb3615 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 20 Feb 2014 11:24:48 +0100 Subject: [PATCH 130/173] Update memory data on crash --- src/PocketMinecraftServer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 7cfb2ee31..910105ac6 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -453,6 +453,7 @@ class PocketMinecraftServer{ } $dump .= "Loaded Modules: ".var_export($extensions, true)."\r\n"; + $this->checkMemory(); $dump .= "Memory Usage Tracking: \r\n".chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9)))."\r\n"; ob_start(); phpinfo(); From fded0394857147480c5a7f13a938c527b14cbd5e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 20 Feb 2014 13:13:46 +0100 Subject: [PATCH 131/173] Fixed #1258 --- src/API/ConsoleAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API/ConsoleAPI.php b/src/API/ConsoleAPI.php index 0dfb688f3..8e8dec58e 100644 --- a/src/API/ConsoleAPI.php +++ b/src/API/ConsoleAPI.php @@ -249,7 +249,7 @@ class ConsoleAPI{ 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){ $output = "You don't have permissions to use this command.\n"; - }elseif($d1 !== true and (isset($d2) and $d2 !== true)){ + }elseif($d1 !== true and (!isset($d2) or $d2 !== true)){ if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){ $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){ From 8208fd23896a76295d70bdcca98fd6a5df6ffd1e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 20 Feb 2014 17:22:51 +0100 Subject: [PATCH 132/173] Changed class name --- src/API/PlayerAPI.php | 4 ++-- src/API/ServerAPI.php | 8 ++++---- src/{PocketMinecraftServer.php => MainServer.php} | 5 +++-- src/Player.php | 2 +- src/network/MinecraftInterface.php | 8 +------- src/network/UDPSocket.php | 7 ------- src/tests/ServerSuiteTest.php | 2 +- 7 files changed, 12 insertions(+), 24 deletions(-) rename src/{PocketMinecraftServer.php => MainServer.php} (99%) diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 4468ca2c7..f8759f460 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -337,7 +337,7 @@ class PlayerAPI{ $players = array(); if($query !== false and $query !== true){ while(($d = $query->fetchArray(SQLITE3_ASSOC)) !== false){ - $CID = PocketMinecraftServer::clientID($d["ip"], $d["port"]); + $CID = MainServer::clientID($d["ip"], $d["port"]); if(isset($this->server->clients[$CID])){ $players[$CID] = $this->server->clients[$CID]; if($multiple === false and $d["name"] === $name){ @@ -384,7 +384,7 @@ class PlayerAPI{ public function getByEID($eid){ $eid = (int) $eid; $CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '".$eid."';", true); - $CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]); + $CID = MainServer::clientID($CID["ip"], $CID["port"]); if(isset($this->server->clients[$CID])){ return $this->server->clients[$CID]; } diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 53f6ed6a7..fe8d8f45f 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -79,7 +79,7 @@ class ServerAPI{ public $tile; /** - * @return PocketMinecraftServer + * @return MainServer */ public static function request(){ return self::$serverRequest; @@ -156,7 +156,7 @@ class ServerAPI{ UPnP_PortForward($this->getProperty("server-port")); } - $this->server = new PocketMinecraftServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"); + $this->server = new MainServer($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed:false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip:"0.0.0.0"); $this->server->api = $this; self::$serverRequest = $this->server; console("[INFO] This server is running PocketMine-MP version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.")", true, true, 0); @@ -293,7 +293,7 @@ class ServerAPI{ $this->setProperty("memory-limit", "128M"); } - if($this->server instanceof PocketMinecraftServer){ + if($this->server instanceof MainServer){ $this->server->setType($this->getProperty("server-type")); $this->server->maxClients = $this->getProperty("max-players"); $this->server->description = $this->getProperty("description"); @@ -339,7 +339,7 @@ class ServerAPI{ } public function init(){ - if(!(self::$serverRequest instanceof PocketMinecraftServer)){ + if(!(self::$serverRequest instanceof MainServer)){ self::$serverRequest = $this->server; } diff --git a/src/PocketMinecraftServer.php b/src/MainServer.php similarity index 99% rename from src/PocketMinecraftServer.php rename to src/MainServer.php index 910105ac6..3faa4188b 100644 --- a/src/PocketMinecraftServer.php +++ b/src/MainServer.php @@ -19,7 +19,7 @@ * */ -class PocketMinecraftServer{ +class MainServer{ public $tCnt; 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, $doTick, $ticks, $memoryStats, $schedule, $asyncThread, $async = array(), $asyncID = 0; @@ -482,7 +482,7 @@ class PocketMinecraftServer{ public function packetHandler(Packet $packet){ $data =& $packet; - $CID = PocketMinecraftServer::clientID($packet->ip, $packet->port); + $CID = MainServer::clientID($packet->ip, $packet->port); if(isset($this->clients[$CID])){ $this->clients[$CID]->handlePacket($packet); }else{ @@ -579,6 +579,7 @@ class PocketMinecraftServer{ } } $this->tick(); + $this->api->server; } } diff --git a/src/Player.php b/src/Player.php index 40ede5726..914952b31 100644 --- a/src/Player.php +++ b/src/Player.php @@ -104,7 +104,7 @@ class Player{ $this->server = ServerAPI::request(); $this->lastBreak = microtime(true); $this->clientID = $clientID; - $this->CID = PocketMinecraftServer::clientID($ip, $port); + $this->CID = MainServer::clientID($ip, $port); $this->ip = $ip; $this->port = $port; $this->spawnPosition = $this->server->spawn; diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 7a4266266..ff210a9bf 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -38,13 +38,7 @@ class MinecraftInterface{ } public function readPacket(){ - if($this->socket->connected === false){ - return false; - } - $buf = ""; - $source = false; - $port = 1; - $len = $this->socket->read($buf, $source, $port); + $len = $this->socket->read($buf = null, $source = null, $port = null); if($len === false or $len === 0){ return false; } diff --git a/src/network/UDPSocket.php b/src/network/UDPSocket.php index 8dc30c717..81a305881 100644 --- a/src/network/UDPSocket.php +++ b/src/network/UDPSocket.php @@ -45,7 +45,6 @@ class UDPSocket{ } public function close($error = 125){ - $this->connected = false; return @socket_close($this->sock); } @@ -58,16 +57,10 @@ class UDPSocket{ } public function read(&$buf, &$source, &$port){ - if($this->connected === false){ - return false; - } return @socket_recvfrom($this->sock, $buf, 65535, 0, $source, $port); } public function write($data, $dest, $port){ - if($this->connected === false){ - return false; - } return @socket_sendto($this->sock, $data, strlen($data), 0, $dest, $port); } diff --git a/src/tests/ServerSuiteTest.php b/src/tests/ServerSuiteTest.php index 4ef030f75..b46cb0c61 100644 --- a/src/tests/ServerSuiteTest.php +++ b/src/tests/ServerSuiteTest.php @@ -12,7 +12,7 @@ } } - if(!class_exists("PocketMinecraftServer", false)){ + if(!class_exists("MainServer", false)){ define("NO_THREADS", true); require_once(dirname(__FILE__)."/../dependencies.php"); require_once(FILE_PATH."/src/functions.php"); From 46ff7d43f426238128d82f07c5bc1041ad18bf96 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 20 Feb 2014 23:41:36 +0100 Subject: [PATCH 133/173] Forgot to remove crash debug code. Fix #1260 --- src/MainServer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/MainServer.php b/src/MainServer.php index 3faa4188b..163a797f4 100644 --- a/src/MainServer.php +++ b/src/MainServer.php @@ -579,7 +579,6 @@ class MainServer{ } } $this->tick(); - $this->api->server; } } From 734abf2fbbbce9be7bb68f29bffd5715f9d302b9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 20 Feb 2014 23:43:42 +0100 Subject: [PATCH 134/173] Fix E_STRICT errors --- src/network/MinecraftInterface.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index ff210a9bf..37a0862b7 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -38,7 +38,10 @@ class MinecraftInterface{ } public function readPacket(){ - $len = $this->socket->read($buf = null, $source = null, $port = null); + $buf = null; + $source = null; + $port = null; + $len = $this->socket->read($buf, $source, $port); if($len === false or $len === 0){ return false; } From ba761faf7445d4795c74eec8126708c9678e3e15 Mon Sep 17 00:00:00 2001 From: iksaku Date: Sat, 22 Feb 2014 22:43:58 -0600 Subject: [PATCH 135/173] Update BanAPI.php /sudo help more descriptive? --- src/API/BanAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 9353e9c01..6c098bd9a 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -48,7 +48,7 @@ class BanAPI{ $this->server->api->console->register("whitelist", " [username]", array($this, "commandHandler")); $this->server->api->console->register("op", "", array($this, "commandHandler")); $this->server->api->console->register("deop", "", array($this, "commandHandler")); - $this->server->api->console->register("sudo", "", array($this, "commandHandler")); + $this->server->api->console->register("sudo", " ", array($this, "commandHandler")); $this->server->api->console->alias("ban-ip", "banip add"); $this->server->api->console->alias("banlist", "ban list"); $this->server->api->console->alias("pardon", "ban remove"); From 13274ebefaa058c313baf6254998009c728c47de Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 21 Feb 2014 13:09:24 +0100 Subject: [PATCH 136/173] send-usage is now an advanced property :P --- src/API/ServerAPI.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index fe8d8f45f..95a86dc91 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -138,7 +138,6 @@ class ServerAPI{ "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10), - "send-usage" => true, "auto-save" => true, )); @@ -343,7 +342,7 @@ class ServerAPI{ self::$serverRequest = $this->server; } - if($this->getProperty("send-usage") !== false){ + if($this->getProperty("send-usage", true) !== false){ $this->server->schedule(6000, array($this, "sendUsage"), array(), true); //Send the info after 5 minutes have passed $this->sendUsage(); } From 24722e3c9ae706f7f222871b27207b181aea6eb1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 23 Feb 2014 13:39:34 +0100 Subject: [PATCH 137/173] Added #1196 async function queuing Type ID: ASYNC_FUNCTION Params: array("function" => $functionName, "arguments" => array $argumentArray) --- src/MainServer.php | 10 ++++++++++ src/utils/pthreads.php | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/MainServer.php b/src/MainServer.php index 163a797f4..9be40b243 100644 --- a/src/MainServer.php +++ b/src/MainServer.php @@ -228,6 +228,10 @@ class MainServer{ $d .= Utils::writeShort(strlen($key)).$key . Utils::writeInt(strlen($value)).$value; } break; + case ASYNC_FUNCTION: + $params = serialize($data["arguments"]); + $d .= Utils::writeShort(strlen($data["function"])).$data["function"] . Utils::writeInt(strlen($params)) . $params; + break; default: return false; } @@ -256,6 +260,12 @@ class MainServer{ $data["result"] = substr($this->asyncThread->output, $offset, $len); $offset += $len; break; + case ASYNC_FUNCTION: + $len = Utils::readInt(substr($this->asyncThread->output, $offset, 4)); + $offset += 4; + $data["result"] = unserialize(substr($this->asyncThread->output, $offset, $len)); + $offset += $len; + break; } $this->asyncThread->output = substr($this->asyncThread->output, $offset); if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){ diff --git a/src/utils/pthreads.php b/src/utils/pthreads.php index d4a3faaf0..38a8d6619 100644 --- a/src/utils/pthreads.php +++ b/src/utils/pthreads.php @@ -21,6 +21,7 @@ define("ASYNC_CURL_GET", 1); define("ASYNC_CURL_POST", 2); +define("ASYNC_FUNCTION", 3); class StackableArray extends Stackable{ public function __construct(){ @@ -94,6 +95,12 @@ class AsyncMultipleQueue extends Thread{ $this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_CURL_POST).Utils::writeInt(strlen($res)).$res; $this->unlock(); break; + case ASYNC_FUNCTION: + $function = $this->get(Utils::readShort($this->get(2), false)); + $params = unserialize($this->get(Utils::readInt($this->get(4)))); + $res = serialize(@call_user_func_array($function, $params)); + $this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_FUNCTION).Utils::writeInt(strlen($res)).$res; + break; } } usleep(10000); From 8e1cd2d6bdfe9c5abd4deec3331f8c78164af087 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 23 Feb 2014 13:47:30 +0100 Subject: [PATCH 138/173] Check for block changes each 2 ticks instead of each 15 ticks --- src/world/Level.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/world/Level.php b/src/world/Level.php index 01a256dde..0ca8b9175 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -34,7 +34,7 @@ class Level{ $this->nextSave = $this->startCheck = microtime(true); $this->nextSave += 90; $this->stopTime = false; - $this->server->schedule(15, array($this, "checkThings"), array(), true); + $this->server->schedule(2, array($this, "checkThings"), array(), true); $this->server->schedule(20 * 13, array($this, "checkTime"), array(), true); $this->name = $name; $this->usedChunks = array(); From 85f8613803851f376435c6544a95e9c40b2d0d40 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 24 Feb 2014 20:13:15 +0100 Subject: [PATCH 139/173] Fix RCON packet structure #1278 --- src/network/RCON.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/network/RCON.php b/src/network/RCON.php index c46ca8e5f..ca41f4d9d 100644 --- a/src/network/RCON.php +++ b/src/network/RCON.php @@ -104,7 +104,11 @@ class RCONInstance extends Thread{ } private function writePacket($client, $requestID, $packetType, $payload){ - return socket_write($client, Utils::writeLInt(strlen($payload)).Utils::writeLInt((int) $requestID).Utils::writeLInt((int) $packetType).($payload === "" ? "\x00":$payload)."\x00"); + $pk = Utils::writeLInt((int) $requestID) + . Utils::writeLInt((int) $packetType) + . $payload + . "\x00\x00"; //Terminate payload and packet + return socket_write($client, Utils::writeLInt(strlen($pk)).$pk); } private function readPacket($client, &$size, &$requestID, &$packetType, &$payload){ From 28d1da12868e83f98f28f2342188b6005179eef2 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 26 Feb 2014 13:08:53 +0100 Subject: [PATCH 140/173] New NBT tags --- src/nbt/NBT.php | 205 ++++++++++++++++++++++++++++++++ src/nbt/NBTTag.php | 55 +++++++++ src/nbt/NamedNBTTag.php | 40 +++++++ src/nbt/tags/TAG_Byte.php | 35 ++++++ src/nbt/tags/TAG_Byte_Array.php | 36 ++++++ src/nbt/tags/TAG_Compound.php | 45 +++++++ src/nbt/tags/TAG_Double.php | 35 ++++++ src/nbt/tags/TAG_End.php | 35 ++++++ src/nbt/tags/TAG_Float.php | 35 ++++++ src/nbt/tags/TAG_Int.php | 35 ++++++ src/nbt/tags/TAG_Int_Array.php | 42 +++++++ src/nbt/tags/TAG_List.php | 108 +++++++++++++++++ src/nbt/tags/TAG_Long.php | 35 ++++++ src/nbt/tags/TAG_Short.php | 35 ++++++ src/nbt/tags/TAG_String.php | 36 ++++++ 15 files changed, 812 insertions(+) create mode 100644 src/nbt/NBT.php create mode 100644 src/nbt/NBTTag.php create mode 100644 src/nbt/NamedNBTTag.php create mode 100644 src/nbt/tags/TAG_Byte.php create mode 100644 src/nbt/tags/TAG_Byte_Array.php create mode 100644 src/nbt/tags/TAG_Compound.php create mode 100644 src/nbt/tags/TAG_Double.php create mode 100644 src/nbt/tags/TAG_End.php create mode 100644 src/nbt/tags/TAG_Float.php create mode 100644 src/nbt/tags/TAG_Int.php create mode 100644 src/nbt/tags/TAG_Int_Array.php create mode 100644 src/nbt/tags/TAG_List.php create mode 100644 src/nbt/tags/TAG_Long.php create mode 100644 src/nbt/tags/TAG_Short.php create mode 100644 src/nbt/tags/TAG_String.php diff --git a/src/nbt/NBT.php b/src/nbt/NBT.php new file mode 100644 index 000000000..6ca8a12dd --- /dev/null +++ b/src/nbt/NBT.php @@ -0,0 +1,205 @@ +offset = strlen($this->buffer) - 1; + return ""; + } + if($len === true){ + return substr($this->buffer, $this->offset); + } + $this->offset += $len; + return substr($this->buffer, $this->offset - $len, $len); + } + + public function put($v){ + $this->buffer .= $v; + } + + public function feof(){ + return !isset($this->buffer{$this->offset}); + } + + public function __construct($endianness = NBT::BIG_ENDIAN){ + $this->offset = 0; + $this->endianness = $endianness & 0x01; + } + + public function read($buffer){ + $this->offset = 0; + $this->buffer = $buffer; + $this->readTag(); + } + + public function write(){ + $this->offset = 0; + if($this->data instanceof NBTTag_Compound){ + $this->writeTag($this->data); + return true; + }else{ + return false; + } + } + + protected function readTag(){ + switch($this->getByte()){ + case NBTTag::TAG_End: //No named tag + $tag = new NBTTag_End; + break; + case NBTTag::TAG_Byte: + $tag = new NBTTag_Byte($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Byte: + $tag = new NBTTag_Byte($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Short: + $tag = new NBTTag_Short($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Int: + $tag = new NBTTag_Int($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Long: + $tag = new NBTTag_Long($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Float: + $tag = new NBTTag_Float($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Double: + $tag = new NBTTag_Double($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Byte_Array: + $tag = new NBTTag_Byte_Array($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_String: + $tag = new NBTTag_String($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_List: + $tag = new NBTTag_List($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Compound: + $tag = new NBTTag_Compound($this->getString()); + $tag->read($this); + break; + case NBTTag::TAG_Int_Array: + $tag = new NBTTag_Int_Array($this->getString()); + $tag->read($this); + break; + + default: + return false; + } + return $tag; + } + + public function writeTag(NBTTag $tag){ + $this->putByte($tag->getType()); + if($tag instanceof NamedNBTTag and $tag->getName() !== false){ + $this->putString($tag->getName()); + } + $tag->write($this); + } + + public function getByte(){ + return Utils::readByte($this->get(1), true); + } + + public function putByte($v){ + $this->buffer .= Utils::writeByte($v); + } + + public function getShort(){ + return $this->endianness === self::BIG_ENDIAN ? Utils::readShort($this->get(2)) : Utils::readLShort($this->get(2)); + } + + public function putShort($v){ + $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeShort($v) : Utils::writeLShort($v); + } + + public function getInt(){ + return $this->endianness === self::BIG_ENDIAN ? Utils::readInt($this->get(4)) : Utils::readLInt($this->get(4)); + } + + public function putInt($v){ + $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeInt($v) : Utils::writeLInt($v); + } + + public function getLong(){ + return $this->endianness === self::BIG_ENDIAN ? Utils::readLong($this->get(8)) : Utils::readLLong($this->get(8)); + } + + public function putLong($v){ + $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeLong($v) : Utils::writeLLong($v); + } + + public function getFloat(){ + return $this->endianness === self::BIG_ENDIAN ? Utils::readFloat($this->get(4)) : Utils::readLFloat($this->get(4)); + } + + public function putFloat($v){ + $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeFloat($v) : Utils::writeLFloat($v); + } + + public function getDouble(){ + return $this->endianness === self::BIG_ENDIAN ? Utils::readDouble($this->get(8)) : Utils::readLDouble($this->get(8)); + } + + public function putDouble($v){ + $this->buffer .= $this->endianness === self::BIG_ENDIAN ? Utils::writeDouble($v) : Utils::writeLDouble($v); + } + + public function getString(){ + return $this->get($this->getShort()); + } + + public function putString($v){ + $this->putShort(strlen($v)); + $this->buffer .= $v; + } + + public function getData(){ + return $this->data; + } + + public function setData(NBTTag_Compound $data){ + $this->data = $data; + } + +} diff --git a/src/nbt/NBTTag.php b/src/nbt/NBTTag.php new file mode 100644 index 000000000..55acec543 --- /dev/null +++ b/src/nbt/NBTTag.php @@ -0,0 +1,55 @@ +value; + } + + public abstract function getType(); + + public function setValue($value){ + $this->value = $value; + } + + abstract public function write(NBT $nbt); + + abstract public function read(NBT $nbt); + + public final function __toString(){ + return $this->value; + } +} diff --git a/src/nbt/NamedNBTTag.php b/src/nbt/NamedNBTTag.php new file mode 100644 index 000000000..7f8c5d805 --- /dev/null +++ b/src/nbt/NamedNBTTag.php @@ -0,0 +1,40 @@ +name = $name; + } + + public function getName(){ + return $this->name; + } + + public function setName($name){ + $this->name = $name; + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_Byte.php b/src/nbt/tags/TAG_Byte.php new file mode 100644 index 000000000..3e9624832 --- /dev/null +++ b/src/nbt/tags/TAG_Byte.php @@ -0,0 +1,35 @@ +value = $nbt->getByte(); + } + + public function write(NBT $nbt){ + $nbt->putByte($this->value); + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_Byte_Array.php b/src/nbt/tags/TAG_Byte_Array.php new file mode 100644 index 000000000..77266ea0a --- /dev/null +++ b/src/nbt/tags/TAG_Byte_Array.php @@ -0,0 +1,36 @@ +value = $nbt->get($this->getInt()); + } + + public function write(NBT $nbt){ + $nbt->putInt(strlen($this->value)); + $nbt->put($this->value); + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_Compound.php b/src/nbt/tags/TAG_Compound.php new file mode 100644 index 000000000..01a4e22e3 --- /dev/null +++ b/src/nbt/tags/TAG_Compound.php @@ -0,0 +1,45 @@ +value = array(); + do{ + $tag = $nbt->readTag(); + if($tag instanceof NamedNBTTag){ + $this->value[$tag->getName()] = $tag; + }else{ + $this->value[] = $tag; + } + }while(!($tag instanceof NBTTag_End) and !$nbt->feof()); + } + + public function write(NBT $nbt){ + foreach($this->value as $tag){ + $nbt->writeTag($tag); + } + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_Double.php b/src/nbt/tags/TAG_Double.php new file mode 100644 index 000000000..6b1437e33 --- /dev/null +++ b/src/nbt/tags/TAG_Double.php @@ -0,0 +1,35 @@ +value = $nbt->getDouble(); + } + + public function write(NBT $nbt){ + $nbt->putDouble($this->value); + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_End.php b/src/nbt/tags/TAG_End.php new file mode 100644 index 000000000..d917566d3 --- /dev/null +++ b/src/nbt/tags/TAG_End.php @@ -0,0 +1,35 @@ +value = $nbt->getFloat(); + } + + public function write(NBT $nbt){ + $nbt->putFloat($this->value); + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_Int.php b/src/nbt/tags/TAG_Int.php new file mode 100644 index 000000000..3f766bd36 --- /dev/null +++ b/src/nbt/tags/TAG_Int.php @@ -0,0 +1,35 @@ +value = $nbt->getInt(); + } + + public function write(NBT $nbt){ + $nbt->putInt($this->value); + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_Int_Array.php b/src/nbt/tags/TAG_Int_Array.php new file mode 100644 index 000000000..821496351 --- /dev/null +++ b/src/nbt/tags/TAG_Int_Array.php @@ -0,0 +1,42 @@ +value = array(); + $size = $nbt->getInt(); + for($i = 0; $i < $size and !$nbt->feof(); ++$i){ + $this->value[] = $nbt->getInt(); + } + } + + public function write(NBT $nbt){ + $nbt->putInt(count($this->value)); + foreach($this->value as $v){ + $nbt->putInt($v); + } + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_List.php b/src/nbt/tags/TAG_List.php new file mode 100644 index 000000000..54dfecf57 --- /dev/null +++ b/src/nbt/tags/TAG_List.php @@ -0,0 +1,108 @@ +value = array(); + $tagId = $nbt->getByte(); + $this->value[-1] = $tagId; + $size = $nbt->getInt(); + for($i = 0; $i < $size and !$nbt->feof(); ++$i){ + switch($tagId){ + case NBTTag::TAG_Byte: + $tag = new NBTTag_Byte(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Byte: + $tag = new NBTTag_Byte(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Short: + $tag = new NBTTag_Short(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Int: + $tag = new NBTTag_Int(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Long: + $tag = new NBTTag_Long(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Float: + $tag = new NBTTag_Float(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Double: + $tag = new NBTTag_Double(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Byte_Array: + $tag = new NBTTag_Byte_Array(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_String: + $tag = new NBTTag_String(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_List: + $tag = new NBTTag_List(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Compound: + $tag = new NBTTag_Compound(false); + $tag->read($this); + $this->value[] = $tag; + break; + case NBTTag::TAG_Int_Array: + $tag = new NBTTag_Int_Array(false); + $tag->read($this); + $this->value[] = $tag; + break; + } + } + } + + public function write(NBT $nbt){ + $nbt->putByte($this->value[-1]); + $nbt->putInt(count($this->value) - 1); + foreach($this->value as $tag){ + if($tag instanceof NBTTag){ + $nbt->writeTag($tag); + } + } + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_Long.php b/src/nbt/tags/TAG_Long.php new file mode 100644 index 000000000..9c4cf740b --- /dev/null +++ b/src/nbt/tags/TAG_Long.php @@ -0,0 +1,35 @@ +value = $nbt->getLong(); + } + + public function write(NBT $nbt){ + $nbt->putLong($this->value); + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_Short.php b/src/nbt/tags/TAG_Short.php new file mode 100644 index 000000000..994a4f63a --- /dev/null +++ b/src/nbt/tags/TAG_Short.php @@ -0,0 +1,35 @@ +value = $nbt->getShort(); + } + + public function write(NBT $nbt){ + $nbt->putShort($this->value); + } +} \ No newline at end of file diff --git a/src/nbt/tags/TAG_String.php b/src/nbt/tags/TAG_String.php new file mode 100644 index 000000000..0950ebb3a --- /dev/null +++ b/src/nbt/tags/TAG_String.php @@ -0,0 +1,36 @@ +value = $nbt->get($this->getShort()); + } + + public function write(NBT $nbt){ + $nbt->putShort(strlen($this->value)); + $nbt->put($this->value); + } +} \ No newline at end of file From 0231bf406e0866a2d0486bd40e41de83c69c8e0e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 26 Feb 2014 13:53:50 +0100 Subject: [PATCH 141/173] new NBT fixes --- src/nbt/NBT.php | 17 ++- src/nbt/tags/TAG_Compound.php | 2 +- src/nbt/tags/TAG_List.php | 24 ++-- src/utils/NBT.php | 213 ---------------------------------- 4 files changed, 21 insertions(+), 235 deletions(-) delete mode 100644 src/utils/NBT.php diff --git a/src/nbt/NBT.php b/src/nbt/NBT.php index 6ca8a12dd..61e3f8901 100644 --- a/src/nbt/NBT.php +++ b/src/nbt/NBT.php @@ -26,10 +26,10 @@ class NBT{ private $buffer; private $offset; private $endianness; - private $data = array(); + private $data; public function get($len){ - if($len <= 0){ + if($len < 0){ $this->offset = strlen($this->buffer) - 1; return ""; } @@ -56,24 +56,21 @@ class NBT{ public function read($buffer){ $this->offset = 0; $this->buffer = $buffer; - $this->readTag(); + $this->data = $this->readTag(); } public function write(){ $this->offset = 0; if($this->data instanceof NBTTag_Compound){ $this->writeTag($this->data); - return true; + return $this->buffer; }else{ return false; } } - protected function readTag(){ + public function readTag(){ switch($this->getByte()){ - case NBTTag::TAG_End: //No named tag - $tag = new NBTTag_End; - break; case NBTTag::TAG_Byte: $tag = new NBTTag_Byte($this->getString()); $tag->read($this); @@ -123,8 +120,10 @@ class NBT{ $tag->read($this); break; + case NBTTag::TAG_End: //No named tag default: - return false; + $tag = new NBTTag_End; + break; } return $tag; } diff --git a/src/nbt/tags/TAG_Compound.php b/src/nbt/tags/TAG_Compound.php index 01a4e22e3..ec95ebf84 100644 --- a/src/nbt/tags/TAG_Compound.php +++ b/src/nbt/tags/TAG_Compound.php @@ -29,7 +29,7 @@ class NBTTag_Compound extends NamedNBTTag{ $this->value = array(); do{ $tag = $nbt->readTag(); - if($tag instanceof NamedNBTTag){ + if($tag instanceof NamedNBTTag and $tag->getName() !== ""){ $this->value[$tag->getName()] = $tag; }else{ $this->value[] = $tag; diff --git a/src/nbt/tags/TAG_List.php b/src/nbt/tags/TAG_List.php index 54dfecf57..2a72a8c52 100644 --- a/src/nbt/tags/TAG_List.php +++ b/src/nbt/tags/TAG_List.php @@ -34,62 +34,62 @@ class NBTTag_List extends NamedNBTTag{ switch($tagId){ case NBTTag::TAG_Byte: $tag = new NBTTag_Byte(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Byte: $tag = new NBTTag_Byte(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Short: $tag = new NBTTag_Short(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Int: $tag = new NBTTag_Int(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Long: $tag = new NBTTag_Long(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Float: $tag = new NBTTag_Float(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Double: $tag = new NBTTag_Double(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Byte_Array: $tag = new NBTTag_Byte_Array(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_String: $tag = new NBTTag_String(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_List: $tag = new NBTTag_List(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Compound: $tag = new NBTTag_Compound(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; case NBTTag::TAG_Int_Array: $tag = new NBTTag_Int_Array(false); - $tag->read($this); + $tag->read($nbt); $this->value[] = $tag; break; } diff --git a/src/utils/NBT.php b/src/utils/NBT.php deleted file mode 100644 index daa6b3932..000000000 --- a/src/utils/NBT.php +++ /dev/null @@ -1,213 +0,0 @@ -offset += $n; - return substr($this->binary, $this->offset - $n, $n); - } - - private function feof(){ - return !isset($this->binary{$this->offset}); - } - - public function write($bin){ - $this->binary .= $bin; - } - - public function load($str){ - $this->offset = 0; - $this->binary = (string) $str; - $this->parseTree($this->tree); - } - - public function readTAG_BYTE(){ - return Utils::readByte($this->read(1)); - } - - public function readTAG_SHORT(){ - return Utils::readLShort($this->read(2)); - } - - public function readTAG_INT(){ - return Utils::readLInt($this->read(4)); - } - - public function readTAG_LONG(){ - return Utils::readLLong($this->read(8)); - } - - public function readTAG_FLOAT(){ - return Utils::readLFloat($this->read(4)); - } - - public function readTAG_DOUBLE(){ - return Utils::readLDouble($this->read(8)); - } - - public function readTAG_BYTE_ARRAY(){ - return $this->read($this->readTAG_INT()); - } - - public function readTAG_STRING(){ - return $this->read(Utils::readLShort($this->read(2), false)); - } - - public function writeTAG_BYTE($v){ - $this->binary .= chr($v); - } - - public function writeTAG_SHORT($v){ - $this->binary .= Utils::writeLShort($v); - } - - public function writeTAG_INT($v){ - $this->binary .= Utils::writeLInt($v); - } - - public function writeTAG_LONG($v){ - $this->binary .= Utils::writeLLong($v); - } - - public function writeTAG_FLOAT($v){ - $this->binary .= Utils::writeLFloat($v); - } - - public function writeTAG_DOUBLE($v){ - $this->binary .= Utils::writeLDouble($v); - } - - public function writeTAG_BYTE_ARRAY($v){ - $this->binary .= $this->writeTAG_INT(strlen($v)).$v; - } - - public function writeTAG_STRING($v){ - $this->binary .= $this->writeTAG_SHORT(strlen($v)).$v; - } - - private function parseList(&$node, $tag, $cnt){ - for($i = 0; $i < $cnt and !$this->feof(); ++$i){ - switch($tag){ - case self::TAG_BYTE: - $value = $this->readTAG_BYTE(); - break; - case self::TAG_SHORT: - $value = $this->readTAG_SHORT(); - break; - case self::TAG_INT: - $value = $this->readTAG_INT(); - break; - case self::TAG_LONG: - $value = $this->readTAG_LONG(); - break; - case self::TAG_FLOAT: - $value = $this->readTAG_FLOAT(); - break; - case self::TAG_DOUBLE: - $value = $this->readTAG_DOUBLE(); - break; - case self::TAG_BYTE_ARRAY: - $value = $this->readTAG_BYTE_ARRAY(); - break; - case self::TAG_STRING: - $value = $this->readTAG_STRING(); - break; - case self::TAG_LIST: - $value = array(); - $this->parseList($value, ord($this->read(1)), Utils::readLInt($this->read(4))); - break; - case self::TAG_COMPOUND: - $value = array(); - $this->parseTree($value); - break; - default: - echo bin2hex(substr($this->binary, $this->offset - 1)).PHP_EOL.PHP_EOL; - die("Invalid NBT Tag $tag"); - break; - } - $node[] = $value; - } - } - - private function parseTree(&$node){ - while(($tag = ord($this->read(1))) !== self::TAG_END and !$this->feof()){ - $name = $this->readTAG_STRING(); - switch($tag){ - case self::TAG_BYTE: - $value = $this->readTAG_BYTE(); - break; - case self::TAG_SHORT: - $value = $this->readTAG_SHORT(); - break; - case self::TAG_INT: - $value = $this->readTAG_INT(); - break; - case self::TAG_LONG: - $value = $this->readTAG_LONG(); - break; - case self::TAG_FLOAT: - $value = $this->readTAG_FLOAT(); - break; - case self::TAG_DOUBLE: - $value = $this->readTAG_DOUBLE(); - break; - case self::TAG_BYTE_ARRAY: - $value = $this->readTAG_BYTE_ARRAY(); - break; - case self::TAG_STRING: - $value = $this->readTAG_STRING(); - break; - case self::TAG_LIST: - $value = array(); - $this->parseList($value, ord($this->read(1)), Utils::readLInt($this->read(4))); - break; - case self::TAG_COMPOUND: - $value = array(); - $this->parseTree($value); - break; - default: - echo bin2hex(substr($this->binary, $this->offset - 1)).PHP_EOL.PHP_EOL; - die("Invalid NBT Tag $tag"); - break; - } - $node[$name] = $value; - } - } -} \ No newline at end of file From 9cfa49c11295208eec3bcb0fa76bb3c843b388ad Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 26 Feb 2014 15:12:58 +0100 Subject: [PATCH 142/173] Added core NBT modifications --- src/Player.php | 7 +-- src/nbt/NBT.php | 22 +++++++- src/nbt/NamedNBTTag.php | 7 ++- src/nbt/tags/TAG_Byte.php | 2 +- src/nbt/tags/TAG_Byte_Array.php | 2 +- src/nbt/tags/TAG_Compound.php | 20 ++++++- src/nbt/tags/TAG_Double.php | 2 +- src/nbt/tags/TAG_End.php | 2 +- src/nbt/tags/TAG_Float.php | 2 +- src/nbt/tags/TAG_Int.php | 2 +- src/nbt/tags/TAG_Int_Array.php | 2 +- src/nbt/tags/TAG_List.php | 20 ++++++- src/nbt/tags/TAG_Long.php | 2 +- src/nbt/tags/TAG_Short.php | 2 +- src/nbt/tags/TAG_String.php | 2 +- src/world/LevelImport.php | 26 ++++----- src/world/Tile.php | 99 +++++++++++---------------------- 17 files changed, 122 insertions(+), 99 deletions(-) diff --git a/src/Player.php b/src/Player.php index 914952b31..67ce4d822 100644 --- a/src/Player.php +++ b/src/Player.php @@ -2250,12 +2250,11 @@ class Player{ $t->spawn($this); }else{ $nbt = new NBT(); - $nbt->load($packet->namedtag); - $d = array_shift($nbt->tree); - if($d["id"] !== TILE_SIGN){ + $nbt->read($packet->namedtag); + if($nbt->id !== TILE_SIGN){ $t->spawn($this); }else{ - $t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]); + $t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4); } } } diff --git a/src/nbt/NBT.php b/src/nbt/NBT.php index 61e3f8901..db773e0ae 100644 --- a/src/nbt/NBT.php +++ b/src/nbt/NBT.php @@ -48,7 +48,7 @@ class NBT{ return !isset($this->buffer{$this->offset}); } - public function __construct($endianness = NBT::BIG_ENDIAN){ + public function __construct($endianness = NBT::LITTLE_ENDIAN){ $this->offset = 0; $this->endianness = $endianness & 0x01; } @@ -193,6 +193,26 @@ class NBT{ $this->buffer .= $v; } + public function __get($name){ + return $this->data instanceof NBTTag_Compound ? $this->data->{$name} : false; + } + + public function __set($name, $value){ + if($this->data instanceof NBTTag_Compound){ + $this->data->{$name} = $value; + } + } + + public function __isset($name){ + return $this->data instanceof NBTTag_Compound ? isset($this->data->{$name}) : false; + } + + public function __unset($name){ + if($this->data instanceof NBTTag_Compound){ + unset($this->data->{$name}); + } + } + public function getData(){ return $this->data; } diff --git a/src/nbt/NamedNBTTag.php b/src/nbt/NamedNBTTag.php index 7f8c5d805..7c27b7aa6 100644 --- a/src/nbt/NamedNBTTag.php +++ b/src/nbt/NamedNBTTag.php @@ -23,11 +23,14 @@ require_once("NBTTag.php"); /***REM_END***/ -class NamedNBTTag{ +abstract class NamedNBTTag extends NBTTag{ protected $name; - public function __construct($name = ""){ + public function __construct($name = "", $value = false){ $this->name = $name; + if($value !== false){ + $this->value = $value; + } } public function getName(){ diff --git a/src/nbt/tags/TAG_Byte.php b/src/nbt/tags/TAG_Byte.php index 3e9624832..ede91b995 100644 --- a/src/nbt/tags/TAG_Byte.php +++ b/src/nbt/tags/TAG_Byte.php @@ -22,7 +22,7 @@ class NBTTag_Byte extends NamedNBTTag{ public function getType(){ - return self::TAG_Byte; + return NBTTag::TAG_Byte; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_Byte_Array.php b/src/nbt/tags/TAG_Byte_Array.php index 77266ea0a..6b155f45a 100644 --- a/src/nbt/tags/TAG_Byte_Array.php +++ b/src/nbt/tags/TAG_Byte_Array.php @@ -22,7 +22,7 @@ class NBTTag_Byte_Array extends NamedNBTTag{ public function getType(){ - return self::TAG_Byte_Array; + return NBTTag::TAG_Byte_Array; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_Compound.php b/src/nbt/tags/TAG_Compound.php index ec95ebf84..d69c67937 100644 --- a/src/nbt/tags/TAG_Compound.php +++ b/src/nbt/tags/TAG_Compound.php @@ -22,7 +22,25 @@ class NBTTag_Compound extends NamedNBTTag{ public function getType(){ - return self::TAG_Compound; + return NBTTag::TAG_Compound; + } + + public function __get($name){ + return isset($this->value[$name]) ? $this->value[$name]->getValue() : false; + } + + public function __set($name, $value){ + if(isset($this->value[$name])){ + $this->value[$name]->setValue($value); + } + } + + public function __isset($name){ + return isset($this->value[$name]); + } + + public function __unset($name){ + unset($this->value[$name]); } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_Double.php b/src/nbt/tags/TAG_Double.php index 6b1437e33..f1ee58b2b 100644 --- a/src/nbt/tags/TAG_Double.php +++ b/src/nbt/tags/TAG_Double.php @@ -22,7 +22,7 @@ class NBTTag_Double extends NamedNBTTag{ public function getType(){ - return self::TAG_Double; + return NBTTag::TAG_Double; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_End.php b/src/nbt/tags/TAG_End.php index d917566d3..535fed402 100644 --- a/src/nbt/tags/TAG_End.php +++ b/src/nbt/tags/TAG_End.php @@ -22,7 +22,7 @@ class NBTTag_End extends NBTTag{ public function getType(){ - return self::TAG_End; + return NBTTag::TAG_End; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_Float.php b/src/nbt/tags/TAG_Float.php index d39ccd043..d993f4640 100644 --- a/src/nbt/tags/TAG_Float.php +++ b/src/nbt/tags/TAG_Float.php @@ -22,7 +22,7 @@ class NBTTag_Float extends NamedNBTTag{ public function getType(){ - return self::TAG_Float; + return NBTTag::TAG_Float; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_Int.php b/src/nbt/tags/TAG_Int.php index 3f766bd36..cfbb3d8bf 100644 --- a/src/nbt/tags/TAG_Int.php +++ b/src/nbt/tags/TAG_Int.php @@ -22,7 +22,7 @@ class NBTTag_Int extends NamedNBTTag{ public function getType(){ - return self::TAG_Int; + return NBTTag::TAG_Int; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_Int_Array.php b/src/nbt/tags/TAG_Int_Array.php index 821496351..352cca275 100644 --- a/src/nbt/tags/TAG_Int_Array.php +++ b/src/nbt/tags/TAG_Int_Array.php @@ -22,7 +22,7 @@ class NBTTag_Int_Array extends NamedNBTTag{ public function getType(){ - return self::TAG_Int_Array; + return NBTTag::TAG_Int_Array; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_List.php b/src/nbt/tags/TAG_List.php index 2a72a8c52..bc431b784 100644 --- a/src/nbt/tags/TAG_List.php +++ b/src/nbt/tags/TAG_List.php @@ -22,7 +22,25 @@ class NBTTag_List extends NamedNBTTag{ public function getType(){ - return self::TAG_List; + return NBTTag::TAG_List; + } + + public function __get($name){ + return isset($this->value[$name]) ? $this->value[$name]->getValue() : false; + } + + public function __set($name, $value){ + if(isset($this->value[$name])){ + $this->value[$name]->setValue($value); + } + } + + public function __isset($name){ + return isset($this->value[$name]); + } + + public function __unset($name){ + unset($this->value[$name]); } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_Long.php b/src/nbt/tags/TAG_Long.php index 9c4cf740b..d4f27dcf8 100644 --- a/src/nbt/tags/TAG_Long.php +++ b/src/nbt/tags/TAG_Long.php @@ -22,7 +22,7 @@ class NBTTag_Long extends NamedNBTTag{ public function getType(){ - return self::TAG_Long; + return NBTTag::TAG_Long; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_Short.php b/src/nbt/tags/TAG_Short.php index 994a4f63a..465d989cd 100644 --- a/src/nbt/tags/TAG_Short.php +++ b/src/nbt/tags/TAG_Short.php @@ -22,7 +22,7 @@ class NBTTag_Short extends NamedNBTTag{ public function getType(){ - return self::TAG_Short; + return NBTTag::TAG_Short; } public function read(NBT $nbt){ diff --git a/src/nbt/tags/TAG_String.php b/src/nbt/tags/TAG_String.php index 0950ebb3a..3a56419e1 100644 --- a/src/nbt/tags/TAG_String.php +++ b/src/nbt/tags/TAG_String.php @@ -22,7 +22,7 @@ class NBTTag_String extends NamedNBTTag{ public function getType(){ - return self::TAG_String; + return NBTTag::TAG_String; } public function read(NBT $nbt){ diff --git a/src/world/LevelImport.php b/src/world/LevelImport.php index b2af2f7ab..9c158278d 100644 --- a/src/world/LevelImport.php +++ b/src/world/LevelImport.php @@ -34,21 +34,21 @@ class LevelImport{ $tiles = new Config($this->path."tiles.yml", CONFIG_YAML, unserialize(file_get_contents($this->path."tileEntities.dat"))); $tiles->save(); }elseif(file_exists($this->path."chunks.dat") and file_exists($this->path."level.dat")){ //Pocket - $nbt = new NBT(); - $nbt->load(substr(file_get_contents($this->path."level.dat"), 8)); - $level = array_shift($nbt->tree); - if($level["LevelName"] == ""){ - $level["LevelName"] = "world".time(); + $nbt = new NBT(NBT::LITTLE_ENDIAN); + $nbt->read(substr(file_get_contents($this->path."level.dat"), 8)); + $level = $nbt->getData(); + if($level->LevelName == ""){ + $level->LevelName = "world".time(); } - console("[INFO] Importing Pocket level \"".$level["LevelName"]."\" to PMF format"); - unset($level["Player"]); - $nbt->load(substr(file_get_contents($this->path."entities.dat"), 12)); - $entities = array_shift($nbt->tree); - if(!isset($entities["TileEntities"])){ - $entities["TileEntities"] = array(); + console("[INFO] Importing Pocket level \"".$level->LevelName."\" to PMF format"); + unset($level->Player); + $nbt->read(substr(file_get_contents($this->path."entities.dat"), 12)); + $entities = $nbt->getData(); + if(!isset($entities->TileEntities)){ + $entities->TileEntities = array(); } - $tiles = $entities["TileEntities"]; - $entities = $entities["Entities"]; + $tiles = $entities->TileEntities; + $entities = $entities->Entities; $entities = new Config($this->path."entities.yml", CONFIG_YAML, $entities); $entities->save(); $tiles = new Config($this->path."tiles.yml", CONFIG_YAML, $tiles); diff --git a/src/world/Tile.php b/src/world/Tile.php index c2b89fbef..b994fbcf9 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -356,87 +356,52 @@ class Tile extends Position{ } switch($this->class){ case TILE_CHEST: - $nbt = new NBT(); - $nbt->write(chr(NBT::TAG_COMPOUND)."\x00\x00"); - - $nbt->write(chr(NBT::TAG_STRING)); - $nbt->writeTAG_String("id"); - $nbt->writeTAG_String($this->class); - - $nbt->write(chr(NBT::TAG_INT)); - $nbt->writeTAG_String("x"); - $nbt->writeTAG_Int((int) $this->x); - - $nbt->write(chr(NBT::TAG_INT)); - $nbt->writeTAG_String("y"); - $nbt->writeTAG_Int((int) $this->y); - - $nbt->write(chr(NBT::TAG_INT)); - $nbt->writeTAG_String("z"); - $nbt->writeTAG_Int((int) $this->z); - + $nbt = new NBT(NBT::LITTLE_ENDIAN); if($this->isPaired()){ - $nbt->write(chr(NBT::TAG_INT)); - $nbt->writeTAG_String("pairx"); - $nbt->writeTAG_Int((int) $this->data["pairx"]); - - $nbt->write(chr(NBT::TAG_INT)); - $nbt->writeTAG_String("pairz"); - $nbt->writeTAG_Int((int) $this->data["pairz"]); + $nbt->setData(new NBTTag_Compound("", array( + new NBTTag_String("id", $this->class), + new NBTTag_Int("x", (int) $this->x), + new NBTTag_Int("y", (int) $this->y), + new NBTTag_Int("z", (int) $this->z), + new NBTTag_Int("pairx", (int) $this->data["pairx"]), + new NBTTag_Int("pairz", (int) $this->data["pairz"]), + new NBTTag_End + ))); + }else{ + $nbt->setData(new NBTTag_Compound("", array( + new NBTTag_String("id", $this->class), + new NBTTag_String("x", (int) $this->x), + new NBTTag_String("y", (int) $this->y), + new NBTTag_String("z", (int) $this->z), + new NBTTag_End + ))); } - $nbt->write(chr(NBT::TAG_END)); - $pk = new EntityDataPacket; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; - $pk->namedtag = $nbt->binary; + $pk->namedtag = $nbt->write(); $player->dataPacket($pk); break; case TILE_SIGN: - $nbt = new NBT(); - $nbt->write(chr(NBT::TAG_COMPOUND)."\x00\x00"); - - $nbt->write(chr(NBT::TAG_STRING)); - $nbt->writeTAG_String("Text1"); - $nbt->writeTAG_String($this->data["Text1"]); - - $nbt->write(chr(NBT::TAG_STRING)); - $nbt->writeTAG_String("Text2"); - $nbt->writeTAG_String($this->data["Text2"]); - - $nbt->write(chr(NBT::TAG_STRING)); - $nbt->writeTAG_String("Text3"); - $nbt->writeTAG_String($this->data["Text3"]); - - $nbt->write(chr(NBT::TAG_STRING)); - $nbt->writeTAG_String("Text4"); - $nbt->writeTAG_String($this->data["Text4"]); - - $nbt->write(chr(NBT::TAG_STRING)); - $nbt->writeTAG_String("id"); - $nbt->writeTAG_String($this->class); - - $nbt->write(chr(NBT::TAG_INT)); - $nbt->writeTAG_String("x"); - $nbt->writeTAG_Int((int) $this->x); - - $nbt->write(chr(NBT::TAG_INT)); - $nbt->writeTAG_String("y"); - $nbt->writeTAG_Int((int) $this->y); - - $nbt->write(chr(NBT::TAG_INT)); - $nbt->writeTAG_String("z"); - $nbt->writeTAG_Int((int) $this->z); - - $nbt->write(chr(NBT::TAG_END)); - + $nbt = new NBT(NBT::LITTLE_ENDIAN); + $nbt->setData(new NBTTag_Compound("", array( + new NBTTag_String("Text1", $this->data["Text1"]), + new NBTTag_String("Text2", $this->data["Text2"]), + new NBTTag_String("Text3", $this->data["Text3"]), + new NBTTag_String("Text4", $this->data["Text4"]), + new NBTTag_String("id", $this->class), + new NBTTag_Int("x", (int) $this->x), + new NBTTag_Int("y", (int) $this->y), + new NBTTag_Int("z", (int) $this->z), + new NBTTag_End + ))); $pk = new EntityDataPacket; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; - $pk->namedtag = $nbt->binary; + $pk->namedtag = $nbt->write(); $player->dataPacket($pk); break; } From 21671b133a048573241d0240c41c533d2dbe589d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 26 Feb 2014 15:20:16 +0100 Subject: [PATCH 143/173] New NBT library finished --- src/nbt/tags/TAG_String.php | 2 +- src/world/Tile.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nbt/tags/TAG_String.php b/src/nbt/tags/TAG_String.php index 3a56419e1..deee590e3 100644 --- a/src/nbt/tags/TAG_String.php +++ b/src/nbt/tags/TAG_String.php @@ -26,7 +26,7 @@ class NBTTag_String extends NamedNBTTag{ } public function read(NBT $nbt){ - $this->value = $nbt->get($this->getShort()); + $this->value = $nbt->get($nbt->getShort()); } public function write(NBT $nbt){ diff --git a/src/world/Tile.php b/src/world/Tile.php index b994fbcf9..7a05c7052 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -370,9 +370,9 @@ class Tile extends Position{ }else{ $nbt->setData(new NBTTag_Compound("", array( new NBTTag_String("id", $this->class), - new NBTTag_String("x", (int) $this->x), - new NBTTag_String("y", (int) $this->y), - new NBTTag_String("z", (int) $this->z), + new NBTTag_Int("x", (int) $this->x), + new NBTTag_Int("y", (int) $this->y), + new NBTTag_Int("z", (int) $this->z), new NBTTag_End ))); } From 16eb45925acf82cdfb292f02dc1ee7fe3f26b7a3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 28 Feb 2014 00:12:57 +0100 Subject: [PATCH 144/173] Remove non-implemented chat colors from player messages --- src/Player.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Player.php b/src/Player.php index 67ce4d822..130ca0a63 100644 --- a/src/Player.php +++ b/src/Player.php @@ -2025,6 +2025,7 @@ class Player{ } $this->craftingItems = array(); $this->toCraft = array(); + $packet->message = TextFormat::clean($packet->message); if(trim($packet->message) != "" and strlen($packet->message) <= 255){ $message = $packet->message; if($message{0} === "/"){ //Command From 5bf440d820cd8d0de12c5bd8ddf8f4f5ae7342e9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 1 Mar 2014 21:45:07 +0100 Subject: [PATCH 145/173] Fixed level upgrade and direct save on load --- src/pmf/PMFLevel.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index acb8776cf..540e298c5 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -243,9 +243,8 @@ class PMFLevel extends PMF{ ); $this->chunks[$index] = array(); $this->chunkChange[$index] = array(-1 => false); - for($Y = 0; $Y < $this->chunkInfo[$index][0]; ++$Y){ - $t = 1 << $Y; - if(($this->chunkInfo[$index][0] & $t) === $t){ + for($Y = 0; $Y < 8; ++$Y){ + if(($this->chunkInfo[$index][0] & (1 << $Y)) !== 0){ // 4096 + 2048 + 2048, Block Data, Meta, Light if(strlen($this->chunks[$index][$Y] = gzread($chunk, 8192)) < 8192){ console("[NOTICE] Empty corrupt chunk detected [$X,$Z,:$Y], recovering contents", true, true, 2); From 11f5691104d372a3735724f9e19d6ae4f56d7b31 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 1 Mar 2014 22:08:28 +0100 Subject: [PATCH 146/173] Fixed Pocket format importing --- src/pmf/PMFLevel.php | 51 +++++++++++++++++++++------------------ src/world/LevelImport.php | 1 + 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 540e298c5..08187737a 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -188,32 +188,37 @@ class PMFLevel extends PMF{ @mkdir(dirname($path), 0755); } $this->initCleanChunk($X, $Z); - $ret = $this->level->generateChunk($X, $Z); - $this->saveChunk($X, $Z); - $this->populateChunk($X - 1, $Z); - $this->populateChunk($X + 1, $Z); - $this->populateChunk($X, $Z - 1); - $this->populateChunk($X, $Z + 1); - $this->populateChunk($X + 1, $Z + 1); - $this->populateChunk($X + 1, $Z - 1); - $this->populateChunk($X - 1, $Z - 1); - $this->populateChunk($X - 1, $Z + 1); - return $ret; + if($this->level instanceof Level){ + $ret = $this->level->generateChunk($X, $Z); + $this->saveChunk($X, $Z); + $this->populateChunk($X - 1, $Z); + $this->populateChunk($X + 1, $Z); + $this->populateChunk($X, $Z - 1); + $this->populateChunk($X, $Z + 1); + $this->populateChunk($X + 1, $Z + 1); + $this->populateChunk($X + 1, $Z - 1); + $this->populateChunk($X - 1, $Z - 1); + $this->populateChunk($X - 1, $Z + 1); + return $ret; + } } public function populateChunk($X, $Z){ - if($this->isGenerating === 0 and - !$this->isPopulated($X, $Z) and - $this->isGenerated($X - 1, $Z) and - $this->isGenerated($X, $Z - 1) and - $this->isGenerated($X + 1, $Z) and - $this->isGenerated($X, $Z + 1) and - $this->isGenerated($X + 1, $Z + 1) and - $this->isGenerated($X - 1, $Z - 1) and - $this->isGenerated($X + 1, $Z - 1) and - $this->isGenerated($X - 1, $Z + 1)){ - $this->level->populateChunk($X, $Z); - $this->saveChunk($X, $Z); + if($this->level instanceof Level){ + if($this->isGenerating === 0 and + $this->isChunkLoaded($X, $Z) and + !$this->isPopulated($X, $Z) and + $this->isGenerated($X - 1, $Z) and + $this->isGenerated($X, $Z - 1) and + $this->isGenerated($X + 1, $Z) and + $this->isGenerated($X, $Z + 1) and + $this->isGenerated($X + 1, $Z + 1) and + $this->isGenerated($X - 1, $Z - 1) and + $this->isGenerated($X + 1, $Z - 1) and + $this->isGenerated($X - 1, $Z + 1)){ + $this->level->populateChunk($X, $Z); + $this->saveChunk($X, $Z); + } } } diff --git a/src/world/LevelImport.php b/src/world/LevelImport.php index 9c158278d..aad449491 100644 --- a/src/world/LevelImport.php +++ b/src/world/LevelImport.php @@ -98,6 +98,7 @@ class LevelImport{ foreach($chunk as $Y => $data){ $pmf->setMiniChunk($X, $Z, $Y, $data); } + $pmf->setPopulated($X, $Z); $pmf->saveChunk($X, $Z); } console("[NOTICE] Importing level ".ceil(($Z + 1)/0.16)."%"); From f6daaf76c8840169048969615448548f74b20006 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 2 Mar 2014 02:05:40 +0100 Subject: [PATCH 147/173] Update CONTRIBUTING.md --- CONTRIBUTING.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0675237f..f015b0c40 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,12 +1,12 @@ -![](http://www.pocketmine.net/favicon.png) +![](http://cdn.pocketmine.net/img/PocketMine-MP-h.png) # PocketMine-MP Contribution Guidelines -Before contributing to PocketMine-MP, please read this. +Before contributing to PocketMine-MP, please read this. Also, take a look if your contribution fits the PocketMine-MP goals below. ## I've a question -* For questions, please refer to the _#pocketmine_ or _#mcpedevs_ IRC channel on Freenode. There is a [WebIRC](http://webchat.freenode.net?channels=pockdetmine,mcpedevs&uio=d4) if you want. +* For questions, please refer to the _#pocketmine_ or _#mcpedevs_ IRC channel on Freenode. There is a [WebIRC](http://webchat.freenode.net?channels=pocketmine,mcpedevs&uio=d4) if you want. * You can ask directly to _[@PocketMine](https://twitter.com/PocketMine)_ in Twitter, but don't expect an inmediate reply. ## I want to create an issue @@ -28,8 +28,7 @@ __Thanks for contributing to PocketMine-MP!__ - -#### Code syntax +### Code syntax It is mainly [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) with a few exceptions. * Opening braces MUST go on the same line. @@ -39,7 +38,7 @@ It is mainly [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accept * Long arrays MAY be split across multiple lines, where each subsequent line is indented once. * Files MUST use only the `` tag. -* Code MUST NOT use namespaces. _(This restriction will be lifted on the Alpha_1.4 code)_ +* Code MUST NOT use namespaces. Descriptive and unique class names are enforced. * Strings SHOULD use the double quote `"` except when the single quote is required. * Arrays SHOULD be declared using `array()`, not the `[]` shortcut. * Argument lists MAY NOT be split across multiple lines, except long arrays. @@ -70,4 +69,4 @@ class ExampleClass{ } } -``` \ No newline at end of file +``` From a375a17d17292210ad1a2cabf200708bf47b69f2 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 04:20:59 +0100 Subject: [PATCH 148/173] New compile script --- src/build/compile.sh | 144 ++++++++++++++++++++++++++++--------------- src/build/jenkins.sh | 22 +++---- 2 files changed, 104 insertions(+), 62 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 08ab28930..d5e9ab734 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -41,36 +41,53 @@ export CC="gcc" COMPILE_FOR_ANDROID=no RANLIB=ranlib HAVE_MYSQLI="--with-mysqli=mysqlnd" -if [ "$1" == "rpi" ]; then - [ -z "$march" ] && march=armv6zk; - [ -z "$mtune" ] && mtune=arm1176jzf-s; - [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; - OPENSSL_TARGET="linux-armv4" - echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float" -elif [ "$1" == "mac" ]; then - [ -z "$march" ] && march=prescott; - [ -z "$mtune" ] && mtune=generic; - [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -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="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 - [ -z "$march" ] && march=armv6; - [ -z "$mtune" ] && mtune=cortex-a8; - echo "[INFO] Compiling for iOS ARMv6" - OPENSSL_TARGET="linux-armv4" -elif [ "$1" == "crosscompile" ]; then - HAVE_MYSQLI="--without-mysqli" - if [ "$2" == "android" ] || [ "$2" == "android-armv6" ]; then +COMPILE_TARGET="" +COMPILE_OPENSSL="no" +COMPILE_CURL="default" +COMPILE_LIBEDIT="no" +IS_CROSSCOMPILE="no" +DO_OPTIMIZE="no" +while getopts "t:oj:cxf" OPTION; do + case $OPTION in + t) + echo "[opt] Set target to $OPTARG" + COMPILE_TARGET=$OPTARG + ;; + j) + echo "[opt] Set make threads to $OPTARG" + THREADS=$OPTARG + ;; + o) + echo "[opt] Will compile OpenSSL" + COMPILE_OPENSSL="yes" + ;; + l) + echo "[opt] Will compile libedit" + COMPILE_LIBEDIT="yes" + ;; + c) + echo "[opt] Will force compile cURL" + COMPILE_CURL="yes" + ;; + x) + echo "[opt] Doing cross-compile" + IS_CROSSCOMPILE="yes" + ;; + f) + echo "[opt] Enabling abusive optimizations..." + DO_OPTIMIZE="yes" + FAST_MATH="-fno-math-errno -funsafe-math-optimizations -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail + CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $FAST_MATH -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -msse2 -ftracer -mfpmath=sse -ftree-loop-im -fprefetch-loop-arrays -ftree-parallelize-loops=4" + ;; + \?) + echo "Invalid option: -$OPTION$OPTARG" >&2 + exit 1 + ;; + esac +done + +if [ "$IS_CROSSCOMPILE" == "yes" ]; then + if [ "$COMPILE_TARGET" == "android" ] || [ "$COMPILE_TARGET" == "android-armv6" ]; then COMPILE_FOR_ANDROID=yes [ -z "$march" ] && march=armv6; [ -z "$mtune" ] && mtune=arm1136jf-s; @@ -80,7 +97,8 @@ elif [ "$1" == "crosscompile" ]; then CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" echo "[INFO] Cross-compiling for Android ARMv6" OPENSSL_TARGET="android" - elif [ "$2" == "android-armv7" ]; then + HAVE_MYSQLI="--without-mysqli" + elif [ "$COMPILE_TARGET" == "android-armv7" ]; then COMPILE_FOR_ANDROID=yes [ -z "$march" ] && march=armv7-a; [ -z "$mtune" ] && mtune=cortex-a8; @@ -90,7 +108,8 @@ elif [ "$1" == "crosscompile" ]; then CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" echo "[INFO] Cross-compiling for Android ARMv7" OPENSSL_TARGET="android-armv7" - elif [ "$2" == "rpi" ]; then + HAVE_MYSQLI="--without-mysqli" + elif [ "$COMPILE_TARGET" == "rpi" ]; then TOOLCHAIN_PREFIX="arm-linux-gnueabihf" [ -z "$march" ] && march=armv6zk; [ -z "$mtune" ] && mtune=arm1176jzf-s; @@ -100,7 +119,7 @@ elif [ "$1" == "crosscompile" ]; then [ -z "$CFLAGS" ] && CFLAGS="-uclibc"; OPENSSL_TARGET="linux-armv4" echo "[INFO] Cross-compiling for Raspberry Pi ARMv6zk hard float" - elif [ "$2" == "mac" ]; then + elif [ "$COMPILE_TARGET" == "mac" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-fomit-frame-pointer"; @@ -111,20 +130,49 @@ elif [ "$1" == "crosscompile" ]; then RANLIB=$TOOLCHAIN_PREFIX-ranlib OPENSSL_TARGET="darwin64-x86_64-cc" echo "[INFO] Cross-compiling for Intel MacOS" - elif [ "$2" == "ios" ] || [ "$2" == "ios-armv6" ]; then + elif [ "$COMPILE_TARGET" == "ios" ] || [ "$COMPILE_TARGET" == "ios-armv6" ]; then [ -z "$march" ] && march=armv6; [ -z "$mtune" ] && mtune=generic-armv6; CONFIGURE_FLAGS="--target=arm-apple-darwin10" OPENSSL_TARGET="linux-armv4" - elif [ "$2" == "ios-armv7" ]; then + HAVE_MYSQLI="--without-mysqli" + elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then [ -z "$march" ] && march=armv7-a; [ -z "$mtune" ] && mtune=generic-armv7-a; CONFIGURE_FLAGS="--target=arm-apple-darwin10" OPENSSL_TARGET="linux-armv4" + HAVE_MYSQLI="--without-mysqli" else echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile" exit 1 fi +elif [ "$COMPILE_TARGET" == "rpi" ]; then + [ -z "$march" ] && march=armv6zk; + [ -z "$mtune" ] && mtune=arm1176jzf-s; + [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; + OPENSSL_TARGET="linux-armv4" + echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float" +elif [ "$COMPILE_TARGET" == "mac" ]; then + [ -z "$march" ] && march=prescott; + [ -z "$mtune" ] && mtune=generic; + [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -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="darwin-i386-cc" + echo "[INFO] Compiling for Intel MacOS x86" +elif [ "$COMPILE_TARGET" == "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 [ "$COMPILE_TARGET" == "ios" ]; then + [ -z "$march" ] && march=armv6; + [ -z "$mtune" ] && mtune=cortex-a8; + echo "[INFO] Compiling for iOS ARMv6" + OPENSSL_TARGET="linux-armv4" elif [ -z "$CFLAGS" ]; then if [ `getconf LONG_BIT` == "64" ]; then echo "[INFO] Compiling for current machine using 64-bit" @@ -188,7 +236,7 @@ download_file "http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror" | ta mv php-$PHP_VERSION php echo " done!" -if [ "$1" == "crosscompile" ] || [ "$1" == "rpi" ] || [ "$1" == "mac" ]; then +if [ "$IS_CROSSCOMPILE" == "yes" ] || [ "$COMPILE_TARGET" == "rpi" ] || [ "$COMPILE_TARGET" == "mac" ] || [ "$COMPILE_LIBEDIT" != "yes" ]; then HAVE_LIBEDIT="--without-readline --without-libedit" else #libedit @@ -234,7 +282,7 @@ cd .. rm -r -f ./zlib echo " done!" -if [ "$2" == "openssl" ] || [ "$2" == "curl" ] && [ "$1" != "crosscompile" ]; then +if [ "$COMPILE_OPENSSL" == "yes" ] || [ "$COMPILE_CURL" == "yes" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; then #OpenSSL WITH_SSL="--with-ssl=$DIR/bin/php5" WITH_OPENSSL="--with-openssl=$DIR/bin/php5" @@ -273,7 +321,7 @@ else fi fi -if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ] && [ "$2" != "curl" ]; then +if [ "$(uname -s)" == "Darwin" ] && [ "$IS_CROSSCOMPILE" != "yes" ] && [ "$COMPILE_CURL" != "yes" ]; then HAVE_CURL="shared,/usr" else #curl @@ -354,31 +402,25 @@ rm -r -f ./yaml echo " done!" echo -n "[PHP]" -set +e -if which free >/dev/null; then - MAX_MEMORY=$(free -m | awk '/^Mem:/{print $2}') -else - MAX_MEMORY=$(top -l 1 | grep PhysMem: | awk '{print $10}' | tr -d 'a-zA-Z') -fi -if [ $MAX_MEMORY -gt 512 2>> /dev/null ] && [ "$1" != "crosscompile" ]; then + +if [ "$DO_OPTIMIZE" != "no" ]; then echo -n " enabling optimizations..." - OPTIMIZATION="--enable-inline-optimization " + PHP_OPTIMIZATION="--enable-inline-optimization " else - OPTIMIZATION="--disable-inline-optimization " + PHP_OPTIMIZATION="--disable-inline-optimization " fi -set -e echo -n " checking..." cd php rm -rf ./aclocal.m4 >> "$DIR/install.log" 2>&1 rm -rf ./autom4te.cache/ >> "$DIR/install.log" 2>&1 rm -f ./configure >> "$DIR/install.log" 2>&1 ./buildconf --force >> "$DIR/install.log" 2>&1 -if [ "$1" == "crosscompile" ]; then +if [ "$IS_CROSSCOMPILE" == "yes" ]; then sed -i 's/pthreads_working=no/pthreads_working=yes/' ./configure export LIBS="-lpthread -ldl" CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" fi -RANLIB=$RANLIB ./configure $OPTIMIZATION--prefix="$DIR/bin/php5" \ +RANLIB=$RANLIB ./configure $PHP_OPTIMIZATION--prefix="$DIR/bin/php5" \ --exec-prefix="$DIR/bin/php5" \ --with-curl="$HAVE_CURL" \ --with-zlib="$DIR/bin/php5" \ @@ -422,7 +464,7 @@ make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." make install >> "$DIR/install.log" 2>&1 -if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then +if [ "$(uname -s)" == "Darwin" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; 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 diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 064649b5d..18300b01a 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -32,7 +32,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i386 mtune=none $SCRIPT linux openssl + OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i686 mtune=pentium4 $SCRIPT -t linux -o -j 1 -c -f 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/ @@ -46,7 +46,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit cd $COMPILEDIR/linux/64bit - OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=none $SCRIPT linux openssl + OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=nocona $SCRIPT -t linux -o -j 1 -c -f 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/ @@ -69,7 +69,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" - $SCRIPT mac curl + $SCRIPT -t mac32 -o -j 1 -c -f tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/ cp -r $COMPILEDIR/mac32/{install.log,PHP_${PHP_VERSION}_x86_MacOS.tar.gz,install_data/*} $ARCHIVE/mac32/ @@ -92,7 +92,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" - $SCRIPT mac64 curl + $SCRIPT -t mac64 -o -j 1 -c -f 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 @@ -106,7 +106,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi cd $COMPILEDIR/rpi - $SCRIPT rpi + $SCRIPT -t rpi -o -j 1 -c 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/ @@ -120,7 +120,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6 cd $COMPILEDIR/crosscompile/android-armv6 - $SCRIPT crosscompile android-armv6 + $SCRIPT -t android-armv6 -o -j 1 -c -x 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/ @@ -134,7 +134,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7 cd $COMPILEDIR/crosscompile/android-armv7 - $SCRIPT crosscompile android-armv7 + $SCRIPT -t android-armv7 -o -j 1 -c -x 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/ @@ -156,7 +156,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize" - PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv6 + PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/ if [ ! -f $COMPILEDIR/crosscompile/ios-armv6/bin/php5/bin/php ]; then @@ -177,7 +177,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize" - PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv7 + PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/ if [ ! -f $COMPILEDIR/crosscompile/ios-armv7/bin/php5/bin/php ]; then @@ -190,7 +190,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi cd $COMPILEDIR/crosscompile/rpi - $SCRIPT crosscompile rpi + $SCRIPT -t rpi -o -j 1 -c -x 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/ @@ -204,7 +204,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac cd $COMPILEDIR/crosscompile/mac - $SCRIPT crosscompile mac curl + $SCRIPT -t mac -o -j 1 -c -f -x cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/ if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then From c12c6f1f180fd35a859bc19c4f454134b1f0f77d Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 04:24:41 +0100 Subject: [PATCH 149/173] Added remaining env. vars to compile.sh --- src/build/compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index d5e9ab734..0f1b20495 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -316,7 +316,7 @@ if [ "$COMPILE_OPENSSL" == "yes" ] || [ "$COMPILE_CURL" == "yes" ] && [ "$IS_CRO else WITH_SSL="--with-ssl" WITH_OPENSSL="--without-ssl" - if [ "$(uname -s)" == "Darwin" ] && [ "$1" != "crosscompile" ]; then + if [ "$(uname -s)" == "Darwin" ] && [ "$COMPILE_TARGET" != "crosscompile" ]; then WITH_SSL="--with-darwinssl" fi fi @@ -483,7 +483,7 @@ TIMEZONE=$(date +%Z) 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 [ "$IS_CROSSCOMPILE" != "crosscompile" ]; then echo "zend_extension=opcache.so" >> "$DIR/bin/php5/bin/php.ini" echo "opcache.enable=1" >> "$DIR/bin/php5/bin/php.ini" echo "opcache.enable_cli=1" >> "$DIR/bin/php5/bin/php.ini" From e81f4430cb0f11f3d21f1bcf7da0e7c85b43e22e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 04:29:47 +0100 Subject: [PATCH 150/173] Fixed mac 32-bit compilation --- src/build/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 0f1b20495..96eed6884 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -152,7 +152,7 @@ elif [ "$COMPILE_TARGET" == "rpi" ]; then [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; OPENSSL_TARGET="linux-armv4" echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float" -elif [ "$COMPILE_TARGET" == "mac" ]; then +elif [ "$COMPILE_TARGET" == "mac" ] || [ "$COMPILE_TARGET" == "mac32" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -fomit-frame-pointer -mmacosx-version-min=10.5"; From 7ad7398f2b80fa8422af4ad7ec7b4e56d36fe41b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 04:47:15 +0100 Subject: [PATCH 151/173] Updated PHP version to 5.5.10 --- src/build/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 96eed6884..26cf3117e 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -1,5 +1,5 @@ #!/bin/bash -PHP_VERSION="5.5.9" +PHP_VERSION="5.5.10" ZEND_VM="GOTO" ZLIB_VERSION="1.2.8" From 73b78e14556a29679d4bacceb1dccead2aec8ff5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 04:49:26 +0100 Subject: [PATCH 152/173] Updated helper scripts PHP version to 5.5.10 --- src/build/installer.sh | 8 ++++---- src/build/jenkins.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/build/installer.sh b/src/build/installer.sh index 1bf0a9804..f9140003f 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -1,9 +1,9 @@ #!/bin/bash PMMP_VERSION="" -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" +LINUX_32_BUILD="PHP_5.5.10_x86_Linux" +LINUX_64_BUILD="PHP_5.5.10_x86-64_Linux" +MAC_32_BUILD="PHP_5.5.10_x86_MacOS" +MAC_64_BUILD="PHP_5.5.10_x86-64_MacOS" RPI_BUILD="PHP_5.5.9_ARM_Raspbian_hard" # Temporal build ODROID_BUILD="PHP_5.5.9_ARM_Raspbian_hard" diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 18300b01a..47c893383 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -1,7 +1,7 @@ #!/bin/bash -x export PATH="/opt/arm-2013.05/bin:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/opt/arm-unknown-linux-uclibcgnueabi/bin:$PATH" export THREADS=2 -PHP_VERSION="5.5.9" +PHP_VERSION="5.5.10" #Needed to use aliases shopt -s expand_aliases From ee51f75c78cf145dfc1a350120ead2853d73e234 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 05:15:01 +0100 Subject: [PATCH 153/173] Fixed issues with zlib --- src/build/compile.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 26cf3117e..335189fd7 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -295,10 +295,12 @@ if [ "$COMPILE_OPENSSL" == "yes" ] || [ "$COMPILE_CURL" == "yes" ] && [ "$IS_CRO $OPENSSL_TARGET \ --prefix="$DIR/bin/php5" \ --openssldir="$DIR/bin/php5" \ + zlib \ + zlib-dynamic \ --with-zlib-lib="$DIR/bin/php5/lib" \ --with-zlib-include="$DIR/bin/php5/include" \ - zlib-dynamic \ shared \ + no-ssl2 \ no-asm \ no-hw \ no-engines \ From 052f6417154e25a673e4d8943b6f9c5659e82735 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 06:29:35 +0100 Subject: [PATCH 154/173] Fixed levels not being read properly --- src/pmf/PMFLevel.php | 2 +- src/world/LevelImport.php | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 08187737a..812c82a49 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -179,7 +179,7 @@ class PMFLevel extends PMF{ } private function getChunkPath($X, $Z){ - return dirname($this->file)."/chunks/".(($X ^ $Z) & 0xff)."/".$Z.".".$X.".pmc"; + return dirname($this->file)."/chunks/".(((int) $X ^ (int) $Z) & 0xff)."/".$Z.".".$X.".pmc"; } public function generateChunk($X, $Z){ diff --git a/src/world/LevelImport.php b/src/world/LevelImport.php index aad449491..a2c1ecb7a 100644 --- a/src/world/LevelImport.php +++ b/src/world/LevelImport.php @@ -58,12 +58,12 @@ class LevelImport{ } $pmf = new PMFLevel($this->path."level.pmf", array( - "name" => $level["LevelName"], - "seed" => $level["RandomSeed"], - "time" => $level["Time"], - "spawnX" => $level["SpawnX"], - "spawnY" => $level["SpawnY"], - "spawnZ" => $level["SpawnZ"], + "name" => $level->LevelName, + "seed" => $level->RandomSeed, + "time" => $level->Time, + "spawnX" => $level->SpawnX, + "spawnY" => $level->SpawnY, + "spawnZ" => $level->SpawnZ, "height" => 8, "generator" => "NormalGenerator", "generatorSettings" => "", @@ -84,6 +84,7 @@ class LevelImport{ 6 => "", 7 => "" ); + for($z = 0; $z < 16; ++$z){ for($x = 0; $x < 16; ++$x){ $block = $chunks->getChunkColumn($X, $Z, $x, $z, 0); @@ -95,6 +96,8 @@ class LevelImport{ } } } + + $pmf->initCleanChunk($X, $Z); foreach($chunk as $Y => $data){ $pmf->setMiniChunk($X, $Z, $Y, $data); } @@ -103,6 +106,7 @@ class LevelImport{ } console("[NOTICE] Importing level ".ceil(($Z + 1)/0.16)."%"); } + $pmf->saveData(); $chunks->map = null; $chunks = null; @unlink($this->path."level.dat"); From 8bfd22c9ac066f92c3b96dee557175326dea9016 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 13:34:31 +0100 Subject: [PATCH 155/173] Added arch-specific compile optimizations --- src/build/compile.sh | 9 +++++++-- src/build/jenkins.sh | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 335189fd7..5ae305ddf 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -47,7 +47,7 @@ COMPILE_CURL="default" COMPILE_LIBEDIT="no" IS_CROSSCOMPILE="no" DO_OPTIMIZE="no" -while getopts "t:oj:cxf" OPTION; do +while getopts "t:oj:cxf::" OPTION; do case $OPTION in t) echo "[opt] Set target to $OPTARG" @@ -77,7 +77,12 @@ while getopts "t:oj:cxf" OPTION; do echo "[opt] Enabling abusive optimizations..." DO_OPTIMIZE="yes" FAST_MATH="-fno-math-errno -funsafe-math-optimizations -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail - CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $FAST_MATH -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -msse2 -ftracer -mfpmath=sse -ftree-loop-im -fprefetch-loop-arrays -ftree-parallelize-loops=4" + CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $FAST_MATH -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -ftracer -ftree-loop-im -fprefetch-loop-arrays -ftree-parallelize-loops=4" + if [ "$OPTARG" == "arm" ]; then + CFLAGS="$CFLAGS -mfloat-abi=softfp -mfpu=vfp -fomit-frame-pointer" + else + CFLAGS="$CFLAGS -msse2 -mfpmath=sse" + fi ;; \?) echo "Invalid option: -$OPTION$OPTARG" >&2 diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 47c893383..458c8c066 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -21,11 +21,11 @@ rm -rf $WORKSPACE/compile.sh download_file "https://github.com/PocketMine/PocketMine-MP/raw/master/src/build/compile.sh" > $WORKSPACE/compile.sh chmod +x $WORKSPACE/compile.sh SCRIPT="$WORKSPACE/compile.sh" -ARCHIVE=$WORKSPACE/archive -COMPILEDIR=$WORKSPACE/compile -rm -rf $ARCHIVE $COMPILEDIR -mkdir -p $ARCHIVE -mkdir -p $COMPILEDIR +ARCHIVE="$WORKSPACE/archive" +COMPILEDIR="$WORKSPACE/compile" +rm -rf "$ARCHIVE" "$COMPILEDIR" +mkdir -p "$ARCHIVE" +mkdir -p "$COMPILEDIR" if [ "$COMPILE_LINUX_32BIT" = "true" ]; then @@ -106,7 +106,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi cd $COMPILEDIR/rpi - $SCRIPT -t rpi -o -j 1 -c + $SCRIPT -t rpi -o -j 1 -c -f arm 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/ @@ -120,7 +120,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6 cd $COMPILEDIR/crosscompile/android-armv6 - $SCRIPT -t android-armv6 -o -j 1 -c -x + $SCRIPT -t android-armv6 -o -j 1 -c -x -f arm 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/ @@ -134,7 +134,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7 cd $COMPILEDIR/crosscompile/android-armv7 - $SCRIPT -t android-armv7 -o -j 1 -c -x + $SCRIPT -t android-armv7 -o -j 1 -c -x -f arm 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/ @@ -190,8 +190,8 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi cd $COMPILEDIR/crosscompile/rpi - $SCRIPT -t rpi -o -j 1 -c -x - + $SCRIPT -t rpi -o -j 1 -c -x -f arm + 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 From c7854a3417dff58f8986dd33c9c912396e49ad64 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 15:33:32 +0100 Subject: [PATCH 156/173] Added arm flags --- src/build/compile.sh | 16 +++++++++------- src/build/jenkins.sh | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 5ae305ddf..16bec4ef7 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -76,12 +76,14 @@ while getopts "t:oj:cxf::" OPTION; do f) echo "[opt] Enabling abusive optimizations..." DO_OPTIMIZE="yes" - FAST_MATH="-fno-math-errno -funsafe-math-optimizations -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail - CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $FAST_MATH -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -ftracer -ftree-loop-im -fprefetch-loop-arrays -ftree-parallelize-loops=4" + ffast_math="-fno-math-errno -funsafe-math-optimizations -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail + CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $ffast_math -fno-signed-zeros -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -ftracer -ftree-loop-im -fprefetch-loop-arrays -ftree-parallelize-loops=4 -fomit-frame-pointer" if [ "$OPTARG" == "arm" ]; then - CFLAGS="$CFLAGS -mfloat-abi=softfp -mfpu=vfp -fomit-frame-pointer" - else - CFLAGS="$CFLAGS -msse2 -mfpmath=sse" + CFLAGS="$CFLAGS -mfloat-abi=softfp -mfpu=vfp" + elif [ "$OPTARG" == "x86_64" ]; then + CFLAGS="$CFLAGS -mmx -msse -msse2 -msse3 -mfpmath=sse -free -msahf" + elif [ "$OPTARG" == "x86" ]; then + CFLAGS="$CFLAGS -mmx -msse -msse2 -mfpmath=sse -m128bit-long-double -malign-double" fi ;; \?) @@ -137,13 +139,13 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then echo "[INFO] Cross-compiling for Intel MacOS" elif [ "$COMPILE_TARGET" == "ios" ] || [ "$COMPILE_TARGET" == "ios-armv6" ]; then [ -z "$march" ] && march=armv6; - [ -z "$mtune" ] && mtune=generic-armv6; + [ -z "$mtune" ] && mtune=arm1176jzf-s; CONFIGURE_FLAGS="--target=arm-apple-darwin10" OPENSSL_TARGET="linux-armv4" HAVE_MYSQLI="--without-mysqli" elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then [ -z "$march" ] && march=armv7-a; - [ -z "$mtune" ] && mtune=generic-armv7-a; + [ -z "$mtune" ] && mtune=cortex-a8; CONFIGURE_FLAGS="--target=arm-apple-darwin10" OPENSSL_TARGET="linux-armv4" HAVE_MYSQLI="--without-mysqli" diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 458c8c066..1e17307d4 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -32,7 +32,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit cd $COMPILEDIR/linux/32bit - OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i686 mtune=pentium4 $SCRIPT -t linux -o -j 1 -c -f + OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i686 mtune=pentium4 $SCRIPT -t linux -o -j 1 -c -f x86 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/ @@ -46,7 +46,7 @@ then mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit cd $COMPILEDIR/linux/64bit - OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=nocona $SCRIPT -t linux -o -j 1 -c -f + OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=nocona $SCRIPT -t linux -o -j 1 -c -f x86_64 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/ @@ -69,7 +69,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" - $SCRIPT -t mac32 -o -j 1 -c -f + $SCRIPT -t mac32 -o -j 1 -c -f x86 tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/ cp -r $COMPILEDIR/mac32/{install.log,PHP_${PHP_VERSION}_x86_MacOS.tar.gz,install_data/*} $ARCHIVE/mac32/ @@ -92,7 +92,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" - $SCRIPT -t mac64 -o -j 1 -c -f + $SCRIPT -t mac64 -o -j 1 -c -f x86_64 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 From 604f0681124256e06f4e97ab7e8f9cf097f9460a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 15:41:08 +0100 Subject: [PATCH 157/173] Added iOS flags --- src/build/compile.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 16bec4ef7..2ced2d516 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -3,7 +3,7 @@ PHP_VERSION="5.5.10" ZEND_VM="GOTO" ZLIB_VERSION="1.2.8" -OPENSSL_VERSION="0.9.8y" +OPENSSL_VERSION="1.0.0l" CURL_VERSION="curl-7_35_0" LIBEDIT_VERSION="0.3" PTHREADS_VERSION="0.1.0" @@ -140,14 +140,14 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then elif [ "$COMPILE_TARGET" == "ios" ] || [ "$COMPILE_TARGET" == "ios-armv6" ]; then [ -z "$march" ] && march=armv6; [ -z "$mtune" ] && mtune=arm1176jzf-s; - CONFIGURE_FLAGS="--target=arm-apple-darwin10" - OPENSSL_TARGET="linux-armv4" + CONFIGURE_FLAGS="--target=arm-apple-darwin10 -arch=armv6 -miphoneos-version-min=4.2" + OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then [ -z "$march" ] && march=armv7-a; [ -z "$mtune" ] && mtune=cortex-a8; - CONFIGURE_FLAGS="--target=arm-apple-darwin10" - OPENSSL_TARGET="linux-armv4" + CONFIGURE_FLAGS="--target=arm-apple-darwin10 -arch=armv7-a -miphoneos-version-min=4.2" + OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" else echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile" From bfe746235f35b581b4aa03b8ec5c56687dbef2bf Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 16:20:17 +0100 Subject: [PATCH 158/173] Removed iOS -arch --- src/build/compile.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 2ced2d516..8bc79c34a 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -140,13 +140,13 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then elif [ "$COMPILE_TARGET" == "ios" ] || [ "$COMPILE_TARGET" == "ios-armv6" ]; then [ -z "$march" ] && march=armv6; [ -z "$mtune" ] && mtune=arm1176jzf-s; - CONFIGURE_FLAGS="--target=arm-apple-darwin10 -arch=armv6 -miphoneos-version-min=4.2" + CONFIGURE_FLAGS="--target=arm-apple-darwin10 -miphoneos-version-min=4.2" OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then [ -z "$march" ] && march=armv7-a; [ -z "$mtune" ] && mtune=cortex-a8; - CONFIGURE_FLAGS="--target=arm-apple-darwin10 -arch=armv7-a -miphoneos-version-min=4.2" + CONFIGURE_FLAGS="--target=arm-apple-darwin10 -miphoneos-version-min=4.2" OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" else @@ -176,9 +176,9 @@ elif [ "$COMPILE_TARGET" == "mac64" ]; then OPENSSL_TARGET="darwin64-x86_64-cc" echo "[INFO] Compiling for Intel MacOS x86_64" elif [ "$COMPILE_TARGET" == "ios" ]; then - [ -z "$march" ] && march=armv6; + [ -z "$march" ] && march=armv7-a; [ -z "$mtune" ] && mtune=cortex-a8; - echo "[INFO] Compiling for iOS ARMv6" + echo "[INFO] Compiling for iOS ARMv7" OPENSSL_TARGET="linux-armv4" elif [ -z "$CFLAGS" ]; then if [ `getconf LONG_BIT` == "64" ]; then @@ -289,7 +289,7 @@ cd .. rm -r -f ./zlib echo " done!" -if [ "$COMPILE_OPENSSL" == "yes" ] || [ "$COMPILE_CURL" == "yes" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; then +if [ "$COMPILE_OPENSSL" == "yes" ] || [ "$COMPILE_CURL" != "no" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; then #OpenSSL WITH_SSL="--with-ssl=$DIR/bin/php5" WITH_OPENSSL="--with-openssl=$DIR/bin/php5" From 2916b0f04997d5fdce825ea935a045b66c1a5700 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 16:22:16 +0100 Subject: [PATCH 159/173] Added Phar extension to PHP --- src/build/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 8bc79c34a..e9de8a487 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -444,11 +444,11 @@ $HAVE_LIBEDIT \ --disable-cgi \ --disable-session \ --disable-debug \ ---disable-phar \ --disable-pdo \ --without-pear \ --without-iconv \ --without-pdo-sqlite \ +--enable-phar \ --enable-ctype \ --enable-sockets \ --enable-shared=no \ From 4a2dea4e45d5ee21d24cae32d76b48abf0240c6b Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 16:25:40 +0100 Subject: [PATCH 160/173] Added correct toolchain for iOS --- src/build/compile.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index e9de8a487..bcf7a576b 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -140,13 +140,17 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then elif [ "$COMPILE_TARGET" == "ios" ] || [ "$COMPILE_TARGET" == "ios-armv6" ]; then [ -z "$march" ] && march=armv6; [ -z "$mtune" ] && mtune=arm1176jzf-s; - CONFIGURE_FLAGS="--target=arm-apple-darwin10 -miphoneos-version-min=4.2" + TOOLCHAIN_PREFIX="arm-apple-darwin10" + export CC="$TOOLCHAIN_PREFIX-gcc" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=arm-apple-darwin10 -miphoneos-version-min=4.2" OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then [ -z "$march" ] && march=armv7-a; [ -z "$mtune" ] && mtune=cortex-a8; - CONFIGURE_FLAGS="--target=arm-apple-darwin10 -miphoneos-version-min=4.2" + TOOLCHAIN_PREFIX="arm-apple-darwin10" + export CC="$TOOLCHAIN_PREFIX-gcc" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=arm-apple-darwin10 -miphoneos-version-min=4.2" OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" else From 971e18d9b0f8644289576943e2add64ba0beb1b8 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 16:33:29 +0100 Subject: [PATCH 161/173] Added php.ini Phar directives --- src/build/compile.sh | 6 ++++-- src/build/installer.sh | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index bcf7a576b..c77ac12cd 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -142,7 +142,7 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then [ -z "$mtune" ] && mtune=arm1176jzf-s; TOOLCHAIN_PREFIX="arm-apple-darwin10" export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=arm-apple-darwin10 -miphoneos-version-min=4.2" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2" OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then @@ -150,7 +150,7 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then [ -z "$mtune" ] && mtune=cortex-a8; TOOLCHAIN_PREFIX="arm-apple-darwin10" export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=arm-apple-darwin10 -miphoneos-version-min=4.2" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2" OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" else @@ -496,6 +496,8 @@ TIMEZONE=$(date +%Z) 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" +echo "phar.readonly=0" >> "$DIR/bin/php5/bin/php.ini" +echo "phar.require_hash=1" >> "$DIR/bin/php5/bin/php.ini" if [ "$IS_CROSSCOMPILE" != "crosscompile" ]; then echo "zend_extension=opcache.so" >> "$DIR/bin/php5/bin/php.ini" echo "opcache.enable=1" >> "$DIR/bin/php5/bin/php.ini" diff --git a/src/build/installer.sh b/src/build/installer.sh index f9140003f..3a27e9261 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -95,6 +95,8 @@ else 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 "phar.readonly=0" >> "./bin/php5/bin/php.ini" + echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini" echo " done" alldone=yes else @@ -127,6 +129,8 @@ else 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 "phar.readonly=0" >> "./bin/php5/bin/php.ini" + echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini" echo " done" alldone=yes else @@ -159,6 +163,8 @@ else 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 "phar.readonly=0" >> "./bin/php5/bin/php.ini" + echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini" echo " done" alldone=yes else @@ -185,6 +191,8 @@ else 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 "phar.readonly=0" >> "./bin/php5/bin/php.ini" + echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini" echo " done" alldone=yes else @@ -217,6 +225,8 @@ else 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 "phar.readonly=0" >> "./bin/php5/bin/php.ini" + echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini" echo " done" alldone=yes else From 612cf98a08ac50ec3a2b654d2d4695db004435c4 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 16:42:18 +0100 Subject: [PATCH 162/173] typo fix --- src/build/installer.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/build/installer.sh b/src/build/installer.sh index 3a27e9261..873a436f9 100644 --- a/src/build/installer.sh +++ b/src/build/installer.sh @@ -74,7 +74,7 @@ rm -f -r PocketMine-MP-$PMMP_VERSION/ rm -f ./start.cmd chmod +x ./start.sh chmod +x ./src/build/compile.sh -if [ $update == on ]; then +if [ "$update" == "on" ]; then echo "[3/3] Skipping PHP recompilation due to user request" else echo -n "[3/3] Obtaining PHP:" @@ -84,7 +84,7 @@ else UNAME_M=$(uname -m) IS_IOS=$(expr match $UNAME_M 'iP[a-zA-Z0-9,]*' 2> /dev/null) set -e - if [[ $IS_IOS -gt 0 ]]; then + if [[ "$IS_IOS" -gt 0 ]]; then rm -r -f bin/ >> /dev/null 2>&1 echo -n "[3/3] iOS PHP build available, downloading $IOS_BUILD.tar.gz..." download_file "http://sourceforge.net/projects/pocketmine/files/builds/$IOS_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 @@ -92,6 +92,7 @@ else echo -n " checking..." if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then echo -n " regenerating php.ini..." + TIMEZONE=$(date +%Z) 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" @@ -106,16 +107,17 @@ else rm -r -f bin/ >> /dev/null 2>&1 if [ `getconf LONG_BIT` == "64" ]; then echo -n "[3/3] MacOS 64-bit PHP build available, downloading $MAC_64_BUILD.tar.gz..." - MAC_BUILD=$MAC_64_BUILD + MAC_BUILD="$MAC_64_BUILD" else echo -n "[3/3] MacOS 32-bit PHP build available, downloading $MAC_32_BUILD.tar.gz..." - MAC_BUILD=$MAC_32_BUILD + MAC_BUILD="$MAC_32_BUILD" fi download_file "http://sourceforge.net/projects/pocketmine/files/builds/$MAC_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 chmod +x ./bin/php5/bin/* echo -n " checking..." if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then echo -n " regenerating php.ini..." + TIMEZONE=$(date +%Z) 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" @@ -142,7 +144,7 @@ else IS_RPI=$? grep -q ODROID /proc/cpuinfo > /dev/null 2>&1 IS_ODROID=$? - if [ $IS_RPI -eq 0 ] && [ "$forcecompile" == "off" ]; then + if [ "$IS_RPI" -eq 0 ] && [ "$forcecompile" == "off" ]; then rm -r -f bin/ >> /dev/null 2>&1 echo -n "[3/3] Raspberry Pi PHP build available, downloading $RPI_BUILD.tar.gz..." download_file "http://sourceforge.net/projects/pocketmine/files/builds/$RPI_BUILD.tar.gz" | tar -zx > /dev/null 2>&1 @@ -150,6 +152,7 @@ else echo -n " checking..." if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then echo -n " regenerating php.ini..." + TIMEZONE=$(date +%Z) 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" @@ -170,7 +173,7 @@ else else echo " invalid build detected" fi - elif [ $IS_ODROID -eq 0 ] && [ "$forcecompile" == "off" ]; then + 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 @@ -202,10 +205,10 @@ else 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 + 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 + 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/* From 8c02555a8d8f51227724d1dc1325a4fc8c0a0a88 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 17:02:05 +0100 Subject: [PATCH 163/173] Added sed -i ".backup" --- src/build/compile.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index c77ac12cd..ce6029df2 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -429,7 +429,7 @@ rm -rf ./autom4te.cache/ >> "$DIR/install.log" 2>&1 rm -f ./configure >> "$DIR/install.log" 2>&1 ./buildconf --force >> "$DIR/install.log" 2>&1 if [ "$IS_CROSSCOMPILE" == "yes" ]; then - sed -i 's/pthreads_working=no/pthreads_working=yes/' ./configure + sed -i ".backup" 's/pthreads_working=no/pthreads_working=yes/' ./configure export LIBS="-lpthread -ldl" CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" fi @@ -471,7 +471,7 @@ $HAVE_MYSQLI \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." if [ $COMPILE_FOR_ANDROID == "yes" ]; then - sed -i 's/-export-dynamic/-all-static/g' Makefile + sed -i ".backup" 's/-export-dynamic/-all-static/g' Makefile fi make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." From a74f5809c7343f09257204795efd7db3347725b6 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 17:38:36 +0100 Subject: [PATCH 164/173] Added -lresolv --- src/build/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index ce6029df2..862b80d64 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -430,7 +430,7 @@ rm -f ./configure >> "$DIR/install.log" 2>&1 ./buildconf --force >> "$DIR/install.log" 2>&1 if [ "$IS_CROSSCOMPILE" == "yes" ]; then sed -i ".backup" 's/pthreads_working=no/pthreads_working=yes/' ./configure - export LIBS="-lpthread -ldl" + export LIBS="-lpthread -ldl -lresolv" CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" fi RANLIB=$RANLIB ./configure $PHP_OPTIMIZATION--prefix="$DIR/bin/php5" \ From 47ad8b6fac21d27a8136200c38e6bd6905cc1e55 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 18:26:12 +0100 Subject: [PATCH 165/173] Added PHP_VAR_NAME to crosscompile --- src/build/compile.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/build/compile.sh b/src/build/compile.sh index 862b80d64..0eb484f95 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -94,6 +94,8 @@ while getopts "t:oj:cxf::" OPTION; do done if [ "$IS_CROSSCOMPILE" == "yes" ]; then + export PHP_VAR_NAME="php" + export php_var_name="php" if [ "$COMPILE_TARGET" == "android" ] || [ "$COMPILE_TARGET" == "android-armv6" ]; then COMPILE_FOR_ANDROID=yes [ -z "$march" ] && march=armv6; From 5ad511cd113562bcb05e12ed4f3b62a987b7610c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 19:12:06 +0100 Subject: [PATCH 166/173] Disabled phar cmdtools generation on crosscompile --- src/build/compile.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 0eb484f95..c501020d0 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -94,8 +94,6 @@ while getopts "t:oj:cxf::" OPTION; do done if [ "$IS_CROSSCOMPILE" == "yes" ]; then - export PHP_VAR_NAME="php" - export php_var_name="php" if [ "$COMPILE_TARGET" == "android" ] || [ "$COMPILE_TARGET" == "android-armv6" ]; then COMPILE_FOR_ANDROID=yes [ -z "$march" ] && march=armv6; @@ -431,7 +429,7 @@ rm -rf ./autom4te.cache/ >> "$DIR/install.log" 2>&1 rm -f ./configure >> "$DIR/install.log" 2>&1 ./buildconf --force >> "$DIR/install.log" 2>&1 if [ "$IS_CROSSCOMPILE" == "yes" ]; then - sed -i ".backup" 's/pthreads_working=no/pthreads_working=yes/' ./configure + sed -i=".backup" 's/pthreads_working=no/pthreads_working=yes/' ./configure export LIBS="-lpthread -ldl -lresolv" CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" fi @@ -472,8 +470,12 @@ $HAVE_MYSQLI \ --with-zend-vm=$ZEND_VM \ $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 echo -n " compiling..." -if [ $COMPILE_FOR_ANDROID == "yes" ]; then - sed -i ".backup" 's/-export-dynamic/-all-static/g' Makefile +if [ "$COMPILE_FOR_ANDROID" == "yes" ]; then + sed -i=".backup" 's/-export-dynamic/-all-static/g' Makefile +fi +if [ "$IS_CROSSCOMPILE" == "yes" ]; then + sed -i=".backup" 's/PHP_BINARIES. pharcmd$/PHP_BINARIES)/g' Makefile + sed -i=".backup" 's/install-programs install-pharcmd$/install-programs/g' Makefile fi make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." From e246e10a82fb347fbd3661c8c9ae4ddd92a5d8ad Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 20:04:18 +0100 Subject: [PATCH 167/173] Added NEON optimizations to iOS --- src/build/compile.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/build/compile.sh b/src/build/compile.sh index c501020d0..15f83afaf 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -153,6 +153,9 @@ if [ "$IS_CROSSCOMPILE" == "yes" ]; then CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2" OPENSSL_TARGET="BSD-generic32" HAVE_MYSQLI="--without-mysqli" + if [ "$DO_OPTIMIZE" == "yes" ]; then + CFLAGS="$CFLAGS -mfpu=neon" + fi else echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile" exit 1 From a817234aa8a8f289eaf99b202e61a484e3f0a0aa Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 7 Mar 2014 23:29:28 +0100 Subject: [PATCH 168/173] Do not generate Phar utilities by default, only generate extension --- src/build/compile.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 15f83afaf..c7eb54f08 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -51,11 +51,11 @@ while getopts "t:oj:cxf::" OPTION; do case $OPTION in t) echo "[opt] Set target to $OPTARG" - COMPILE_TARGET=$OPTARG + COMPILE_TARGET="$OPTARG" ;; j) echo "[opt] Set make threads to $OPTARG" - THREADS=$OPTARG + THREADS="$OPTARG" ;; o) echo "[opt] Will compile OpenSSL" @@ -476,10 +476,8 @@ echo -n " compiling..." if [ "$COMPILE_FOR_ANDROID" == "yes" ]; then sed -i=".backup" 's/-export-dynamic/-all-static/g' Makefile fi -if [ "$IS_CROSSCOMPILE" == "yes" ]; then - sed -i=".backup" 's/PHP_BINARIES. pharcmd$/PHP_BINARIES)/g' Makefile - sed -i=".backup" 's/install-programs install-pharcmd$/install-programs/g' Makefile -fi +sed -i=".backup" 's/PHP_BINARIES. pharcmd$/PHP_BINARIES)/g' Makefile +sed -i=".backup" 's/install-programs install-pharcmd$/install-programs/g' Makefile make -j $THREADS >> "$DIR/install.log" 2>&1 echo -n " installing..." make install >> "$DIR/install.log" 2>&1 From ba21d7f66191cc95c1748caace89a1ba3226e534 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 8 Mar 2014 05:35:31 +0100 Subject: [PATCH 169/173] Update compile.sh --- src/build/compile.sh | 683 ++++++++++++------------------------------- 1 file changed, 180 insertions(+), 503 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index c7eb54f08..1e17307d4 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -1,35 +1,15 @@ -#!/bin/bash +#!/bin/bash -x +export PATH="/opt/arm-2013.05/bin:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/opt/arm-unknown-linux-uclibcgnueabi/bin:$PATH" +export THREADS=2 PHP_VERSION="5.5.10" -ZEND_VM="GOTO" - -ZLIB_VERSION="1.2.8" -OPENSSL_VERSION="1.0.0l" -CURL_VERSION="curl-7_35_0" -LIBEDIT_VERSION="0.3" -PTHREADS_VERSION="0.1.0" -PHPYAML_VERSION="1.1.1" -YAML_VERSION="0.1.4" - -echo "[PocketMine] PHP compiler for Linux, MacOS and Android" -DIR="$(pwd)" -date > "$DIR/install.log" 2>&1 -uname -a >> "$DIR/install.log" 2>&1 -echo "[INFO] Checking dependecies" -type make >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"make\""; read -p "Press [Enter] to continue..."; exit 1; } -type autoconf >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"autoconf\""; read -p "Press [Enter] to continue..."; exit 1; } -type automake >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"automake\""; read -p "Press [Enter] to continue..."; exit 1; } -type libtool >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"libtool\""; read -p "Press [Enter] to continue..."; exit 1; } -type m4 >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"m4\""; read -p "Press [Enter] to continue..."; exit 1; } -type wget >> "$DIR/install.log" 2>&1 || type curl >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"wget\" or \"curl\""; read -p "Press [Enter] to continue..."; exit 1; } -type getconf >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"getconf\""; read -p "Press [Enter] to continue..."; exit 1; } #Needed to use aliases shopt -s expand_aliases -type wget >> "$DIR/install.log" 2>&1 +type wget > /dev/null 2>&1 if [ $? -eq 0 ]; then alias download_file="wget --no-check-certificate -q -O -" else - type curl >> "$DIR/install.log" 2>&1 + type curl >> /dev/null 2>&1 if [ $? -eq 0 ]; then alias download_file="curl --insecure --silent --location" else @@ -37,500 +17,197 @@ else fi fi -export CC="gcc" -COMPILE_FOR_ANDROID=no -RANLIB=ranlib -HAVE_MYSQLI="--with-mysqli=mysqlnd" -COMPILE_TARGET="" -COMPILE_OPENSSL="no" -COMPILE_CURL="default" -COMPILE_LIBEDIT="no" -IS_CROSSCOMPILE="no" -DO_OPTIMIZE="no" -while getopts "t:oj:cxf::" OPTION; do - case $OPTION in - t) - echo "[opt] Set target to $OPTARG" - COMPILE_TARGET="$OPTARG" - ;; - j) - echo "[opt] Set make threads to $OPTARG" - THREADS="$OPTARG" - ;; - o) - echo "[opt] Will compile OpenSSL" - COMPILE_OPENSSL="yes" - ;; - l) - echo "[opt] Will compile libedit" - COMPILE_LIBEDIT="yes" - ;; - c) - echo "[opt] Will force compile cURL" - COMPILE_CURL="yes" - ;; - x) - echo "[opt] Doing cross-compile" - IS_CROSSCOMPILE="yes" - ;; - f) - echo "[opt] Enabling abusive optimizations..." - DO_OPTIMIZE="yes" - ffast_math="-fno-math-errno -funsafe-math-optimizations -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail - CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $ffast_math -fno-signed-zeros -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -ftracer -ftree-loop-im -fprefetch-loop-arrays -ftree-parallelize-loops=4 -fomit-frame-pointer" - if [ "$OPTARG" == "arm" ]; then - CFLAGS="$CFLAGS -mfloat-abi=softfp -mfpu=vfp" - elif [ "$OPTARG" == "x86_64" ]; then - CFLAGS="$CFLAGS -mmx -msse -msse2 -msse3 -mfpmath=sse -free -msahf" - elif [ "$OPTARG" == "x86" ]; then - CFLAGS="$CFLAGS -mmx -msse -msse2 -mfpmath=sse -m128bit-long-double -malign-double" - fi - ;; - \?) - echo "Invalid option: -$OPTION$OPTARG" >&2 - exit 1 - ;; - esac -done +rm -rf $WORKSPACE/compile.sh +download_file "https://github.com/PocketMine/PocketMine-MP/raw/master/src/build/compile.sh" > $WORKSPACE/compile.sh +chmod +x $WORKSPACE/compile.sh +SCRIPT="$WORKSPACE/compile.sh" +ARCHIVE="$WORKSPACE/archive" +COMPILEDIR="$WORKSPACE/compile" +rm -rf "$ARCHIVE" "$COMPILEDIR" +mkdir -p "$ARCHIVE" +mkdir -p "$COMPILEDIR" -if [ "$IS_CROSSCOMPILE" == "yes" ]; then - if [ "$COMPILE_TARGET" == "android" ] || [ "$COMPILE_TARGET" == "android-armv6" ]; then - COMPILE_FOR_ANDROID=yes - [ -z "$march" ] && march=armv6; - [ -z "$mtune" ] && mtune=arm1136jf-s; - TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" - export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" - CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" - echo "[INFO] Cross-compiling for Android ARMv6" - OPENSSL_TARGET="android" - HAVE_MYSQLI="--without-mysqli" - elif [ "$COMPILE_TARGET" == "android-armv7" ]; then - COMPILE_FOR_ANDROID=yes - [ -z "$march" ] && march=armv7-a; - [ -z "$mtune" ] && mtune=cortex-a8; - TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" - export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" - CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" - echo "[INFO] Cross-compiling for Android ARMv7" - OPENSSL_TARGET="android-armv7" - HAVE_MYSQLI="--without-mysqli" - elif [ "$COMPILE_TARGET" == "rpi" ]; then - TOOLCHAIN_PREFIX="arm-linux-gnueabihf" - [ -z "$march" ] && march=armv6zk; - [ -z "$mtune" ] && mtune=arm1176jzf-s; - [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; - export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" - [ -z "$CFLAGS" ] && CFLAGS="-uclibc"; - OPENSSL_TARGET="linux-armv4" - echo "[INFO] Cross-compiling for Raspberry Pi ARMv6zk hard float" - elif [ "$COMPILE_TARGET" == "mac" ]; then - [ -z "$march" ] && march=prescott; - [ -z "$mtune" ] && mtune=generic; - [ -z "$CFLAGS" ] && CFLAGS="-fomit-frame-pointer"; - TOOLCHAIN_PREFIX="i686-apple-darwin10" - export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" - #zlib doesn't use the correct ranlib - RANLIB=$TOOLCHAIN_PREFIX-ranlib - OPENSSL_TARGET="darwin64-x86_64-cc" - echo "[INFO] Cross-compiling for Intel MacOS" - elif [ "$COMPILE_TARGET" == "ios" ] || [ "$COMPILE_TARGET" == "ios-armv6" ]; then - [ -z "$march" ] && march=armv6; - [ -z "$mtune" ] && mtune=arm1176jzf-s; - TOOLCHAIN_PREFIX="arm-apple-darwin10" - export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2" - OPENSSL_TARGET="BSD-generic32" - HAVE_MYSQLI="--without-mysqli" - elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then - [ -z "$march" ] && march=armv7-a; - [ -z "$mtune" ] && mtune=cortex-a8; - TOOLCHAIN_PREFIX="arm-apple-darwin10" - export CC="$TOOLCHAIN_PREFIX-gcc" - CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2" - OPENSSL_TARGET="BSD-generic32" - HAVE_MYSQLI="--without-mysqli" - if [ "$DO_OPTIMIZE" == "yes" ]; then - CFLAGS="$CFLAGS -mfpu=neon" - fi - else - echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile" +if [ "$COMPILE_LINUX_32BIT" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit + cd $COMPILEDIR/linux/32bit + + OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i686 mtune=pentium4 $SCRIPT -t linux -o -j 1 -c -f x86 + + 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 exit 1 fi -elif [ "$COMPILE_TARGET" == "rpi" ]; then - [ -z "$march" ] && march=armv6zk; - [ -z "$mtune" ] && mtune=arm1176jzf-s; - [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; - OPENSSL_TARGET="linux-armv4" - echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float" -elif [ "$COMPILE_TARGET" == "mac" ] || [ "$COMPILE_TARGET" == "mac32" ]; then - [ -z "$march" ] && march=prescott; - [ -z "$mtune" ] && mtune=generic; - [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -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="darwin-i386-cc" - echo "[INFO] Compiling for Intel MacOS x86" -elif [ "$COMPILE_TARGET" == "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 [ "$COMPILE_TARGET" == "ios" ]; then - [ -z "$march" ] && march=armv7-a; - [ -z "$mtune" ] && mtune=cortex-a8; - echo "[INFO] Compiling for iOS ARMv7" - OPENSSL_TARGET="linux-armv4" -elif [ -z "$CFLAGS" ]; then - if [ `getconf LONG_BIT` == "64" ]; then - echo "[INFO] Compiling for current machine using 64-bit" - CFLAGS="-m64 $CFLAGS" - OPENSSL_TARGET="linux-x86_64" - else - echo "[INFO] Compiling for current machine using 32-bit" - CFLAGS="-m32 $CFLAGS" - OPENSSL_TARGET="linux-generic32" +fi + +if [ "$COMPILE_LINUX_64BIT" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit + cd $COMPILEDIR/linux/64bit + + OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=nocona $SCRIPT -t linux -o -j 1 -c -f x86_64 + + 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 + exit 1 fi fi -cat > test.c <<'CTEST' -#include -int main(void){ - printf("Hello world\n"); - return 0; -} -CTEST - - -type $CC >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"$CC\""; read -p "Press [Enter] to continue..."; exit 1; } - -[ -z "$THREADS" ] && THREADS=1; -[ -z "$march" ] && march=native; -[ -z "$mtune" ] && mtune=native; -[ -z "$CFLAGS" ] && CFLAGS=""; -[ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib'"; -[ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS=""; - - -if [ "$mtune" != "none" ]; then - $CC -march=$march -mtune=$mtune $CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 - if [ $? -eq 0 ]; then - CFLAGS="-march=$march -mtune=$mtune -fno-gcse $CFLAGS" - fi -else - $CC -march=$march $CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 - if [ $? -eq 0 ]; then - CFLAGS="-march=$march -fno-gcse $CFLAGS" +if [ "$COMPILE_MAC_32" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/mac32 + cd $COMPILEDIR/mac32 + + 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 -t mac32 -o -j 1 -c -f x86 + + tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/ + 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 -rm test.* >> "$DIR/install.log" 2>&1 -rm test >> "$DIR/install.log" 2>&1 - -export CFLAGS="-O2 $CFLAGS" -export LDFLAGS="$LDFLAGS" - -rm -r -f install_data/ >> "$DIR/install.log" 2>&1 -rm -r -f bin/ >> "$DIR/install.log" 2>&1 -mkdir -m 0755 install_data >> "$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 -set -e - -#PHP 5 -echo -n "[PHP] downloading $PHP_VERSION..." -download_file "http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror" | tar -zx >> "$DIR/install.log" 2>&1 -mv php-$PHP_VERSION php -echo " done!" - -if [ "$IS_CROSSCOMPILE" == "yes" ] || [ "$COMPILE_TARGET" == "rpi" ] || [ "$COMPILE_TARGET" == "mac" ] || [ "$COMPILE_LIBEDIT" != "yes" ]; then - HAVE_LIBEDIT="--without-readline --without-libedit" -else - #libedit - set +e - 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 - echo -n " checking..." - cd libedit - ./configure --prefix="$DIR/bin/php5" \ - --enable-shared=yes \ - --enable-static=no \ - $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 - echo -n " compiling..." - if make -j $THREADS >> "$DIR/install.log" 2>&1; then - echo -n " installing..." - make install >> "$DIR/install.log" 2>&1 - HAVE_LIBEDIT="--without-readline --with-libedit=\"$DIR/bin/php5\"" - else - echo -n " disabling..." - HAVE_LIBEDIT="--without-readline --without-libedit" - fi - echo -n " cleaning..." - cd .. - rm -r -f ./libedit - echo " done!" - set -e -fi - -#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..." -mv zlib-$ZLIB_VERSION zlib -echo -n " checking..." -cd zlib -RANLIB=$RANLIB ./configure --prefix="$DIR/bin/php5" \ ---shared >> "$DIR/install.log" 2>&1 -echo -n " compiling..." -make -j $THREADS >> "$DIR/install.log" 2>&1 -echo -n " installing..." -make install >> "$DIR/install.log" 2>&1 -echo -n " cleaning..." -cd .. -rm -r -f ./zlib -echo " done!" - -if [ "$COMPILE_OPENSSL" == "yes" ] || [ "$COMPILE_CURL" != "no" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; 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" \ - zlib \ - zlib-dynamic \ - --with-zlib-lib="$DIR/bin/php5/lib" \ - --with-zlib-include="$DIR/bin/php5/include" \ - shared \ - no-ssl2 \ - 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" ] && [ "$COMPILE_TARGET" != "crosscompile" ]; then - WITH_SSL="--with-darwinssl" +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 -t mac64 -o -j 1 -c -f x86_64 + + 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 fi fi -if [ "$(uname -s)" == "Darwin" ] && [ "$IS_CROSSCOMPILE" != "yes" ] && [ "$COMPILE_CURL" != "yes" ]; then - HAVE_CURL="shared,/usr" -else - #curl - echo -n "[cURL] downloading $CURL_VERSION..." - download_file "https://github.com/bagder/curl/archive/$CURL_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 - mv curl-$CURL_VERSION curl - echo -n " checking..." - cd curl - if [ ! -f ./configure ]; then - ./buildconf --force >> "$DIR/install.log" 2>&1 +if [ "$COMPILE_RPI" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi + cd $COMPILEDIR/rpi + + $SCRIPT -t rpi -o -j 1 -c -f arm + + 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 + exit 1 fi - RANLIB=$RANLIB ./configure --disable-dependency-tracking \ - --enable-ipv6 \ - --enable-optimize \ - --enable-http \ - --enable-ftp \ - --disable-dict \ - --enable-file \ - --without-librtmp \ - --disable-gopher \ - --disable-imap \ - --disable-pop3 \ - --disable-rtsp \ - --disable-smtp \ - --disable-telnet \ - --disable-tftp \ - --disable-ldap \ - --disable-ldaps \ - --without-libidn \ - --with-zlib="$DIR/bin/php5" \ - $WITH_SSL \ - --enable-threaded-resolver \ - --prefix="$DIR/bin/php5" \ - --disable-shared \ - --enable-static \ - $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 - echo -n " compiling..." - make -j $THREADS >> "$DIR/install.log" 2>&1 - echo -n " installing..." - make install >> "$DIR/install.log" 2>&1 - echo -n " cleaning..." - cd .. - rm -r -f ./curl - echo " done!" - HAVE_CURL="$DIR/bin/php5" fi -#pthreads -echo -n "[PHP pthreads] downloading $PTHREADS_VERSION..." -download_file "http://pecl.php.net/get/pthreads-$PTHREADS_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1 -mv pthreads-$PTHREADS_VERSION "$DIR/install_data/php/ext/pthreads" -echo " done!" - -#PHP YAML -echo -n "[PHP YAML] downloading $PHPYAML_VERSION..." -download_file "http://pecl.php.net/get/yaml-$PHPYAML_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1 -mv yaml-$PHPYAML_VERSION "$DIR/install_data/php/ext/yaml" -echo " done!" - -#YAML -echo -n "[YAML] downloading $YAML_VERSION..." -download_file "http://pyyaml.org/download/libyaml/yaml-$YAML_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 -mv yaml-$YAML_VERSION yaml -echo -n " checking..." -cd yaml -RANLIB=$RANLIB ./configure \ ---prefix="$DIR/bin/php5" \ ---disable-static \ ---enable-shared \ -$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 -echo -n " compiling..." -make -j $THREADS >> "$DIR/install.log" 2>&1 -echo -n " installing..." -make install >> "$DIR/install.log" 2>&1 -echo -n " cleaning..." -cd .. -rm -r -f ./yaml -echo " done!" - -echo -n "[PHP]" - -if [ "$DO_OPTIMIZE" != "no" ]; then - echo -n " enabling optimizations..." - PHP_OPTIMIZATION="--enable-inline-optimization " -else - PHP_OPTIMIZATION="--disable-inline-optimization " -fi -echo -n " checking..." -cd php -rm -rf ./aclocal.m4 >> "$DIR/install.log" 2>&1 -rm -rf ./autom4te.cache/ >> "$DIR/install.log" 2>&1 -rm -f ./configure >> "$DIR/install.log" 2>&1 -./buildconf --force >> "$DIR/install.log" 2>&1 -if [ "$IS_CROSSCOMPILE" == "yes" ]; then - sed -i=".backup" 's/pthreads_working=no/pthreads_working=yes/' ./configure - export LIBS="-lpthread -ldl -lresolv" - CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" -fi -RANLIB=$RANLIB ./configure $PHP_OPTIMIZATION--prefix="$DIR/bin/php5" \ ---exec-prefix="$DIR/bin/php5" \ ---with-curl="$HAVE_CURL" \ ---with-zlib="$DIR/bin/php5" \ ---with-yaml="$DIR/bin/php5" \ -$HAVE_LIBEDIT \ ---disable-libxml \ ---disable-xml \ ---disable-dom \ ---disable-simplexml \ ---disable-xmlreader \ ---disable-xmlwriter \ ---disable-cgi \ ---disable-session \ ---disable-debug \ ---disable-pdo \ ---without-pear \ ---without-iconv \ ---without-pdo-sqlite \ ---enable-phar \ ---enable-ctype \ ---enable-sockets \ ---enable-shared=no \ ---enable-static=yes \ ---enable-shmop \ ---enable-pcntl \ ---enable-pthreads \ ---enable-maintainer-zts \ ---enable-zend-signals \ -$HAVE_MYSQLI \ ---enable-embedded-mysqli \ ---enable-bcmath \ ---enable-cli \ ---enable-zip \ ---with-zend-vm=$ZEND_VM \ -$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 -echo -n " compiling..." -if [ "$COMPILE_FOR_ANDROID" == "yes" ]; then - sed -i=".backup" 's/-export-dynamic/-all-static/g' Makefile -fi -sed -i=".backup" 's/PHP_BINARIES. pharcmd$/PHP_BINARIES)/g' Makefile -sed -i=".backup" 's/install-programs install-pharcmd$/install-programs/g' Makefile -make -j $THREADS >> "$DIR/install.log" 2>&1 -echo -n " installing..." -make install >> "$DIR/install.log" 2>&1 - -if [ "$(uname -s)" == "Darwin" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; 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 +if [ "$CROSSCOMPILE_ANDROID_ARMV6" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6 + cd $COMPILEDIR/crosscompile/android-armv6 + + $SCRIPT -t android-armv6 -o -j 1 -c -x -f arm + + 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 + exit 1 + fi fi -echo -n " generating php.ini..." - -TIMEZONE=$(date +%Z) -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" -echo "phar.readonly=0" >> "$DIR/bin/php5/bin/php.ini" -echo "phar.require_hash=1" >> "$DIR/bin/php5/bin/php.ini" -if [ "$IS_CROSSCOMPILE" != "crosscompile" ]; then - echo "zend_extension=opcache.so" >> "$DIR/bin/php5/bin/php.ini" - echo "opcache.enable=1" >> "$DIR/bin/php5/bin/php.ini" - echo "opcache.enable_cli=1" >> "$DIR/bin/php5/bin/php.ini" - echo "opcache.save_comments=0" >> "$DIR/bin/php5/bin/php.ini" - echo "opcache.fast_shutdown=1" >> "$DIR/bin/php5/bin/php.ini" - echo "opcache.max_accelerated_files=4096" >> "$DIR/bin/php5/bin/php.ini" - echo "opcache.interned_strings_buffer=8" >> "$DIR/bin/php5/bin/php.ini" - echo "opcache.memory_consumption=128" >> "$DIR/bin/php5/bin/php.ini" - echo "opcache.optimization_level=0xffffffff" >> "$DIR/bin/php5/bin/php.ini" -fi -if [ "$HAVE_CURL" == "shared,/usr" ]; then - echo "extension=curl.so" >> "$DIR/bin/php5/bin/php.ini" +if [ "$CROSSCOMPILE_ANDROID_ARMV7" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7 + cd $COMPILEDIR/crosscompile/android-armv7 + + $SCRIPT -t android-armv7 -o -j 1 -c -x -f arm + + 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 + exit 1 + fi fi -echo " done!" -cd "$DIR" -echo -n "[INFO] Cleaning up..." -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 -echo " done!" -echo "[PocketMine] You should start the server now using \"./start.sh.\"" -echo "[PocketMine] If it doesn't work, please send the \"install.log\" file to the Bug Tracker." +if [ "$CROSSCOMPILE_IOS_ARMV6" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6 + cd $COMPILEDIR/crosscompile/ios-armv6 + curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null + cd libtool-2.4.2 + ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv6/libtool" > /dev/null + make > /dev/null + make install + cd ../ + rm -rf libtool-2.4.2 + export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool" + export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize" + PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x + + cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/ + if [ ! -f $COMPILEDIR/crosscompile/ios-armv6/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_IOS_ARMV7" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7 + cd $COMPILEDIR/crosscompile/ios-armv7 + curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null + cd libtool-2.4.2 + ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv7/libtool" > /dev/null + make > /dev/null + make install + cd ../ + rm -rf libtool-2.4.2 + export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool" + export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize" + PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x + + cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/ + if [ ! -f $COMPILEDIR/crosscompile/ios-armv7/bin/php5/bin/php ]; then + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_RPI" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi + cd $COMPILEDIR/crosscompile/rpi + + $SCRIPT -t rpi -o -j 1 -c -x -f arm + + 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 + exit 1 + fi +fi + +if [ "$CROSSCOMPILE_MAC" = "true" ]; +then + mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac + cd $COMPILEDIR/crosscompile/mac + + $SCRIPT -t mac -o -j 1 -c -f -x + + cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/ + if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then + exit 1 + fi +fi From 564a504ef70bddaa46291a78401e6abbd63c0bc8 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 8 Mar 2014 05:49:27 +0100 Subject: [PATCH 170/173] Update compile.sh --- src/build/compile.sh | 685 +++++++++++++++++++++++++++++++------------ 1 file changed, 504 insertions(+), 181 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 1e17307d4..24e3dc38a 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -1,15 +1,35 @@ -#!/bin/bash -x -export PATH="/opt/arm-2013.05/bin:/opt/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/opt/arm-unknown-linux-uclibcgnueabi/bin:$PATH" -export THREADS=2 +#!/bin/bash PHP_VERSION="5.5.10" +ZEND_VM="GOTO" + +ZLIB_VERSION="1.2.8" +OPENSSL_VERSION="1.0.0l" +CURL_VERSION="curl-7_35_0" +LIBEDIT_VERSION="0.3" +PTHREADS_VERSION="0.1.0" +PHPYAML_VERSION="1.1.1" +YAML_VERSION="0.1.4" + +echo "[PocketMine] PHP compiler for Linux, MacOS and Android" +DIR="$(pwd)" +date > "$DIR/install.log" 2>&1 +uname -a >> "$DIR/install.log" 2>&1 +echo "[INFO] Checking dependecies" +type make >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"make\""; read -p "Press [Enter] to continue..."; exit 1; } +type autoconf >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"autoconf\""; read -p "Press [Enter] to continue..."; exit 1; } +type automake >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"automake\""; read -p "Press [Enter] to continue..."; exit 1; } +type libtool >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"libtool\""; read -p "Press [Enter] to continue..."; exit 1; } +type m4 >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"m4\""; read -p "Press [Enter] to continue..."; exit 1; } +type wget >> "$DIR/install.log" 2>&1 || type curl >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"wget\" or \"curl\""; read -p "Press [Enter] to continue..."; exit 1; } +type getconf >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"getconf\""; read -p "Press [Enter] to continue..."; exit 1; } #Needed to use aliases shopt -s expand_aliases -type wget > /dev/null 2>&1 +type wget >> "$DIR/install.log" 2>&1 if [ $? -eq 0 ]; then alias download_file="wget --no-check-certificate -q -O -" else - type curl >> /dev/null 2>&1 + type curl >> "$DIR/install.log" 2>&1 if [ $? -eq 0 ]; then alias download_file="curl --insecure --silent --location" else @@ -17,197 +37,500 @@ else fi fi -rm -rf $WORKSPACE/compile.sh -download_file "https://github.com/PocketMine/PocketMine-MP/raw/master/src/build/compile.sh" > $WORKSPACE/compile.sh -chmod +x $WORKSPACE/compile.sh -SCRIPT="$WORKSPACE/compile.sh" -ARCHIVE="$WORKSPACE/archive" -COMPILEDIR="$WORKSPACE/compile" -rm -rf "$ARCHIVE" "$COMPILEDIR" -mkdir -p "$ARCHIVE" -mkdir -p "$COMPILEDIR" +export CC="gcc" +COMPILE_FOR_ANDROID=no +RANLIB=ranlib +HAVE_MYSQLI="--with-mysqli=mysqlnd" +COMPILE_TARGET="" +COMPILE_OPENSSL="no" +COMPILE_CURL="default" +COMPILE_LIBEDIT="no" +IS_CROSSCOMPILE="no" +DO_OPTIMIZE="no" +while getopts "t:oj:cxf::" OPTION; do + case $OPTION in + t) + echo "[opt] Set target to $OPTARG" + COMPILE_TARGET="$OPTARG" + ;; + j) + echo "[opt] Set make threads to $OPTARG" + THREADS="$OPTARG" + ;; + o) + echo "[opt] Will compile OpenSSL" + COMPILE_OPENSSL="yes" + ;; + l) + echo "[opt] Will compile libedit" + COMPILE_LIBEDIT="yes" + ;; + c) + echo "[opt] Will force compile cURL" + COMPILE_CURL="yes" + ;; + x) + echo "[opt] Doing cross-compile" + IS_CROSSCOMPILE="yes" + ;; + f) + echo "[opt] Enabling abusive optimizations..." + DO_OPTIMIZE="yes" + ffast_math="-fno-math-errno -funsafe-math-optimizations -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail + CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $ffast_math -fno-signed-zeros -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -ftracer -ftree-loop-im -ftree-parallelize-loops=4 -fomit-frame-pointer" + if [ "$OPTARG" == "arm" ]; then + CFLAGS="$CFLAGS -mfloat-abi=softfp -mfpu=vfp" + elif [ "$OPTARG" == "x86_64" ]; then + CFLAGS="$CFLAGS -mmx -msse -msse2 -msse3 -mfpmath=sse -free -msahf" + elif [ "$OPTARG" == "x86" ]; then + CFLAGS="$CFLAGS -mmx -msse -msse2 -mfpmath=sse -m128bit-long-double -malign-double" + fi + ;; + \?) + echo "Invalid option: -$OPTION$OPTARG" >&2 + exit 1 + ;; + esac +done -if [ "$COMPILE_LINUX_32BIT" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit - cd $COMPILEDIR/linux/32bit - - OPENSSL_TARGET="linux-generic32" CFLAGS="-m32" march=i686 mtune=pentium4 $SCRIPT -t linux -o -j 1 -c -f x86 - - 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 [ "$IS_CROSSCOMPILE" == "yes" ]; then + if [ "$COMPILE_TARGET" == "android" ] || [ "$COMPILE_TARGET" == "android-armv6" ]; then + COMPILE_FOR_ANDROID=yes + [ -z "$march" ] && march=armv6; + [ -z "$mtune" ] && mtune=arm1136jf-s; + TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" + export CC="$TOOLCHAIN_PREFIX-gcc" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" + CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" + echo "[INFO] Cross-compiling for Android ARMv6" + OPENSSL_TARGET="android" + HAVE_MYSQLI="--without-mysqli" + elif [ "$COMPILE_TARGET" == "android-armv7" ]; then + COMPILE_FOR_ANDROID=yes + [ -z "$march" ] && march=armv7-a; + [ -z "$mtune" ] && mtune=cortex-a8; + TOOLCHAIN_PREFIX="arm-unknown-linux-uclibcgnueabi" + export CC="$TOOLCHAIN_PREFIX-gcc" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --enable-static-link --disable-ipv6" + CFLAGS="-static -uclibc -Wl,-Bdynamic $CFLAGS" + echo "[INFO] Cross-compiling for Android ARMv7" + OPENSSL_TARGET="android-armv7" + HAVE_MYSQLI="--without-mysqli" + elif [ "$COMPILE_TARGET" == "rpi" ]; then + TOOLCHAIN_PREFIX="arm-linux-gnueabihf" + [ -z "$march" ] && march=armv6zk; + [ -z "$mtune" ] && mtune=arm1176jzf-s; + [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; + export CC="$TOOLCHAIN_PREFIX-gcc" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" + [ -z "$CFLAGS" ] && CFLAGS="-uclibc"; + OPENSSL_TARGET="linux-armv4" + echo "[INFO] Cross-compiling for Raspberry Pi ARMv6zk hard float" + elif [ "$COMPILE_TARGET" == "mac" ]; then + [ -z "$march" ] && march=prescott; + [ -z "$mtune" ] && mtune=generic; + [ -z "$CFLAGS" ] && CFLAGS="-fomit-frame-pointer"; + TOOLCHAIN_PREFIX="i686-apple-darwin10" + export CC="$TOOLCHAIN_PREFIX-gcc" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX" + #zlib doesn't use the correct ranlib + RANLIB=$TOOLCHAIN_PREFIX-ranlib + OPENSSL_TARGET="darwin64-x86_64-cc" + echo "[INFO] Cross-compiling for Intel MacOS" + elif [ "$COMPILE_TARGET" == "ios" ] || [ "$COMPILE_TARGET" == "ios-armv6" ]; then + [ -z "$march" ] && march=armv6; + [ -z "$mtune" ] && mtune=arm1176jzf-s; + TOOLCHAIN_PREFIX="arm-apple-darwin10" + export CC="$TOOLCHAIN_PREFIX-gcc" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2" + OPENSSL_TARGET="BSD-generic32" + HAVE_MYSQLI="--without-mysqli" + elif [ "$COMPILE_TARGET" == "ios-armv7" ]; then + [ -z "$march" ] && march=armv7-a; + [ -z "$mtune" ] && mtune=cortex-a8; + TOOLCHAIN_PREFIX="arm-apple-darwin10" + export CC="$TOOLCHAIN_PREFIX-gcc" + CONFIGURE_FLAGS="--host=$TOOLCHAIN_PREFIX --target=$TOOLCHAIN_PREFIX -miphoneos-version-min=4.2" + OPENSSL_TARGET="BSD-generic32" + HAVE_MYSQLI="--without-mysqli" + if [ "$DO_OPTIMIZE" == "yes" ]; then + CFLAGS="$CFLAGS -mfpu=neon" + fi + else + echo "Please supply a proper platform [android android-armv6 android-armv7 rpi mac ios ios-armv6 ios-armv7] to cross-compile" exit 1 fi +elif [ "$COMPILE_TARGET" == "rpi" ]; then + [ -z "$march" ] && march=armv6zk; + [ -z "$mtune" ] && mtune=arm1176jzf-s; + [ -z "$CFLAGS" ] && CFLAGS="-mfloat-abi=hard -mfpu=vfp"; + OPENSSL_TARGET="linux-armv4" + echo "[INFO] Compiling for Raspberry Pi ARMv6zk hard float" +elif [ "$COMPILE_TARGET" == "mac" ] || [ "$COMPILE_TARGET" == "mac32" ]; then + [ -z "$march" ] && march=prescott; + [ -z "$mtune" ] && mtune=generic; + [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i686 -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="darwin-i386-cc" + echo "[INFO] Compiling for Intel MacOS x86" +elif [ "$COMPILE_TARGET" == "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 [ "$COMPILE_TARGET" == "ios" ]; then + [ -z "$march" ] && march=armv7-a; + [ -z "$mtune" ] && mtune=cortex-a8; + echo "[INFO] Compiling for iOS ARMv7" + OPENSSL_TARGET="linux-armv4" +elif [ -z "$CFLAGS" ]; then + if [ `getconf LONG_BIT` == "64" ]; then + echo "[INFO] Compiling for current machine using 64-bit" + CFLAGS="-m64 $CFLAGS" + OPENSSL_TARGET="linux-x86_64" + else + echo "[INFO] Compiling for current machine using 32-bit" + CFLAGS="-m32 $CFLAGS" + OPENSSL_TARGET="linux-generic32" + fi fi -if [ "$COMPILE_LINUX_64BIT" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit - cd $COMPILEDIR/linux/64bit - - OPENSSL_TARGET="linux-x86_64" CFLAGS="-m64" march=x86-64 mtune=nocona $SCRIPT -t linux -o -j 1 -c -f x86_64 - - 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 - exit 1 +cat > test.c <<'CTEST' +#include +int main(void){ + printf("Hello world\n"); + return 0; +} +CTEST + + +type $CC >> "$DIR/install.log" 2>&1 || { echo >&2 "[ERROR] Please install \"$CC\""; read -p "Press [Enter] to continue..."; exit 1; } + +[ -z "$THREADS" ] && THREADS=1; +[ -z "$march" ] && march=native; +[ -z "$mtune" ] && mtune=native; +[ -z "$CFLAGS" ] && CFLAGS=""; +[ -z "$LDFLAGS" ] && LDFLAGS="-Wl,-rpath='\$\$ORIGIN/../lib'"; +[ -z "$CONFIGURE_FLAGS" ] && CONFIGURE_FLAGS=""; + + +if [ "$mtune" != "none" ]; then + $CC -march=$march -mtune=$mtune $CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 + if [ $? -eq 0 ]; then + CFLAGS="-march=$march -mtune=$mtune -fno-gcse $CFLAGS" + fi +else + $CC -march=$march $CFLAGS -o test test.c >> "$DIR/install.log" 2>&1 + if [ $? -eq 0 ]; then + CFLAGS="-march=$march -fno-gcse $CFLAGS" fi fi -if [ "$COMPILE_MAC_32" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/mac32 - cd $COMPILEDIR/mac32 - - 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 -t mac32 -o -j 1 -c -f x86 - - tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/ - 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 +rm test.* >> "$DIR/install.log" 2>&1 +rm test >> "$DIR/install.log" 2>&1 + +export CFLAGS="-O2 $CFLAGS" +export LDFLAGS="$LDFLAGS" + +rm -r -f install_data/ >> "$DIR/install.log" 2>&1 +rm -r -f bin/ >> "$DIR/install.log" 2>&1 +mkdir -m 0755 install_data >> "$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 +set -e + +#PHP 5 +echo -n "[PHP] downloading $PHP_VERSION..." +download_file "http://php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror" | tar -zx >> "$DIR/install.log" 2>&1 +mv php-$PHP_VERSION php +echo " done!" + +if [ "$IS_CROSSCOMPILE" == "yes" ] || [ "$COMPILE_TARGET" == "rpi" ] || [ "$COMPILE_TARGET" == "mac" ] || [ "$COMPILE_LIBEDIT" != "yes" ]; then + HAVE_LIBEDIT="--without-readline --without-libedit" +else + #libedit + set +e + 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 + echo -n " checking..." + cd libedit + ./configure --prefix="$DIR/bin/php5" \ + --enable-shared=yes \ + --enable-static=no \ + $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 + echo -n " compiling..." + if make -j $THREADS >> "$DIR/install.log" 2>&1; then + echo -n " installing..." + make install >> "$DIR/install.log" 2>&1 + HAVE_LIBEDIT="--without-readline --with-libedit=\"$DIR/bin/php5\"" + else + echo -n " disabling..." + HAVE_LIBEDIT="--without-readline --without-libedit" + fi + echo -n " cleaning..." + cd .. + rm -r -f ./libedit + echo " done!" + set -e +fi + +#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..." +mv zlib-$ZLIB_VERSION zlib +echo -n " checking..." +cd zlib +RANLIB=$RANLIB ./configure --prefix="$DIR/bin/php5" \ +--shared >> "$DIR/install.log" 2>&1 +echo -n " compiling..." +make -j $THREADS >> "$DIR/install.log" 2>&1 +echo -n " installing..." +make install >> "$DIR/install.log" 2>&1 +echo -n " cleaning..." +cd .. +rm -r -f ./zlib +echo " done!" + +if [ "$COMPILE_OPENSSL" == "yes" ] || [ "$COMPILE_CURL" != "no" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; 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" \ + zlib \ + zlib-dynamic \ + --with-zlib-lib="$DIR/bin/php5/lib" \ + --with-zlib-include="$DIR/bin/php5/include" \ + shared \ + no-ssl2 \ + 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" ] && [ "$COMPILE_TARGET" != "crosscompile" ]; then + WITH_SSL="--with-darwinssl" 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 -t mac64 -o -j 1 -c -f x86_64 - - 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 +if [ "$(uname -s)" == "Darwin" ] && [ "$IS_CROSSCOMPILE" != "yes" ] && [ "$COMPILE_CURL" != "yes" ]; then + HAVE_CURL="shared,/usr" +else + #curl + echo -n "[cURL] downloading $CURL_VERSION..." + download_file "https://github.com/bagder/curl/archive/$CURL_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 + mv curl-$CURL_VERSION curl + echo -n " checking..." + cd curl + if [ ! -f ./configure ]; then + ./buildconf --force >> "$DIR/install.log" 2>&1 fi + RANLIB=$RANLIB ./configure --disable-dependency-tracking \ + --enable-ipv6 \ + --enable-optimize \ + --enable-http \ + --enable-ftp \ + --disable-dict \ + --enable-file \ + --without-librtmp \ + --disable-gopher \ + --disable-imap \ + --disable-pop3 \ + --disable-rtsp \ + --disable-smtp \ + --disable-telnet \ + --disable-tftp \ + --disable-ldap \ + --disable-ldaps \ + --without-libidn \ + --with-zlib="$DIR/bin/php5" \ + $WITH_SSL \ + --enable-threaded-resolver \ + --prefix="$DIR/bin/php5" \ + --disable-shared \ + --enable-static \ + $CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 + echo -n " compiling..." + make -j $THREADS >> "$DIR/install.log" 2>&1 + echo -n " installing..." + make install >> "$DIR/install.log" 2>&1 + echo -n " cleaning..." + cd .. + rm -r -f ./curl + echo " done!" + HAVE_CURL="$DIR/bin/php5" fi -if [ "$COMPILE_RPI" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi - cd $COMPILEDIR/rpi - - $SCRIPT -t rpi -o -j 1 -c -f arm - - 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 - exit 1 - fi +#pthreads +echo -n "[PHP pthreads] downloading $PTHREADS_VERSION..." +download_file "http://pecl.php.net/get/pthreads-$PTHREADS_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1 +mv pthreads-$PTHREADS_VERSION "$DIR/install_data/php/ext/pthreads" +echo " done!" + +#PHP YAML +echo -n "[PHP YAML] downloading $PHPYAML_VERSION..." +download_file "http://pecl.php.net/get/yaml-$PHPYAML_VERSION.tgz" | tar -zx >> "$DIR/install.log" 2>&1 +mv yaml-$PHPYAML_VERSION "$DIR/install_data/php/ext/yaml" +echo " done!" + +#YAML +echo -n "[YAML] downloading $YAML_VERSION..." +download_file "http://pyyaml.org/download/libyaml/yaml-$YAML_VERSION.tar.gz" | tar -zx >> "$DIR/install.log" 2>&1 +mv yaml-$YAML_VERSION yaml +echo -n " checking..." +cd yaml +RANLIB=$RANLIB ./configure \ +--prefix="$DIR/bin/php5" \ +--disable-static \ +--enable-shared \ +$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 +echo -n " compiling..." +make -j $THREADS >> "$DIR/install.log" 2>&1 +echo -n " installing..." +make install >> "$DIR/install.log" 2>&1 +echo -n " cleaning..." +cd .. +rm -r -f ./yaml +echo " done!" + +echo -n "[PHP]" + +if [ "$DO_OPTIMIZE" != "no" ]; then + echo -n " enabling optimizations..." + PHP_OPTIMIZATION="--enable-inline-optimization " +else + PHP_OPTIMIZATION="--disable-inline-optimization " +fi +echo -n " checking..." +cd php +rm -rf ./aclocal.m4 >> "$DIR/install.log" 2>&1 +rm -rf ./autom4te.cache/ >> "$DIR/install.log" 2>&1 +rm -f ./configure >> "$DIR/install.log" 2>&1 +./buildconf --force >> "$DIR/install.log" 2>&1 +if [ "$IS_CROSSCOMPILE" == "yes" ]; then + sed -i=".backup" 's/pthreads_working=no/pthreads_working=yes/' ./configure + export LIBS="-lpthread -ldl -lresolv" + CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-opcache=no" +fi +RANLIB=$RANLIB ./configure $PHP_OPTIMIZATION--prefix="$DIR/bin/php5" \ +--exec-prefix="$DIR/bin/php5" \ +--with-curl="$HAVE_CURL" \ +--with-zlib="$DIR/bin/php5" \ +--with-yaml="$DIR/bin/php5" \ +$HAVE_LIBEDIT \ +--disable-libxml \ +--disable-xml \ +--disable-dom \ +--disable-simplexml \ +--disable-xmlreader \ +--disable-xmlwriter \ +--disable-cgi \ +--disable-session \ +--disable-debug \ +--disable-pdo \ +--without-pear \ +--without-iconv \ +--without-pdo-sqlite \ +--enable-phar \ +--enable-ctype \ +--enable-sockets \ +--enable-shared=no \ +--enable-static=yes \ +--enable-shmop \ +--enable-pcntl \ +--enable-pthreads \ +--enable-maintainer-zts \ +--enable-zend-signals \ +$HAVE_MYSQLI \ +--enable-embedded-mysqli \ +--enable-bcmath \ +--enable-cli \ +--enable-zip \ +--with-zend-vm=$ZEND_VM \ +$CONFIGURE_FLAGS >> "$DIR/install.log" 2>&1 +echo -n " compiling..." +if [ "$COMPILE_FOR_ANDROID" == "yes" ]; then + sed -i=".backup" 's/-export-dynamic/-all-static/g' Makefile +fi +sed -i=".backup" 's/PHP_BINARIES. pharcmd$/PHP_BINARIES)/g' Makefile +sed -i=".backup" 's/install-programs install-pharcmd$/install-programs/g' Makefile +make -j $THREADS >> "$DIR/install.log" 2>&1 +echo -n " installing..." +make install >> "$DIR/install.log" 2>&1 + +if [ "$(uname -s)" == "Darwin" ] && [ "$IS_CROSSCOMPILE" != "yes" ]; 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 -if [ "$CROSSCOMPILE_ANDROID_ARMV6" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6 - cd $COMPILEDIR/crosscompile/android-armv6 - - $SCRIPT -t android-armv6 -o -j 1 -c -x -f arm - - 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 - exit 1 - fi +echo -n " generating php.ini..." + +TIMEZONE=$(date +%Z) +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" +echo "phar.readonly=0" >> "$DIR/bin/php5/bin/php.ini" +echo "phar.require_hash=1" >> "$DIR/bin/php5/bin/php.ini" +if [ "$IS_CROSSCOMPILE" != "crosscompile" ]; then + echo "zend_extension=opcache.so" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.enable=1" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.enable_cli=1" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.save_comments=0" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.fast_shutdown=1" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.max_accelerated_files=4096" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.interned_strings_buffer=8" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.memory_consumption=128" >> "$DIR/bin/php5/bin/php.ini" + echo "opcache.optimization_level=0xffffffff" >> "$DIR/bin/php5/bin/php.ini" +fi +if [ "$HAVE_CURL" == "shared,/usr" ]; then + echo "extension=curl.so" >> "$DIR/bin/php5/bin/php.ini" fi -if [ "$CROSSCOMPILE_ANDROID_ARMV7" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7 - cd $COMPILEDIR/crosscompile/android-armv7 - - $SCRIPT -t android-armv7 -o -j 1 -c -x -f arm - - 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 - exit 1 - fi -fi - -if [ "$CROSSCOMPILE_IOS_ARMV6" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6 - cd $COMPILEDIR/crosscompile/ios-armv6 - curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null - cd libtool-2.4.2 - ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv6/libtool" > /dev/null - make > /dev/null - make install - cd ../ - rm -rf libtool-2.4.2 - export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool" - export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize" - PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x - - cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/ - if [ ! -f $COMPILEDIR/crosscompile/ios-armv6/bin/php5/bin/php ]; then - exit 1 - fi -fi - -if [ "$CROSSCOMPILE_IOS_ARMV7" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7 - cd $COMPILEDIR/crosscompile/ios-armv7 - curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null - cd libtool-2.4.2 - ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv7/libtool" > /dev/null - make > /dev/null - make install - cd ../ - rm -rf libtool-2.4.2 - export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool" - export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize" - PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT -t ios-armv6 -o -j 1 -c -x - - cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/ - if [ ! -f $COMPILEDIR/crosscompile/ios-armv7/bin/php5/bin/php ]; then - exit 1 - fi -fi - -if [ "$CROSSCOMPILE_RPI" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi - cd $COMPILEDIR/crosscompile/rpi - - $SCRIPT -t rpi -o -j 1 -c -x -f arm - - 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 - exit 1 - fi -fi - -if [ "$CROSSCOMPILE_MAC" = "true" ]; -then - mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac - cd $COMPILEDIR/crosscompile/mac - - $SCRIPT -t mac -o -j 1 -c -f -x - - cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/ - if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then - exit 1 - fi -fi +echo " done!" +cd "$DIR" +echo -n "[INFO] Cleaning up..." +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 +echo " done!" +echo "[PocketMine] You should start the server now using \"./start.sh.\"" +echo "[PocketMine] If it doesn't work, please send the \"install.log\" file to the Bug Tracker." From 45ee209c5895e532edc7e708776b9cea30dd7ce9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 8 Mar 2014 06:21:22 +0100 Subject: [PATCH 171/173] Update jenkins.sh --- src/build/jenkins.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 1e17307d4..429086301 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -92,7 +92,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" - $SCRIPT -t mac64 -o -j 1 -c -f x86_64 + $SCRIPT -t mac64 -o -j 1 -c -f x86 #removes non-supported optimizations 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 From 5d2884716d0a4d8d8373a3e2a2db4bda0c792d0a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 8 Mar 2014 13:53:27 +0100 Subject: [PATCH 172/173] Update jenkins.sh --- src/build/jenkins.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/jenkins.sh b/src/build/jenkins.sh index 429086301..f3e13c283 100644 --- a/src/build/jenkins.sh +++ b/src/build/jenkins.sh @@ -69,7 +69,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" - $SCRIPT -t mac32 -o -j 1 -c -f x86 + $SCRIPT -t mac32 -o -j 1 -c -f tar -czf PHP_${PHP_VERSION}_x86_MacOS.tar.gz bin/ cp -r $COMPILEDIR/mac32/{install.log,PHP_${PHP_VERSION}_x86_MacOS.tar.gz,install_data/*} $ARCHIVE/mac32/ @@ -92,7 +92,7 @@ then rm -rf libtool-2.4.2 export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" - $SCRIPT -t mac64 -o -j 1 -c -f x86 #removes non-supported optimizations + $SCRIPT -t mac64 -o -j 1 -c -f 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 From e0705c80e258b166f5ae5f5da20472033192acdd Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 8 Mar 2014 18:14:43 +0100 Subject: [PATCH 173/173] Fixed getopts on compile.sh --- src/build/compile.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/build/compile.sh b/src/build/compile.sh index 24e3dc38a..238ec04ee 100755 --- a/src/build/compile.sh +++ b/src/build/compile.sh @@ -47,7 +47,7 @@ COMPILE_CURL="default" COMPILE_LIBEDIT="no" IS_CROSSCOMPILE="no" DO_OPTIMIZE="no" -while getopts "t:oj:cxf::" OPTION; do +while getopts "::t:oj:cxff:" OPTION; do case $OPTION in t) echo "[opt] Set target to $OPTARG" @@ -77,7 +77,7 @@ while getopts "t:oj:cxf::" OPTION; do echo "[opt] Enabling abusive optimizations..." DO_OPTIMIZE="yes" ffast_math="-fno-math-errno -funsafe-math-optimizations -fno-trapping-math -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fcx-limited-range" #workaround SQLite3 fail - CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $ffast_math -fno-signed-zeros -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -ftracer -ftree-loop-im -ftree-parallelize-loops=4 -fomit-frame-pointer" + CFLAGS="$CFLAGS -O2 -DSQLITE_HAVE_ISNAN $ffast_math -fno-signed-zeros -finline-functions -funsafe-loop-optimizations -fomit-frame-pointer -frename-registers -funroll-loops -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -ftracer -ftree-loop-im -fivopts -ftree-parallelize-loops=4 -fomit-frame-pointer" if [ "$OPTARG" == "arm" ]; then CFLAGS="$CFLAGS -mfloat-abi=softfp -mfpu=vfp" elif [ "$OPTARG" == "x86_64" ]; then @@ -169,7 +169,7 @@ elif [ "$COMPILE_TARGET" == "rpi" ]; then elif [ "$COMPILE_TARGET" == "mac" ] || [ "$COMPILE_TARGET" == "mac32" ]; then [ -z "$march" ] && march=prescott; [ -z "$mtune" ] && mtune=generic; - [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i686 -fomit-frame-pointer -mmacosx-version-min=10.5"; + [ -z "$CFLAGS" ] && CFLAGS="-m32 -arch i386 -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="darwin-i386-cc"