From 1e85a6576438155a07d913860af6e19fbef074ff Mon Sep 17 00:00:00 2001 From: Sunch <120295462+Sunch233@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:21:59 +0800 Subject: [PATCH] cs fix --- src/API/BlockAPI.php | 28 +- src/API/PlayerAPI.php | 20 +- src/Player.php | 2754 ++++++++--------- src/network/PacketPool.php | 2 +- src/network/protocol/ProtocolInfo.php | 702 ++--- .../protocol/packet/AddEntityPacket.php | 6 +- .../protocol/packet/AddItemEntityPacket.php | 6 +- .../protocol/packet/AddPaintingPacket.php | 6 +- .../packet/AdventureSettingsPacket.php | 14 +- src/network/protocol/packet/AnimatePacket.php | 26 +- src/network/protocol/packet/ChatPacket.php | 18 +- .../protocol/packet/ChunkDataPacket.php | 18 +- .../protocol/packet/ContainerAckPacket.php | 76 +- .../protocol/packet/ContainerClosePacket.php | 26 +- .../protocol/packet/ContainerOpenPacket.php | 26 +- .../packet/ContainerSetContentPacket.php | 22 +- .../packet/ContainerSetDataPacket.php | 22 +- .../packet/ContainerSetSlotPacket.php | 26 +- .../protocol/packet/DropItemPacket.php | 26 +- .../protocol/packet/EntityDataPacket.php | 14 +- .../protocol/packet/EntityEventPacket.php | 18 +- src/network/protocol/packet/ExplodePacket.php | 14 +- .../protocol/packet/HurtArmorPacket.php | 6 +- .../protocol/packet/InteractPacket.php | 22 +- .../protocol/packet/LevelEventPacket.php | 14 +- src/network/protocol/packet/LoginPacket.php | 4 +- src/network/protocol/packet/MessagePacket.php | 12 +- .../protocol/packet/MoveEntityPacket.php | 6 +- .../packet/MoveEntityPacket_PosRot.php | 6 +- .../protocol/packet/MovePlayerPacket.php | 22 +- .../protocol/packet/PlaceBlockPacket.php | 68 +- .../protocol/packet/PlayerActionPacket.php | 14 +- .../packet/PlayerArmorEquipmentPacket.php | 6 +- .../protocol/packet/PlayerEquipmentPacket.php | 18 +- .../protocol/packet/PlayerInputPacket.php | 10 +- .../protocol/packet/RemoveBlockPacket.php | 10 +- .../protocol/packet/RemoveEntityPacket.php | 6 +- .../protocol/packet/RequestChunkPacket.php | 18 +- src/network/protocol/packet/RespawnPacket.php | 26 +- .../protocol/packet/RotateHeadPacket.php | 6 +- .../protocol/packet/SendInventoryPacket.php | 26 +- .../protocol/packet/SetEntityDataPacket.php | 24 +- .../protocol/packet/SetEntityLinkPacket.php | 6 +- .../protocol/packet/SetEntityMotionPacket.php | 18 +- .../protocol/packet/SetHealthPacket.php | 26 +- .../packet/SetSpawnPositionPacket.php | 14 +- .../protocol/packet/TakeItemEntityPacket.php | 6 +- .../protocol/packet/TileEventPacket.php | 14 +- .../protocol/packet/UpdateBlockPacket.php | 10 +- src/network/protocol/packet/UseItemPacket.php | 32 +- src/network/raknet/RakNetDataPacket.php | 24 +- src/network/raknet/RakNetParser.php | 462 +-- 52 files changed, 2400 insertions(+), 2406 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index fde6521f..951e05da 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -645,12 +645,12 @@ class BlockAPI{ /** * 方块/物品id转换,防止新版本影响旧版本视觉效果 */ - public static function convertHighItemIdsToOldItemIds(int $protocolId, int $itemId) : int{ - if ($protocolId >= ProtocolInfo12::CURRENT_PROTOCOL_12) { - return $itemId; - } + public static function convertHighItemIdsToOldItemIds(int $protocolId, int $itemId) : int{ + if ($protocolId >= ProtocolInfo12::CURRENT_PROTOCOL_12) { + return $itemId; + } - $idMap = [ //default for protocol < 12 + $idMap = [ //default for protocol < 12 LIT_PUMPKIN => MELON_BLOCK, //block PUMPKIN_SEEDS => MELON_SEEDS, //item PUMPKIN_PIE => BREAD, //item @@ -658,14 +658,14 @@ class BlockAPI{ BEETROOT_SEEDS => SEEDS, //item ]; - if ($protocolId < ProtocolInfo9::CURRENT_PROTOCOL_9) { - $idMap += [ - NETHERRACK => OBSIDIAN, //block - NETHER_BRICK => BRICK, //item - NETHER_QUARTZ => BRICK, //item - ]; - } + if ($protocolId < ProtocolInfo9::CURRENT_PROTOCOL_9) { + $idMap += [ + NETHERRACK => OBSIDIAN, //block + NETHER_BRICK => BRICK, //item + NETHER_QUARTZ => BRICK, //item + ]; + } - return $idMap[$itemId] ?? $itemId; - } + return $idMap[$itemId] ?? $itemId; + } } diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 8605300d..2bba2486 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -327,16 +327,16 @@ class PlayerAPI{ return $o; } - /** - * @return int - */ - public static function decodeProtocol($ip){ - foreach(ServerAPI::request()->clients as $p) { - if($p->ip == $ip){ - return $p->PROTOCOL; - } - } - } + /** + * @return int + */ + public static function decodeProtocol($ip){ + foreach(ServerAPI::request()->clients as $p) { + if($p->ip == $ip){ + return $p->PROTOCOL; + } + } + } public function add($CID){ if(isset($this->server->clients[$CID])){ diff --git a/src/Player.php b/src/Player.php index 777d3667..8bf86ecf 100755 --- a/src/Player.php +++ b/src/Player.php @@ -78,7 +78,7 @@ class Player{ public $blockUpdateQueueLength = 0; public $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL; - + /** * Sent by a client while it is linked to some entity. * @var boolean $isJumping @@ -350,13 +350,13 @@ class Player{ if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY){ return; } - - $packet->PROTOCOL = $this->PROTOCOL; + + $packet->PROTOCOL = $this->PROTOCOL; $packet->encode(); - if($packet->pid() == 163 or $packet->pid() == 164 && $this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return; - } + if($packet->pid() == 163 or $packet->pid() == 164 && $this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return; + } $len = strlen($packet->buffer) + 1; $MTU = $this->MTU - 24; if($len > $MTU){ @@ -1209,9 +1209,9 @@ class Player{ } $this->received[$p->messageIndex] = true; } - $p->PROTOCOL = $this->PROTOCOL; + $p->PROTOCOL = $this->PROTOCOL; $p->decode(); - $this->handleDataPacket($p); + $this->handleDataPacket($p); } } } @@ -1275,7 +1275,7 @@ class Player{ $packet->z = $z; $packet->block = $id; $packet->meta = $meta; - $packet->PROTOCOL = $this->PROTOCOL; + $packet->PROTOCOL = $this->PROTOCOL; $packet->encode(); $len = 1 + strlen($packet->buffer); @@ -1308,7 +1308,7 @@ class Player{ $motion->speedX = $e->speedX; $motion->speedY = $e->speedY; $motion->speedZ = $e->speedZ; - $motion->PROTOCOL = $this->PROTOCOL; + $motion->PROTOCOL = $this->PROTOCOL; $motion->encode(); $len += 1 + strlen($motion->buffer); ++$packets; @@ -1330,7 +1330,7 @@ class Player{ $move->yaw = $e->yaw; $move->pitch = $e->pitch; $move->bodyYaw = $e->headYaw; - $move->PROTOCOL = $this->PROTOCOL; + $move->PROTOCOL = $this->PROTOCOL; $move->encode(); }else{ $move = new MoveEntityPacket_PosRot(); @@ -1340,19 +1340,19 @@ class Player{ $move->z = $e->z; $move->yaw = $e->yaw; $move->pitch = $e->pitch; - $move->PROTOCOL = $this->PROTOCOL; + $move->PROTOCOL = $this->PROTOCOL; $move->encode(); } $len += strlen($move->buffer) + 1; ++$packets; $moveSent = true; - - }else if($this->PROTOCOL > ProtocolInfo12::CURRENT_PROTOCOL_12 && $e->headYaw != $e->lastHeadYaw){ + + }elseif($this->PROTOCOL > ProtocolInfo12::CURRENT_PROTOCOL_12 && $e->headYaw != $e->lastHeadYaw){ $headyaw = new RotateHeadPacket(); $headyaw->eid = $e->eid; $headyaw->yaw = $e->headYaw; - $headyaw->PROTOCOL = $this->PROTOCOL; + $headyaw->PROTOCOL = $this->PROTOCOL; $headyaw->encode(); $len += strlen($headyaw->buffer) + 1; ++$packets; @@ -1468,7 +1468,6 @@ class Player{ $this->data->set("gamemode", $this->gamemode); } } - public function directDataPacket(RakNetDataPacket $packet, $reliability = 0, $recover = true){ if($this->connected === false){ @@ -1479,7 +1478,7 @@ class Player{ return []; } - $packet->PROTOCOL = $this->PROTOCOL; + $packet->PROTOCOL = $this->PROTOCOL; $packet->encode(); $pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $pk->data[] = $packet; @@ -1502,1371 +1501,1366 @@ class Player{ } } - public function sendPing() { - $pk = new PingPacket; - $pk->time = intdiv(hrtime(true), 1_000_000); - $this->directDataPacket($pk); - } + public function sendPing() { + $pk = new PingPacket; + $pk->time = intdiv(hrtime(true), 1_000_000); + $this->directDataPacket($pk); + } + + public function getPing() { + return $this->lastPing; + } - public function getPing() { - return $this->lastPing; - } - public function handleDataPacket(RakNetDataPacket $packet) - { - if ($this->connected === false) { - return; - } - - if (EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY) { - return; - } - - if ($packet->pid() == ProtocolInfo::LOGIN_PACKET) { - if ($this->loggedIn === true) { - return; - } - $this->username = $packet->username; - $this->iusername = strtolower($this->username); - $this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData]; - $this->PROTOCOL = $packet->PROTOCOL; - if (count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)) { - $this->close("server is full!", false); - return; - } - if ($packet->protocol1 < ProtocolInfo3::CURRENT_PROTOCOL_3 && $packet->protocol1 > ProtocolInfo::CURRENT_PROTOCOL) { - if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) { - $pk = new LoginStatusPacket; - $pk->status = 1; - $this->directDataPacket($pk); - } else { - $pk = new LoginStatusPacket; - $pk->status = 2; - $this->directDataPacket($pk); - } - $this->close("Incorrect protocol #" . $packet->protocol1, false); - return; - } - if (preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 || $this->username === "" || $this->iusername === "rcon" || $this->iusername === "console" || $this->iusername === "server" || strlen($this->iusername) > 16) { - $this->close("Bad username", false); - return; - } - if ($this->server->api->handle("player.connect", $this) === false) { - $this->close("Unknown reason", false); - return; - } - - if ($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)) { - $this->close("Server is white-listed", false); - return; - } elseif ($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)) { - $this->close("You are banned!", false); - return; - } - $this->loggedIn = true; - - if (!isset($this->CID) or $this->CID == null) { - console("[DEBUG] Player " . $this->username . " does not have a CID", true, true, 2); - $this->CID = Utils::readLong(Utils::getRandomBytes(8, false)); - } - $u = $this->server->api->player->get($this->iusername, false); - if ($u !== false) { - $u = $this->server->clients[$this->CID]; - $u->close("this player already in game"); - } - - $this->server->api->player->add($this->CID); - if ($this->server->api->handle("player.join", $this) === false) { - $this->close("join cancelled", false); - return; - } - - if (!($this->data instanceof Config)) { - $this->close("no config created", false); - return; - } - - $this->auth = true; - if (!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01) { - if (($this->gamemode & 0x01) === 0x01) { - $inv = []; - if (($this->gamemode & 0x02) === 0x02) { - foreach (BlockAPI::$creative as $item) { - $inv[] = [0, 0, 1]; - } - } else { - foreach (BlockAPI::$creative as $item) { - $inv[] = [$item[0], $item[1], 1]; - } - } - } - $this->data->set("inventory", $inv); - } - $this->achievements = $this->data->get("achievements"); - $this->data->set("caseusername", $this->username); - $this->inventory = []; - foreach ($this->data->get("inventory") as $slot => $item) { - if (!is_array($item) or count($item) < 3) { - $item = [AIR, 0, 0]; - } - $this->inventory[$slot] = BlockAPI::getItem($item[0], $item[1], $item[2]); - } - - $this->armor = []; - foreach ($this->data->get("armor") as $slot => $item) { - $this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], $item[0] === 0 ? 0 : 1); - } - - $this->data->set("lastIP", $this->ip); - $this->data->set("lastID", $this->clientID); - - $this->server->api->player->saveOffline($this->data); - - - $pk = new LoginStatusPacket; - $pk->status = 0; - $this->dataPacket($pk); - - $pk = new StartGamePacket; - $pk->seed = $this->level->getSeed(); - $pk->x = $this->data->get("position")["x"]; - $pk->y = $this->data->get("position")["y"]; - $pk->z = $this->data->get("position")["z"]; - $pk->generator = 0; - $pk->gamemode = $this->gamemode & 0x01; - $pk->eid = 0; - $this->dataPacket($pk); - - if (($this->gamemode & 0x01) === 0x01) { - $this->slot = 0; - $this->hotbar = []; - } elseif ($this->data->exists("hotbar")) { - $this->hotbar = $this->data->get("hotbar"); - $this->slot = $this->hotbar[0]; - } else { - $this->slot = 0; - $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; - } - for ($i = 0; $i < count($this->hotbar); ++$i) { - if ($this->hotbar[$i] > 36) $this->hotbar[$i] = -1; //XXX unsafe? - if ($this->hotbar[$i] < -1) $this->hotbar[$i] = -1; - } - if ($this->data->exists("slot-count")) { - $this->slotCount = $this->data->get("slot-count"); - } else { - $this->data->set("slot-count", $this->slotCount); - } - - $this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, ["player" => $this]); - $this->eid = $this->entity->eid; - $this->server->query("UPDATE players SET EID = " . $this->eid . " WHERE CID = " . $this->CID . ";"); - $this->entity->x = $this->data->get("position")["x"]; - $this->entity->y = $this->data->get("position")["y"]; - $this->entity->z = $this->data->get("position")["z"]; - if (($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false) { - $this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level); - - $pk = new SetSpawnPositionPacket; - $pk->x = (int)$this->spawnPosition->x; - $pk->y = (int)$this->spawnPosition->y; - $pk->z = (int)$this->spawnPosition->z; - $this->dataPacket($pk); - } - $this->entity->check = false; - $this->entity->setName($this->username); - $this->entity->data["CID"] = $this->CID; - $this->evid[] = $this->server->event("server.chat", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.motion", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.animate", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.event", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.metadata", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.link", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("player.equipment.change", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("player.armor", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("player.pickup", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("tile.container.slot", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("tile.update", [$this, "eventHandler"]); - $this->lastMeasure = microtime(true); - $this->server->schedule(50, [$this, "measureLag"], [], true); - - $pk = new SetTimePacket; - $pk->time = $this->level->getTime(); - $pk->started = !$this->level->isTimeStopped(); - $this->dataPacket($pk); - - - console("[INFO] " . FORMAT_AQUA . $this->username . FORMAT_RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->eid . " at (" . $this->entity->level->getName() . ", " . round($this->entity->x, 2) . ", " . round($this->entity->y, 2) . ", " . round($this->entity->z, 2) . ")"); - return; - } - - $internalPid = $packet->getInternalPid(); - - switch ($internalPid) { - case 0x01: - break; - case ProtocolInfo::PONG_PACKET: - $currentTime = intdiv(hrtime(true), 1_000_000); - if ($currentTime > $packet->ptime) { - $this->lastPing = $currentTime - $packet->ptime; - } - break; - case ProtocolInfo::PING_PACKET: - $pk = new PongPacket; - $pk->ptime = $packet->time; - $pk->time = intdiv(hrtime(true), 1_000_000); - $this->directDataPacket($pk); - break; - case ProtocolInfo::DISCONNECT_PACKET: - $this->close("client disconnect"); - break; - case ProtocolInfo::CLIENT_CONNECT_PACKET: - if ($this->loggedIn === true) { - break; - } - $pk = new ServerHandshakePacket; - $pk->port = $this->port; - $pk->session = $packet->session; - $pk->session2 = Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9"); - $this->dataPacket($pk); - break; - case ProtocolInfo::CLIENT_HANDSHAKE_PACKET: - if ($this->loggedIn === true) { - break; - } - break; - case ProtocolInfo::LOGIN_PACKET: - if ($this->loggedIn === true) { - break; - } - $this->username = $packet->username; - $this->iusername = strtolower($this->username); - $this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData]; - $this->PROTOCOL = $packet->PROTOCOL; - if (count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)) { - $this->close("server is full!", false); - return; - } - if ($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL) { - if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) { - $pk = new LoginStatusPacket; - $pk->status = 1; - $this->directDataPacket($pk); - } else { - $pk = new LoginStatusPacket; - $pk->status = 2; - $this->directDataPacket($pk); - } - $this->close("Incorrect protocol #" . $packet->protocol1, false); - return; - } - if (preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 || $this->username === "" || $this->iusername === "rcon" || $this->iusername === "console" || $this->iusername === "server" || strlen($this->iusername) > 16) { - $this->close("Bad username", false); - return; - } - if ($this->server->api->handle("player.connect", $this) === false) { - $this->close("Unknown reason", false); - return; - } - - if ($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)) { - $this->close("Server is white-listed", false); - return; - } elseif ($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)) { - $this->close("You are banned!", false); - return; - } - $this->loggedIn = true; - - if (!isset($this->CID) or $this->CID == null) { - console("[DEBUG] Player " . $this->username . " does not have a CID", true, true, 2); - $this->CID = Utils::readLong(Utils::getRandomBytes(8, false)); - } - $u = $this->server->api->player->get($this->iusername, false); - if ($u !== false) { - $u = $this->server->clients[$this->CID]; - $u->close("this player already in game"); - } - - $this->server->api->player->add($this->CID); - if ($this->server->api->handle("player.join", $this) === false) { - $this->close("join cancelled", false); - return; - } - - if (!($this->data instanceof Config)) { - $this->close("no config created", false); - return; - } - - $this->auth = true; - if (!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01) { - if (($this->gamemode & 0x01) === 0x01) { - $inv = []; - if (($this->gamemode & 0x02) === 0x02) { - foreach (BlockAPI::$creative as $item) { - $inv[] = [0, 0, 1]; - } - } else { - foreach (BlockAPI::$creative as $item) { - $inv[] = [$item[0], $item[1], 1]; - } - } - } - $this->data->set("inventory", $inv); - } - $this->achievements = $this->data->get("achievements"); - $this->data->set("caseusername", $this->username); - $this->inventory = []; - foreach ($this->data->get("inventory") as $slot => $item) { - if (!is_array($item) or count($item) < 3) { - $item = [AIR, 0, 0]; - } - $this->inventory[$slot] = BlockAPI::getItem($item[0], $item[1], $item[2]); - } - - $this->armor = []; - foreach ($this->data->get("armor") as $slot => $item) { - $this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], $item[0] === 0 ? 0 : 1); - } - - $this->data->set("lastIP", $this->ip); - $this->data->set("lastID", $this->clientID); - - $this->server->api->player->saveOffline($this->data); - - - $pk = new LoginStatusPacket; - $pk->status = 0; - $this->dataPacket($pk); - - $pk = new StartGamePacket; - $pk->seed = $this->level->getSeed(); - $pk->x = $this->data->get("position")["x"]; - $pk->y = $this->data->get("position")["y"]; - $pk->z = $this->data->get("position")["z"]; - $pk->generator = 0; - $pk->gamemode = $this->gamemode & 0x01; - $pk->eid = 0; - $this->dataPacket($pk); - - if (($this->gamemode & 0x01) === 0x01) { - $this->slot = 0; - $this->hotbar = []; - } elseif ($this->data->exists("hotbar")) { - $this->hotbar = $this->data->get("hotbar"); - $this->slot = $this->hotbar[0]; - } else { - $this->slot = 0; - $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; - } - for ($i = 0; $i < count($this->hotbar); ++$i) { - if ($this->hotbar[$i] > 36) $this->hotbar[$i] = -1; //XXX unsafe? - if ($this->hotbar[$i] < -1) $this->hotbar[$i] = -1; - } - if ($this->data->exists("slot-count")) { - $this->slotCount = $this->data->get("slot-count"); - } else { - $this->data->set("slot-count", $this->slotCount); - } - - $this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, ["player" => $this]); - $this->eid = $this->entity->eid; - $this->server->query("UPDATE players SET EID = " . $this->eid . " WHERE CID = " . $this->CID . ";"); - $this->entity->x = $this->data->get("position")["x"]; - $this->entity->y = $this->data->get("position")["y"]; - $this->entity->z = $this->data->get("position")["z"]; - if (($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false) { - $this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level); - - $pk = new SetSpawnPositionPacket; - $pk->x = (int)$this->spawnPosition->x; - $pk->y = (int)$this->spawnPosition->y; - $pk->z = (int)$this->spawnPosition->z; - $this->dataPacket($pk); - } - $this->entity->check = false; - $this->entity->setName($this->username); - $this->entity->data["CID"] = $this->CID; - $this->evid[] = $this->server->event("server.chat", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.motion", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.animate", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.event", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.metadata", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("entity.link", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("player.equipment.change", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("player.armor", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("player.pickup", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("tile.container.slot", [$this, "eventHandler"]); - $this->evid[] = $this->server->event("tile.update", [$this, "eventHandler"]); - $this->lastMeasure = microtime(true); - $this->server->schedule(50, [$this, "measureLag"], [], true); - - $pk = new SetTimePacket; - $pk->time = $this->level->getTime(); - $pk->started = !$this->level->isTimeStopped(); - $this->dataPacket($pk); - - - console("[INFO] " . FORMAT_AQUA . $this->username . FORMAT_RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->eid . " at (" . $this->entity->level->getName() . ", " . round($this->entity->x, 2) . ", " . round($this->entity->y, 2) . ", " . round($this->entity->z, 2) . ")"); - break; - case ProtocolInfo::READY_PACKET: - if ($this->loggedIn === false) { - break; - } - switch ($packet->status) { - case 1: //Spawn!! - if ($this->spawned !== false) { - break; - } - - $pos = new Position($this->entity->x, $this->entity->y, $this->entity->z, $this->level); - $pData = $this->data->get("position"); - $this->entity->setHealth($this->data->get("health"), "spawn", true, false); - $this->spawned = true; - $this->teleport($pos, $pData["yaw"] ?? false, $pData["pitch"] ?? false, true, true); - $this->server->api->player->spawnAllPlayers($this); - $this->server->api->player->spawnToAllPlayers($this); - $this->server->api->entity->spawnAll($this); - $this->server->api->entity->spawnToAll($this->entity); - - //$this->server->schedule(5, [$this->entity, "update"], [], true); - //$this->server->schedule(2, [$this->entity, "updateMovement"], [], true); - $this->sendArmor(); - $array = explode("@n", (string)$this->server->motd); - foreach ($array as $msg) { - $this->sendChat($msg . "\n"); - } - - $this->sendInventory(); - $this->sendSettings(); - $this->server->schedule(50, [$this, "orderChunks"], []); - $this->blocked = false; - - $this->server->send2Discord($this->username . " joined the game"); - $this->server->handle("player.spawn", $this); - break; - case 2://Chunk loaded? - break; - } - break; - case ProtocolInfo::ROTATE_HEAD_PACKET: - if ($this->spawned === false) { - break; - } - if (($this->entity instanceof Entity)) { - if ($this->blocked === true or $this->server->api->handle("player.move", $this->entity) === false) { - if ($this->lastCorrect instanceof Vector3 && !$this->entity->dead) { - $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); - } - } else { - $this->entity->setPosition($this->entity, $packet->yaw, $this->entity->pitch); - } - } - break; - case ProtocolInfo::MOVE_PLAYER_PACKET: - if ($this->spawned === false) { - break; - } - if ($this->isSleeping) break; - if (($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement) { - $this->lastMovement = $packet->messageIndex; - $newPos = new Vector3($packet->x, $packet->y, $packet->z); - if ($this->forceMovement instanceof Vector3) { - if ($this->forceMovement->distance($newPos) <= 0.7) { - $this->forceMovement = false; - } else { - $this->teleport($this->forceMovement, $this->entity->yaw, $this->entity->pitch, false); - break; - } - } - $speed = $this->entity->getSpeedMeasure(); - if ($this->blocked === true or ($this->server->api->getProperty("allow-flight") !== true and (($speed > 9 and ($this->gamemode & 0x01) === 0x00) or $speed > 20 or $this->entity->distance($newPos) > 7)) or $this->server->api->handle("player.move", $this->entity) === false) { - if ($this->lastCorrect instanceof Vector3 && !$this->entity->dead) { - $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); - } - } else { - $this->entity->setPosition($newPos, $packet->yaw, $packet->pitch, $packet->bodyYaw); - } - $this->entity->updateAABB(); - } - break; - case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: - if ($this->spawned === false) { - break; - } - $packet->eid = $this->eid; - - $data = []; - $data["eid"] = $packet->eid; - $data["player"] = $this; - - if ($packet->slot === 0) { - $data["slot"] = -1; - $data["item"] = BlockAPI::getItem(AIR, 0, 0); - if ($this->server->handle("player.equipment.change", $data) !== false) { - $this->slot = -1; - } - break; - } else if ($packet->slot > 0) { - $packet->slot -= 9; - } - - - if (($this->gamemode & 0x01) === SURVIVAL) { - $data["item"] = $this->getSlot($packet->slot); - if (!($data["item"] instanceof Item)) { - break; - } - } elseif (($this->gamemode & 0x01) === CREATIVE) { - $packet->slot = false; - foreach (BlockAPI::$creative as $i => $d) { - if ($d[0] === $packet->item and $d[1] === $packet->meta) { - $packet->slot = $i; - } - } - if ($packet->slot !== false) { - $data["item"] = $this->getSlot($packet->slot); - } else { - break; - } - } else { - break;//????? - } - - $data["slot"] = $packet->slot; - - if ($this->server->handle("player.equipment.change", $data) !== false) { - if (!Player::$experimentalHotbar) $this->slot = $packet->slot; - if (($this->gamemode & 0x01) === SURVIVAL) { - $has = false; - $slotPos = 0; - $packetSlotPos = 0; - for ($i = 0; $i < $this->slotCount; ++$i) { - if ($this->slot == $this->hotbar[$i]) $slotPos = $i; - if ($packet->slot == $this->hotbar[$i]) { - $packetSlotPos = $i; - $has = true; - break; - } - } - - if (Player::$experimentalHotbar && $has) { - $this->slot = $packet->slot; - $this->curHotbarIndex = $packetSlotPos; - } - if (!$has) { - if (Player::$experimentalHotbar) { - $this->slot = $packet->slot; - $this->hotbar[$this->curHotbarIndex] = $packet->slot; - } else { - $this->curHotbarIndex = 0; - array_pop($this->hotbar); - array_unshift($this->hotbar, $this->slot); - } - } - if (Player::$experimentalHotbar) $this->sendInventory(); - } else { - $this->slot = $packet->slot; - } - } else { - //$this->sendInventorySlot($packet->slot); - $this->sendInventory(); - } - if ($this->entity->inAction === true) { - $this->entity->inAction = false; - $this->entity->inActionCounter = 0; - $this->entity->updateMetadata(); - } - break; - case ProtocolInfo::REQUEST_CHUNK_PACKET: - //console("request x:".$packet->chunkX.", z: ".$packet->chunkZ." chunk"); - //$this->useChunk($packet->chunkX, $packet->chunkZ); - //$this->lastChunk = [$packet->chunkX, $packet->chunkZ]; - break; - case ProtocolInfo::USE_ITEM_PACKET: - if (!($this->entity instanceof Entity)) { - break; - } - - $blockVector = new Vector3($packet->x, $packet->y, $packet->z); - - if (($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5) { - $target = $this->level->getBlock($blockVector); - $block = $target->getSide($packet->face); - - $pk = new UpdateBlockPacket; - $pk->x = $target->x; - $pk->y = $target->y; - $pk->z = $target->z; - $pk->block = $target->getID(); - $pk->meta = $target->getMetadata(); - $this->dataPacket($pk); - - $pk = new UpdateBlockPacket; - $pk->x = $block->x; - $pk->y = $block->y; - $pk->z = $block->z; - $pk->block = $block->getID(); - $pk->meta = $block->getMetadata(); - $this->dataPacket($pk); - break; - } - $this->craftingItems = []; - $this->toCraft = []; - $packet->eid = $this->eid; - $data = []; - $data["eid"] = $packet->eid; - $data["player"] = $this; - $data["face"] = $packet->face; - $data["x"] = $packet->x; - $data["y"] = $packet->y; - $data["z"] = $packet->z; - $data["item"] = $packet->item; - $data["meta"] = $packet->meta; - $data["fx"] = $packet->fx; - $data["fy"] = $packet->fy; - $data["fz"] = $packet->fz; - $data["posX"] = $packet->posX; - $data["posY"] = $packet->posY; - $data["posZ"] = $packet->posZ; - - if ($packet->face >= 0 and $packet->face <= 5) { //Use Block, place - if ($this->entity->inAction === true) { - $this->entity->inAction = false; - $this->entity->inActionCounter = 0; - $this->entity->updateMetadata(); - } - - if ($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 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); - } else { - $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz); - break; - } - $target = $this->level->getBlock($blockVector); - $block = $target->getSide($packet->face); - - $pk = new UpdateBlockPacket; - $pk->x = $target->x; - $pk->y = $target->y; - $pk->z = $target->z; - $pk->block = $target->getID(); - $pk->meta = $target->getMetadata(); - $this->dataPacket($pk); - - $pk = new UpdateBlockPacket; - $pk->x = $block->x; - $pk->y = $block->y; - $pk->z = $block->z; - $pk->block = $block->getID(); - $pk->meta = $block->getMetadata(); - $this->dataPacket($pk); - break; - } elseif ($packet->face === 0xff) { - - $slotItem = $this->getHeldItem(); - if ($slotItem->getID() == SNOWBALL || $slotItem->getID() == EGG) { //TODO better way - $x = $packet->x * 0.000030518; - $y = $packet->y * 0.000030518; - $z = $packet->z * 0.000030518; - - $d = sqrt($x * $x + $y * $y + $z * $z); - - if ($d >= 0.0001) { - $shootX = $x / $d; - $shootY = $y / $d; - $shootZ = $z / $d; - - $data = [ - "x" => $this->entity->x, - "y" => $this->entity->y + $this->entity->getEyeHeight(), - "z" => $this->entity->z, - "yaw" => $this->entity->yaw, - "pitch" => $this->entity->pitch, - "shooter" => $this->entity->eid, - "shootX" => $shootX, - "shootY" => $shootY, - "shootZ" => $shootZ - ]; - - if ($slotItem->getID() == EGG) { - $e = $this->server->api->entity->add($this->entity->level, ENTITY_OBJECT, OBJECT_EGG, $data); - } else { - $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_SNOWBALL, $data); - } - - if (($this->gamemode & 0x01) == 0x0) { - if ($slotItem !== false) { - if ($slotItem->count == 1) $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0); - else $slotItem->count -= 1; - //$this->sendInventory(); - } - } - - $this->server->api->entity->spawnToAll($e); - } - - } else { - if ($this->server->handle("player.action", $data) !== false) { - $this->entity->inAction = true; - $this->entity->inActionCounter = 0; - $this->startAction = microtime(true); - $this->entity->updateMetadata(); - } - } - } - break; - case ProtocolInfo::PLACE_BLOCK_PACKET: - if (!($this->entity instanceof Entity)) { - break; - } - - $blockVector = new Vector3($packet->x, $packet->y, $packet->z); - - if (($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5) { - $target = $this->level->getBlock($blockVector); - $block = $target->getSide($packet->face); - - $pk = new UpdateBlockPacket; - $pk->x = $target->x; - $pk->y = $target->y; - $pk->z = $target->z; - $pk->block = $target->getID(); - $pk->meta = $target->getMetadata(); - $this->dataPacket($pk); - - $pk = new UpdateBlockPacket; - $pk->x = $block->x; - $pk->y = $block->y; - $pk->z = $block->z; - $pk->block = $block->getID(); - $pk->meta = $block->getMetadata(); - $this->dataPacket($pk); - break; - } - $this->craftingItems = []; - $this->toCraft = []; - $packet->eid = $this->eid; - $data = []; - - if ($packet->face >= 0 and $packet->face <= 5) { - if ($this->entity->inAction === true) { - $this->entity->inAction = false; - $this->entity->inActionCounter = 0; - $this->entity->updateMetadata(); - } - - if ($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 10)) { - - } else { - $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->x, $packet->y, $packet->z); - break; - } - $target = $this->level->getBlock($blockVector); - $block = $target->getSide($packet->face); - - $pk = new UpdateBlockPacket; - $pk->x = $target->x; - $pk->y = $target->y; - $pk->z = $target->z; - $pk->block = $target->getID(); - $pk->meta = $target->getMetadata(); - $this->dataPacket($pk); - - $pk = new UpdateBlockPacket; - $pk->x = $block->x; - $pk->y = $block->y; - $pk->z = $block->z; - $pk->block = $block->getID(); - $pk->meta = $block->getMetadata(); - $this->dataPacket($pk); - break; - } - break; - case ProtocolInfo::PLAYER_ACTION_PACKET: - if ($this->spawned === false or $this->blocked === true) { - break; - } - $packet->eid = $this->eid; - $this->craftingItems = []; - $this->toCraft = []; - - switch ($packet->action) { - case 5: //Shot arrow - if ($this->entity->inAction) { - $arrowSlot = $this->hasItem(ARROW); - if ($this->getSlot($this->slot)->getID() === BOW && (($this->gamemode & 0x01) == 0x1 || $arrowSlot !== false)) { - if ($this->startAction !== false) { - $initalPower = $this->entity->inActionCounter; - $power = $initalPower / 20; - $power = ($power * $power + $power * 2) / 3; - if ($power >= 0.1) { - if ($power > 1) $power = 1; - $this->server->dhandle("player.shoot", [ - "player" => $this, - "power" => &$power, - ]); - - $d = [ - "x" => $this->entity->x, - "y" => $this->entity->y + 1.6, - "z" => $this->entity->z, - "yaw" => $this->entity->yaw, - "pitch" => $this->entity->pitch, - "shooter" => $this->entity->eid, - ]; - $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d); - $e->speedX = -sin(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI); - $e->speedZ = cos(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI); - $e->speedY = -sin(($e->pitch / 180) * M_PI); - $e->shooterEID = $this->entity->eid; - $e->shotByEntity = true; - /** - * Max usage: 72000ticks - * initalPower = 72000 - (72000 - usedCtr) - * power = initialPower / 20' - * power = (power*power+power*2)/3 - * powerMax is 1, powerMin is 0.1 - * args: xvel, yvel, zvel, (power+power)*1.5, 1.0 - */ - $e->critical = ($power == 1); - $e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power + $power) * 1.5, 1.0); - $this->server->api->entity->spawnToAll($e); - if (($this->gamemode & 0x01) == 0x0) { - $bow = $this->getSlot($this->slot); - if (++$bow->meta >= $bow->getMaxDurability()) { - $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0); - } - $this->removeItem(ARROW, 0, 1, false); - $this->sendInventory(); - } - } - } - } else { //inv desynced, resend - $this->sendInventory(); - } - } - $this->startAction = false; - $this->entity->inAction = false; - $this->entity->inActionCounter = 0; - $this->entity->updateMetadata(); - break; - case 6: //get out of the bed - $this->stopSleep(); - } - break; - case ProtocolInfo::REMOVE_BLOCK_PACKET: - $blockVector = new Vector3($packet->x, $packet->y, $packet->z); - if ($this->spawned === false or $this->blocked === true or $this->entity->distance($blockVector) > 8) { - $target = $this->level->getBlock($blockVector); - - $pk = new UpdateBlockPacket; - $pk->x = $target->x; - $pk->y = $target->y; - $pk->z = $target->z; - $pk->block = $target->getID(); - $pk->meta = $target->getMetadata(); - $this->dataPacket($pk); - break; - } - $this->craftingItems = []; - $this->toCraft = []; - $this->server->api->block->playerBlockBreak($this, $blockVector); - break; - case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: - if ($this->spawned === false or $this->blocked === true) { - break; - } - $this->craftingItems = []; - $this->toCraft = []; - - $packet->eid = $this->eid; - for ($i = 0; $i < 4; ++$i) { - $s = $packet->slots[$i]; - if ($s === 0 or $s === 255) { - $s = BlockAPI::getItem(AIR, 0, 0); - } else { - $s = BlockAPI::getItem($s + 256, 0, 1); - } - $slot = $this->armor[$i]; - if ($slot->getID() !== AIR and $s->getID() === AIR) { - $this->addItem($slot->getID(), $slot->getMetadata(), 1, false); - $this->armor[$i] = BlockAPI::getItem(AIR, 0, 0); - $packet->slots[$i] = 255; - } elseif ($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false) { - $this->armor[$i] = $this->getSlot($sl); - $this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0), false); - } elseif ($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false) { - $item = $this->armor[$i]; - $this->armor[$i] = $this->getSlot($sl); - $this->setSlot($sl, $item, false); - } else { - $packet->slots[$i] = 255; - } - - } - $this->sendArmor(); - if ($this->entity->inAction === true) { - $this->entity->inAction = false; - $this->entity->inActionCounter = 0; - $this->entity->updateMetadata(); - } - break; - case ProtocolInfo::INTERACT_PACKET: - if ($this->spawned === false) { - break; - } - $packet->eid = $this->eid; - $data = []; - $data["target"] = $packet->target; - $data["eid"] = $packet->eid; - $data["action"] = $packet->action; - $this->craftingItems = []; - $this->toCraft = []; - $target = $this->server->api->entity->get($packet->target); - if ($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8) { - $data["targetentity"] = $packet->target; - $data["entity"] = $this->entity; - $data["player"] = $this; - if ($this->server->handle("player.interact", $data) !== false) { - $target->interactWith($this->entity, $packet->action); - } - } - - break; - case ProtocolInfo::ANIMATE_PACKET: - if ($this->spawned === false) { - break; - } - $packet->eid = $this->eid; - $this->server->api->dhandle("entity.animate", ["eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action]); - break; - case ProtocolInfo::RESPAWN_PACKET: - if ($this->spawned === false) { - break; - } - if (@$this->entity->dead === false) { - break; - } - $this->craftingItems = []; - $this->toCraft = []; - - $this->checkSpawnPosition(); - $this->teleport($this->spawnPosition, false, false, true, false); - - $pk = new MovePlayerPacket(); - $pk->eid = $this->entity->eid; - $pk->x = $this->entity->x; - $pk->y = $this->entity->y; - $pk->z = $this->entity->z; - $pk->yaw = $this->entity->yaw; - $pk->pitch = $this->entity->pitch; - $pk->bodyYaw = $this->entity->headYaw; - foreach ($this->entity->level->players as $player) { - if ($player->entity->eid != $this->entity->eid) { - $player->dataPacket(clone $pk); - } - } - - if ($this->entity instanceof Entity) { - $this->entity->fire = 0; - $this->entity->air = $this->entity->maxAir; - $this->entity->setHealth(20, "respawn", true); - $this->entity->updateMetadata(); - } else { - break; - } - $this->sendInventory(); - $this->blocked = false; - $this->server->handle("player.respawn", $this); - break; - case ProtocolInfo::SET_HEALTH_PACKET: //Not used - break; - case ProtocolInfo::ENTITY_EVENT_PACKET: - if ($this->spawned === false or $this->blocked === true) { - break; - } - $this->craftingItems = []; - $this->toCraft = []; - $packet->eid = $this->eid; - if ($this->entity->inAction === true) { - $this->entity->inAction = false; - $this->entity->inActionCounter = 0; - $this->entity->updateMetadata(); - } - switch ($packet->event) { - case 9: //Eating - $slot = $this->getSlot($this->slot); - $foodHeal = Item::getFoodHeal($slot->getID()); - if ($this->entity->getHealth() < 20 && $foodHeal != 0) { - $pk = new EntityEventPacket; - $pk->eid = 0; - $pk->event = 9; - $this->dataPacket($pk); - - $this->entity->heal($foodHeal, "eating"); - --$slot->count; - if ($slot->count <= 0) { - $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); - } - if ($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP) { - $this->addItem(BOWL, 0, 1, false); - } - } - break; - } - break; - case ProtocolInfo::DROP_ITEM_PACKET: - if ($this->spawned === false or $this->blocked === true) { - break; - } - - if ($this->gamemode & 0x01 == 1) { - ConsoleAPI::warn("{$this->iusername} tried dropping item while in creative!"); - return; - } - - $packet->eid = $this->eid; - $prevItem = $packet->item; - $packet->item = $this->getSlot($this->slot); - $sendOnDrop = false; - - if ($prevItem->getID() != $packet->item->getID() || $prevItem->getMetadata() != $packet->item->getMetadata()) { - if (count($this->inventory) >= 36) { - foreach ($this->inventory as $slot => $item) { - if ($item->getID() == 0) goto inv_desync_on_drop; - } - - $this->toCraft[] = $prevItem; //vanilla drops only result? - $this->lastCraft = microtime(true); - break; - } - } else { - inv_desync_on_drop: - ConsoleAPI::debug("Inventory desync on drop({$this->iusername})"); - $sendOnDrop = true; - } - - $this->craftingItems = []; - $this->toCraft = []; - $data["eid"] = $packet->eid; - $data["unknown"] = $packet->unknown; - $data["item"] = $packet->item; - $data["player"] = $this; - if ($this->blocked === false and $this->server->handle("player.drop", $data) !== false) { - $f1 = 0.3; - $sX = -sin(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; - $sZ = cos(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; - $sY = -sin(($this->entity->pitch / 180) * M_PI) * $f1 + 0.1; - $f1 = 0.02; - $f3 = $this->entity->random->nextFloat() * M_PI * 2.0; - $f1 *= $this->entity->random->nextFloat(); - $sX += cos($f3) * $f1; - $sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1; - $sZ += sin($f3) * $f1; - $this->server->api->entity->dropRawPos($this->level, $this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $packet->item, $sX, $sY, $sZ); - $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), $sendOnDrop); - } else { - $this->sendInventory(); //send if blocked - } - if ($this->entity->inAction === true) { - $this->entity->inAction = false; - $this->entity->inActionCounter = 0; - $this->entity->updateMetadata(); - } - break; - case ProtocolInfo::MESSAGE_PACKET: - if ($this->spawned === false) { - break; - } - $this->craftingItems = []; - $this->toCraft = []; - if (trim($packet->message) != "" and strlen($packet->message) <= 255) { - $message = $packet->message; - if ($message[0] === "/") { //Command - if ($this instanceof Player) { - console("[DEBUG] " . FORMAT_AQUA . $this->username . FORMAT_RESET . " issued server command: " . $message); - } else { - console("[DEBUG] " . FORMAT_YELLOW . "*" . $this . FORMAT_RESET . " issued server command: " . $message); - } - $this->server->api->console->run(substr($message, 1), $this); - } else { - $data = ["player" => $this, "message" => $message]; - if (Utils::hasEmoji($data["message"])) { - $this->sendChat("Your message contains illegal characters"); - break; - } - - //if($message == "pf"){ - // Living::$pathfind = !Living::$pathfind; - //} - - if ($this->server->api->handle("player.chat", $data) !== false) { - $this->server->send2Discord("<" . $this->username . "> " . $message); - if (isset($data["message"])) { - $this->server->api->chat->send($this, $data["message"]); - } else { - $this->server->api->chat->send($this, $message); - } - } - } - } - break; - case ProtocolInfo::CONTAINER_CLOSE_PACKET: - if ($this->spawned === false) { - break; - } - $this->craftingItems = []; - $this->toCraft = []; - if (isset($this->windows[$packet->windowid])) { - if (is_array($this->windows[$packet->windowid])) { - foreach ($this->windows[$packet->windowid] as $ob) { - $pk = new TileEventPacket; - $pk->x = $ob->x; - $pk->y = $ob->y; - $pk->z = $ob->z; - $pk->case1 = 1; - $pk->case2 = 0; - $this->server->api->player->broadcastPacket($this->level->players, $pk); - } - } elseif ($this->windows[$packet->windowid]->class === TILE_CHEST) { - $pk = new TileEventPacket; - $pk->x = $this->windows[$packet->windowid]->x; - $pk->y = $this->windows[$packet->windowid]->y; - $pk->z = $this->windows[$packet->windowid]->z; - $pk->case1 = 1; - $pk->case2 = 0; - $this->server->api->player->broadcastPacket($this->level->players, $pk); - } - } - unset($this->windows[$packet->windowid]); - - $pk = new ContainerClosePacket; - $pk->windowid = $packet->windowid; - $this->dataPacket($pk); - break; - case ProtocolInfo::CONTAINER_SET_SLOT_PACKET: - if ($this->spawned === false or $this->blocked === true) { - break; - } - - if ($this->lastCraft <= (microtime(true) - 1)) { - if (isset($this->toCraft[-1])) { - $this->toCraft = [-1 => $this->toCraft[-1]]; - } else { - $this->toCraft = []; - } - $this->craftingItems = []; - } - - if ($packet->windowid === 0) { - $craft = false; - $slot = $this->getSlot($packet->slot); - if ($slot->count >= $packet->item->count and (($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()) or ($packet->item->getID() === AIR and $packet->item->count === 0)) and !isset($this->craftingItems[$packet->slot])) { //Crafting recipe - $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count - $packet->item->count); - $this->craftingItems[$packet->slot] = $use; - $craft = true; - } elseif ($slot->count <= $packet->item->count and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))) { //Crafting final - $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count - $slot->count); - if (count($this->toCraft) === 0) { - $this->toCraft[-1] = 0; - } - $this->toCraft[$packet->slot] = $craftItem; - $craft = true; - } elseif (((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->count > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())) { //Crafting final - $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); - if (count($this->toCraft) === 0) { - $this->toCraft[-1] = 0; - } - $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count); - $this->craftingItems[$packet->slot] = $use; - $this->toCraft[$packet->slot] = $craftItem; - $craft = true; - } - - if ($craft === true) { - $this->lastCraft = microtime(true); - } - - if ($craft === true and count($this->craftingItems) > 0 and count($this->toCraft) > 0 and ($recipe = $this->craftItems($this->toCraft, $this->craftingItems, $this->toCraft[-1])) !== true) { - if ($recipe === false) { - $this->sendInventory(); - $this->toCraft = []; - } else { - $this->toCraft = [-1 => $this->toCraft[-1]]; - } - $this->craftingItems = []; - } - } else { - $this->toCraft = []; - $this->craftingItems = []; - } - if (!isset($this->windows[$packet->windowid])) { - break; - } - - if (is_array($this->windows[$packet->windowid])) { - $tiles = $this->windows[$packet->windowid]; - if ($packet->slot >= 0 and $packet->slot < CHEST_SLOTS) { - $tile = $tiles[0]; - $slotn = $packet->slot; - $offset = 0; - } elseif ($packet->slot >= CHEST_SLOTS and $packet->slot <= (CHEST_SLOTS << 1)) { - $tile = $tiles[1]; - $slotn = $packet->slot - CHEST_SLOTS; - $offset = CHEST_SLOTS; - } else { - break; - } - - $item = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); - - $slot = $tile->getSlot($slotn); - if ($this->server->api->dhandle("player.container.slot", [ - "tile" => $tile, - "slot" => $packet->slot, - "offset" => $offset, - "slotdata" => $slot, - "itemdata" => $item, - "player" => $this - ]) === false) { - $pk = new ContainerSetSlotPacket; - $pk->windowid = $packet->windowid; - $pk->slot = $packet->slot; - $pk->item = $slot; - $this->dataPacket($pk); - break; - } - 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) { - break; - } - } elseif ($slot->count > $item->count) { - $this->addItem($item->getID(), $item->getMetadata(), $slot->count - $item->count, false); - } - } else { - if ($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false) { - break; - } - $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); - } - $tile->setSlot($slotn, $item, true, $offset); - } else { - $tile = $this->windows[$packet->windowid]; - if (($tile->class !== TILE_CHEST and $tile->class !== TILE_FURNACE) or $packet->slot < 0 or ($tile->class === TILE_CHEST and $packet->slot >= CHEST_SLOTS) or ($tile->class === TILE_FURNACE and $packet->slot >= FURNACE_SLOTS)) { - break; - } - $item = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); - - $slot = $tile->getSlot($packet->slot); - if ($this->server->api->dhandle("player.container.slot", [ - "tile" => $tile, - "slot" => $packet->slot, - "slotdata" => $slot, - "itemdata" => $item, - "player" => $this, - ]) === false) { - $pk = new ContainerSetSlotPacket; - $pk->windowid = $packet->windowid; - $pk->slot = $packet->slot; - $pk->item = $slot; - $this->dataPacket($pk); - break; - } - - if ($tile->class === TILE_FURNACE and $packet->slot == 2) { - switch ($slot->getID()) { - case IRON_INGOT: - AchievementAPI::grantAchievement($this, "acquireIron"); - break; - } - } - - 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) { - break; - } - } elseif ($slot->count > $item->count) { - $this->addItem($item->getID(), $item->getMetadata(), $slot->count - $item->count, false); - } - } else { - if ($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false) { - break; - } - $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); - } - - $tile->setSlot($packet->slot, $item); - } - break; - case ProtocolInfo::SEND_INVENTORY_PACKET: - if ($this->spawned === false) { - break; - } - break; - case ProtocolInfo::ENTITY_DATA_PACKET: - if ($this->spawned === false or $this->blocked === true) { - break; - } - $this->craftingItems = []; - $this->toCraft = []; - $t = $this->server->api->tile->get(new Position($packet->x, $packet->y, $packet->z, $this->level)); - if (($t instanceof Tile) and $t->class === TILE_SIGN) { - if ($t->data["creator"] !== $this->username) { - $t->spawn($this); - } else { - $nbt = new NBT(); - $nbt->load($packet->namedtag); - $d = array_shift($nbt->tree); - if ($d["id"] !== TILE_SIGN) { - $t->spawn($this); - } else { - $t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]); - } - } - } - break; - case ProtocolInfo::PLAYER_INPUT_PACKET: - $this->isJumping = $packet->isJumping; - $this->isSneaking = $packet->isSneaking; - $this->entity->moveForward = $packet->moveForward; - $this->entity->moveStrafing = $packet->moveStrafe; - - if (strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity != 0) { - $this->entity->stopRiding(); - break; - } - if ($this->entity->linkedEntity != 0) { //TODO better riding - $e = $this->entity->level->entityList[$this->entity->linkedEntity] ?? false; - if ($e === false) { - ConsoleAPI::warn("Player is riding on entity that doesnt exist in world! ({$this->iusername}, {$this->entity->linkedEntity})"); - $this->entity->stopRiding(); - break; - } - /*$pk = new SetEntityMotionPacket; - $pk->eid = $e->eid; - $pk->speedX = ($this->entity->x - $e->x)*1.2; - $pk->speedY = ($this->entity->y - $e->y)*1.2; - $pk->speedZ = ($this->entity->z - $e->z)*1.2; - foreach($this->level->players as $p){ - if($p->entity->eid != $this->entity->eid){ - $p->dataPacket(clone $pk); - } - } - console("{$e} {$this->entity}"); - //$this->entity->linkedEntity->moveFlying($packet->moveStrafe, $packet->moveForward, 1);*/ - } - - break; - default: - console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2); - break; - } - } + { + if ($this->connected === false) { + return; + } + + if (EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY) { + return; + } + + if ($packet->pid() == ProtocolInfo::LOGIN_PACKET) { + if ($this->loggedIn === true) { + return; + } + $this->username = $packet->username; + $this->iusername = strtolower($this->username); + $this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData]; + $this->PROTOCOL = $packet->PROTOCOL; + if (count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)) { + $this->close("server is full!", false); + return; + } + if ($packet->protocol1 < ProtocolInfo3::CURRENT_PROTOCOL_3 && $packet->protocol1 > ProtocolInfo::CURRENT_PROTOCOL) { + if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) { + $pk = new LoginStatusPacket; + $pk->status = 1; + $this->directDataPacket($pk); + } else { + $pk = new LoginStatusPacket; + $pk->status = 2; + $this->directDataPacket($pk); + } + $this->close("Incorrect protocol #" . $packet->protocol1, false); + return; + } + if (preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 || $this->username === "" || $this->iusername === "rcon" || $this->iusername === "console" || $this->iusername === "server" || strlen($this->iusername) > 16) { + $this->close("Bad username", false); + return; + } + if ($this->server->api->handle("player.connect", $this) === false) { + $this->close("Unknown reason", false); + return; + } + + if ($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)) { + $this->close("Server is white-listed", false); + return; + } elseif ($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)) { + $this->close("You are banned!", false); + return; + } + $this->loggedIn = true; + + if (!isset($this->CID) or $this->CID == null) { + console("[DEBUG] Player " . $this->username . " does not have a CID", true, true, 2); + $this->CID = Utils::readLong(Utils::getRandomBytes(8, false)); + } + $u = $this->server->api->player->get($this->iusername, false); + if ($u !== false) { + $u = $this->server->clients[$this->CID]; + $u->close("this player already in game"); + } + + $this->server->api->player->add($this->CID); + if ($this->server->api->handle("player.join", $this) === false) { + $this->close("join cancelled", false); + return; + } + + if (!($this->data instanceof Config)) { + $this->close("no config created", false); + return; + } + + $this->auth = true; + if (!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01) { + if (($this->gamemode & 0x01) === 0x01) { + $inv = []; + if (($this->gamemode & 0x02) === 0x02) { + foreach (BlockAPI::$creative as $item) { + $inv[] = [0, 0, 1]; + } + } else { + foreach (BlockAPI::$creative as $item) { + $inv[] = [$item[0], $item[1], 1]; + } + } + } + $this->data->set("inventory", $inv); + } + $this->achievements = $this->data->get("achievements"); + $this->data->set("caseusername", $this->username); + $this->inventory = []; + foreach ($this->data->get("inventory") as $slot => $item) { + if (!is_array($item) or count($item) < 3) { + $item = [AIR, 0, 0]; + } + $this->inventory[$slot] = BlockAPI::getItem($item[0], $item[1], $item[2]); + } + + $this->armor = []; + foreach ($this->data->get("armor") as $slot => $item) { + $this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], $item[0] === 0 ? 0 : 1); + } + + $this->data->set("lastIP", $this->ip); + $this->data->set("lastID", $this->clientID); + + $this->server->api->player->saveOffline($this->data); + + $pk = new LoginStatusPacket; + $pk->status = 0; + $this->dataPacket($pk); + + $pk = new StartGamePacket; + $pk->seed = $this->level->getSeed(); + $pk->x = $this->data->get("position")["x"]; + $pk->y = $this->data->get("position")["y"]; + $pk->z = $this->data->get("position")["z"]; + $pk->generator = 0; + $pk->gamemode = $this->gamemode & 0x01; + $pk->eid = 0; + $this->dataPacket($pk); + + if (($this->gamemode & 0x01) === 0x01) { + $this->slot = 0; + $this->hotbar = []; + } elseif ($this->data->exists("hotbar")) { + $this->hotbar = $this->data->get("hotbar"); + $this->slot = $this->hotbar[0]; + } else { + $this->slot = 0; + $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; + } + for ($i = 0; $i < count($this->hotbar); ++$i) { + if ($this->hotbar[$i] > 36) $this->hotbar[$i] = -1; //XXX unsafe? + if ($this->hotbar[$i] < -1) $this->hotbar[$i] = -1; + } + if ($this->data->exists("slot-count")) { + $this->slotCount = $this->data->get("slot-count"); + } else { + $this->data->set("slot-count", $this->slotCount); + } + + $this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, ["player" => $this]); + $this->eid = $this->entity->eid; + $this->server->query("UPDATE players SET EID = " . $this->eid . " WHERE CID = " . $this->CID . ";"); + $this->entity->x = $this->data->get("position")["x"]; + $this->entity->y = $this->data->get("position")["y"]; + $this->entity->z = $this->data->get("position")["z"]; + if (($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false) { + $this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level); + + $pk = new SetSpawnPositionPacket; + $pk->x = (int) $this->spawnPosition->x; + $pk->y = (int) $this->spawnPosition->y; + $pk->z = (int) $this->spawnPosition->z; + $this->dataPacket($pk); + } + $this->entity->check = false; + $this->entity->setName($this->username); + $this->entity->data["CID"] = $this->CID; + $this->evid[] = $this->server->event("server.chat", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.motion", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.animate", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.event", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.metadata", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.link", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.equipment.change", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.armor", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.pickup", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("tile.container.slot", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("tile.update", [$this, "eventHandler"]); + $this->lastMeasure = microtime(true); + $this->server->schedule(50, [$this, "measureLag"], [], true); + + $pk = new SetTimePacket; + $pk->time = $this->level->getTime(); + $pk->started = !$this->level->isTimeStopped(); + $this->dataPacket($pk); + + console("[INFO] " . FORMAT_AQUA . $this->username . FORMAT_RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->eid . " at (" . $this->entity->level->getName() . ", " . round($this->entity->x, 2) . ", " . round($this->entity->y, 2) . ", " . round($this->entity->z, 2) . ")"); + return; + } + + $internalPid = $packet->getInternalPid(); + + switch ($internalPid) { + case 0x01: + break; + case ProtocolInfo::PONG_PACKET: + $currentTime = intdiv(hrtime(true), 1_000_000); + if ($currentTime > $packet->ptime) { + $this->lastPing = $currentTime - $packet->ptime; + } + break; + case ProtocolInfo::PING_PACKET: + $pk = new PongPacket; + $pk->ptime = $packet->time; + $pk->time = intdiv(hrtime(true), 1_000_000); + $this->directDataPacket($pk); + break; + case ProtocolInfo::DISCONNECT_PACKET: + $this->close("client disconnect"); + break; + case ProtocolInfo::CLIENT_CONNECT_PACKET: + if ($this->loggedIn === true) { + break; + } + $pk = new ServerHandshakePacket; + $pk->port = $this->port; + $pk->session = $packet->session; + $pk->session2 = Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9"); + $this->dataPacket($pk); + break; + case ProtocolInfo::CLIENT_HANDSHAKE_PACKET: + if ($this->loggedIn === true) { + break; + } + break; + case ProtocolInfo::LOGIN_PACKET: + if ($this->loggedIn === true) { + break; + } + $this->username = $packet->username; + $this->iusername = strtolower($this->username); + $this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData]; + $this->PROTOCOL = $packet->PROTOCOL; + if (count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)) { + $this->close("server is full!", false); + return; + } + if ($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL) { + if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) { + $pk = new LoginStatusPacket; + $pk->status = 1; + $this->directDataPacket($pk); + } else { + $pk = new LoginStatusPacket; + $pk->status = 2; + $this->directDataPacket($pk); + } + $this->close("Incorrect protocol #" . $packet->protocol1, false); + return; + } + if (preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 || $this->username === "" || $this->iusername === "rcon" || $this->iusername === "console" || $this->iusername === "server" || strlen($this->iusername) > 16) { + $this->close("Bad username", false); + return; + } + if ($this->server->api->handle("player.connect", $this) === false) { + $this->close("Unknown reason", false); + return; + } + + if ($this->server->whitelist === true and !$this->server->api->ban->inWhitelist($this->iusername)) { + $this->close("Server is white-listed", false); + return; + } elseif ($this->server->api->ban->isBanned($this->iusername) or $this->server->api->ban->isIPBanned($this->ip)) { + $this->close("You are banned!", false); + return; + } + $this->loggedIn = true; + + if (!isset($this->CID) or $this->CID == null) { + console("[DEBUG] Player " . $this->username . " does not have a CID", true, true, 2); + $this->CID = Utils::readLong(Utils::getRandomBytes(8, false)); + } + $u = $this->server->api->player->get($this->iusername, false); + if ($u !== false) { + $u = $this->server->clients[$this->CID]; + $u->close("this player already in game"); + } + + $this->server->api->player->add($this->CID); + if ($this->server->api->handle("player.join", $this) === false) { + $this->close("join cancelled", false); + return; + } + + if (!($this->data instanceof Config)) { + $this->close("no config created", false); + return; + } + + $this->auth = true; + if (!$this->data->exists("inventory") or ($this->gamemode & 0x01) === 0x01) { + if (($this->gamemode & 0x01) === 0x01) { + $inv = []; + if (($this->gamemode & 0x02) === 0x02) { + foreach (BlockAPI::$creative as $item) { + $inv[] = [0, 0, 1]; + } + } else { + foreach (BlockAPI::$creative as $item) { + $inv[] = [$item[0], $item[1], 1]; + } + } + } + $this->data->set("inventory", $inv); + } + $this->achievements = $this->data->get("achievements"); + $this->data->set("caseusername", $this->username); + $this->inventory = []; + foreach ($this->data->get("inventory") as $slot => $item) { + if (!is_array($item) or count($item) < 3) { + $item = [AIR, 0, 0]; + } + $this->inventory[$slot] = BlockAPI::getItem($item[0], $item[1], $item[2]); + } + + $this->armor = []; + foreach ($this->data->get("armor") as $slot => $item) { + $this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], $item[0] === 0 ? 0 : 1); + } + + $this->data->set("lastIP", $this->ip); + $this->data->set("lastID", $this->clientID); + + $this->server->api->player->saveOffline($this->data); + + $pk = new LoginStatusPacket; + $pk->status = 0; + $this->dataPacket($pk); + + $pk = new StartGamePacket; + $pk->seed = $this->level->getSeed(); + $pk->x = $this->data->get("position")["x"]; + $pk->y = $this->data->get("position")["y"]; + $pk->z = $this->data->get("position")["z"]; + $pk->generator = 0; + $pk->gamemode = $this->gamemode & 0x01; + $pk->eid = 0; + $this->dataPacket($pk); + + if (($this->gamemode & 0x01) === 0x01) { + $this->slot = 0; + $this->hotbar = []; + } elseif ($this->data->exists("hotbar")) { + $this->hotbar = $this->data->get("hotbar"); + $this->slot = $this->hotbar[0]; + } else { + $this->slot = 0; + $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8]; + } + for ($i = 0; $i < count($this->hotbar); ++$i) { + if ($this->hotbar[$i] > 36) $this->hotbar[$i] = -1; //XXX unsafe? + if ($this->hotbar[$i] < -1) $this->hotbar[$i] = -1; + } + if ($this->data->exists("slot-count")) { + $this->slotCount = $this->data->get("slot-count"); + } else { + $this->data->set("slot-count", $this->slotCount); + } + + $this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, ["player" => $this]); + $this->eid = $this->entity->eid; + $this->server->query("UPDATE players SET EID = " . $this->eid . " WHERE CID = " . $this->CID . ";"); + $this->entity->x = $this->data->get("position")["x"]; + $this->entity->y = $this->data->get("position")["y"]; + $this->entity->z = $this->data->get("position")["z"]; + if (($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false) { + $this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level); + + $pk = new SetSpawnPositionPacket; + $pk->x = (int) $this->spawnPosition->x; + $pk->y = (int) $this->spawnPosition->y; + $pk->z = (int) $this->spawnPosition->z; + $this->dataPacket($pk); + } + $this->entity->check = false; + $this->entity->setName($this->username); + $this->entity->data["CID"] = $this->CID; + $this->evid[] = $this->server->event("server.chat", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.motion", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.animate", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.event", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.metadata", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("entity.link", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.equipment.change", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.armor", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("player.pickup", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("tile.container.slot", [$this, "eventHandler"]); + $this->evid[] = $this->server->event("tile.update", [$this, "eventHandler"]); + $this->lastMeasure = microtime(true); + $this->server->schedule(50, [$this, "measureLag"], [], true); + + $pk = new SetTimePacket; + $pk->time = $this->level->getTime(); + $pk->started = !$this->level->isTimeStopped(); + $this->dataPacket($pk); + + console("[INFO] " . FORMAT_AQUA . $this->username . FORMAT_RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->eid . " at (" . $this->entity->level->getName() . ", " . round($this->entity->x, 2) . ", " . round($this->entity->y, 2) . ", " . round($this->entity->z, 2) . ")"); + break; + case ProtocolInfo::READY_PACKET: + if ($this->loggedIn === false) { + break; + } + switch ($packet->status) { + case 1: //Spawn!! + if ($this->spawned !== false) { + break; + } + + $pos = new Position($this->entity->x, $this->entity->y, $this->entity->z, $this->level); + $pData = $this->data->get("position"); + $this->entity->setHealth($this->data->get("health"), "spawn", true, false); + $this->spawned = true; + $this->teleport($pos, $pData["yaw"] ?? false, $pData["pitch"] ?? false, true, true); + $this->server->api->player->spawnAllPlayers($this); + $this->server->api->player->spawnToAllPlayers($this); + $this->server->api->entity->spawnAll($this); + $this->server->api->entity->spawnToAll($this->entity); + + //$this->server->schedule(5, [$this->entity, "update"], [], true); + //$this->server->schedule(2, [$this->entity, "updateMovement"], [], true); + $this->sendArmor(); + $array = explode("@n", (string) $this->server->motd); + foreach ($array as $msg) { + $this->sendChat($msg . "\n"); + } + + $this->sendInventory(); + $this->sendSettings(); + $this->server->schedule(50, [$this, "orderChunks"], []); + $this->blocked = false; + + $this->server->send2Discord($this->username . " joined the game"); + $this->server->handle("player.spawn", $this); + break; + case 2://Chunk loaded? + break; + } + break; + case ProtocolInfo::ROTATE_HEAD_PACKET: + if ($this->spawned === false) { + break; + } + if (($this->entity instanceof Entity)) { + if ($this->blocked === true or $this->server->api->handle("player.move", $this->entity) === false) { + if ($this->lastCorrect instanceof Vector3 && !$this->entity->dead) { + $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); + } + } else { + $this->entity->setPosition($this->entity, $packet->yaw, $this->entity->pitch); + } + } + break; + case ProtocolInfo::MOVE_PLAYER_PACKET: + if ($this->spawned === false) { + break; + } + if ($this->isSleeping) break; + if (($this->entity instanceof Entity) and $packet->messageIndex > $this->lastMovement) { + $this->lastMovement = $packet->messageIndex; + $newPos = new Vector3($packet->x, $packet->y, $packet->z); + if ($this->forceMovement instanceof Vector3) { + if ($this->forceMovement->distance($newPos) <= 0.7) { + $this->forceMovement = false; + } else { + $this->teleport($this->forceMovement, $this->entity->yaw, $this->entity->pitch, false); + break; + } + } + $speed = $this->entity->getSpeedMeasure(); + if ($this->blocked === true or ($this->server->api->getProperty("allow-flight") !== true and (($speed > 9 and ($this->gamemode & 0x01) === 0x00) or $speed > 20 or $this->entity->distance($newPos) > 7)) or $this->server->api->handle("player.move", $this->entity) === false) { + if ($this->lastCorrect instanceof Vector3 && !$this->entity->dead) { + $this->teleport($this->lastCorrect, $this->entity->yaw, $this->entity->pitch, false); + } + } else { + $this->entity->setPosition($newPos, $packet->yaw, $packet->pitch, $packet->bodyYaw); + } + $this->entity->updateAABB(); + } + break; + case ProtocolInfo::PLAYER_EQUIPMENT_PACKET: + if ($this->spawned === false) { + break; + } + $packet->eid = $this->eid; + + $data = []; + $data["eid"] = $packet->eid; + $data["player"] = $this; + + if ($packet->slot === 0) { + $data["slot"] = -1; + $data["item"] = BlockAPI::getItem(AIR, 0, 0); + if ($this->server->handle("player.equipment.change", $data) !== false) { + $this->slot = -1; + } + break; + } elseif ($packet->slot > 0) { + $packet->slot -= 9; + } + + if (($this->gamemode & 0x01) === SURVIVAL) { + $data["item"] = $this->getSlot($packet->slot); + if (!($data["item"] instanceof Item)) { + break; + } + } elseif (($this->gamemode & 0x01) === CREATIVE) { + $packet->slot = false; + foreach (BlockAPI::$creative as $i => $d) { + if ($d[0] === $packet->item and $d[1] === $packet->meta) { + $packet->slot = $i; + } + } + if ($packet->slot !== false) { + $data["item"] = $this->getSlot($packet->slot); + } else { + break; + } + } else { + break;//????? + } + + $data["slot"] = $packet->slot; + + if ($this->server->handle("player.equipment.change", $data) !== false) { + if (!Player::$experimentalHotbar) $this->slot = $packet->slot; + if (($this->gamemode & 0x01) === SURVIVAL) { + $has = false; + $slotPos = 0; + $packetSlotPos = 0; + for ($i = 0; $i < $this->slotCount; ++$i) { + if ($this->slot == $this->hotbar[$i]) $slotPos = $i; + if ($packet->slot == $this->hotbar[$i]) { + $packetSlotPos = $i; + $has = true; + break; + } + } + + if (Player::$experimentalHotbar && $has) { + $this->slot = $packet->slot; + $this->curHotbarIndex = $packetSlotPos; + } + if (!$has) { + if (Player::$experimentalHotbar) { + $this->slot = $packet->slot; + $this->hotbar[$this->curHotbarIndex] = $packet->slot; + } else { + $this->curHotbarIndex = 0; + array_pop($this->hotbar); + array_unshift($this->hotbar, $this->slot); + } + } + if (Player::$experimentalHotbar) $this->sendInventory(); + } else { + $this->slot = $packet->slot; + } + } else { + //$this->sendInventorySlot($packet->slot); + $this->sendInventory(); + } + if ($this->entity->inAction === true) { + $this->entity->inAction = false; + $this->entity->inActionCounter = 0; + $this->entity->updateMetadata(); + } + break; + case ProtocolInfo::REQUEST_CHUNK_PACKET: + //console("request x:".$packet->chunkX.", z: ".$packet->chunkZ." chunk"); + //$this->useChunk($packet->chunkX, $packet->chunkZ); + //$this->lastChunk = [$packet->chunkX, $packet->chunkZ]; + break; + case ProtocolInfo::USE_ITEM_PACKET: + if (!($this->entity instanceof Entity)) { + break; + } + + $blockVector = new Vector3($packet->x, $packet->y, $packet->z); + + if (($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5) { + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->dataPacket($pk); + break; + } + $this->craftingItems = []; + $this->toCraft = []; + $packet->eid = $this->eid; + $data = []; + $data["eid"] = $packet->eid; + $data["player"] = $this; + $data["face"] = $packet->face; + $data["x"] = $packet->x; + $data["y"] = $packet->y; + $data["z"] = $packet->z; + $data["item"] = $packet->item; + $data["meta"] = $packet->meta; + $data["fx"] = $packet->fx; + $data["fy"] = $packet->fy; + $data["fz"] = $packet->fz; + $data["posX"] = $packet->posX; + $data["posY"] = $packet->posY; + $data["posZ"] = $packet->posZ; + + if ($packet->face >= 0 and $packet->face <= 5) { //Use Block, place + if ($this->entity->inAction === true) { + $this->entity->inAction = false; + $this->entity->inActionCounter = 0; + $this->entity->updateMetadata(); + } + + if ($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 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); + } else { + $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz); + break; + } + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->dataPacket($pk); + break; + } elseif ($packet->face === 0xff) { + + $slotItem = $this->getHeldItem(); + if ($slotItem->getID() == SNOWBALL || $slotItem->getID() == EGG) { //TODO better way + $x = $packet->x * 0.000030518; + $y = $packet->y * 0.000030518; + $z = $packet->z * 0.000030518; + + $d = sqrt($x * $x + $y * $y + $z * $z); + + if ($d >= 0.0001) { + $shootX = $x / $d; + $shootY = $y / $d; + $shootZ = $z / $d; + + $data = [ + "x" => $this->entity->x, + "y" => $this->entity->y + $this->entity->getEyeHeight(), + "z" => $this->entity->z, + "yaw" => $this->entity->yaw, + "pitch" => $this->entity->pitch, + "shooter" => $this->entity->eid, + "shootX" => $shootX, + "shootY" => $shootY, + "shootZ" => $shootZ + ]; + + if ($slotItem->getID() == EGG) { + $e = $this->server->api->entity->add($this->entity->level, ENTITY_OBJECT, OBJECT_EGG, $data); + } else { + $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_SNOWBALL, $data); + } + + if (($this->gamemode & 0x01) == 0x0) { + if ($slotItem !== false) { + if ($slotItem->count == 1) $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0); + else $slotItem->count -= 1; + //$this->sendInventory(); + } + } + + $this->server->api->entity->spawnToAll($e); + } + + } else { + if ($this->server->handle("player.action", $data) !== false) { + $this->entity->inAction = true; + $this->entity->inActionCounter = 0; + $this->startAction = microtime(true); + $this->entity->updateMetadata(); + } + } + } + break; + case ProtocolInfo::PLACE_BLOCK_PACKET: + if (!($this->entity instanceof Entity)) { + break; + } + + $blockVector = new Vector3($packet->x, $packet->y, $packet->z); + + if (($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5) { + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->dataPacket($pk); + break; + } + $this->craftingItems = []; + $this->toCraft = []; + $packet->eid = $this->eid; + $data = []; + + if ($packet->face >= 0 and $packet->face <= 5) { + if ($this->entity->inAction === true) { + $this->entity->inAction = false; + $this->entity->inActionCounter = 0; + $this->entity->updateMetadata(); + } + + if ($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 10)) { + + } else { + $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->x, $packet->y, $packet->z); + break; + } + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getMetadata(); + $this->dataPacket($pk); + break; + } + break; + case ProtocolInfo::PLAYER_ACTION_PACKET: + if ($this->spawned === false or $this->blocked === true) { + break; + } + $packet->eid = $this->eid; + $this->craftingItems = []; + $this->toCraft = []; + + switch ($packet->action) { + case 5: //Shot arrow + if ($this->entity->inAction) { + $arrowSlot = $this->hasItem(ARROW); + if ($this->getSlot($this->slot)->getID() === BOW && (($this->gamemode & 0x01) == 0x1 || $arrowSlot !== false)) { + if ($this->startAction !== false) { + $initalPower = $this->entity->inActionCounter; + $power = $initalPower / 20; + $power = ($power * $power + $power * 2) / 3; + if ($power >= 0.1) { + if ($power > 1) $power = 1; + $this->server->dhandle("player.shoot", [ + "player" => $this, + "power" => &$power, + ]); + + $d = [ + "x" => $this->entity->x, + "y" => $this->entity->y + 1.6, + "z" => $this->entity->z, + "yaw" => $this->entity->yaw, + "pitch" => $this->entity->pitch, + "shooter" => $this->entity->eid, + ]; + $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d); + $e->speedX = -sin(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI); + $e->speedZ = cos(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI); + $e->speedY = -sin(($e->pitch / 180) * M_PI); + $e->shooterEID = $this->entity->eid; + $e->shotByEntity = true; + /** + * Max usage: 72000ticks + * initalPower = 72000 - (72000 - usedCtr) + * power = initialPower / 20' + * power = (power*power+power*2)/3 + * powerMax is 1, powerMin is 0.1 + * args: xvel, yvel, zvel, (power+power)*1.5, 1.0 + */ + $e->critical = ($power == 1); + $e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power + $power) * 1.5, 1.0); + $this->server->api->entity->spawnToAll($e); + if (($this->gamemode & 0x01) == 0x0) { + $bow = $this->getSlot($this->slot); + if (++$bow->meta >= $bow->getMaxDurability()) { + $this->inventory[$this->slot] = BlockAPI::getItem(AIR, 0, 0); + } + $this->removeItem(ARROW, 0, 1, false); + $this->sendInventory(); + } + } + } + } else { //inv desynced, resend + $this->sendInventory(); + } + } + $this->startAction = false; + $this->entity->inAction = false; + $this->entity->inActionCounter = 0; + $this->entity->updateMetadata(); + break; + case 6: //get out of the bed + $this->stopSleep(); + } + break; + case ProtocolInfo::REMOVE_BLOCK_PACKET: + $blockVector = new Vector3($packet->x, $packet->y, $packet->z); + if ($this->spawned === false or $this->blocked === true or $this->entity->distance($blockVector) > 8) { + $target = $this->level->getBlock($blockVector); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->dataPacket($pk); + break; + } + $this->craftingItems = []; + $this->toCraft = []; + $this->server->api->block->playerBlockBreak($this, $blockVector); + break; + case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: + if ($this->spawned === false or $this->blocked === true) { + break; + } + $this->craftingItems = []; + $this->toCraft = []; + + $packet->eid = $this->eid; + for ($i = 0; $i < 4; ++$i) { + $s = $packet->slots[$i]; + if ($s === 0 or $s === 255) { + $s = BlockAPI::getItem(AIR, 0, 0); + } else { + $s = BlockAPI::getItem($s + 256, 0, 1); + } + $slot = $this->armor[$i]; + if ($slot->getID() !== AIR and $s->getID() === AIR) { + $this->addItem($slot->getID(), $slot->getMetadata(), 1, false); + $this->armor[$i] = BlockAPI::getItem(AIR, 0, 0); + $packet->slots[$i] = 255; + } elseif ($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false) { + $this->armor[$i] = $this->getSlot($sl); + $this->setSlot($sl, BlockAPI::getItem(AIR, 0, 0), false); + } elseif ($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false) { + $item = $this->armor[$i]; + $this->armor[$i] = $this->getSlot($sl); + $this->setSlot($sl, $item, false); + } else { + $packet->slots[$i] = 255; + } + + } + $this->sendArmor(); + if ($this->entity->inAction === true) { + $this->entity->inAction = false; + $this->entity->inActionCounter = 0; + $this->entity->updateMetadata(); + } + break; + case ProtocolInfo::INTERACT_PACKET: + if ($this->spawned === false) { + break; + } + $packet->eid = $this->eid; + $data = []; + $data["target"] = $packet->target; + $data["eid"] = $packet->eid; + $data["action"] = $packet->action; + $this->craftingItems = []; + $this->toCraft = []; + $target = $this->server->api->entity->get($packet->target); + if ($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8) { + $data["targetentity"] = $packet->target; + $data["entity"] = $this->entity; + $data["player"] = $this; + if ($this->server->handle("player.interact", $data) !== false) { + $target->interactWith($this->entity, $packet->action); + } + } + + break; + case ProtocolInfo::ANIMATE_PACKET: + if ($this->spawned === false) { + break; + } + $packet->eid = $this->eid; + $this->server->api->dhandle("entity.animate", ["eid" => $packet->eid, "entity" => $this->entity, "action" => $packet->action]); + break; + case ProtocolInfo::RESPAWN_PACKET: + if ($this->spawned === false) { + break; + } + if (@$this->entity->dead === false) { + break; + } + $this->craftingItems = []; + $this->toCraft = []; + + $this->checkSpawnPosition(); + $this->teleport($this->spawnPosition, false, false, true, false); + + $pk = new MovePlayerPacket(); + $pk->eid = $this->entity->eid; + $pk->x = $this->entity->x; + $pk->y = $this->entity->y; + $pk->z = $this->entity->z; + $pk->yaw = $this->entity->yaw; + $pk->pitch = $this->entity->pitch; + $pk->bodyYaw = $this->entity->headYaw; + foreach ($this->entity->level->players as $player) { + if ($player->entity->eid != $this->entity->eid) { + $player->dataPacket(clone $pk); + } + } + + if ($this->entity instanceof Entity) { + $this->entity->fire = 0; + $this->entity->air = $this->entity->maxAir; + $this->entity->setHealth(20, "respawn", true); + $this->entity->updateMetadata(); + } else { + break; + } + $this->sendInventory(); + $this->blocked = false; + $this->server->handle("player.respawn", $this); + break; + case ProtocolInfo::SET_HEALTH_PACKET: //Not used + break; + case ProtocolInfo::ENTITY_EVENT_PACKET: + if ($this->spawned === false or $this->blocked === true) { + break; + } + $this->craftingItems = []; + $this->toCraft = []; + $packet->eid = $this->eid; + if ($this->entity->inAction === true) { + $this->entity->inAction = false; + $this->entity->inActionCounter = 0; + $this->entity->updateMetadata(); + } + switch ($packet->event) { + case 9: //Eating + $slot = $this->getSlot($this->slot); + $foodHeal = Item::getFoodHeal($slot->getID()); + if ($this->entity->getHealth() < 20 && $foodHeal != 0) { + $pk = new EntityEventPacket; + $pk->eid = 0; + $pk->event = 9; + $this->dataPacket($pk); + + $this->entity->heal($foodHeal, "eating"); + --$slot->count; + if ($slot->count <= 0) { + $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); + } + if ($slot->getID() === MUSHROOM_STEW or $slot->getID() === BEETROOT_SOUP) { + $this->addItem(BOWL, 0, 1, false); + } + } + break; + } + break; + case ProtocolInfo::DROP_ITEM_PACKET: + if ($this->spawned === false or $this->blocked === true) { + break; + } + + if ($this->gamemode & 0x01 == 1) { + ConsoleAPI::warn("{$this->iusername} tried dropping item while in creative!"); + return; + } + + $packet->eid = $this->eid; + $prevItem = $packet->item; + $packet->item = $this->getSlot($this->slot); + $sendOnDrop = false; + + if ($prevItem->getID() != $packet->item->getID() || $prevItem->getMetadata() != $packet->item->getMetadata()) { + if (count($this->inventory) >= 36) { + foreach ($this->inventory as $slot => $item) { + if ($item->getID() == 0) goto inv_desync_on_drop; + } + + $this->toCraft[] = $prevItem; //vanilla drops only result? + $this->lastCraft = microtime(true); + break; + } + } else { + inv_desync_on_drop: + ConsoleAPI::debug("Inventory desync on drop({$this->iusername})"); + $sendOnDrop = true; + } + + $this->craftingItems = []; + $this->toCraft = []; + $data["eid"] = $packet->eid; + $data["unknown"] = $packet->unknown; + $data["item"] = $packet->item; + $data["player"] = $this; + if ($this->blocked === false and $this->server->handle("player.drop", $data) !== false) { + $f1 = 0.3; + $sX = -sin(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; + $sZ = cos(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; + $sY = -sin(($this->entity->pitch / 180) * M_PI) * $f1 + 0.1; + $f1 = 0.02; + $f3 = $this->entity->random->nextFloat() * M_PI * 2.0; + $f1 *= $this->entity->random->nextFloat(); + $sX += cos($f3) * $f1; + $sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1; + $sZ += sin($f3) * $f1; + $this->server->api->entity->dropRawPos($this->level, $this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $packet->item, $sX, $sY, $sZ); + $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), $sendOnDrop); + } else { + $this->sendInventory(); //send if blocked + } + if ($this->entity->inAction === true) { + $this->entity->inAction = false; + $this->entity->inActionCounter = 0; + $this->entity->updateMetadata(); + } + break; + case ProtocolInfo::MESSAGE_PACKET: + if ($this->spawned === false) { + break; + } + $this->craftingItems = []; + $this->toCraft = []; + if (trim($packet->message) != "" and strlen($packet->message) <= 255) { + $message = $packet->message; + if ($message[0] === "/") { //Command + if ($this instanceof Player) { + console("[DEBUG] " . FORMAT_AQUA . $this->username . FORMAT_RESET . " issued server command: " . $message); + } else { + console("[DEBUG] " . FORMAT_YELLOW . "*" . $this . FORMAT_RESET . " issued server command: " . $message); + } + $this->server->api->console->run(substr($message, 1), $this); + } else { + $data = ["player" => $this, "message" => $message]; + if (Utils::hasEmoji($data["message"])) { + $this->sendChat("Your message contains illegal characters"); + break; + } + + //if($message == "pf"){ + // Living::$pathfind = !Living::$pathfind; + //} + + if ($this->server->api->handle("player.chat", $data) !== false) { + $this->server->send2Discord("<" . $this->username . "> " . $message); + if (isset($data["message"])) { + $this->server->api->chat->send($this, $data["message"]); + } else { + $this->server->api->chat->send($this, $message); + } + } + } + } + break; + case ProtocolInfo::CONTAINER_CLOSE_PACKET: + if ($this->spawned === false) { + break; + } + $this->craftingItems = []; + $this->toCraft = []; + if (isset($this->windows[$packet->windowid])) { + if (is_array($this->windows[$packet->windowid])) { + foreach ($this->windows[$packet->windowid] as $ob) { + $pk = new TileEventPacket; + $pk->x = $ob->x; + $pk->y = $ob->y; + $pk->z = $ob->z; + $pk->case1 = 1; + $pk->case2 = 0; + $this->server->api->player->broadcastPacket($this->level->players, $pk); + } + } elseif ($this->windows[$packet->windowid]->class === TILE_CHEST) { + $pk = new TileEventPacket; + $pk->x = $this->windows[$packet->windowid]->x; + $pk->y = $this->windows[$packet->windowid]->y; + $pk->z = $this->windows[$packet->windowid]->z; + $pk->case1 = 1; + $pk->case2 = 0; + $this->server->api->player->broadcastPacket($this->level->players, $pk); + } + } + unset($this->windows[$packet->windowid]); + + $pk = new ContainerClosePacket; + $pk->windowid = $packet->windowid; + $this->dataPacket($pk); + break; + case ProtocolInfo::CONTAINER_SET_SLOT_PACKET: + if ($this->spawned === false or $this->blocked === true) { + break; + } + + if ($this->lastCraft <= (microtime(true) - 1)) { + if (isset($this->toCraft[-1])) { + $this->toCraft = [-1 => $this->toCraft[-1]]; + } else { + $this->toCraft = []; + } + $this->craftingItems = []; + } + + if ($packet->windowid === 0) { + $craft = false; + $slot = $this->getSlot($packet->slot); + if ($slot->count >= $packet->item->count and (($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()) or ($packet->item->getID() === AIR and $packet->item->count === 0)) and !isset($this->craftingItems[$packet->slot])) { //Crafting recipe + $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count - $packet->item->count); + $this->craftingItems[$packet->slot] = $use; + $craft = true; + } elseif ($slot->count <= $packet->item->count and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))) { //Crafting final + $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count - $slot->count); + if (count($this->toCraft) === 0) { + $this->toCraft[-1] = 0; + } + $this->toCraft[$packet->slot] = $craftItem; + $craft = true; + } elseif (((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->count > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())) { //Crafting final + $craftItem = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); + if (count($this->toCraft) === 0) { + $this->toCraft[-1] = 0; + } + $use = BlockAPI::getItem($slot->getID(), $slot->getMetadata(), $slot->count); + $this->craftingItems[$packet->slot] = $use; + $this->toCraft[$packet->slot] = $craftItem; + $craft = true; + } + + if ($craft === true) { + $this->lastCraft = microtime(true); + } + + if ($craft === true and count($this->craftingItems) > 0 and count($this->toCraft) > 0 and ($recipe = $this->craftItems($this->toCraft, $this->craftingItems, $this->toCraft[-1])) !== true) { + if ($recipe === false) { + $this->sendInventory(); + $this->toCraft = []; + } else { + $this->toCraft = [-1 => $this->toCraft[-1]]; + } + $this->craftingItems = []; + } + } else { + $this->toCraft = []; + $this->craftingItems = []; + } + if (!isset($this->windows[$packet->windowid])) { + break; + } + + if (is_array($this->windows[$packet->windowid])) { + $tiles = $this->windows[$packet->windowid]; + if ($packet->slot >= 0 and $packet->slot < CHEST_SLOTS) { + $tile = $tiles[0]; + $slotn = $packet->slot; + $offset = 0; + } elseif ($packet->slot >= CHEST_SLOTS and $packet->slot <= (CHEST_SLOTS << 1)) { + $tile = $tiles[1]; + $slotn = $packet->slot - CHEST_SLOTS; + $offset = CHEST_SLOTS; + } else { + break; + } + + $item = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); + + $slot = $tile->getSlot($slotn); + if ($this->server->api->dhandle("player.container.slot", [ + "tile" => $tile, + "slot" => $packet->slot, + "offset" => $offset, + "slotdata" => $slot, + "itemdata" => $item, + "player" => $this + ]) === false) { + $pk = new ContainerSetSlotPacket; + $pk->windowid = $packet->windowid; + $pk->slot = $packet->slot; + $pk->item = $slot; + $this->dataPacket($pk); + break; + } + 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) { + break; + } + } elseif ($slot->count > $item->count) { + $this->addItem($item->getID(), $item->getMetadata(), $slot->count - $item->count, false); + } + } else { + if ($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false) { + break; + } + $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); + } + $tile->setSlot($slotn, $item, true, $offset); + } else { + $tile = $this->windows[$packet->windowid]; + if (($tile->class !== TILE_CHEST and $tile->class !== TILE_FURNACE) or $packet->slot < 0 or ($tile->class === TILE_CHEST and $packet->slot >= CHEST_SLOTS) or ($tile->class === TILE_FURNACE and $packet->slot >= FURNACE_SLOTS)) { + break; + } + $item = BlockAPI::getItem($packet->item->getID(), $packet->item->getMetadata(), $packet->item->count); + + $slot = $tile->getSlot($packet->slot); + if ($this->server->api->dhandle("player.container.slot", [ + "tile" => $tile, + "slot" => $packet->slot, + "slotdata" => $slot, + "itemdata" => $item, + "player" => $this, + ]) === false) { + $pk = new ContainerSetSlotPacket; + $pk->windowid = $packet->windowid; + $pk->slot = $packet->slot; + $pk->item = $slot; + $this->dataPacket($pk); + break; + } + + if ($tile->class === TILE_FURNACE and $packet->slot == 2) { + switch ($slot->getID()) { + case IRON_INGOT: + AchievementAPI::grantAchievement($this, "acquireIron"); + break; + } + } + + 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) { + break; + } + } elseif ($slot->count > $item->count) { + $this->addItem($item->getID(), $item->getMetadata(), $slot->count - $item->count, false); + } + } else { + if ($this->removeItem($item->getID(), $item->getMetadata(), $item->count, false) === false) { + break; + } + $this->addItem($slot->getID(), $slot->getMetadata(), $slot->count, false); + } + + $tile->setSlot($packet->slot, $item); + } + break; + case ProtocolInfo::SEND_INVENTORY_PACKET: + if ($this->spawned === false) { + break; + } + break; + case ProtocolInfo::ENTITY_DATA_PACKET: + if ($this->spawned === false or $this->blocked === true) { + break; + } + $this->craftingItems = []; + $this->toCraft = []; + $t = $this->server->api->tile->get(new Position($packet->x, $packet->y, $packet->z, $this->level)); + if (($t instanceof Tile) and $t->class === TILE_SIGN) { + if ($t->data["creator"] !== $this->username) { + $t->spawn($this); + } else { + $nbt = new NBT(); + $nbt->load($packet->namedtag); + $d = array_shift($nbt->tree); + if ($d["id"] !== TILE_SIGN) { + $t->spawn($this); + } else { + $t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]); + } + } + } + break; + case ProtocolInfo::PLAYER_INPUT_PACKET: + $this->isJumping = $packet->isJumping; + $this->isSneaking = $packet->isSneaking; + $this->entity->moveForward = $packet->moveForward; + $this->entity->moveStrafing = $packet->moveStrafe; + + if (strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity != 0) { + $this->entity->stopRiding(); + break; + } + if ($this->entity->linkedEntity != 0) { //TODO better riding + $e = $this->entity->level->entityList[$this->entity->linkedEntity] ?? false; + if ($e === false) { + ConsoleAPI::warn("Player is riding on entity that doesnt exist in world! ({$this->iusername}, {$this->entity->linkedEntity})"); + $this->entity->stopRiding(); + break; + } + /*$pk = new SetEntityMotionPacket; + $pk->eid = $e->eid; + $pk->speedX = ($this->entity->x - $e->x)*1.2; + $pk->speedY = ($this->entity->y - $e->y)*1.2; + $pk->speedZ = ($this->entity->z - $e->z)*1.2; + foreach($this->level->players as $p){ + if($p->entity->eid != $this->entity->eid){ + $p->dataPacket(clone $pk); + } + } + console("{$e} {$this->entity}"); + //$this->entity->linkedEntity->moveFlying($packet->moveStrafe, $packet->moveForward, 1);*/ + } + + break; + default: + console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2); + break; + } + } /** * Get an Item which is currently held by player diff --git a/src/network/PacketPool.php b/src/network/PacketPool.php index fa7ed5be..9c63130c 100644 --- a/src/network/PacketPool.php +++ b/src/network/PacketPool.php @@ -57,7 +57,7 @@ class PacketPool{ self::registerPacket(ContainerSetContentPacket::class); self::registerPacket(ContainerSetDataPacket::class); self::registerPacket(ContainerSetSlotPacket::class); - self::registerPacket(ContainerAckPacket::class); + self::registerPacket(ContainerAckPacket::class); self::registerPacket(DisconnectPacket::class); self::registerPacket(DropItemPacket::class); diff --git a/src/network/protocol/ProtocolInfo.php b/src/network/protocol/ProtocolInfo.php index ce7312b8..81f4986f 100644 --- a/src/network/protocol/ProtocolInfo.php +++ b/src/network/protocol/ProtocolInfo.php @@ -78,411 +78,411 @@ abstract class ProtocolInfo{ */ abstract class ProtocolInfo12{ - const CURRENT_PROTOCOL_12 = 12; + const CURRENT_PROTOCOL_12 = 12; - const PING_PACKET = 0x00; + const PING_PACKET = 0x00; - const PONG_PACKET = 0x03; + const PONG_PACKET = 0x03; - const CLIENT_CONNECT_PACKET = 0x09; - const SERVER_HANDSHAKE_PACKET = 0x10; + const CLIENT_CONNECT_PACKET = 0x09; + const SERVER_HANDSHAKE_PACKET = 0x10; - const CLIENT_HANDSHAKE_PACKET = 0x13; - //const SERVER_FULL_PACKET = 0x14; - const DISCONNECT_PACKET = 0x15; - const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; - const READY_PACKET = 0x84; - const MESSAGE_PACKET = 0x85; - const SET_TIME_PACKET = 0x86; - const START_GAME_PACKET = 0x87; - const ADD_MOB_PACKET = 0x88; - const ADD_PLAYER_PACKET = 0x89; - const REMOVE_PLAYER_PACKET = 0x8a; + const CLIENT_HANDSHAKE_PACKET = 0x13; + //const SERVER_FULL_PACKET = 0x14; + const DISCONNECT_PACKET = 0x15; + const LOGIN_PACKET = 0x82; + const LOGIN_STATUS_PACKET = 0x83; + const READY_PACKET = 0x84; + const MESSAGE_PACKET = 0x85; + const SET_TIME_PACKET = 0x86; + const START_GAME_PACKET = 0x87; + const ADD_MOB_PACKET = 0x88; + const ADD_PLAYER_PACKET = 0x89; + const REMOVE_PLAYER_PACKET = 0x8a; - const ADD_ENTITY_PACKET = 0x8c; - const REMOVE_ENTITY_PACKET = 0x8d; - const ADD_ITEM_ENTITY_PACKET = 0x8e; - const TAKE_ITEM_ENTITY_PACKET = 0x8f; - const MOVE_ENTITY_PACKET = 0x90; + const ADD_ENTITY_PACKET = 0x8c; + const REMOVE_ENTITY_PACKET = 0x8d; + const ADD_ITEM_ENTITY_PACKET = 0x8e; + const TAKE_ITEM_ENTITY_PACKET = 0x8f; + const MOVE_ENTITY_PACKET = 0x90; - const MOVE_ENTITY_PACKET_POSROT = 0x93; - const ROTATE_HEAD_PACKET = 0xff; - const MOVE_PLAYER_PACKET = 0x94; - const PLACE_BLOCK_PACKET = 0x95; - const REMOVE_BLOCK_PACKET = 0x96; - const UPDATE_BLOCK_PACKET = 0x97; - const ADD_PAINTING_PACKET = 0x98; - const EXPLODE_PACKET = 0x99; - const LEVEL_EVENT_PACKET = 0x9a; - const TILE_EVENT_PACKET = 0x9b; - const ENTITY_EVENT_PACKET = 0x9c; - const REQUEST_CHUNK_PACKET = 0x9d; - const CHUNK_DATA_PACKET = 0x9e; - const PLAYER_EQUIPMENT_PACKET = 0x9f; - const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; - const INTERACT_PACKET = 0xa1; - const USE_ITEM_PACKET = 0xa2; - const PLAYER_ACTION_PACKET = 0xa3; + const MOVE_ENTITY_PACKET_POSROT = 0x93; + const ROTATE_HEAD_PACKET = 0xff; + const MOVE_PLAYER_PACKET = 0x94; + const PLACE_BLOCK_PACKET = 0x95; + const REMOVE_BLOCK_PACKET = 0x96; + const UPDATE_BLOCK_PACKET = 0x97; + const ADD_PAINTING_PACKET = 0x98; + const EXPLODE_PACKET = 0x99; + const LEVEL_EVENT_PACKET = 0x9a; + const TILE_EVENT_PACKET = 0x9b; + const ENTITY_EVENT_PACKET = 0x9c; + const REQUEST_CHUNK_PACKET = 0x9d; + const CHUNK_DATA_PACKET = 0x9e; + const PLAYER_EQUIPMENT_PACKET = 0x9f; + const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; + const INTERACT_PACKET = 0xa1; + const USE_ITEM_PACKET = 0xa2; + const PLAYER_ACTION_PACKET = 0xa3; - const HURT_ARMOR_PACKET = 0xa5; - const SET_ENTITY_DATA_PACKET = 0xa6; - const SET_ENTITY_MOTION_PACKET = 0xa7; - const SET_ENTITY_LINK_PACKET = 0xa8; - const SET_HEALTH_PACKET = 0xa9; - const SET_SPAWN_POSITION_PACKET = 0xaa; - const ANIMATE_PACKET = 0xab; - const RESPAWN_PACKET = 0xac; - const SEND_INVENTORY_PACKET = 0xad; - const DROP_ITEM_PACKET = 0xae; - const CONTAINER_OPEN_PACKET = 0xaf; - const CONTAINER_CLOSE_PACKET = 0xb0; - const CONTAINER_SET_SLOT_PACKET = 0xb1; - const CONTAINER_SET_DATA_PACKET = 0xb2; - const CONTAINER_SET_CONTENT_PACKET = 0xb3; - const CONTAINER_ACK_PACKET = 0xb4; - const CHAT_PACKET = 0xb5; - const ADVENTURE_SETTINGS_PACKET = 0xb6; - const ENTITY_DATA_PACKET = 0xb7; - const PLAYER_INPUT_PACKET = 0xb9; + const HURT_ARMOR_PACKET = 0xa5; + const SET_ENTITY_DATA_PACKET = 0xa6; + const SET_ENTITY_MOTION_PACKET = 0xa7; + const SET_ENTITY_LINK_PACKET = 0xa8; + const SET_HEALTH_PACKET = 0xa9; + const SET_SPAWN_POSITION_PACKET = 0xaa; + const ANIMATE_PACKET = 0xab; + const RESPAWN_PACKET = 0xac; + const SEND_INVENTORY_PACKET = 0xad; + const DROP_ITEM_PACKET = 0xae; + const CONTAINER_OPEN_PACKET = 0xaf; + const CONTAINER_CLOSE_PACKET = 0xb0; + const CONTAINER_SET_SLOT_PACKET = 0xb1; + const CONTAINER_SET_DATA_PACKET = 0xb2; + const CONTAINER_SET_CONTENT_PACKET = 0xb3; + const CONTAINER_ACK_PACKET = 0xb4; + const CHAT_PACKET = 0xb5; + const ADVENTURE_SETTINGS_PACKET = 0xb6; + const ENTITY_DATA_PACKET = 0xb7; + const PLAYER_INPUT_PACKET = 0xb9; } abstract class ProtocolInfo9{ - const CURRENT_PROTOCOL_9 = 9; + const CURRENT_PROTOCOL_9 = 9; - const PING_PACKET = 0x00; + const PING_PACKET = 0x00; - const PONG_PACKET = 0x03; + const PONG_PACKET = 0x03; - const CLIENT_CONNECT_PACKET = 0x09; - const SERVER_HANDSHAKE_PACKET = 0x10; + const CLIENT_CONNECT_PACKET = 0x09; + const SERVER_HANDSHAKE_PACKET = 0x10; - const CLIENT_HANDSHAKE_PACKET = 0x13; - //const SERVER_FULL_PACKET = 0x14; - const DISCONNECT_PACKET = 0x15; - const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; - const READY_PACKET = 0x84; - const MESSAGE_PACKET = 0x85; - const SET_TIME_PACKET = 0x86; - const START_GAME_PACKET = 0x87; - const ADD_MOB_PACKET = 0x88; - const ADD_PLAYER_PACKET = 0x89; - const REMOVE_PLAYER_PACKET = 0x8a; + const CLIENT_HANDSHAKE_PACKET = 0x13; + //const SERVER_FULL_PACKET = 0x14; + const DISCONNECT_PACKET = 0x15; + const LOGIN_PACKET = 0x82; + const LOGIN_STATUS_PACKET = 0x83; + const READY_PACKET = 0x84; + const MESSAGE_PACKET = 0x85; + const SET_TIME_PACKET = 0x86; + const START_GAME_PACKET = 0x87; + const ADD_MOB_PACKET = 0x88; + const ADD_PLAYER_PACKET = 0x89; + const REMOVE_PLAYER_PACKET = 0x8a; - const ADD_ENTITY_PACKET = 0x8c; - const REMOVE_ENTITY_PACKET = 0x8d; - const ADD_ITEM_ENTITY_PACKET = 0x8e; - const TAKE_ITEM_ENTITY_PACKET = 0x8f; - const MOVE_ENTITY_PACKET = 0x90; + const ADD_ENTITY_PACKET = 0x8c; + const REMOVE_ENTITY_PACKET = 0x8d; + const ADD_ITEM_ENTITY_PACKET = 0x8e; + const TAKE_ITEM_ENTITY_PACKET = 0x8f; + const MOVE_ENTITY_PACKET = 0x90; - const MOVE_ENTITY_PACKET_POSROT = 0x93; - const MOVE_PLAYER_PACKET = 0x94; - const PLACE_BLOCK_PACKET = 0x95; - const REMOVE_BLOCK_PACKET = 0x96; - const UPDATE_BLOCK_PACKET = 0x97; - const ADD_PAINTING_PACKET = 0x98; - const EXPLODE_PACKET = 0x99; - const LEVEL_EVENT_PACKET = 0x9a; - const TILE_EVENT_PACKET = 0x9b; - const ENTITY_EVENT_PACKET = 0x9c; - const REQUEST_CHUNK_PACKET = 0x9d; - const CHUNK_DATA_PACKET = 0x9e; - const PLAYER_EQUIPMENT_PACKET = 0x9f; - const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; - const INTERACT_PACKET = 0xa1; - const USE_ITEM_PACKET = 0xa2; - const PLAYER_ACTION_PACKET = 0xa3; + const MOVE_ENTITY_PACKET_POSROT = 0x93; + const MOVE_PLAYER_PACKET = 0x94; + const PLACE_BLOCK_PACKET = 0x95; + const REMOVE_BLOCK_PACKET = 0x96; + const UPDATE_BLOCK_PACKET = 0x97; + const ADD_PAINTING_PACKET = 0x98; + const EXPLODE_PACKET = 0x99; + const LEVEL_EVENT_PACKET = 0x9a; + const TILE_EVENT_PACKET = 0x9b; + const ENTITY_EVENT_PACKET = 0x9c; + const REQUEST_CHUNK_PACKET = 0x9d; + const CHUNK_DATA_PACKET = 0x9e; + const PLAYER_EQUIPMENT_PACKET = 0x9f; + const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; + const INTERACT_PACKET = 0xa1; + const USE_ITEM_PACKET = 0xa2; + const PLAYER_ACTION_PACKET = 0xa3; - const HURT_ARMOR_PACKET = 0xa5; - const SET_ENTITY_DATA_PACKET = 0xa6; - const SET_ENTITY_MOTION_PACKET = 0xa7; - //const SET_ENTITY_LINK_PACKET = 0xa?;// Change - const SET_HEALTH_PACKET = 0xa8;// Change - const SET_SPAWN_POSITION_PACKET = 0xa9; - const ANIMATE_PACKET = 0xaa; - const RESPAWN_PACKET = 0xab; - const SEND_INVENTORY_PACKET = 0xac; - const DROP_ITEM_PACKET = 0xad; - const CONTAINER_OPEN_PACKET = 0xae; - const CONTAINER_CLOSE_PACKET = 0xaf; - const CONTAINER_SET_SLOT_PACKET = 0xb0; - const CONTAINER_SET_DATA_PACKET = 0xb1; - const CONTAINER_SET_CONTENT_PACKET = 0xb2; - const CONTAINER_ACK_PACKET = 0xb3; - const CHAT_PACKET = 0xb4;//12 change - const ADVENTURE_SETTINGS_PACKET = 0xb6; - const ENTITY_DATA_PACKET = 0xb7; - const PLAYER_INPUT_PACKET = 0xb9; + const HURT_ARMOR_PACKET = 0xa5; + const SET_ENTITY_DATA_PACKET = 0xa6; + const SET_ENTITY_MOTION_PACKET = 0xa7; + //const SET_ENTITY_LINK_PACKET = 0xa?;// Change + const SET_HEALTH_PACKET = 0xa8;// Change + const SET_SPAWN_POSITION_PACKET = 0xa9; + const ANIMATE_PACKET = 0xaa; + const RESPAWN_PACKET = 0xab; + const SEND_INVENTORY_PACKET = 0xac; + const DROP_ITEM_PACKET = 0xad; + const CONTAINER_OPEN_PACKET = 0xae; + const CONTAINER_CLOSE_PACKET = 0xaf; + const CONTAINER_SET_SLOT_PACKET = 0xb0; + const CONTAINER_SET_DATA_PACKET = 0xb1; + const CONTAINER_SET_CONTENT_PACKET = 0xb2; + const CONTAINER_ACK_PACKET = 0xb3; + const CHAT_PACKET = 0xb4;//12 change + const ADVENTURE_SETTINGS_PACKET = 0xb6; + const ENTITY_DATA_PACKET = 0xb7; + const PLAYER_INPUT_PACKET = 0xb9; } abstract class ProtocolInfo7{ - const CURRENT_PROTOCOL_7 = 7; + const CURRENT_PROTOCOL_7 = 7; - const PING_PACKET = 0x00; + const PING_PACKET = 0x00; - const PONG_PACKET = 0x03; + const PONG_PACKET = 0x03; - const CLIENT_CONNECT_PACKET = 0x09; - const SERVER_HANDSHAKE_PACKET = 0x10; + const CLIENT_CONNECT_PACKET = 0x09; + const SERVER_HANDSHAKE_PACKET = 0x10; - const CLIENT_HANDSHAKE_PACKET = 0x13; - //const SERVER_FULL_PACKET = 0x14; - const DISCONNECT_PACKET = 0x15; - const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; - const READY_PACKET = 0x84; - const MESSAGE_PACKET = 0x85; - const SET_TIME_PACKET = 0x86; - const START_GAME_PACKET = 0x87; - const ADD_MOB_PACKET = 0x88; - const ADD_PLAYER_PACKET = 0x89; - const REMOVE_PLAYER_PACKET = 0x8a;//Maybe Exist + const CLIENT_HANDSHAKE_PACKET = 0x13; + //const SERVER_FULL_PACKET = 0x14; + const DISCONNECT_PACKET = 0x15; + const LOGIN_PACKET = 0x82; + const LOGIN_STATUS_PACKET = 0x83; + const READY_PACKET = 0x84; + const MESSAGE_PACKET = 0x85; + const SET_TIME_PACKET = 0x86; + const START_GAME_PACKET = 0x87; + const ADD_MOB_PACKET = 0x88; + const ADD_PLAYER_PACKET = 0x89; + const REMOVE_PLAYER_PACKET = 0x8a;//Maybe Exist - const ADD_ENTITY_PACKET = 0x8c; - const REMOVE_ENTITY_PACKET = 0x8d; - const ADD_ITEM_ENTITY_PACKET = 0x8e; - const TAKE_ITEM_ENTITY_PACKET = 0x8f; - const MOVE_ENTITY_PACKET = 0x90; + const ADD_ENTITY_PACKET = 0x8c; + const REMOVE_ENTITY_PACKET = 0x8d; + const ADD_ITEM_ENTITY_PACKET = 0x8e; + const TAKE_ITEM_ENTITY_PACKET = 0x8f; + const MOVE_ENTITY_PACKET = 0x90; - const MOVE_ENTITY_PACKET_POSROT = 0x93; - const MOVE_PLAYER_PACKET = 0x94; - const PLACE_BLOCK_PACKET = 0x95; - const REMOVE_BLOCK_PACKET = 0x96; - const UPDATE_BLOCK_PACKET = 0x97; - const ADD_PAINTING_PACKET = 0x98;// Maybe exist - const EXPLODE_PACKET = 0x99; - const LEVEL_EVENT_PACKET = 0x9a; - const TILE_EVENT_PACKET = 0x9b;//Maybe exist - const ENTITY_EVENT_PACKET = 0x9c; - const REQUEST_CHUNK_PACKET = 0x9d; - const CHUNK_DATA_PACKET = 0x9e; - const PLAYER_EQUIPMENT_PACKET = 0x9f; - // const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; - const INTERACT_PACKET = 0xa0;//Change - const USE_ITEM_PACKET = 0xa1; - const PLAYER_ACTION_PACKET = 0xa2; - const SET_ENTITY_DATA_PACKET = 0xa3; - const SET_ENTITY_MOTION_PACKET = 0xa4; - //const SET_ENTITY_LINK_PACKET = 0xa?; - const SET_HEALTH_PACKET = 0xa5; - const SET_SPAWN_POSITION_PACKET = 0xa6; - const ANIMATE_PACKET = 0xa7; - const RESPAWN_PACKET = 0xa8; - const SEND_INVENTORY_PACKET = 0xa9;//Maybe exist - const DROP_ITEM_PACKET = 0xaa; - const CONTAINER_OPEN_PACKET = 0xab; - const CONTAINER_CLOSE_PACKET = 0xac; - const CONTAINER_SET_SLOT_PACKET = 0xad; - const CONTAINER_SET_DATA_PACKET = 0xae; - const CONTAINER_SET_CONTENT_PACKET = 0xaf; - const CONTAINER_ACK_PACKET = 0xb; - const CHAT_PACKET = 0xb1;//12 change - const ADVENTURE_SETTINGS_PACKET = 0xb3; - const ENTITY_DATA_PACKET = 0xb2; - const PLAYER_INPUT_PACKET = 0xb9; + const MOVE_ENTITY_PACKET_POSROT = 0x93; + const MOVE_PLAYER_PACKET = 0x94; + const PLACE_BLOCK_PACKET = 0x95; + const REMOVE_BLOCK_PACKET = 0x96; + const UPDATE_BLOCK_PACKET = 0x97; + const ADD_PAINTING_PACKET = 0x98;// Maybe exist + const EXPLODE_PACKET = 0x99; + const LEVEL_EVENT_PACKET = 0x9a; + const TILE_EVENT_PACKET = 0x9b;//Maybe exist + const ENTITY_EVENT_PACKET = 0x9c; + const REQUEST_CHUNK_PACKET = 0x9d; + const CHUNK_DATA_PACKET = 0x9e; + const PLAYER_EQUIPMENT_PACKET = 0x9f; + // const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; + const INTERACT_PACKET = 0xa0;//Change + const USE_ITEM_PACKET = 0xa1; + const PLAYER_ACTION_PACKET = 0xa2; + const SET_ENTITY_DATA_PACKET = 0xa3; + const SET_ENTITY_MOTION_PACKET = 0xa4; + //const SET_ENTITY_LINK_PACKET = 0xa?; + const SET_HEALTH_PACKET = 0xa5; + const SET_SPAWN_POSITION_PACKET = 0xa6; + const ANIMATE_PACKET = 0xa7; + const RESPAWN_PACKET = 0xa8; + const SEND_INVENTORY_PACKET = 0xa9;//Maybe exist + const DROP_ITEM_PACKET = 0xaa; + const CONTAINER_OPEN_PACKET = 0xab; + const CONTAINER_CLOSE_PACKET = 0xac; + const CONTAINER_SET_SLOT_PACKET = 0xad; + const CONTAINER_SET_DATA_PACKET = 0xae; + const CONTAINER_SET_CONTENT_PACKET = 0xaf; + const CONTAINER_ACK_PACKET = 0xb; + const CHAT_PACKET = 0xb1;//12 change + const ADVENTURE_SETTINGS_PACKET = 0xb3; + const ENTITY_DATA_PACKET = 0xb2; + const PLAYER_INPUT_PACKET = 0xb9; } abstract class ProtocolInfo5{ - const CURRENT_PROTOCOL_5 = 5; + const CURRENT_PROTOCOL_5 = 5; - const PING_PACKET = 0x00; + const PING_PACKET = 0x00; - const PONG_PACKET = 0x03; + const PONG_PACKET = 0x03; - const CLIENT_CONNECT_PACKET = 0x09; - const SERVER_HANDSHAKE_PACKET = 0x10; + const CLIENT_CONNECT_PACKET = 0x09; + const SERVER_HANDSHAKE_PACKET = 0x10; - const CLIENT_HANDSHAKE_PACKET = 0x13; - //const SERVER_FULL_PACKET = 0x14; - const DISCONNECT_PACKET = 0x15; - const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; - const READY_PACKET = 0x84; - const MESSAGE_PACKET = 0x85; - const SET_TIME_PACKET = 0x86; - const START_GAME_PACKET = 0x87; - const ADD_MOB_PACKET = 0x88; - const ADD_PLAYER_PACKET = 0x89; - const REMOVE_PLAYER_PACKET = 0x8a;//Maybe Exist + const CLIENT_HANDSHAKE_PACKET = 0x13; + //const SERVER_FULL_PACKET = 0x14; + const DISCONNECT_PACKET = 0x15; + const LOGIN_PACKET = 0x82; + const LOGIN_STATUS_PACKET = 0x83; + const READY_PACKET = 0x84; + const MESSAGE_PACKET = 0x85; + const SET_TIME_PACKET = 0x86; + const START_GAME_PACKET = 0x87; + const ADD_MOB_PACKET = 0x88; + const ADD_PLAYER_PACKET = 0x89; + const REMOVE_PLAYER_PACKET = 0x8a;//Maybe Exist - const ADD_ENTITY_PACKET = 0x8c; - const REMOVE_ENTITY_PACKET = 0x8d; - const ADD_ITEM_ENTITY_PACKET = 0x8e; - const TAKE_ITEM_ENTITY_PACKET = 0x8f; - const MOVE_ENTITY_PACKET = 0x90; + const ADD_ENTITY_PACKET = 0x8c; + const REMOVE_ENTITY_PACKET = 0x8d; + const ADD_ITEM_ENTITY_PACKET = 0x8e; + const TAKE_ITEM_ENTITY_PACKET = 0x8f; + const MOVE_ENTITY_PACKET = 0x90; - const MOVE_ENTITY_PACKET_POSROT = 0x93; - const MOVE_PLAYER_PACKET = 0x94; - const PLACE_BLOCK_PACKET = 0x95; - const REMOVE_BLOCK_PACKET = 0x96; - const UPDATE_BLOCK_PACKET = 0x97; - //const ADD_PAINTING_PACKET = 0x98; - const EXPLODE_PACKET = 0x98;// Change - const LEVEL_EVENT_PACKET = 0x99; - const TILE_EVENT_PACKET = 0x9a; - const ENTITY_EVENT_PACKET = 0x9b; - const REQUEST_CHUNK_PACKET = 0x9c; - const CHUNK_DATA_PACKET = 0x9d; - const PLAYER_EQUIPMENT_PACKET = 0x9e; - // const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; - const INTERACT_PACKET = 0x9f; - const USE_ITEM_PACKET = 0xa0; - const PLAYER_ACTION_PACKET = 0xa1; - const SET_ENTITY_DATA_PACKET = 0xa2; - const SET_ENTITY_MOTION_PACKET = 0xa3; - //const SET_ENTITY_LINK_PACKET = 0xa?; - const SET_HEALTH_PACKET = 0xa4; - //const SET_SPAWN_POSITION_PACKET = 0xa6; - const ANIMATE_PACKET = 0xa5; - const RESPAWN_PACKET = 0xa6; - const SEND_INVENTORY_PACKET = 0xa7; - const DROP_ITEM_PACKET = 0xa8; - const CONTAINER_OPEN_PACKET = 0xa9; - const CONTAINER_CLOSE_PACKET = 0xaa; - const CONTAINER_SET_SLOT_PACKET = 0xab; - const CONTAINER_SET_DATA_PACKET = 0xac; - const CONTAINER_SET_CONTENT_PACKET = 0xad; - const CONTAINER_ACK_PACKET = 0xae; - const CHAT_PACKET = 0xaf; - //const ADVENTURE_SETTINGS_PACKET = 0xb3; - //const ENTITY_DATA_PACKET = 0xb2; - //const PLAYER_INPUT_PACKET = 0xb9; + const MOVE_ENTITY_PACKET_POSROT = 0x93; + const MOVE_PLAYER_PACKET = 0x94; + const PLACE_BLOCK_PACKET = 0x95; + const REMOVE_BLOCK_PACKET = 0x96; + const UPDATE_BLOCK_PACKET = 0x97; + //const ADD_PAINTING_PACKET = 0x98; + const EXPLODE_PACKET = 0x98;// Change + const LEVEL_EVENT_PACKET = 0x99; + const TILE_EVENT_PACKET = 0x9a; + const ENTITY_EVENT_PACKET = 0x9b; + const REQUEST_CHUNK_PACKET = 0x9c; + const CHUNK_DATA_PACKET = 0x9d; + const PLAYER_EQUIPMENT_PACKET = 0x9e; + // const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; + const INTERACT_PACKET = 0x9f; + const USE_ITEM_PACKET = 0xa0; + const PLAYER_ACTION_PACKET = 0xa1; + const SET_ENTITY_DATA_PACKET = 0xa2; + const SET_ENTITY_MOTION_PACKET = 0xa3; + //const SET_ENTITY_LINK_PACKET = 0xa?; + const SET_HEALTH_PACKET = 0xa4; + //const SET_SPAWN_POSITION_PACKET = 0xa6; + const ANIMATE_PACKET = 0xa5; + const RESPAWN_PACKET = 0xa6; + const SEND_INVENTORY_PACKET = 0xa7; + const DROP_ITEM_PACKET = 0xa8; + const CONTAINER_OPEN_PACKET = 0xa9; + const CONTAINER_CLOSE_PACKET = 0xaa; + const CONTAINER_SET_SLOT_PACKET = 0xab; + const CONTAINER_SET_DATA_PACKET = 0xac; + const CONTAINER_SET_CONTENT_PACKET = 0xad; + const CONTAINER_ACK_PACKET = 0xae; + const CHAT_PACKET = 0xaf; + //const ADVENTURE_SETTINGS_PACKET = 0xb3; + //const ENTITY_DATA_PACKET = 0xb2; + //const PLAYER_INPUT_PACKET = 0xb9; } abstract class ProtocolInfo4{ - const CURRENT_PROTOCOL_4 = 4; + const CURRENT_PROTOCOL_4 = 4; - const PING_PACKET = 0x00; + const PING_PACKET = 0x00; - const PONG_PACKET = 0x03; + const PONG_PACKET = 0x03; - const CLIENT_CONNECT_PACKET = 0x09; - const SERVER_HANDSHAKE_PACKET = 0x10; + const CLIENT_CONNECT_PACKET = 0x09; + const SERVER_HANDSHAKE_PACKET = 0x10; - const CLIENT_HANDSHAKE_PACKET = 0x13; - //const SERVER_FULL_PACKET = 0x14; - const DISCONNECT_PACKET = 0x15; - const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; - const READY_PACKET = 0x84; - const MESSAGE_PACKET = 0x85; - const SET_TIME_PACKET = 0x86; - const START_GAME_PACKET = 0x87; - const ADD_MOB_PACKET = 0x88; - const ADD_PLAYER_PACKET = 0x89; - const REMOVE_PLAYER_PACKET = 0x8a; + const CLIENT_HANDSHAKE_PACKET = 0x13; + //const SERVER_FULL_PACKET = 0x14; + const DISCONNECT_PACKET = 0x15; + const LOGIN_PACKET = 0x82; + const LOGIN_STATUS_PACKET = 0x83; + const READY_PACKET = 0x84; + const MESSAGE_PACKET = 0x85; + const SET_TIME_PACKET = 0x86; + const START_GAME_PACKET = 0x87; + const ADD_MOB_PACKET = 0x88; + const ADD_PLAYER_PACKET = 0x89; + const REMOVE_PLAYER_PACKET = 0x8a; - const ADD_ENTITY_PACKET = 0x8b; //Maybe exist // Change - const REMOVE_ENTITY_PACKET = 0x8c; - const ADD_ITEM_ENTITY_PACKET = 0x8d; - const TAKE_ITEM_ENTITY_PACKET = 0x8e; - const MOVE_ENTITY_PACKET = 0x8f;//unused ? + const ADD_ENTITY_PACKET = 0x8b; //Maybe exist // Change + const REMOVE_ENTITY_PACKET = 0x8c; + const ADD_ITEM_ENTITY_PACKET = 0x8d; + const TAKE_ITEM_ENTITY_PACKET = 0x8e; + const MOVE_ENTITY_PACKET = 0x8f;//unused ? - const MOVE_ENTITY_PACKET_POSROT = 0x92; - const MOVE_PLAYER_PACKET = 0x93; - const PLACE_BLOCK_PACKET = 0x94; - const REMOVE_BLOCK_PACKET = 0x95;//Maybe exist - const UPDATE_BLOCK_PACKET = 0x96; - //const ADD_PAINTING_PACKET = 0x98; - const EXPLODE_PACKET = 0x97; - const LEVEL_EVENT_PACKET = 0x98; - const TILE_EVENT_PACKET = 0x99; - const ENTITY_EVENT_PACKET = 0x9a; - const REQUEST_CHUNK_PACKET = 0x9b; - const CHUNK_DATA_PACKET = 0x9c; - const PLAYER_EQUIPMENT_PACKET = 0x9d; - // const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; - const INTERACT_PACKET = 0x9e; - const USE_ITEM_PACKET = 0x9f; - // const PLAYER_ACTION_PACKET = 0xa1; - const SET_ENTITY_DATA_PACKET = 0xa0; - const SET_ENTITY_MOTION_PACKET = 0xa1; - //const SET_ENTITY_LINK_PACKET = 0xa?; - const SET_HEALTH_PACKET = 0xa2; - //const SET_SPAWN_POSITION_PACKET = 0xa6; - const ANIMATE_PACKET = 0xa3; - const RESPAWN_PACKET = 0xa4; - const SEND_INVENTORY_PACKET = 0xa5; - const DROP_ITEM_PACKET = 0xa6; - const CONTAINER_OPEN_PACKET = 0xa7; - const CONTAINER_CLOSE_PACKET = 0xa8; - const CONTAINER_SET_SLOT_PACKET = 0xa9; - const CONTAINER_SET_DATA_PACKET = 0xaa; - const CONTAINER_SET_CONTENT_PACKET = 0xab; - const CONTAINER_ACK_PACKET = 0xac; - //const CHAT_PACKET = 0xaf; - //const ADVENTURE_SETTINGS_PACKET = 0xb3; - //const ENTITY_DATA_PACKET = 0xb2; - //const PLAYER_INPUT_PACKET = 0xb9; + const MOVE_ENTITY_PACKET_POSROT = 0x92; + const MOVE_PLAYER_PACKET = 0x93; + const PLACE_BLOCK_PACKET = 0x94; + const REMOVE_BLOCK_PACKET = 0x95;//Maybe exist + const UPDATE_BLOCK_PACKET = 0x96; + //const ADD_PAINTING_PACKET = 0x98; + const EXPLODE_PACKET = 0x97; + const LEVEL_EVENT_PACKET = 0x98; + const TILE_EVENT_PACKET = 0x99; + const ENTITY_EVENT_PACKET = 0x9a; + const REQUEST_CHUNK_PACKET = 0x9b; + const CHUNK_DATA_PACKET = 0x9c; + const PLAYER_EQUIPMENT_PACKET = 0x9d; + // const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; + const INTERACT_PACKET = 0x9e; + const USE_ITEM_PACKET = 0x9f; + // const PLAYER_ACTION_PACKET = 0xa1; + const SET_ENTITY_DATA_PACKET = 0xa0; + const SET_ENTITY_MOTION_PACKET = 0xa1; + //const SET_ENTITY_LINK_PACKET = 0xa?; + const SET_HEALTH_PACKET = 0xa2; + //const SET_SPAWN_POSITION_PACKET = 0xa6; + const ANIMATE_PACKET = 0xa3; + const RESPAWN_PACKET = 0xa4; + const SEND_INVENTORY_PACKET = 0xa5; + const DROP_ITEM_PACKET = 0xa6; + const CONTAINER_OPEN_PACKET = 0xa7; + const CONTAINER_CLOSE_PACKET = 0xa8; + const CONTAINER_SET_SLOT_PACKET = 0xa9; + const CONTAINER_SET_DATA_PACKET = 0xaa; + const CONTAINER_SET_CONTENT_PACKET = 0xab; + const CONTAINER_ACK_PACKET = 0xac; + //const CHAT_PACKET = 0xaf; + //const ADVENTURE_SETTINGS_PACKET = 0xb3; + //const ENTITY_DATA_PACKET = 0xb2; + //const PLAYER_INPUT_PACKET = 0xb9; } abstract class ProtocolInfo3{ - const CURRENT_PROTOCOL_3 = 3; + const CURRENT_PROTOCOL_3 = 3; - const PING_PACKET = 0x00; + const PING_PACKET = 0x00; - const PONG_PACKET = 0x03; + const PONG_PACKET = 0x03; - const CLIENT_CONNECT_PACKET = 0x09; - const SERVER_HANDSHAKE_PACKET = 0x10; + const CLIENT_CONNECT_PACKET = 0x09; + const SERVER_HANDSHAKE_PACKET = 0x10; - const CLIENT_HANDSHAKE_PACKET = 0x13; - //const SERVER_FULL_PACKET = 0x14; - const DISCONNECT_PACKET = 0x15; - const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; - const READY_PACKET = 0x84; - const MESSAGE_PACKET = 0x85; - const SET_TIME_PACKET = 0x86; - const START_GAME_PACKET = 0x87; - const ADD_MOB_PACKET = 0x88; - const ADD_PLAYER_PACKET = 0x89; - const REMOVE_PLAYER_PACKET = 0x8a; + const CLIENT_HANDSHAKE_PACKET = 0x13; + //const SERVER_FULL_PACKET = 0x14; + const DISCONNECT_PACKET = 0x15; + const LOGIN_PACKET = 0x82; + const LOGIN_STATUS_PACKET = 0x83; + const READY_PACKET = 0x84; + const MESSAGE_PACKET = 0x85; + const SET_TIME_PACKET = 0x86; + const START_GAME_PACKET = 0x87; + const ADD_MOB_PACKET = 0x88; + const ADD_PLAYER_PACKET = 0x89; + const REMOVE_PLAYER_PACKET = 0x8a; - const ADD_ENTITY_PACKET = 0x8b; //Maybe exist - const REMOVE_ENTITY_PACKET = 0x8c; - const ADD_ITEM_ENTITY_PACKET = 0x8d; - const TAKE_ITEM_ENTITY_PACKET = 0x8e; - const MOVE_ENTITY_PACKET = 0x8f;//unused ? + const ADD_ENTITY_PACKET = 0x8b; //Maybe exist + const REMOVE_ENTITY_PACKET = 0x8c; + const ADD_ITEM_ENTITY_PACKET = 0x8d; + const TAKE_ITEM_ENTITY_PACKET = 0x8e; + const MOVE_ENTITY_PACKET = 0x8f;//unused ? - const MOVE_ENTITY_PACKET_POSROT = 0x92; - const MOVE_PLAYER_PACKET = 0x93; - const PLACE_BLOCK_PACKET = 0x94; - const REMOVE_BLOCK_PACKET = 0x95; - const UPDATE_BLOCK_PACKET = 0x96; - //const ADD_PAINTING_PACKET = 0x98; - const EXPLODE_PACKET = 0x97; - const LEVEL_EVENT_PACKET = 0x98; - //const TILE_EVENT_PACKET = 0x99; - const ENTITY_EVENT_PACKET = 0x99;//Change - const REQUEST_CHUNK_PACKET = 0x9a; - const CHUNK_DATA_PACKET = 0x9b;//Change - const PLAYER_EQUIPMENT_PACKET = 0x9c; - // const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; - const INTERACT_PACKET = 0x9d; - const USE_ITEM_PACKET = 0x9e; - // const PLAYER_ACTION_PACKET = 0xa1; - const SET_ENTITY_DATA_PACKET = 0x9f; - // const SET_ENTITY_MOTION_PACKET = 0xa1; - //const SET_ENTITY_LINK_PACKET = 0xa?; - const SET_HEALTH_PACKET = 0xa0; - //const SET_SPAWN_POSITION_PACKET = 0xa6; - const ANIMATE_PACKET = 0xa1; - const RESPAWN_PACKET = 0xa2; - const SEND_INVENTORY_PACKET = 0xa3; - const DROP_ITEM_PACKET = 0xa4; - const CONTAINER_OPEN_PACKET = 0xa7; - const CONTAINER_CLOSE_PACKET = 0xa8; - const CONTAINER_SET_SLOT_PACKET = 0xa9; - const CONTAINER_SET_DATA_PACKET = 0xaa; - const CONTAINER_SET_CONTENT_PACKET = 0xab; - const CONTAINER_ACK_PACKET = 0xac; - //const CHAT_PACKET = 0xaf; - //const ADVENTURE_SETTINGS_PACKET = 0xb3; - //const ENTITY_DATA_PACKET = 0xb2; - //const PLAYER_INPUT_PACKET = 0xb9; + const MOVE_ENTITY_PACKET_POSROT = 0x92; + const MOVE_PLAYER_PACKET = 0x93; + const PLACE_BLOCK_PACKET = 0x94; + const REMOVE_BLOCK_PACKET = 0x95; + const UPDATE_BLOCK_PACKET = 0x96; + //const ADD_PAINTING_PACKET = 0x98; + const EXPLODE_PACKET = 0x97; + const LEVEL_EVENT_PACKET = 0x98; + //const TILE_EVENT_PACKET = 0x99; + const ENTITY_EVENT_PACKET = 0x99;//Change + const REQUEST_CHUNK_PACKET = 0x9a; + const CHUNK_DATA_PACKET = 0x9b;//Change + const PLAYER_EQUIPMENT_PACKET = 0x9c; + // const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa0; + const INTERACT_PACKET = 0x9d; + const USE_ITEM_PACKET = 0x9e; + // const PLAYER_ACTION_PACKET = 0xa1; + const SET_ENTITY_DATA_PACKET = 0x9f; + // const SET_ENTITY_MOTION_PACKET = 0xa1; + //const SET_ENTITY_LINK_PACKET = 0xa?; + const SET_HEALTH_PACKET = 0xa0; + //const SET_SPAWN_POSITION_PACKET = 0xa6; + const ANIMATE_PACKET = 0xa1; + const RESPAWN_PACKET = 0xa2; + const SEND_INVENTORY_PACKET = 0xa3; + const DROP_ITEM_PACKET = 0xa4; + const CONTAINER_OPEN_PACKET = 0xa7; + const CONTAINER_CLOSE_PACKET = 0xa8; + const CONTAINER_SET_SLOT_PACKET = 0xa9; + const CONTAINER_SET_DATA_PACKET = 0xaa; + const CONTAINER_SET_CONTENT_PACKET = 0xab; + const CONTAINER_ACK_PACKET = 0xac; + //const CHAT_PACKET = 0xaf; + //const ADVENTURE_SETTINGS_PACKET = 0xb3; + //const ENTITY_DATA_PACKET = 0xb2; + //const PLAYER_INPUT_PACKET = 0xb9; } /***REM_START***/ require_once(FILE_PATH . "src/network/raknet/RakNetDataPacket.php"); diff --git a/src/network/protocol/packet/AddEntityPacket.php b/src/network/protocol/packet/AddEntityPacket.php index 1295767c..93b3abc6 100644 --- a/src/network/protocol/packet/AddEntityPacket.php +++ b/src/network/protocol/packet/AddEntityPacket.php @@ -12,9 +12,9 @@ class AddEntityPacket extends RakNetDataPacket{ public $speedZ; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::ADD_ENTITY_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::ADD_ENTITY_PACKET; + } return ProtocolInfo::ADD_ENTITY_PACKET; } diff --git a/src/network/protocol/packet/AddItemEntityPacket.php b/src/network/protocol/packet/AddItemEntityPacket.php index 720a5041..8e10eba3 100644 --- a/src/network/protocol/packet/AddItemEntityPacket.php +++ b/src/network/protocol/packet/AddItemEntityPacket.php @@ -11,9 +11,9 @@ class AddItemEntityPacket extends RakNetDataPacket{ public $roll; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::ADD_ITEM_ENTITY_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::ADD_ITEM_ENTITY_PACKET; + } return ProtocolInfo::ADD_ITEM_ENTITY_PACKET; } diff --git a/src/network/protocol/packet/AddPaintingPacket.php b/src/network/protocol/packet/AddPaintingPacket.php index d5fb4dce..405f22d4 100644 --- a/src/network/protocol/packet/AddPaintingPacket.php +++ b/src/network/protocol/packet/AddPaintingPacket.php @@ -9,9 +9,9 @@ class AddPaintingPacket extends RakNetDataPacket{ public $title; public function pid(){ - if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::ADD_PAINTING_PACKET; - } + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ADD_PAINTING_PACKET; + } return ProtocolInfo::ADD_PAINTING_PACKET; } diff --git a/src/network/protocol/packet/AdventureSettingsPacket.php b/src/network/protocol/packet/AdventureSettingsPacket.php index 1474a75e..8c1937e4 100644 --- a/src/network/protocol/packet/AdventureSettingsPacket.php +++ b/src/network/protocol/packet/AdventureSettingsPacket.php @@ -4,13 +4,13 @@ class AdventureSettingsPacket extends RakNetDataPacket{ public $flags; public function pid(){ - if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::ADVENTURE_SETTINGS_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::ADVENTURE_SETTINGS_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::ADVENTURE_SETTINGS_PACKET; - } + if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::ADVENTURE_SETTINGS_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::ADVENTURE_SETTINGS_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ADVENTURE_SETTINGS_PACKET; + } return ProtocolInfo::ADVENTURE_SETTINGS_PACKET; } diff --git a/src/network/protocol/packet/AnimatePacket.php b/src/network/protocol/packet/AnimatePacket.php index 2c5744c9..1222d2a8 100644 --- a/src/network/protocol/packet/AnimatePacket.php +++ b/src/network/protocol/packet/AnimatePacket.php @@ -8,19 +8,19 @@ class AnimatePacket extends RakNetDataPacket{ public $eid; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::ANIMATE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::ANIMATE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::ANIMATE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::ANIMATE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::ANIMATE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::ANIMATE_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::ANIMATE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ANIMATE_PACKET; + } return ProtocolInfo::ANIMATE_PACKET; } diff --git a/src/network/protocol/packet/ChatPacket.php b/src/network/protocol/packet/ChatPacket.php index 2207a25f..4d4b10dd 100644 --- a/src/network/protocol/packet/ChatPacket.php +++ b/src/network/protocol/packet/ChatPacket.php @@ -4,15 +4,15 @@ class ChatPacket extends RakNetDataPacket{ public $message; public function pid(){ - if($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::CHAT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::CHAT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::CHAT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::CHAT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::CHAT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::CHAT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CHAT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CHAT_PACKET; + } return ProtocolInfo::CHAT_PACKET; } diff --git a/src/network/protocol/packet/ChunkDataPacket.php b/src/network/protocol/packet/ChunkDataPacket.php index f996c216..c727f583 100644 --- a/src/network/protocol/packet/ChunkDataPacket.php +++ b/src/network/protocol/packet/ChunkDataPacket.php @@ -6,15 +6,15 @@ class ChunkDataPacket extends RakNetDataPacket{ public $data; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::CHUNK_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::CHUNK_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::CHUNK_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::CHUNK_DATA_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CHUNK_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::CHUNK_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::CHUNK_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CHUNK_DATA_PACKET; + } return ProtocolInfo::CHUNK_DATA_PACKET; } diff --git a/src/network/protocol/packet/ContainerAckPacket.php b/src/network/protocol/packet/ContainerAckPacket.php index 71db5313..ae42a290 100644 --- a/src/network/protocol/packet/ContainerAckPacket.php +++ b/src/network/protocol/packet/ContainerAckPacket.php @@ -1,46 +1,46 @@ PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::CONTAINER_ACK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::CONTAINER_ACK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::CONTAINER_ACK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::CONTAINER_ACK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::CONTAINER_ACK_PACKET; - } - return ProtocolInfo::CONTAINER_ACK_PACKET; - } + public function pid(){ + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::CONTAINER_ACK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::CONTAINER_ACK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::CONTAINER_ACK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_ACK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_ACK_PACKET; + } + return ProtocolInfo::CONTAINER_ACK_PACKET; + } - public function decode(){ - $this->unknwonubyte1 = $this->getByte(); - $this->unknownshort = $this->getShort(); - $this->write1 = $this->get(); - $this->write0 = $this->get(); - ConsoleAPI::debug($this->unknwonubyte1); - ConsoleAPI::debug($this->unknownshort); - ConsoleAPI::debug($this->write1); - ConsoleAPI::debug($this->write0); - } + public function decode(){ + $this->unknwonubyte1 = $this->getByte(); + $this->unknownshort = $this->getShort(); + $this->write1 = $this->get(); + $this->write0 = $this->get(); + ConsoleAPI::debug($this->unknwonubyte1); + ConsoleAPI::debug($this->unknownshort); + ConsoleAPI::debug($this->write1); + ConsoleAPI::debug($this->write0); + } - public function encode(){ - $this->putByte($this->unknwonubyte1); - $this->putShort($this->unknownshort); - $this->put($this->write1); - $this->put($this->write0); - ConsoleAPI::debug($this->unknwonubyte1); - ConsoleAPI::debug($this->unknownshort); - ConsoleAPI::debug($this->write1); - ConsoleAPI::debug($this->write0); - } + public function encode(){ + $this->putByte($this->unknwonubyte1); + $this->putShort($this->unknownshort); + $this->put($this->write1); + $this->put($this->write0); + ConsoleAPI::debug($this->unknwonubyte1); + ConsoleAPI::debug($this->unknownshort); + ConsoleAPI::debug($this->write1); + ConsoleAPI::debug($this->write0); + } } \ No newline at end of file diff --git a/src/network/protocol/packet/ContainerClosePacket.php b/src/network/protocol/packet/ContainerClosePacket.php index 97a2b5bf..913fcdb4 100644 --- a/src/network/protocol/packet/ContainerClosePacket.php +++ b/src/network/protocol/packet/ContainerClosePacket.php @@ -4,19 +4,19 @@ class ContainerClosePacket extends RakNetDataPacket{ public $windowid; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::CONTAINER_CLOSE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::CONTAINER_CLOSE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::CONTAINER_CLOSE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::CONTAINER_CLOSE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::CONTAINER_CLOSE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::CONTAINER_CLOSE_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_CLOSE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_CLOSE_PACKET; + } return ProtocolInfo::CONTAINER_CLOSE_PACKET; } diff --git a/src/network/protocol/packet/ContainerOpenPacket.php b/src/network/protocol/packet/ContainerOpenPacket.php index c775b674..8c6f44da 100644 --- a/src/network/protocol/packet/ContainerOpenPacket.php +++ b/src/network/protocol/packet/ContainerOpenPacket.php @@ -9,19 +9,19 @@ class ContainerOpenPacket extends RakNetDataPacket{ public $z; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::CONTAINER_OPEN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::CONTAINER_OPEN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::CONTAINER_OPEN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::CONTAINER_OPEN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::CONTAINER_OPEN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::CONTAINER_OPEN_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_OPEN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_OPEN_PACKET; + } return ProtocolInfo::CONTAINER_OPEN_PACKET; } diff --git a/src/network/protocol/packet/ContainerSetContentPacket.php b/src/network/protocol/packet/ContainerSetContentPacket.php index 82840abb..663187b5 100644 --- a/src/network/protocol/packet/ContainerSetContentPacket.php +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -6,19 +6,19 @@ class ContainerSetContentPacket extends RakNetDataPacket{ public $hotbar = []; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::CONTAINER_SET_CONTENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::CONTAINER_SET_CONTENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::CONTAINER_SET_CONTENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ return ProtocolInfo7::CONTAINER_SET_CONTENT_PACKET; }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::CONTAINER_SET_CONTENT_PACKET; - }else if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::CONTAINER_SET_CONTENT_PACKET; - } + return ProtocolInfo9::CONTAINER_SET_CONTENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_SET_CONTENT_PACKET; + } return ProtocolInfo::CONTAINER_SET_CONTENT_PACKET; } diff --git a/src/network/protocol/packet/ContainerSetDataPacket.php b/src/network/protocol/packet/ContainerSetDataPacket.php index 77c5f711..1a6c73ea 100644 --- a/src/network/protocol/packet/ContainerSetDataPacket.php +++ b/src/network/protocol/packet/ContainerSetDataPacket.php @@ -6,19 +6,19 @@ class ContainerSetDataPacket extends RakNetDataPacket{ public $value; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::CONTAINER_SET_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::CONTAINER_SET_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::CONTAINER_SET_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ return ProtocolInfo7::CONTAINER_SET_DATA_PACKET; }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::CONTAINER_SET_DATA_PACKET; - }else if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::CONTAINER_SET_DATA_PACKET; - } + return ProtocolInfo9::CONTAINER_SET_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_SET_DATA_PACKET; + } return ProtocolInfo::CONTAINER_SET_DATA_PACKET; } diff --git a/src/network/protocol/packet/ContainerSetSlotPacket.php b/src/network/protocol/packet/ContainerSetSlotPacket.php index 61bee052..f6e8d18d 100644 --- a/src/network/protocol/packet/ContainerSetSlotPacket.php +++ b/src/network/protocol/packet/ContainerSetSlotPacket.php @@ -6,19 +6,19 @@ class ContainerSetSlotPacket extends RakNetDataPacket{ public $item; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::CONTAINER_SET_SLOT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::CONTAINER_SET_SLOT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::CONTAINER_SET_SLOT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::CONTAINER_SET_SLOT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::CONTAINER_SET_SLOT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::CONTAINER_SET_SLOT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::CONTAINER_SET_SLOT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::CONTAINER_SET_SLOT_PACKET; + } return ProtocolInfo::CONTAINER_SET_SLOT_PACKET; } diff --git a/src/network/protocol/packet/DropItemPacket.php b/src/network/protocol/packet/DropItemPacket.php index 2f2de32c..0217d602 100644 --- a/src/network/protocol/packet/DropItemPacket.php +++ b/src/network/protocol/packet/DropItemPacket.php @@ -6,19 +6,19 @@ class DropItemPacket extends RakNetDataPacket{ public $item; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::DROP_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::DROP_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::DROP_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::DROP_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::DROP_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::DROP_ITEM_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::DROP_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::DROP_ITEM_PACKET; + } return ProtocolInfo::DROP_ITEM_PACKET; } diff --git a/src/network/protocol/packet/EntityDataPacket.php b/src/network/protocol/packet/EntityDataPacket.php index 9e9ff78fa..87512adb 100644 --- a/src/network/protocol/packet/EntityDataPacket.php +++ b/src/network/protocol/packet/EntityDataPacket.php @@ -7,13 +7,13 @@ class EntityDataPacket extends RakNetDataPacket{ public $namedtag; public function pid(){ - if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::ENTITY_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::ENTITY_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::ENTITY_DATA_PACKET; - } + if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ENTITY_DATA_PACKET; + } return ProtocolInfo::ENTITY_DATA_PACKET; } diff --git a/src/network/protocol/packet/EntityEventPacket.php b/src/network/protocol/packet/EntityEventPacket.php index 4dbd4f0c..78daf662 100644 --- a/src/network/protocol/packet/EntityEventPacket.php +++ b/src/network/protocol/packet/EntityEventPacket.php @@ -14,15 +14,15 @@ class EntityEventPacket extends RakNetDataPacket{ } public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::ENTITY_EVENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::ENTITY_EVENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::ENTITY_EVENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::ENTITY_EVENT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::ENTITY_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::ENTITY_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::ENTITY_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ENTITY_EVENT_PACKET; + } return ProtocolInfo::ENTITY_EVENT_PACKET; } diff --git a/src/network/protocol/packet/ExplodePacket.php b/src/network/protocol/packet/ExplodePacket.php index cac8d6e8..c0bfae10 100644 --- a/src/network/protocol/packet/ExplodePacket.php +++ b/src/network/protocol/packet/ExplodePacket.php @@ -8,13 +8,13 @@ class ExplodePacket extends RakNetDataPacket{ public $records; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::EXPLODE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::EXPLODE_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::EXPLODE_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::EXPLODE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::EXPLODE_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::EXPLODE_PACKET; + } return ProtocolInfo::EXPLODE_PACKET; } diff --git a/src/network/protocol/packet/HurtArmorPacket.php b/src/network/protocol/packet/HurtArmorPacket.php index 5f038955..a8ddcf98 100644 --- a/src/network/protocol/packet/HurtArmorPacket.php +++ b/src/network/protocol/packet/HurtArmorPacket.php @@ -4,9 +4,9 @@ class HurtArmorPacket extends RakNetDataPacket{ public $health; public function pid(){ - if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::HURT_ARMOR_PACKET; - } + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::HURT_ARMOR_PACKET; + } return ProtocolInfo::HURT_ARMOR_PACKET; } diff --git a/src/network/protocol/packet/InteractPacket.php b/src/network/protocol/packet/InteractPacket.php index 91f60f72..844edc7c 100644 --- a/src/network/protocol/packet/InteractPacket.php +++ b/src/network/protocol/packet/InteractPacket.php @@ -9,17 +9,17 @@ class InteractPacket extends RakNetDataPacket{ public $target; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::INTERACT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::INTERACT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::INTERACT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::INTERACT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::INTERACT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::INTERACT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::INTERACT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::INTERACT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::INTERACT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::INTERACT_PACKET; + } return ProtocolInfo::INTERACT_PACKET; } diff --git a/src/network/protocol/packet/LevelEventPacket.php b/src/network/protocol/packet/LevelEventPacket.php index 2c0deda3..94d5b4cc 100644 --- a/src/network/protocol/packet/LevelEventPacket.php +++ b/src/network/protocol/packet/LevelEventPacket.php @@ -12,13 +12,13 @@ class LevelEventPacket extends RakNetDataPacket{ public $data; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::LEVEL_EVENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::LEVEL_EVENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::LEVEL_EVENT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::LEVEL_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::LEVEL_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::LEVEL_EVENT_PACKET; + } return ProtocolInfo::LEVEL_EVENT_PACKET; } diff --git a/src/network/protocol/packet/LoginPacket.php b/src/network/protocol/packet/LoginPacket.php index ba0f5919..9bd59938 100644 --- a/src/network/protocol/packet/LoginPacket.php +++ b/src/network/protocol/packet/LoginPacket.php @@ -17,8 +17,8 @@ class LoginPacket extends RakNetDataPacket{ $this->protocol2 = $this->getInt(); $this->clientId = $this->getInt();//null $this->loginData = $this->getString(); - $this->PROTOCOL = $this->protocol1; - } + $this->PROTOCOL = $this->protocol1; + } public function encode(){ diff --git a/src/network/protocol/packet/MessagePacket.php b/src/network/protocol/packet/MessagePacket.php index 50f72746..5af2520e 100644 --- a/src/network/protocol/packet/MessagePacket.php +++ b/src/network/protocol/packet/MessagePacket.php @@ -9,17 +9,17 @@ class MessagePacket extends RakNetDataPacket{ } public function decode(){ - if($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9){ //0.6.1 and below From NostalgiaCore-BackPort Author:Gameherobrine - $this->source = $this->getString(); - } + if($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9){ //0.6.1 and below From NostalgiaCore-BackPort Author:Gameherobrine + $this->source = $this->getString(); + } $this->message = $this->getString(); } public function encode(){ $this->reset(); - if($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9){ //0.6.1 and below From NostalgiaCore-BackPort Author:Gameherobrine - $this->putString($this->source); - } + if($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9){ //0.6.1 and below From NostalgiaCore-BackPort Author:Gameherobrine + $this->putString($this->source); + } $this->putString($this->message); } diff --git a/src/network/protocol/packet/MoveEntityPacket.php b/src/network/protocol/packet/MoveEntityPacket.php index 332748f6..1272ea68 100644 --- a/src/network/protocol/packet/MoveEntityPacket.php +++ b/src/network/protocol/packet/MoveEntityPacket.php @@ -3,9 +3,9 @@ class MoveEntityPacket extends RakNetDataPacket{ public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::MOVE_ENTITY_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::MOVE_ENTITY_PACKET; + } return ProtocolInfo::MOVE_ENTITY_PACKET; } diff --git a/src/network/protocol/packet/MoveEntityPacket_PosRot.php b/src/network/protocol/packet/MoveEntityPacket_PosRot.php index ce0ecae9..6d4ff310 100644 --- a/src/network/protocol/packet/MoveEntityPacket_PosRot.php +++ b/src/network/protocol/packet/MoveEntityPacket_PosRot.php @@ -9,9 +9,9 @@ class MoveEntityPacket_PosRot extends RakNetDataPacket{ public $pitch; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::MOVE_ENTITY_PACKET_POSROT; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::MOVE_ENTITY_PACKET_POSROT; + } return ProtocolInfo::MOVE_ENTITY_PACKET_POSROT; } diff --git a/src/network/protocol/packet/MovePlayerPacket.php b/src/network/protocol/packet/MovePlayerPacket.php index 58cb258a..05153c50 100644 --- a/src/network/protocol/packet/MovePlayerPacket.php +++ b/src/network/protocol/packet/MovePlayerPacket.php @@ -10,11 +10,11 @@ class MovePlayerPacket extends RakNetDataPacket{ public $bodyYaw; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::MOVE_PLAYER_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::MOVE_PLAYER_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::MOVE_PLAYER_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::MOVE_PLAYER_PACKET; + } return ProtocolInfo::MOVE_PLAYER_PACKET; } @@ -25,9 +25,9 @@ class MovePlayerPacket extends RakNetDataPacket{ $this->z = $this->getFloat(); $this->yaw = $this->getFloat(); $this->pitch = $this->getFloat(); - if($this->PROTOCOL > 13){ - $this->bodyYaw = $this->getFloat(); - } + if($this->PROTOCOL > 13){ + $this->bodyYaw = $this->getFloat(); + } } public function encode(){ @@ -38,9 +38,9 @@ class MovePlayerPacket extends RakNetDataPacket{ $this->putFloat($this->z); $this->putFloat($this->yaw); $this->putFloat($this->pitch); - if($this->PROTOCOL > 13){ - $this->putFloat($this->bodyYaw); - } + if($this->PROTOCOL > 13){ + $this->putFloat($this->bodyYaw); + } } } \ No newline at end of file diff --git a/src/network/protocol/packet/PlaceBlockPacket.php b/src/network/protocol/packet/PlaceBlockPacket.php index ec25c760..f31b749d 100644 --- a/src/network/protocol/packet/PlaceBlockPacket.php +++ b/src/network/protocol/packet/PlaceBlockPacket.php @@ -1,42 +1,42 @@ PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::PLACE_BLOCK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL) { - return ProtocolInfo12::PLACE_BLOCK_PACKET; - } - return ProtocolInfo::PLACE_BLOCK_PACKET; - } + public function pid(){ + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::PLACE_BLOCK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL) { + return ProtocolInfo12::PLACE_BLOCK_PACKET; + } + return ProtocolInfo::PLACE_BLOCK_PACKET; + } - public function decode(){ - $this->eid = $this->getInt(); - $this->x = $this->getInt(); - $this->z = $this->getInt(); - $this->y = $this->getByte(); - $this->block = $this->getByte(); - $this->meta = $this->getByte(); - $this->face = $this->getByte(); - } + public function decode(){ + $this->eid = $this->getInt(); + $this->x = $this->getInt(); + $this->z = $this->getInt(); + $this->y = $this->getByte(); + $this->block = $this->getByte(); + $this->meta = $this->getByte(); + $this->face = $this->getByte(); + } - public function encode(){ - $this->reset(); - $this->putInt($this->eid); - $this->putInt($this->x); - $this->putInt($this->z); - $this->putByte($this->y); - $this->putByte(BlockAPI::convertHighItemIdsToOldItemIds($this->PROTOCOL, $this->block)); - $this->putByte($this->meta); - $this->putByte($this->face); - } + public function encode(){ + $this->reset(); + $this->putInt($this->eid); + $this->putInt($this->x); + $this->putInt($this->z); + $this->putByte($this->y); + $this->putByte(BlockAPI::convertHighItemIdsToOldItemIds($this->PROTOCOL, $this->block)); + $this->putByte($this->meta); + $this->putByte($this->face); + } } \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerActionPacket.php b/src/network/protocol/packet/PlayerActionPacket.php index d2bea662..edc7ee4b 100644 --- a/src/network/protocol/packet/PlayerActionPacket.php +++ b/src/network/protocol/packet/PlayerActionPacket.php @@ -9,13 +9,13 @@ class PlayerActionPacket extends RakNetDataPacket{ public $eid; public function pid(){ - if($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::PLAYER_ACTION_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::PLAYER_ACTION_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::PLAYER_ACTION_PACKET; - } + if($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::PLAYER_ACTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::PLAYER_ACTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::PLAYER_ACTION_PACKET; + } return ProtocolInfo::PLAYER_ACTION_PACKET; } diff --git a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php index 5e2b8e90..41424a25 100644 --- a/src/network/protocol/packet/PlayerArmorEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerArmorEquipmentPacket.php @@ -5,9 +5,9 @@ class PlayerArmorEquipmentPacket extends RakNetDataPacket{ public $slots = []; public function pid(){ - if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::PLAYER_ARMOR_EQUIPMENT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::PLAYER_ARMOR_EQUIPMENT_PACKET; + } return ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET; } diff --git a/src/network/protocol/packet/PlayerEquipmentPacket.php b/src/network/protocol/packet/PlayerEquipmentPacket.php index ee06a539..d313f7ce 100644 --- a/src/network/protocol/packet/PlayerEquipmentPacket.php +++ b/src/network/protocol/packet/PlayerEquipmentPacket.php @@ -7,15 +7,15 @@ class PlayerEquipmentPacket extends RakNetDataPacket{ public $slot; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::PLAYER_EQUIPMENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::PLAYER_EQUIPMENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::PLAYER_EQUIPMENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::PLAYER_EQUIPMENT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::PLAYER_EQUIPMENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::PLAYER_EQUIPMENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::PLAYER_EQUIPMENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::PLAYER_EQUIPMENT_PACKET; + } return ProtocolInfo::PLAYER_EQUIPMENT_PACKET; } diff --git a/src/network/protocol/packet/PlayerInputPacket.php b/src/network/protocol/packet/PlayerInputPacket.php index ebd335f6..618dba70 100644 --- a/src/network/protocol/packet/PlayerInputPacket.php +++ b/src/network/protocol/packet/PlayerInputPacket.php @@ -8,11 +8,11 @@ class PlayerInputPacket extends RakNetDataPacket{ } public function pid(){ - if($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::PLAYER_INPUT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::PLAYER_INPUT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::PLAYER_INPUT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::PLAYER_INPUT_PACKET; + } return ProtocolInfo::PLAYER_INPUT_PACKET; } diff --git a/src/network/protocol/packet/RemoveBlockPacket.php b/src/network/protocol/packet/RemoveBlockPacket.php index 909657b9..1964cf4b 100644 --- a/src/network/protocol/packet/RemoveBlockPacket.php +++ b/src/network/protocol/packet/RemoveBlockPacket.php @@ -7,11 +7,11 @@ class RemoveBlockPacket extends RakNetDataPacket{ public $z; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::REMOVE_BLOCK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::REMOVE_BLOCK_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::REMOVE_BLOCK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::REMOVE_BLOCK_PACKET; + } return ProtocolInfo::REMOVE_BLOCK_PACKET; } diff --git a/src/network/protocol/packet/RemoveEntityPacket.php b/src/network/protocol/packet/RemoveEntityPacket.php index 5ef3e0b6..bbf7ea95 100644 --- a/src/network/protocol/packet/RemoveEntityPacket.php +++ b/src/network/protocol/packet/RemoveEntityPacket.php @@ -4,9 +4,9 @@ class RemoveEntityPacket extends RakNetDataPacket{ public $eid; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::REMOVE_ENTITY_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::REMOVE_ENTITY_PACKET; + } return ProtocolInfo::REMOVE_ENTITY_PACKET; } diff --git a/src/network/protocol/packet/RequestChunkPacket.php b/src/network/protocol/packet/RequestChunkPacket.php index 7d2ef64c..70c5e050 100644 --- a/src/network/protocol/packet/RequestChunkPacket.php +++ b/src/network/protocol/packet/RequestChunkPacket.php @@ -5,15 +5,15 @@ class RequestChunkPacket extends RakNetDataPacket{ public $chunkZ; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::REQUEST_CHUNK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::REQUEST_CHUNK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::REQUEST_CHUNK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::REQUEST_CHUNK_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::REQUEST_CHUNK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::REQUEST_CHUNK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::REQUEST_CHUNK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::REQUEST_CHUNK_PACKET; + } return ProtocolInfo::REQUEST_CHUNK_PACKET; } diff --git a/src/network/protocol/packet/RespawnPacket.php b/src/network/protocol/packet/RespawnPacket.php index adc61798..544193bc 100644 --- a/src/network/protocol/packet/RespawnPacket.php +++ b/src/network/protocol/packet/RespawnPacket.php @@ -7,19 +7,19 @@ class RespawnPacket extends RakNetDataPacket{ public $z; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::RESPAWN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::RESPAWN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::RESPAWN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::RESPAWN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::RESPAWN_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::RESPAWN_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::RESPAWN_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::RESPAWN_PACKET; + } return ProtocolInfo::RESPAWN_PACKET; } diff --git a/src/network/protocol/packet/RotateHeadPacket.php b/src/network/protocol/packet/RotateHeadPacket.php index 3827c023..634e3851 100644 --- a/src/network/protocol/packet/RotateHeadPacket.php +++ b/src/network/protocol/packet/RotateHeadPacket.php @@ -11,9 +11,9 @@ class RotateHeadPacket extends RakNetDataPacket{ */ public $rawYaw = false; public function pid(){ - if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::ROTATE_HEAD_PACKET; - } + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::ROTATE_HEAD_PACKET; + } return ProtocolInfo::ROTATE_HEAD_PACKET; } diff --git a/src/network/protocol/packet/SendInventoryPacket.php b/src/network/protocol/packet/SendInventoryPacket.php index 8ac9f4bb..c762c7ee 100644 --- a/src/network/protocol/packet/SendInventoryPacket.php +++ b/src/network/protocol/packet/SendInventoryPacket.php @@ -7,19 +7,19 @@ class SendInventoryPacket extends RakNetDataPacket{ public $armor = []; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::SEND_INVENTORY_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::SEND_INVENTORY_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::SEND_INVENTORY_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::SEND_INVENTORY_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::SEND_INVENTORY_PACKET; - }else if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::SEND_INVENTORY_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::SEND_INVENTORY_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SEND_INVENTORY_PACKET; + } return ProtocolInfo::SEND_INVENTORY_PACKET; } diff --git a/src/network/protocol/packet/SetEntityDataPacket.php b/src/network/protocol/packet/SetEntityDataPacket.php index d6f205bc..cb1c80d4 100644 --- a/src/network/protocol/packet/SetEntityDataPacket.php +++ b/src/network/protocol/packet/SetEntityDataPacket.php @@ -5,17 +5,17 @@ class SetEntityDataPacket extends RakNetDataPacket{ public $metadata; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::SET_ENTITY_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::SET_ENTITY_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::SET_ENTITY_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::SET_ENTITY_DATA_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::SET_ENTITY_DATA_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::SET_ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::SET_ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::SET_ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::SET_ENTITY_DATA_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_ENTITY_DATA_PACKET; + } return ProtocolInfo::SET_ENTITY_DATA_PACKET; } @@ -25,7 +25,7 @@ class SetEntityDataPacket extends RakNetDataPacket{ public function encode(){ $this->reset(); - if($this->PROTOCOL >= ProtocolInfo7::CURRENT_PROTOCOL_7) + if($this->PROTOCOL >= ProtocolInfo7::CURRENT_PROTOCOL_7) $this->putInt($this->eid); $this->put(Utils::writeMetadata($this->metadata)); } diff --git a/src/network/protocol/packet/SetEntityLinkPacket.php b/src/network/protocol/packet/SetEntityLinkPacket.php index 68eaf805..c473ef13 100644 --- a/src/network/protocol/packet/SetEntityLinkPacket.php +++ b/src/network/protocol/packet/SetEntityLinkPacket.php @@ -22,9 +22,9 @@ class SetEntityLinkPacket extends RakNetDataPacket{ } public function pid(){ - if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::SET_ENTITY_LINK_PACKET; - } + if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_ENTITY_LINK_PACKET; + } return ProtocolInfo::SET_ENTITY_LINK_PACKET; } diff --git a/src/network/protocol/packet/SetEntityMotionPacket.php b/src/network/protocol/packet/SetEntityMotionPacket.php index 78116795..1b58c07f 100644 --- a/src/network/protocol/packet/SetEntityMotionPacket.php +++ b/src/network/protocol/packet/SetEntityMotionPacket.php @@ -7,15 +7,15 @@ class SetEntityMotionPacket extends RakNetDataPacket{ public $speedZ; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::SET_ENTITY_MOTION_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::SET_ENTITY_MOTION_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::SET_ENTITY_MOTION_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::SET_ENTITY_MOTION_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::SET_ENTITY_MOTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::SET_ENTITY_MOTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::SET_ENTITY_MOTION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_ENTITY_MOTION_PACKET; + } return ProtocolInfo::SET_ENTITY_MOTION_PACKET; } diff --git a/src/network/protocol/packet/SetHealthPacket.php b/src/network/protocol/packet/SetHealthPacket.php index 0cb33616..02f36425 100644 --- a/src/network/protocol/packet/SetHealthPacket.php +++ b/src/network/protocol/packet/SetHealthPacket.php @@ -4,19 +4,19 @@ class SetHealthPacket extends RakNetDataPacket{ public $health; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::SET_HEALTH_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::SET_HEALTH_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::SET_HEALTH_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::SET_HEALTH_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::SET_HEALTH_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::SET_HEALTH_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::SET_HEALTH_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_HEALTH_PACKET; + } return ProtocolInfo::SET_HEALTH_PACKET; } diff --git a/src/network/protocol/packet/SetSpawnPositionPacket.php b/src/network/protocol/packet/SetSpawnPositionPacket.php index 2e767d32..ae9c7571 100644 --- a/src/network/protocol/packet/SetSpawnPositionPacket.php +++ b/src/network/protocol/packet/SetSpawnPositionPacket.php @@ -6,13 +6,13 @@ class SetSpawnPositionPacket extends RakNetDataPacket{ public $y; public function pid(){ - if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::SET_SPAWN_POSITION_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ - return ProtocolInfo9::SET_SPAWN_POSITION_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::SET_SPAWN_POSITION_PACKET; - } + if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::SET_SPAWN_POSITION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){ + return ProtocolInfo9::SET_SPAWN_POSITION_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::SET_SPAWN_POSITION_PACKET; + } return ProtocolInfo::SET_SPAWN_POSITION_PACKET; } diff --git a/src/network/protocol/packet/TakeItemEntityPacket.php b/src/network/protocol/packet/TakeItemEntityPacket.php index 22d8c892..314674eb 100644 --- a/src/network/protocol/packet/TakeItemEntityPacket.php +++ b/src/network/protocol/packet/TakeItemEntityPacket.php @@ -5,9 +5,9 @@ class TakeItemEntityPacket extends RakNetDataPacket{ public $eid; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::TAKE_ITEM_ENTITY_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::TAKE_ITEM_ENTITY_PACKET; + } return ProtocolInfo::TAKE_ITEM_ENTITY_PACKET; } diff --git a/src/network/protocol/packet/TileEventPacket.php b/src/network/protocol/packet/TileEventPacket.php index a15e5c73..af225590 100644 --- a/src/network/protocol/packet/TileEventPacket.php +++ b/src/network/protocol/packet/TileEventPacket.php @@ -8,13 +8,13 @@ class TileEventPacket extends RakNetDataPacket{ public $case2; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::TILE_EVENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::TILE_EVENT_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::TILE_EVENT_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::TILE_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::TILE_EVENT_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::TILE_EVENT_PACKET; + } return ProtocolInfo::TILE_EVENT_PACKET; } diff --git a/src/network/protocol/packet/UpdateBlockPacket.php b/src/network/protocol/packet/UpdateBlockPacket.php index 239aa472..271ba18d 100644 --- a/src/network/protocol/packet/UpdateBlockPacket.php +++ b/src/network/protocol/packet/UpdateBlockPacket.php @@ -8,11 +8,11 @@ class UpdateBlockPacket extends RakNetDataPacket{ public $meta; public function pid(){ - if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::UPDATE_BLOCK_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::UPDATE_BLOCK_PACKET; - } + if($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::UPDATE_BLOCK_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::UPDATE_BLOCK_PACKET; + } return ProtocolInfo::UPDATE_BLOCK_PACKET; } diff --git a/src/network/protocol/packet/UseItemPacket.php b/src/network/protocol/packet/UseItemPacket.php index 19fd3128..379cd58f 100644 --- a/src/network/protocol/packet/UseItemPacket.php +++ b/src/network/protocol/packet/UseItemPacket.php @@ -16,17 +16,17 @@ class UseItemPacket extends RakNetDataPacket{ public $posZ; public function pid(){ - if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ - return ProtocolInfo3::USE_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ - return ProtocolInfo4::USE_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ - return ProtocolInfo5::USE_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ - return ProtocolInfo7::USE_ITEM_PACKET; - }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ - return ProtocolInfo12::USE_ITEM_PACKET; - } + if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ + return ProtocolInfo3::USE_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo5::CURRENT_PROTOCOL_5){ + return ProtocolInfo4::USE_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){ + return ProtocolInfo5::USE_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9){ + return ProtocolInfo7::USE_ITEM_PACKET; + }elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){ + return ProtocolInfo12::USE_ITEM_PACKET; + } return ProtocolInfo::USE_ITEM_PACKET; } @@ -41,11 +41,11 @@ class UseItemPacket extends RakNetDataPacket{ $this->fx = $this->getFloat(); $this->fy = $this->getFloat(); $this->fz = $this->getFloat(); - if ($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9) { - $this->posX = $this->getFloat(); - $this->posY = $this->getFloat(); - $this->posZ = $this->getFloat(); - } + if ($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9) { + $this->posX = $this->getFloat(); + $this->posY = $this->getFloat(); + $this->posZ = $this->getFloat(); + } } public function encode(){ diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php index b3d8da8b..4c882c4f 100755 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -15,7 +15,7 @@ abstract class RakNetDataPacket extends stdClass{ private $offset = 0; public $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL; - + abstract public function encode(); abstract public function decode(); @@ -37,21 +37,21 @@ abstract class RakNetDataPacket extends stdClass{ $this->setBuffer(chr($this->pid())); } - public function isPacketExist(int $protocol) : int{ + public function isPacketExist(int $protocol) : int{ - $exist = true; - return $exist; - } + $exist = true; + return $exist; + } abstract public function pid(); - public function getInternalPid() : int{ - $rawProtocol = $this->PROTOCOL; - $this->PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL; - $pid = (int) $this->pid(); - $this->PROTOCOL = $rawProtocol; - return $pid; - } + public function getInternalPid() : int{ + $rawProtocol = $this->PROTOCOL; + $this->PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL; + $pid = (int) $this->pid(); + $this->PROTOCOL = $rawProtocol; + return $pid; + } protected function getLong($unsigned = false){ return Utils::readLong($this->get(8), $unsigned); diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index af5498a1..20b08b58 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -4,13 +4,13 @@ class RakNetParser{ public $packet; private $buffer; - private $source; + private $source; private $offset; - private $isparse = false; + private $isparse = false; public function __construct(&$buffer, $source){ - $this->source =& $source; - $this->buffer =& $buffer; + $this->source = &$source; + $this->buffer = &$buffer; $this->offset = 0; if(strlen($this->buffer) > 0){ $this->parse(); @@ -59,8 +59,8 @@ class RakNetParser{ case RakNetInfo::DATA_PACKET_F: $this->packet->seqNumber = $this->getLTriad(); $this->packet->data = []; - $this->packet->ip = $this->source; - $PROTOCOL = PlayerAPI::decodeProtocol($this->packet->ip); + $this->packet->ip = $this->source; + $PROTOCOL = PlayerAPI::decodeProtocol($this->packet->ip); while(!$this->feof() and ($pk = $this->parseDataPacket($PROTOCOL)) instanceof RakNetDataPacket){ $this->packet->data[] = $pk; @@ -184,234 +184,234 @@ class RakNetParser{ return $data; } - private function parseDataPacket12(){ - $packetFlags = $this->getByte(); - $reliability = ($packetFlags & 0b11100000) >> 5; - $hasSplit = ($packetFlags & 0b00010000) > 0; - $length = (int) ceil($this->getShort() / 8); - if($reliability === 2 - or $reliability === 3 - or $reliability === 4 - or $reliability === 6 - or $reliability === 7){ - $messageIndex = $this->getLTriad(); - }else{ - $messageIndex = false; - } + private function parseDataPacket12(){ + $packetFlags = $this->getByte(); + $reliability = ($packetFlags & 0b11100000) >> 5; + $hasSplit = ($packetFlags & 0b00010000) > 0; + $length = (int) ceil($this->getShort() / 8); + if($reliability === 2 + or $reliability === 3 + or $reliability === 4 + or $reliability === 6 + or $reliability === 7){ + $messageIndex = $this->getLTriad(); + }else{ + $messageIndex = false; + } - if($reliability === 1 - or $reliability === 3 - or $reliability === 4 - or $reliability === 7){ - $orderIndex = $this->getLTriad(); - $orderChannel = $this->getByte(); - }else{ - $orderIndex = false; - $orderChannel = false; - } + if($reliability === 1 + or $reliability === 3 + or $reliability === 4 + or $reliability === 7){ + $orderIndex = $this->getLTriad(); + $orderChannel = $this->getByte(); + }else{ + $orderIndex = false; + $orderChannel = false; + } - if($hasSplit){ - $splitCount = $this->getInt(); - $splitID = $this->getShort(); - $splitIndex = $this->getInt(); - }else{ - $splitCount = false; - $splitID = false; - $splitIndex = false; - } + if($hasSplit){ + $splitCount = $this->getInt(); + $splitID = $this->getShort(); + $splitIndex = $this->getInt(); + }else{ + $splitCount = false; + $splitID = false; + $splitIndex = false; + } - if($length <= 0 - or $orderChannel >= 32 - or ($hasSplit === true and $splitIndex >= $splitCount)){ - return false; - }else{ - $pid = $this->getByte(); - $buffer = $this->get($length - 1); - if(strlen($buffer) < ($length - 1)){ - return false; - } - switch($pid){ - case ProtocolInfo12::PING_PACKET: - $data = new PingPacket; - break; - case ProtocolInfo12::PONG_PACKET: - $data = new PongPacket; - break; - case ProtocolInfo12::CLIENT_CONNECT_PACKET: - $data = new ClientConnectPacket; - break; - case ProtocolInfo12::SERVER_HANDSHAKE_PACKET: - $data = new ServerHandshakePacket; - break; - case ProtocolInfo12::DISCONNECT_PACKET: - $data = new DisconnectPacket; - break; - case ProtocolInfo12::LOGIN_PACKET: - $data = new LoginPacket; - break; - case ProtocolInfo12::LOGIN_STATUS_PACKET: - $data = new LoginStatusPacket; - break; - case ProtocolInfo12::READY_PACKET: - $data = new ReadyPacket; - break; - case ProtocolInfo12::MESSAGE_PACKET: - $data = new MessagePacket; - break; - case ProtocolInfo12::SET_TIME_PACKET: - $data = new SetTimePacket; - break; - case ProtocolInfo12::START_GAME_PACKET: - $data = new StartGamePacket; - break; - case ProtocolInfo12::ADD_MOB_PACKET: - $data = new AddMobPacket; - break; - case ProtocolInfo12::ADD_PLAYER_PACKET: - $data = new AddPlayerPacket; - break; - case ProtocolInfo12::REMOVE_PLAYER_PACKET: - $data = new RemovePlayerPacket; - break; - case ProtocolInfo12::ADD_ENTITY_PACKET: - $data = new AddEntityPacket; - break; - case ProtocolInfo12::REMOVE_ENTITY_PACKET: - $data = new RemoveEntityPacket; - break; - case ProtocolInfo12::ADD_ITEM_ENTITY_PACKET: - $data = new AddItemEntityPacket; - break; - case ProtocolInfo12::TAKE_ITEM_ENTITY_PACKET: - $data = new TakeItemEntityPacket; - break; - case ProtocolInfo12::MOVE_ENTITY_PACKET: - $data = new MoveEntityPacket; - break; - case ProtocolInfo12::MOVE_ENTITY_PACKET_POSROT: - $data = new MoveEntityPacket_PosRot; - break; - case ProtocolInfo12::ROTATE_HEAD_PACKET: - $data = new RotateHeadPacket; - break; - case ProtocolInfo12::MOVE_PLAYER_PACKET: - $data = new MovePlayerPacket; - break; - case ProtocolInfo12::REMOVE_BLOCK_PACKET: - $data = new RemoveBlockPacket; - break; - case ProtocolInfo12::UPDATE_BLOCK_PACKET: - $data = new UpdateBlockPacket; - break; - case ProtocolInfo12::ADD_PAINTING_PACKET: - $data = new AddPaintingPacket; - break; - case ProtocolInfo12::EXPLODE_PACKET: - $data = new ExplodePacket; - break; - case ProtocolInfo12::LEVEL_EVENT_PACKET: - $data = new LevelEventPacket; - break; - case ProtocolInfo12::TILE_EVENT_PACKET: - $data = new TileEventPacket; - break; - case ProtocolInfo12::ENTITY_EVENT_PACKET: - $data = new EntityEventPacket; - break; - case ProtocolInfo12::REQUEST_CHUNK_PACKET: - $data = new RequestChunkPacket; - break; - case ProtocolInfo12::CHUNK_DATA_PACKET: - $data = new ChunkDataPacket; - break; - case ProtocolInfo12::PLAYER_EQUIPMENT_PACKET: - $data = new PlayerEquipmentPacket; - break; - case ProtocolInfo12::PLAYER_ARMOR_EQUIPMENT_PACKET: - $data = new PlayerArmorEquipmentPacket; - break; - case ProtocolInfo12::INTERACT_PACKET: - $data = new InteractPacket; - break; - case ProtocolInfo12::USE_ITEM_PACKET: - $data = new UseItemPacket; - break; - case ProtocolInfo12::PLAYER_ACTION_PACKET: - $data = new PlayerActionPacket; - break; - case ProtocolInfo12::HURT_ARMOR_PACKET: - $data = new HurtArmorPacket; - break; - case ProtocolInfo12::SET_ENTITY_DATA_PACKET: - $data = new SetEntityDataPacket; - break; - case ProtocolInfo12::SET_ENTITY_MOTION_PACKET: - $data = new SetEntityMotionPacket; - break; - case ProtocolInfo12::SET_HEALTH_PACKET: - $data = new SetHealthPacket; - break; - case ProtocolInfo12::SET_SPAWN_POSITION_PACKET: - $data = new SetSpawnPositionPacket; - break; - case ProtocolInfo12::ANIMATE_PACKET: - $data = new AnimatePacket; - break; - case ProtocolInfo12::RESPAWN_PACKET: - $data = new RespawnPacket; - break; - case ProtocolInfo12::SEND_INVENTORY_PACKET: - $data = new SendInventoryPacket; - break; - case ProtocolInfo12::DROP_ITEM_PACKET: - $data = new DropItemPacket; - break; - case ProtocolInfo12::CONTAINER_OPEN_PACKET: - $data = new ContainerOpenPacket; - break; - case ProtocolInfo12::CONTAINER_CLOSE_PACKET: - $data = new ContainerClosePacket; - break; - case ProtocolInfo12::CONTAINER_SET_SLOT_PACKET: - $data = new ContainerSetSlotPacket; - break; - case ProtocolInfo12::CONTAINER_SET_DATA_PACKET: - $data = new ContainerSetDataPacket; - break; - case ProtocolInfo12::CONTAINER_SET_CONTENT_PACKET: - $data = new ContainerSetContentPacket; - break; - case ProtocolInfo12::CHAT_PACKET: - $data = new ChatPacket; - break; - case ProtocolInfo12::ADVENTURE_SETTINGS_PACKET: - $data = new AdventureSettingsPacket; - break; - case ProtocolInfo12::ENTITY_DATA_PACKET: - $data = new EntityDataPacket; - break; - case ProtocolInfo12::SET_ENTITY_LINK_PACKET: - $data = new SetEntityLinkPacket; - case ProtocolInfo12::PLAYER_INPUT_PACKET: - $data = new PlayerInputPacket; - break; - default: - $data = new UnknownPacket(); - $data->packetID = $pid; - break; - } - $data->reliability = $reliability; - $data->hasSplit = $hasSplit; - $data->messageIndex = $messageIndex; - $data->orderIndex = $orderIndex; - $data->orderChannel = $orderChannel; - $data->splitCount = $splitCount; - $data->splitID = $splitID; - $data->splitIndex = $splitIndex; - $data->setBuffer($buffer); - } - return $data; - } + if($length <= 0 + or $orderChannel >= 32 + or ($hasSplit === true and $splitIndex >= $splitCount)){ + return false; + }else{ + $pid = $this->getByte(); + $buffer = $this->get($length - 1); + if(strlen($buffer) < ($length - 1)){ + return false; + } + switch($pid){ + case ProtocolInfo12::PING_PACKET: + $data = new PingPacket; + break; + case ProtocolInfo12::PONG_PACKET: + $data = new PongPacket; + break; + case ProtocolInfo12::CLIENT_CONNECT_PACKET: + $data = new ClientConnectPacket; + break; + case ProtocolInfo12::SERVER_HANDSHAKE_PACKET: + $data = new ServerHandshakePacket; + break; + case ProtocolInfo12::DISCONNECT_PACKET: + $data = new DisconnectPacket; + break; + case ProtocolInfo12::LOGIN_PACKET: + $data = new LoginPacket; + break; + case ProtocolInfo12::LOGIN_STATUS_PACKET: + $data = new LoginStatusPacket; + break; + case ProtocolInfo12::READY_PACKET: + $data = new ReadyPacket; + break; + case ProtocolInfo12::MESSAGE_PACKET: + $data = new MessagePacket; + break; + case ProtocolInfo12::SET_TIME_PACKET: + $data = new SetTimePacket; + break; + case ProtocolInfo12::START_GAME_PACKET: + $data = new StartGamePacket; + break; + case ProtocolInfo12::ADD_MOB_PACKET: + $data = new AddMobPacket; + break; + case ProtocolInfo12::ADD_PLAYER_PACKET: + $data = new AddPlayerPacket; + break; + case ProtocolInfo12::REMOVE_PLAYER_PACKET: + $data = new RemovePlayerPacket; + break; + case ProtocolInfo12::ADD_ENTITY_PACKET: + $data = new AddEntityPacket; + break; + case ProtocolInfo12::REMOVE_ENTITY_PACKET: + $data = new RemoveEntityPacket; + break; + case ProtocolInfo12::ADD_ITEM_ENTITY_PACKET: + $data = new AddItemEntityPacket; + break; + case ProtocolInfo12::TAKE_ITEM_ENTITY_PACKET: + $data = new TakeItemEntityPacket; + break; + case ProtocolInfo12::MOVE_ENTITY_PACKET: + $data = new MoveEntityPacket; + break; + case ProtocolInfo12::MOVE_ENTITY_PACKET_POSROT: + $data = new MoveEntityPacket_PosRot; + break; + case ProtocolInfo12::ROTATE_HEAD_PACKET: + $data = new RotateHeadPacket; + break; + case ProtocolInfo12::MOVE_PLAYER_PACKET: + $data = new MovePlayerPacket; + break; + case ProtocolInfo12::REMOVE_BLOCK_PACKET: + $data = new RemoveBlockPacket; + break; + case ProtocolInfo12::UPDATE_BLOCK_PACKET: + $data = new UpdateBlockPacket; + break; + case ProtocolInfo12::ADD_PAINTING_PACKET: + $data = new AddPaintingPacket; + break; + case ProtocolInfo12::EXPLODE_PACKET: + $data = new ExplodePacket; + break; + case ProtocolInfo12::LEVEL_EVENT_PACKET: + $data = new LevelEventPacket; + break; + case ProtocolInfo12::TILE_EVENT_PACKET: + $data = new TileEventPacket; + break; + case ProtocolInfo12::ENTITY_EVENT_PACKET: + $data = new EntityEventPacket; + break; + case ProtocolInfo12::REQUEST_CHUNK_PACKET: + $data = new RequestChunkPacket; + break; + case ProtocolInfo12::CHUNK_DATA_PACKET: + $data = new ChunkDataPacket; + break; + case ProtocolInfo12::PLAYER_EQUIPMENT_PACKET: + $data = new PlayerEquipmentPacket; + break; + case ProtocolInfo12::PLAYER_ARMOR_EQUIPMENT_PACKET: + $data = new PlayerArmorEquipmentPacket; + break; + case ProtocolInfo12::INTERACT_PACKET: + $data = new InteractPacket; + break; + case ProtocolInfo12::USE_ITEM_PACKET: + $data = new UseItemPacket; + break; + case ProtocolInfo12::PLAYER_ACTION_PACKET: + $data = new PlayerActionPacket; + break; + case ProtocolInfo12::HURT_ARMOR_PACKET: + $data = new HurtArmorPacket; + break; + case ProtocolInfo12::SET_ENTITY_DATA_PACKET: + $data = new SetEntityDataPacket; + break; + case ProtocolInfo12::SET_ENTITY_MOTION_PACKET: + $data = new SetEntityMotionPacket; + break; + case ProtocolInfo12::SET_HEALTH_PACKET: + $data = new SetHealthPacket; + break; + case ProtocolInfo12::SET_SPAWN_POSITION_PACKET: + $data = new SetSpawnPositionPacket; + break; + case ProtocolInfo12::ANIMATE_PACKET: + $data = new AnimatePacket; + break; + case ProtocolInfo12::RESPAWN_PACKET: + $data = new RespawnPacket; + break; + case ProtocolInfo12::SEND_INVENTORY_PACKET: + $data = new SendInventoryPacket; + break; + case ProtocolInfo12::DROP_ITEM_PACKET: + $data = new DropItemPacket; + break; + case ProtocolInfo12::CONTAINER_OPEN_PACKET: + $data = new ContainerOpenPacket; + break; + case ProtocolInfo12::CONTAINER_CLOSE_PACKET: + $data = new ContainerClosePacket; + break; + case ProtocolInfo12::CONTAINER_SET_SLOT_PACKET: + $data = new ContainerSetSlotPacket; + break; + case ProtocolInfo12::CONTAINER_SET_DATA_PACKET: + $data = new ContainerSetDataPacket; + break; + case ProtocolInfo12::CONTAINER_SET_CONTENT_PACKET: + $data = new ContainerSetContentPacket; + break; + case ProtocolInfo12::CHAT_PACKET: + $data = new ChatPacket; + break; + case ProtocolInfo12::ADVENTURE_SETTINGS_PACKET: + $data = new AdventureSettingsPacket; + break; + case ProtocolInfo12::ENTITY_DATA_PACKET: + $data = new EntityDataPacket; + break; + case ProtocolInfo12::SET_ENTITY_LINK_PACKET: + $data = new SetEntityLinkPacket; + case ProtocolInfo12::PLAYER_INPUT_PACKET: + $data = new PlayerInputPacket; + break; + default: + $data = new UnknownPacket(); + $data->packetID = $pid; + break; + } + $data->reliability = $reliability; + $data->hasSplit = $hasSplit; + $data->messageIndex = $messageIndex; + $data->orderIndex = $orderIndex; + $data->orderChannel = $orderChannel; + $data->splitCount = $splitCount; + $data->splitID = $splitID; + $data->splitIndex = $splitIndex; + $data->setBuffer($buffer); + } + return $data; + } private function getInt($unsigned = false){ return Utils::readInt($this->get(4), $unsigned);