From a9be309de96f6d56da90c38b7794ff55cd72bebc Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 21 Feb 2023 07:51:21 +0300 Subject: [PATCH] changed some packets + tried to make client join the server --- src/Player.php | 18 ++++++++++------ src/network/protocol/ProtocolInfo.php | 4 ++-- .../protocol/packet/FullChunkDataPacket.php | 21 +++++++++++++++++++ .../protocol/packet/StartGamePacket.php | 11 +++++----- 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/network/protocol/packet/FullChunkDataPacket.php diff --git a/src/Player.php b/src/Player.php index 95e32a43..53c0d934 100755 --- a/src/Player.php +++ b/src/Player.php @@ -236,10 +236,10 @@ class Player{ $this->entity->resetSpeed(); $this->entity->updateLast(); $this->entity->calculateVelocity(); - if($terrain === true){ + /*if($terrain === true){ $this->orderChunks(); $this->getNextChunk($this->level); - } + }*/ $this->entity->check = true; if($force === true){ $this->forceMovement = $pos; @@ -458,7 +458,9 @@ class Player{ } } - $pk = new ChunkDataPacket; + $pk = new FullChunkDataPacket; + $pk->putInt($X); + $pk->putInt($Z); $pk->chunkX = $X; $pk->chunkZ = $Z; $pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex); @@ -1391,13 +1393,16 @@ class Player{ $pk = new LoginStatusPacket; $pk->status = 0; $this->dataPacket($pk); - + $spawnPos = $this->getSpawn(); $pk = new StartGamePacket; $pk->seed = $this->level->getSeed(); + $pk->spawnX = (int) $spawnPos->x; + $pk->spawnY = (int) $spawnPos->y; + $pk->spawnZ = (int) $spawnPos->z; $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->generator = 0; //1 - inf, 0 - old, 2 - flat $pk->gamemode = $this->gamemode & 0x01; $pk->eid = 0; $this->dataPacket($pk); @@ -1482,7 +1487,8 @@ class Player{ $this->sendInventory(); $this->sendSettings(); - //$this->server->schedule(50, [$this, "orderChunks"], []); + $this->orderChunks(); + $this->getNextChunk($this->level); $this->blocked = false; $this->server->handle("player.spawn", $this); diff --git a/src/network/protocol/ProtocolInfo.php b/src/network/protocol/ProtocolInfo.php index c2992bb5..c4269489 100644 --- a/src/network/protocol/ProtocolInfo.php +++ b/src/network/protocol/ProtocolInfo.php @@ -71,7 +71,7 @@ abstract class ProtocolInfo{ const ADVENTURE_SETTINGS_PACKET = 0xb7; const ENTITY_DATA_PACKET = 0xb8; const PLAYER_INPUT_PACKET = 0xb9; - //const FULL_CHUNK_DATA_PACKET = 0xba; + const FULL_CHUNK_DATA_PACKET = 0xba; //const UNLOAD_CHUNK_PACKET = 0xbb; } @@ -85,4 +85,4 @@ abstract class ProtocolInfo{ /***REM_START***/ require_once(FILE_PATH . "src/network/raknet/RakNetDataPacket.php"); -/***REM_END***/ \ No newline at end of file +/***REM_END***/ diff --git a/src/network/protocol/packet/FullChunkDataPacket.php b/src/network/protocol/packet/FullChunkDataPacket.php new file mode 100644 index 00000000..f79b5d68 --- /dev/null +++ b/src/network/protocol/packet/FullChunkDataPacket.php @@ -0,0 +1,21 @@ +reset(); + $this->put($this->data); + } + +} diff --git a/src/network/protocol/packet/StartGamePacket.php b/src/network/protocol/packet/StartGamePacket.php index a746ea3a..e617ad9a 100644 --- a/src/network/protocol/packet/StartGamePacket.php +++ b/src/network/protocol/packet/StartGamePacket.php @@ -5,10 +5,8 @@ class StartGamePacket extends RakNetDataPacket{ public $generator; public $gamemode; public $eid; - public $x; - public $y; - public $z; - + public $x, $y, $z; + public $spawnX, $spawnY, $spawnZ; public function pid(){ return ProtocolInfo::START_GAME_PACKET; } @@ -23,9 +21,12 @@ class StartGamePacket extends RakNetDataPacket{ $this->putInt($this->generator); $this->putInt($this->gamemode); $this->putInt($this->eid); + $this->putInt($this->spawnX); + $this->putInt($this->spawnY); + $this->putInt($this->spawnZ); $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); } -} \ No newline at end of file +}