diff --git a/src/Player.php b/src/Player.php index 829b6782d..237c081de 100644 --- a/src/Player.php +++ b/src/Player.php @@ -604,13 +604,13 @@ class Player{ break; } switch($data["id"]){ - - case MC_KEEP_ALIVE: - - break; case 0x01: - case 0x03: - + break; + case MC_PING: + $this->dataPacket(MC_PONG, array( + "ptime" => $data["time"], + "time" => (int) (microtime(true) * 1000), + )); break; case MC_DISCONNECT: $this->close("client disconnect"); diff --git a/src/constants/ProtocolInfo.php b/src/constants/ProtocolInfo.php index 2bd67cafd..8c24f2b7d 100644 --- a/src/constants/ProtocolInfo.php +++ b/src/constants/ProtocolInfo.php @@ -27,7 +27,9 @@ the Free Software Foundation, either version 3 of the License, or define("RAKNET_MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"); -define("MC_KEEP_ALIVE", 0x00); +define("MC_PING", 0x00); + +define("MC_PONG", 0x03); define("MC_CLIENT_CONNECT", 0x09); define("MC_SERVER_HANDSHAKE", 0x10); diff --git a/src/network/CustomPacketHandler.php b/src/network/CustomPacketHandler.php index 13698e4a5..35b929617 100644 --- a/src/network/CustomPacketHandler.php +++ b/src/network/CustomPacketHandler.php @@ -53,20 +53,20 @@ class CustomPacketHandler{ $this->offset = 0; $this->c = (bool) $create; switch($pid){ - case MC_KEEP_ALIVE: + case MC_PING: if($this->c === false){ - $this->data["payload"] = Utils::readLong($this->get(8)); + $this->data["time"] = Utils::readLong($this->get(8)); }else{ - $this->raw .= Utils::writeLong($this->data["payload"]); + $this->raw .= Utils::writeLong($this->data["time"]); } break; - case 0x03: + case MC_PONG: if($this->c === false){ - $this->data["unknown1"] = Utils::readLong($this->get(8)); - $this->data["unknown2"] = Utils::readLong($this->get(8)); + $this->data["ptime"] = Utils::readLong($this->get(8)); + $this->data["time"] = Utils::readLong($this->get(8)); }else{ - $this->raw .= Utils::writeLong($this->data["unknown1"]); - $this->raw .= Utils::writeLong($this->data["unknown2"]); + $this->raw .= Utils::writeLong($this->data["ptime"]); + $this->raw .= Utils::writeLong($this->data["time"]); } break; case MC_CLIENT_CONNECT: