Skip to content

Commit

Permalink
Session: Prevent bogus pongs from reaching the event listener
Browse files Browse the repository at this point in the history
this should never normally happen, but if the pong has a timestamp in the future, we'll end up reporting a negative ping to the event listener.
  • Loading branch information
dktapps committed Sep 20, 2021
1 parent e49157d commit ed27bfd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/server/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ private function handleEncapsulatedPacketRoute(EncapsulatedPacket $packet) : voi
* @param int $sendPongTime TODO: clock differential stuff
*/
private function handlePong(int $sendPingTime, int $sendPongTime) : void{
$this->lastPingMeasure = $this->server->getRakNetTimeMS() - $sendPingTime;
$this->server->getEventListener()->onPingMeasure($this->internalId, $this->lastPingMeasure);
$currentTime = $this->server->getRakNetTimeMS();
if($currentTime < $sendPingTime){
$this->logger->debug("Received invalid pong: timestamp is in the future by " . ($sendPingTime - $currentTime) . " ms");
}else{
$this->lastPingMeasure = $currentTime - $sendPingTime;
$this->server->getEventListener()->onPingMeasure($this->internalId, $this->lastPingMeasure);
}
}

public function handlePacket(Packet $packet) : void{
Expand Down

0 comments on commit ed27bfd

Please sign in to comment.