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

@ -62,6 +62,8 @@ class NetworkSession{
/** @var bool */
private $connected = true;
/** @var int */
private $connectTime;
/** @var NetworkCipher */
private $cipher;
@ -72,6 +74,9 @@ class NetworkSession{
$this->ip = $ip;
$this->port = $port;
$this->connectTime = time();
$this->server->getNetwork()->scheduleSessionTick($this);
//TODO: this should happen later in the login sequence
$this->createPlayer();
@ -328,4 +333,18 @@ class NetworkSession{
public function onRespawn() : void{
$this->setHandler(new SimpleSessionHandler($this->player));
}
public function tick() : bool{
if($this->handler instanceof LoginSessionHandler){
if(time() >= $this->connectTime + 10){
$this->disconnect("Login timeout");
return false;
}
return true; //keep ticking until timeout
}
//TODO: more stuff on tick
return false;
}
}