diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 57eb1f699..88b888fdd 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -544,6 +544,8 @@ class NetworkSession{ $this->disconnectGuard = true; $func(); $this->disconnectGuard = false; + $this->flushSendBuffer(true); + $this->sender->close(""); foreach($this->disposeHooks as $callback){ $callback(); } @@ -567,10 +569,12 @@ class NetworkSession{ */ public function disconnect(string $reason, bool $notify = true) : void{ $this->tryDisconnect(function() use ($reason, $notify) : void{ + if($notify){ + $this->sendDataPacket(DisconnectPacket::create($reason)); + } if($this->player !== null){ $this->player->onPostDisconnect($reason, null); } - $this->doServerDisconnect($reason, $notify); }, $reason); } @@ -583,7 +587,6 @@ class NetworkSession{ if($this->player !== null){ $this->player->onPostDisconnect($reason, null); } - $this->doServerDisconnect($reason, false); }, $reason); } @@ -592,21 +595,10 @@ class NetworkSession{ */ public function onPlayerDestroyed(string $reason) : void{ $this->tryDisconnect(function() use ($reason) : void{ - $this->doServerDisconnect($reason, true); + $this->sendDataPacket(DisconnectPacket::create($reason)); }, $reason); } - /** - * Internal helper function used to handle server disconnections. - */ - private function doServerDisconnect(string $reason, bool $notify = true) : void{ - if($notify){ - $this->sendDataPacket(DisconnectPacket::create($reason !== "" ? $reason : null), true); - } - - $this->sender->close($notify ? $reason : ""); - } - /** * Called by the network interface to close the session when the client disconnects without server input, for * example in a timeout condition or voluntary client disconnect.