From ca74f4f0c17c5af6afae90220dcf11c4f266bb6e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 12 Dec 2012 19:44:49 +0100 Subject: [PATCH] Fixes --- classes/CustomPacketHandler.class.php | 23 +++++++------- classes/PocketMinecraftServer.class.php | 3 +- classes/Session.class.php | 40 ++++++++++++++++++++----- 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/classes/CustomPacketHandler.class.php b/classes/CustomPacketHandler.class.php index 94ac7c2f0..574850d08 100644 --- a/classes/CustomPacketHandler.class.php +++ b/classes/CustomPacketHandler.class.php @@ -332,12 +332,16 @@ class CustomPacketHandler{ $this->data["x"] = Utils::readInt($this->get(4)); $this->data["z"] = Utils::readInt($this->get(4)); $this->data["y"] = ord($this->get(1)); + $this->data["block"] = ord($this->get(1)); + $this->data["meta"] = ord($this->get(1)); $this->data["face"] = Utils::readByte($this->get(1)); }else{ $this->raw .= Utils::writeInt($this->data["eid"]); $this->raw .= Utils::writeInt($this->data["x"]); $this->raw .= Utils::writeInt($this->data["z"]); $this->raw .= chr($this->data["y"]); + $this->raw .= chr($this->data["block"]); + $this->raw .= chr($this->data["meta"]); $this->raw .= chr($this->data["face"]); } break; @@ -356,17 +360,17 @@ class CustomPacketHandler{ break; case MC_UPDATE_BLOCK: if($this->c === false){ - $this->data["block"] = Utils::readShort($this->get(2)); - $this->data["meta"] = Utils::readShort($this->get(2)); $this->data["x"] = Utils::readInt($this->get(4)); - $this->data["y"] = Utils::readInt($this->get(4)); $this->data["z"] = Utils::readInt($this->get(4)); + $this->data["y"] = ord($this->get(1)); + $this->data["block"] = ord($this->get(1)); + $this->data["meta"] = ord($this->get(1)); }else{ - $this->raw .= Utils::writeShort($this->data["block"]); - $this->raw .= Utils::writeShort($this->data["meta"]); $this->raw .= Utils::writeInt($this->data["x"]); - $this->raw .= Utils::writeInt($this->data["y"]); $this->raw .= Utils::writeInt($this->data["z"]); + $this->raw .= chr($this->data["y"]); + $this->raw .= chr($this->data["block"]); + $this->raw .= chr($this->data["meta"]); } break; case MC_REQUEST_CHUNK: @@ -376,16 +380,13 @@ class CustomPacketHandler{ }else{ $this->raw .= Utils::writeInt($this->data["x"]); $this->raw .= Utils::writeInt($this->data["y"]); - } + } break; case MC_CHUNK_DATA: if($this->c === false){ $this->data["x"] = Utils::readInt($this->get(4)); $this->data["z"] = Utils::readInt($this->get(4)); - //$this->data["unknown1"] = $this->get(WTF); - $this->data["unknown1"] = Utils::readInt($this->get(4)); - $this->data["unknown2"] = Utils::readInt($this->get(4)); - //$this->data["unknown3"] = $this->get(WTF); + $this->data["data"] = $this->get(256); }else{ $this->raw .= Utils::writeInt($this->data["x"]); $this->raw .= Utils::writeInt($this->data["y"]); diff --git a/classes/PocketMinecraftServer.class.php b/classes/PocketMinecraftServer.class.php index 0ce30e5ed..57bbbdfe8 100644 --- a/classes/PocketMinecraftServer.class.php +++ b/classes/PocketMinecraftServer.class.php @@ -99,6 +99,7 @@ class PocketMinecraftServer extends stdClass{ } public function query($sql, $fetch = false){ + console("[INTERNAL] [SQL] ".$sql, true, true, 3); $result = $this->database->query($sql) or console("[ERROR] [SQL Error] ".$this->database->lastErrorMsg().". Query: ".$sql, true, true, 0); if($fetch === true and ($result !== false and $result !== true)){ $result = $result->fetchArray(SQLITE3_ASSOC); @@ -328,7 +329,7 @@ class PocketMinecraftServer extends stdClass{ $MTU = $data[3]; $clientID = $data[4]; $eid = $this->eidCnt++; - $this->clients[$CID] = new Session($this, $clientID, $eid, $packet["ip"], $packet["port"]); + $this->clients[$CID] = new Session($this, $clientID, $eid, $packet["ip"], $packet["port"], $MTU); $this->clients[$CID]->handle(0x07, $data); break; } diff --git a/classes/Session.class.php b/classes/Session.class.php index 68a495fa2..69d639daf 100644 --- a/classes/Session.class.php +++ b/classes/Session.class.php @@ -27,9 +27,10 @@ the Free Software Foundation, either version 3 of the License, or class Session{ - private $server, $serverID, $timeout, $connected, $evid; - var $clientID, $ip, $port, $counter, $username, $eid, $data, $entity, $auth; - function __construct($server, $clientID, $eid, $ip, $port){ + private $server, $timeout, $connected, $evid; + var $clientID, $ip, $port, $counter, $username, $eid, $data, $entity, $auth, $CID, $MTU; + function __construct($server, $clientID, $eid, $ip, $port, $MTU){ + $this->MTU = $MTU; $this->server = $server; $this->clientID = $clientID; $this->CID = $this->server->clientID($ip, $port); @@ -38,12 +39,11 @@ class Session{ $this->ip = $ip; $this->entity = false; $this->port = $port; - $this->serverID =& $this->server->serverID; $this->timeout = microtime(true) + 25; $this->evid = array(); $this->evid[] = array("onTick", $this->server->event("onTick", array($this, "checkTimeout"))); $this->evid[] = array("onClose", $this->server->event("onClose", array($this, "close"))); - console("[DEBUG] New Session started with ".$ip.":".$port.". Client ID ".$this->clientID, true, true, 2); + console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2); $this->connected = true; $this->auth = false; $this->counter = array(0, 0); @@ -232,7 +232,7 @@ class Session{ case 0x07: $this->send(0x08, array( MAGIC, - $this->serverID, + $this->server->serverID, $this->port, $data[3], 0, @@ -373,11 +373,22 @@ class Session{ case MC_PLAYER_EQUIPMENT: console("[DEBUG] EID ".$this->eid." has now ".$data["block"].":".$data["meta"]." in their hands!", true, true, 2); break; - case MC_REQUEST_CHUNK: + case MC_REQUEST_CHUNK: + $this->send(0x84, array( + $this->counter[0], + 0x00, + array( + "id" => MC_CHUNK_DATA, + "x" => $data["x"], + "z" => $data["z"], + "data" => str_repeat("\x00", 256), + ), + )); + ++$this->counter[0]; console("[DEBUG] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 2); break; case MC_REMOVE_BLOCK: - $this->eventHandler("Blocks broken will not be saved", "onChat"); + //$this->eventHandler("Blocks broken will not be saved", "onChat"); console("[DEBUG] EID ".$this->eid." broke block at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2); $this->send(0x84, array( $this->counter[0], @@ -394,6 +405,19 @@ class Session{ ), )); ++$this->counter[0]; + /*$this->send(0x84, array( + $this->counter[0], + 0x00, + array( + "id" => MC_UPDATE_BLOCK, + "x" => $data["x"], + "y" => $data["y"], + "z" => $data["z"], + "block" => 56, + "meta" => 0, + ), + )); + ++$this->counter[0];*/ break; case MC_INTERACT: if($this->server->gamemode !== 1 and $this->server->difficulty > 0 and isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){