Init Commit

This commit is contained in:
yefengeeeeeeeeeee 2026-04-06 14:01:50 +08:00
parent 845ff19ba1
commit 5d0d586ce5
6 changed files with 237 additions and 222 deletions

View file

@ -673,6 +673,30 @@ class BlockAPI{
}
}
}
public static function convertHighItemIdsToOldItemIds(int $protocolId, int $itemId) : int{
if ($protocolId >= ProtocolInfo12::CURRENT_PROTOCOL_12) {
return $itemId;
}
$idMap = [ //default for protocol < 12
LIT_PUMPKIN => MELON_BLOCK, //block
PUMPKIN_SEEDS => MELON_SEEDS, //item
PUMPKIN_PIE => BREAD, //item
BEETROOT => BREAD, //item
BEETROOT_SEEDS => SEEDS, //item
];
if ($protocolId < ProtocolInfo9::CURRENT_PROTOCOL_9) {
$idMap += [
NETHERRACK => OBSIDIAN, //block
NETHER_BRICK => BRICK, //item
NETHER_QUARTZ => BRICK, //item
];
}
return $idMap[$itemId] ?? $itemId;
}
/**
* @deprecated random updates are handled differently now.

View file

@ -522,6 +522,18 @@ class PlayerAPI{
}
}
/**
* @return int
*/
public static function decodeProtocol($ip, $port){
foreach(ServerAPI::request()->clients as $p) {
ConsoleAPI::info($p->ip);
if($p->ip == $ip && $p->port == $port){
return $p->PROTOCOL;
}
}
}
public function remove($CID){
if(isset($this->server->clients[$CID])){
$player = $this->server->clients[$CID];

View file

@ -45,6 +45,7 @@ class Player{
public $CID;
public $MTU;
public $spawned = false;
public $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL;
/**
* Stores player inventory. Should not be accessed directly: use Player::addItem/Player::removeItem/Player::setSlot for setting and Player::getSlot for getting.
* @var array
@ -481,6 +482,7 @@ class Player{
if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) return [];
if(!$this->convertToLocalEIDPacket($packet)) return false;
$packet->PROTOCOL = $this->PROTOCOL;
$packet->encode();
$pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0);
$pk->data[] = $packet;
@ -508,7 +510,6 @@ class Player{
}
$packet->PROTOCOL = $this->PROTOCOL;
$packet->encode();
$len = strlen($packet->buffer) + 1;
$MTU = $this->MTU - 24;
@ -541,6 +542,7 @@ class Player{
$pk->seqNumber = $this->counter[0]++;
$pk->sendtime = microtime(true);
$packet->PROTOCOL = $this->PROTOCOL;
$packet->encode();
$len = strlen($packet->buffer) + 1;
$MTU = $this->MTU - 24;
@ -570,6 +572,7 @@ class Player{
$cnts[] = $count = $this->counter[0]++;
$pk = new UnknownPacket;
$pk->PROTOCOL = $this->PROTOCOL;
$pk->packetID = $pk->pid();
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED;
@ -607,6 +610,7 @@ class Player{
$cnts[] = $count = $this->counter[0]++;
$pk = new UnknownPacket;
$pk->PROTOCOL = $this->PROTOCOL;
$pk->packetID = $pk->pid();
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED;
@ -645,6 +649,7 @@ class Player{
$cnts[] = $count = $this->counter[0]++;
$pk = new UnknownPacket;
$pk->PROTOCOL = $this->PROTOCOL;
$pk->packetID = $pk->pid();
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED;
@ -685,6 +690,7 @@ class Player{
$cnts[] = $count = $this->counter[0]++;
$pk = new UnknownPacket;
$pk->PROTOCOL = $this->PROTOCOL;
$pk->packetID = $pk->pid();
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE;
$pk->hasSplit = true;
@ -722,6 +728,7 @@ class Player{
$cnts[] = $count = $this->counter[0]++;
$pk = new UnknownPacket;
$pk->PROTOCOL = $this->PROTOCOL;
$pk->packetID = $packet->pid();
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE;
$pk->hasSplit = true;
@ -743,6 +750,8 @@ class Player{
public function send(RakNetPacket $packet){
if($this->connected === true){
$packet->PROTOCOL = $this->PROTOCOL;
$packet->packetID = $packet->pid();
$packet->ip = $this->ip;
$packet->port = $this->port;
$len = $this->server->send($packet);
@ -1831,6 +1840,7 @@ class Player{
if($this->connected === false) return false;
if(EventHandler::callEvent(new DataPacketSendEvent($this, $pk)) === BaseEvent::DENY) return;
if(!$this->convertToLocalEIDPacket($pk)) return false;
$pk->PROTOCOL = $this->PROTOCOL;
$pk->encode();
$len = 1 + strlen($pk->buffer);
@ -2144,178 +2154,200 @@ class Player{
}
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->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 === "" || isset(Player::$blacklistedUsernames[$this->iusername]) || 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($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");
}
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){
$this->close("this player already in game");
return;
}
$this->server->api->player->add($this->CID);
if ($this->server->api->handle("player.join", $this) === false) {
$this->close("join cancelled", false);
return;
}
$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;
}
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->auth = true;
$this->armor = [];
foreach ($this->data->get("armor") as $slot => $item) {
$this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], $item[0] === 0 ? 0 : 1);
}
$inv = [];
if(!$this->data->exists("inventory") || ($this->gamemode & 0x01) === 0x01){
if(($this->gamemode & 0x01) === 0x01){
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];
}
}
}
}else{
$inv = [];
foreach($this->data->get("inventory") as $slot => $item){
$inv[$slot] = [$item[0], $item[1], $item[2]];
}
}
$this->data->set("lastIP", $this->ip);
$this->data->set("lastID", $this->clientID);
$this->achievements = $this->data->get("achievements");
$this->data->set("caseusername", $this->username);
$this->inventory = [];
foreach($inv 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->server->api->player->saveOffline($this->data);
$this->armor = [];
if(($this->gamemode & 0x01) == 0){
foreach($this->data->get("armor") as $slot => $item){
$this->armor[$slot] = BlockAPI::getItem($item[0], $item[1], $item[0] === 0 ? 0 : 1);
}
}
$pk = new LoginStatusPacket;
$pk->status = 0;
$this->dataPacket($pk);
$this->data->set("lastIP", $this->ip);
$this->data->set("lastID", $this->clientID);
$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);
$this->server->api->player->saveOffline($this->data);
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 LoginStatusPacket;
$pk->status = 0;
$this->dataPacket($pk);
$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);
if($this->data->exists("hotbar")){
$this->hotbar = $this->data->get("hotbar");
}else{
if(($this->gamemode & 0x01) === 0x01) $this->hotbar = BlockAPI::$creativeHotbarSlots;
else $this->hotbar = [0, 1, 2, 3, 4, 5, 6, 7, 8];
}
$pk = new SetTimePacket;
$pk->time = $this->level->getTime();
$pk->started = !$this->level->isTimeStopped();
$this->dataPacket($pk);
$this->slot = $this->hotbar[0];
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;
for($i = 0; $i < count($this->hotbar); ++$i){
if($this->hotbar[$i] > (($this->gamemode & 1) == 0 ? 36 : count(BlockAPI::$creative))) $this->hotbar[$i] = -1;
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);
}
if($this->data->exists("bed-position")){
$this->bedPosition = $this->data->get("bed-position");
}else{
$this->setBedPosition(null);
}
$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->addEntity($this->entity);
$pk = new StartGamePacket;
$pk->seed = $this->level->getSeed();
$pk->x = $this->data->get("position")["x"];
$pk->y = ceil($this->data->get("position")["y"])+1;
$pk->z = $this->data->get("position")["z"];
$pk->generator = 0;
$pk->gamemode = $this->gamemode & 0x01;
$pk->eid = $this->entity->eid;
$this->entity->x = $pk->x;
$this->entity->y = $pk->y-0.9;
$this->entity->z = $pk->z;
$this->dataPacket($pk);
//should cache it for client(unless the queue was full and startgamepacket was sent without settime
//and client receives time before startgame - TODO maybe make it ordered?)
$pk = new SetTimePacket;
$pk->time = $this->level->getTime();
$pk->started = !$this->level->isTimeStopped();
$this->dataPacket($pk);
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->evid[] = $this->server->event("player.invisible", [$this, "invisibilityHandler"]);
$this->lastMeasure = microtime(true);
$this->server->schedule(50, [$this, "measureLag"], [], true);
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) . ") MTU: {$this->MTU}");
return;
}
$internalPid = $packet->getInternalPid();

View file

@ -78,6 +78,7 @@ class PocketMinecraftServer{
$this->spawn = false;
$this->saveEnabled = true;
$this->tickMeasure = array_fill(0, 40, 0);
PacketPool::init();
$this->setType("normal");
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, $this->serverip);
$this->stop = false;

View file

@ -41,7 +41,7 @@ class MinecraftInterface{
$pid = ord($buffer[0]);
if(RakNetInfo::isValid($pid)){
$packet = RakNetParser::parse($buffer);
$packet = RakNetParser::parse($buffer, $source, $port);
if($packet !== false){
$packet->ip = $source;
$packet->port = $port;

View file

@ -1,11 +1,13 @@
<?php
class RakNetParser{
public static function parse(&$buffer){
public static function parse(&$buffer, $source, $port){
$offset = 0;
++$offset;
$packet = new RakNetPacket(ord(substr($buffer, $offset - 1, 1)));
$packet->source = &$source;
$packet->buffer = &$buffer;
$packet->port = &$port;
$packet->length = strlen($buffer);
switch($packet->pid()){
case RakNetInfo::UNCONNECTED_PING:
@ -50,8 +52,11 @@ class RakNetParser{
$offset += 3;
$packet->seqNumber = Utils::readTriad(strrev(substr($buffer, $offset - 3, 3)));
$packet->data = [];
$packet->ip = $packet->source;
$packet->port = $packet->port;
$PROTOCOL = PlayerAPI::decodeProtocol($packet->ip, $packet->port);
while(isset($buffer[$offset]) and ($pk = static::parseDataPacket($offset, $buffer)) instanceof RakNetDataPacket){
while(isset($buffer[$offset]) and ($pk = static::parseDataPacket($offset, $buffer, $PROTOCOL)) instanceof RakNetDataPacket){
$packet->data[] = $pk;
}
break;
@ -110,7 +115,7 @@ class RakNetParser{
return Utils::readTriad(strrev($this->get(3)));
}
private static function parseDataPacket(&$offset, &$buffer){
private static function parseDataPacket(&$offset, &$buffer, $protocol = ProtocolInfo::CURRENT_PROTOCOL){
++$offset;
$packetFlags = ord(substr($buffer, $offset - 1, 1));
$reliability = ($packetFlags & 0b11100000) >> 5;
@ -166,66 +171,7 @@ class RakNetParser{
if(strlen($buf) < ($length - 1)){
return false;
}
$data = match($pid){
ProtocolInfo::PING_PACKET => new PingPacket(),
ProtocolInfo::PONG_PACKET => new PongPacket(),
ProtocolInfo::CLIENT_CONNECT_PACKET => new ClientConnectPacket(),
ProtocolInfo::SERVER_HANDSHAKE_PACKET => new ServerHandshakePacket(),
ProtocolInfo::DISCONNECT_PACKET => new DisconnectPacket(),
ProtocolInfo::LOGIN_PACKET => new LoginPacket(),
ProtocolInfo::LOGIN_STATUS_PACKET => new LoginStatusPacket(),
ProtocolInfo::READY_PACKET => new ReadyPacket(),
ProtocolInfo::MESSAGE_PACKET => new MessagePacket(),
ProtocolInfo::SET_TIME_PACKET => new SetTimePacket(),
ProtocolInfo::START_GAME_PACKET => new StartGamePacket(),
ProtocolInfo::ADD_MOB_PACKET => new AddMobPacket(),
ProtocolInfo::ADD_PLAYER_PACKET => new AddPlayerPacket(),
ProtocolInfo::REMOVE_PLAYER_PACKET => new RemovePlayerPacket(),
ProtocolInfo::ADD_ENTITY_PACKET => new AddEntityPacket(),
ProtocolInfo::REMOVE_ENTITY_PACKET => new RemoveEntityPacket(),
ProtocolInfo::ADD_ITEM_ENTITY_PACKET => new AddItemEntityPacket(),
ProtocolInfo::TAKE_ITEM_ENTITY_PACKET => new TakeItemEntityPacket(),
ProtocolInfo::MOVE_ENTITY_PACKET => new MoveEntityPacket(),
ProtocolInfo::MOVE_ENTITY_PACKET_POSROT => new MoveEntityPacket_PosRot(),
ProtocolInfo::ROTATE_HEAD_PACKET => new RotateHeadPacket(),
ProtocolInfo::MOVE_PLAYER_PACKET => new MovePlayerPacket(),
ProtocolInfo::REMOVE_BLOCK_PACKET => new RemoveBlockPacket(),
ProtocolInfo::UPDATE_BLOCK_PACKET => new UpdateBlockPacket(),
ProtocolInfo::ADD_PAINTING_PACKET => new AddPaintingPacket(),
ProtocolInfo::EXPLODE_PACKET => new ExplodePacket(),
ProtocolInfo::LEVEL_EVENT_PACKET => new LevelEventPacket(),
ProtocolInfo::TILE_EVENT_PACKET => new TileEventPacket(),
ProtocolInfo::ENTITY_EVENT_PACKET => new EntityEventPacket(),
ProtocolInfo::REQUEST_CHUNK_PACKET => new RequestChunkPacket(),
ProtocolInfo::CHUNK_DATA_PACKET => new ChunkDataPacket(),
ProtocolInfo::PLAYER_EQUIPMENT_PACKET => new PlayerEquipmentPacket(),
ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET => new PlayerArmorEquipmentPacket(),
ProtocolInfo::INTERACT_PACKET => new InteractPacket(),
ProtocolInfo::USE_ITEM_PACKET => new UseItemPacket(),
ProtocolInfo::PLAYER_ACTION_PACKET => new PlayerActionPacket(),
ProtocolInfo::HURT_ARMOR_PACKET => new HurtArmorPacket(),
ProtocolInfo::SET_ENTITY_DATA_PACKET => new SetEntityDataPacket(),
ProtocolInfo::SET_ENTITY_MOTION_PACKET => new SetEntityMotionPacket(),
ProtocolInfo::SET_HEALTH_PACKET => new SetHealthPacket(),
ProtocolInfo::SET_SPAWN_POSITION_PACKET => new SetSpawnPositionPacket(),
ProtocolInfo::ANIMATE_PACKET => new AnimatePacket(),
ProtocolInfo::RESPAWN_PACKET => new RespawnPacket(),
ProtocolInfo::SEND_INVENTORY_PACKET => new SendInventoryPacket(),
ProtocolInfo::DROP_ITEM_PACKET => new DropItemPacket(),
ProtocolInfo::CONTAINER_OPEN_PACKET => new ContainerOpenPacket(),
ProtocolInfo::CONTAINER_CLOSE_PACKET => new ContainerClosePacket(),
ProtocolInfo::CONTAINER_SET_SLOT_PACKET => new ContainerSetSlotPacket(),
ProtocolInfo::CONTAINER_SET_DATA_PACKET => new ContainerSetDataPacket(),
ProtocolInfo::CONTAINER_SET_CONTENT_PACKET => new ContainerSetContentPacket(),
ProtocolInfo::CHAT_PACKET => new ChatPacket(),
ProtocolInfo::ADVENTURE_SETTINGS_PACKET => new AdventureSettingsPacket(),
ProtocolInfo::ENTITY_DATA_PACKET => new EntityDataPacket(),
ProtocolInfo::SET_ENTITY_LINK_PACKET => new SetEntityLinkPacket(),
ProtocolInfo::PLAYER_INPUT_PACKET => new PlayerInputPacket(),
default => new UnknownPacket($pid)
};
$data = PacketPool::getPacket($pid, $protocol);
$data->reliability = $reliability;
$data->hasSplit = $hasSplit;
$data->messageIndex = $messageIndex;