Network: add ability to tick sessions

moved responsibility for login timeout checks to NetworkSession instead of Server
This commit is contained in:
Dylan K. Taylor
2018-08-02 17:39:09 +01:00
parent e43496e7e4
commit 10ba3d6359
3 changed files with 42 additions and 9 deletions

View File

@ -29,6 +29,7 @@ namespace pocketmine\network;
use pocketmine\event\server\NetworkInterfaceCrashEvent;
use pocketmine\event\server\NetworkInterfaceRegisterEvent;
use pocketmine\event\server\NetworkInterfaceUnregisterEvent;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\Server;
@ -48,6 +49,9 @@ class Network{
/** @var string */
private $name;
/** @var NetworkSession[] */
private $updateSessions = [];
public function __construct(Server $server){
PacketPool::init();
@ -80,7 +84,7 @@ class Network{
return $this->interfaces;
}
public function tickInterfaces() : void{
public function tick() : void{
foreach($this->interfaces as $interface){
try{
$interface->tick();
@ -97,6 +101,12 @@ class Network{
$logger->critical($this->server->getLanguage()->translateString("pocketmine.server.networkError", [get_class($interface), $e->getMessage()]));
}
}
foreach($this->updateSessions as $k => $session){
if(!$session->isConnected() or !$session->tick()){
unset($this->updateSessions[$k]);
}
}
}
/**
@ -183,4 +193,8 @@ class Network{
$interface->unblockAddress($address);
}
}
public function scheduleSessionTick(NetworkSession $session) : void{
$this->updateSessions[spl_object_hash($session)] = $session;
}
}