mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Added Ping / Pong system
This commit is contained in:
parent
1cb30601b5
commit
1ef0a41944
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user