Fixed RakLib crashing when exceptions are thrown in packet handlers after the player was closed

This occurred if the player happened to be closed during the packet being handled, and then an uncaught exception bubbled up to the RakLibInterface. This resulted in a crash due to trying to get the address of a player who no longer had a network session, in order to block their IP address.
This commit is contained in:
Dylan K. Taylor 2017-09-01 20:22:02 +01:00
parent 14ea76ecd7
commit 2603f5cc63

View File

@ -133,6 +133,8 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
public function handleEncapsulated($identifier, EncapsulatedPacket $packet, $flags){
if(isset($this->players[$identifier])){
//get this now for blocking in case the player was closed before the exception was raised
$address = $this->players[$identifier]->getAddress();
try{
if($packet->buffer !== ""){
$pk = $this->getPacket($packet->buffer);
@ -143,7 +145,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
$logger->debug("Packet " . (isset($pk) ? get_class($pk) : "unknown") . " 0x" . bin2hex($packet->buffer));
$logger->logException($e);
$this->interface->blockAddress($this->players[$identifier]->getAddress(), 5);
$this->interface->blockAddress($address, 5);
}
}
}