From 2c4a428698c44219e97c75f3e867933435270f96 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sun, 19 May 2013 13:51:02 +0200 Subject: [PATCH] Packets bigger than the MTU are automagically split in different packets --- src/Player.php | 16 ++++++++++---- src/constants/GeneralConstants.php | 35 +++++++++++++++++++++++++++++- src/world/Entity.php | 20 ----------------- src/world/TileEntity.php | 7 ------ 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/Player.php b/src/Player.php index eaf3ee5c17..0531acee85 100644 --- a/src/Player.php +++ b/src/Player.php @@ -166,7 +166,11 @@ class Player{ $z = $Z << 4; $y = $Y << 4; $this->level->useChunk($X, $Z, $this); - $this->directBigRawPacket(MC_CHUNK_DATA, Utils::writeInt($X) . Utils::writeInt($Z) . $this->level->getOrderedMiniChunk($X, $Z, $Y)); + $this->dataPacket(MC_CHUNK_DATA, array( + "x" => $X, + "z" => $Z, + "data" => $this->level->getOrderedMiniChunk($X, $Z, $Y), + )); $tiles = $this->server->query("SELECT ID FROM tileentities WHERE spawnable = 1 AND level = '".$this->level->getName()."' AND x >= ".($x - 1)." AND x < ".($x + 17)." AND z >= ".($z - 1)." AND z < ".($z + 17)." AND y >= ".($y - 1)." AND y < ".($y + 17).";"); if($tiles !== false and $tiles !== true){ @@ -1380,7 +1384,7 @@ class Player{ $data["raw"] = Utils::writeShort(strlen($buf) << 3).strrev(Utils::writeTriad($this->counter[3]++)).$h.Utils::writeInt($i).$buf; $this->counter[3] %= 0x1000000; $count = $this->counter[0]++; - if(count($this->recovery) >= 1024){ + if(count($this->recovery) >= PLAYER_RECOVERY_BUFFER){ reset($this->recovery); $k = key($this->recovery); $this->recovery[$k] = null; @@ -1404,7 +1408,7 @@ class Player{ $data["sendtime"] = microtime(true); if($count === false){ $count = $this->counter[0]++; - if(count($this->recovery) >= 1024){ + if(count($this->recovery) >= PLAYER_RECOVERY_BUFFER){ reset($this->recovery); $k = key($this->recovery); $this->recovery[$k] = null; @@ -1427,7 +1431,11 @@ class Player{ }else{ $data = new CustomPacketHandler($id, "", $data, true); $len = strlen($data->raw) + 1; - $MTU = $this->MTU - 7; + $MTU = $this->MTU - 32; + if($len > $MTU){ + $this->directBigRawPacket($id, $data->raw); + return; + } if((strlen($this->buffer) + $len) >= $MTU){ $this->sendBuffer(); diff --git a/src/constants/GeneralConstants.php b/src/constants/GeneralConstants.php index 61718e9af3..5e5ab82992 100644 --- a/src/constants/GeneralConstants.php +++ b/src/constants/GeneralConstants.php @@ -30,4 +30,37 @@ define("SURVIVAL", 0); define("CREATIVE", 1); define("ADVENTURE", 2); define("VIEW", 3); -define("VIEWER", 3); \ No newline at end of file +define("VIEWER", 3); + + +//Players +define("PLAYER_RECOVERY_BUFFER", 2048); + + +//Entities +define("ENTITY_PLAYER", 0); + +define("ENTITY_MOB", 1); + define("MOB_CHICKEN", 10); + define("MOB_COW", 11); + define("MOB_PIG", 12); + define("MOB_SHEEP", 13); + + define("MOB_ZOMBIE", 32); + define("MOB_CREEPER", 33); + define("MOB_SKELETON", 34); + define("MOB_SPIDER", 35); + define("MOB_PIGMAN", 36); + +define("ENTITY_OBJECT", 2); + define("OBJECT_PAINTING", 83); + +define("ENTITY_ITEM", 3); + + +//TileEntities +define("TILE_SIGN", "Sign"); +define("TILE_CHEST", "Chest"); + define("CHEST_SLOTS", 27); +define("TILE_FURNACE", "Furnace"); + define("FURNACE_SLOTS", 3); \ No newline at end of file diff --git a/src/world/Entity.php b/src/world/Entity.php index 4874c2f338..7490f9fe48 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -25,26 +25,6 @@ the Free Software Foundation, either version 3 of the License, or */ - -define("ENTITY_PLAYER", 0); - -define("ENTITY_MOB", 1); - define("MOB_CHICKEN", 10); - define("MOB_COW", 11); - define("MOB_PIG", 12); - define("MOB_SHEEP", 13); - - define("MOB_ZOMBIE", 32); - define("MOB_CREEPER", 33); - define("MOB_SKELETON", 34); - define("MOB_SPIDER", 35); - define("MOB_PIGMAN", 36); - -define("ENTITY_OBJECT", 2); - define("OBJECT_PAINTING", 83); - -define("ENTITY_ITEM", 3); - class Entity extends Position{ public $age; public $air; diff --git a/src/world/TileEntity.php b/src/world/TileEntity.php index ae6dea22ad..353c22d72d 100644 --- a/src/world/TileEntity.php +++ b/src/world/TileEntity.php @@ -25,13 +25,6 @@ the Free Software Foundation, either version 3 of the License, or */ - -define("TILE_SIGN", "Sign"); -define("TILE_CHEST", "Chest"); - define("CHEST_SLOTS", 27); -define("TILE_FURNACE", "Furnace"); - define("FURNACE_SLOTS", 3); - class TileEntity extends Position{ public $name; public $normal;