Break circular dependency in Player->disconnect() usages

none of these usages require onPlayerDestroyed() to be fired since they are all being called during disconnects anyway.
This commit is contained in:
Dylan K. Taylor
2020-11-16 23:05:56 +00:00
parent 09b22c1e79
commit 62b9d97060
2 changed files with 25 additions and 9 deletions

View File

@@ -258,7 +258,7 @@ class NetworkSession{
}
public function isConnected() : bool{
return $this->connected;
return $this->connected && !$this->disconnectGuard;
}
public function getIp() : string{
@@ -503,7 +503,7 @@ class NetworkSession{
public function disconnect(string $reason, bool $notify = true) : void{
$this->tryDisconnect(function() use ($reason, $notify) : void{
if($this->player !== null){
$this->player->disconnect($reason, null, $notify);
$this->player->onPostDisconnect($reason, null);
}
$this->doServerDisconnect($reason, $notify);
}, $reason);
@@ -518,7 +518,7 @@ class NetworkSession{
$this->tryDisconnect(function() use ($ip, $port, $reason) : void{
$this->sendDataPacket(TransferPacket::create($ip, $port), true);
if($this->player !== null){
$this->player->disconnect($reason, null, false);
$this->player->onPostDisconnect($reason, null);
}
$this->doServerDisconnect($reason, false);
}, $reason);
@@ -527,9 +527,9 @@ class NetworkSession{
/**
* Called by the Player when it is closed (for example due to getting kicked).
*/
public function onPlayerDestroyed(string $reason, bool $notify = true) : void{
$this->tryDisconnect(function() use ($reason, $notify) : void{
$this->doServerDisconnect($reason, $notify);
public function onPlayerDestroyed(string $reason) : void{
$this->tryDisconnect(function() use ($reason) : void{
$this->doServerDisconnect($reason, true);
}, $reason);
}
@@ -551,7 +551,7 @@ class NetworkSession{
public function onClientDisconnect(string $reason) : void{
$this->tryDisconnect(function() use ($reason) : void{
if($this->player !== null){
$this->player->disconnect($reason, null, false);
$this->player->onPostDisconnect($reason, null);
}
}, $reason);
}