Skip to content

Commit ed27bfd

Browse files
committed
Session: Prevent bogus pongs from reaching the event listener
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.
1 parent e49157d commit ed27bfd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/server/Session.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,13 @@ private function handleEncapsulatedPacketRoute(EncapsulatedPacket $packet) : voi
263263
* @param int $sendPongTime TODO: clock differential stuff
264264
*/
265265
private function handlePong(int $sendPingTime, int $sendPongTime) : void{
266-
$this->lastPingMeasure = $this->server->getRakNetTimeMS() - $sendPingTime;
267-
$this->server->getEventListener()->onPingMeasure($this->internalId, $this->lastPingMeasure);
266+
$currentTime = $this->server->getRakNetTimeMS();
267+
if($currentTime < $sendPingTime){
268+
$this->logger->debug("Received invalid pong: timestamp is in the future by " . ($sendPingTime - $currentTime) . " ms");
269+
}else{
270+
$this->lastPingMeasure = $currentTime - $sendPingTime;
271+
$this->server->getEventListener()->onPingMeasure($this->internalId, $this->lastPingMeasure);
272+
}
268273
}
269274

270275
public function handlePacket(Packet $packet) : void{

0 commit comments

Comments
 (0)