mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
commit
980e5f9ca7
2 changed files with 21 additions and 3 deletions
|
|
@ -84,6 +84,8 @@ class Player{
|
|||
* @var boolean $isSneaking
|
||||
*/
|
||||
public $isJumping, $isSneaking;
|
||||
|
||||
private $lastPing = -1;
|
||||
|
||||
/**
|
||||
* @param integer $clientID
|
||||
|
|
@ -1503,6 +1505,17 @@ class Player{
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
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 handleDataPacket(RakNetDataPacket $packet){
|
||||
if($this->connected === false){
|
||||
return;
|
||||
|
|
@ -1511,18 +1524,20 @@ class Player{
|
|||
if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch($packet->pid()){
|
||||
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 = abs(microtime(true) * 1000);
|
||||
$pk->time = intdiv(hrtime(true), 1_000_000);
|
||||
$this->directDataPacket($pk);
|
||||
break;
|
||||
case ProtocolInfo::DISCONNECT_PACKET:
|
||||
|
|
|
|||
|
|
@ -618,6 +618,9 @@ class PocketMinecraftServer{
|
|||
|
||||
foreach($this->clients as $client){
|
||||
$client->handlePacketQueues();
|
||||
if($this->ticks % 40 == 0){ //2s
|
||||
$client->sendPing();
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->api->level->levels as $l){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue