NetworkSession: do not send packets to disconnected sessions

this is mostly harmless, since the packets land in a buffer that gets discarded, but we also need to avoid calling DataPacketSendEvent.
This commit is contained in:
Dylan K. Taylor 2022-12-24 20:12:50 +00:00
parent f7d0d16eb3
commit 80832ff763
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -424,6 +424,9 @@ class NetworkSession{
}
public function sendDataPacket(ClientboundPacket $packet, bool $immediate = false) : bool{
if(!$this->connected){
return false;
}
//Basic safety restriction. TODO: improve this
if(!$this->loggedIn && !$packet->canBeSentBeforeLogin()){
throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getDisplayName() . " too early");