sessions[$idx] = $session; $this->pendingLoginSessions[$idx] = $session; } /** * Marks the session as having sent a login request. After this point, they are counted towards the total player * count. */ public function markLoginReceived(NetworkSession $session) : void{ $idx = spl_object_id($session); unset($this->pendingLoginSessions[$idx]); } /** * Removes the given network session, due to disconnect. This should only be called by a network session on * disconnection. */ public function remove(NetworkSession $session) : void{ $idx = spl_object_id($session); unset($this->sessions[$idx]); unset($this->pendingLoginSessions[$idx]); } /** * Returns the number of known connected sessions, including sessions which have not yet sent a login request. */ public function getSessionCount() : int{ return count($this->sessions); } /** * Returns the number of connected sessions which have either sent a login request, or have already completed the * login sequence. */ public function getValidSessionCount() : int{ return count($this->sessions) - count($this->pendingLoginSessions); } /** @return NetworkSession[] */ public function getSessions() : array{ return $this->sessions; } /** * Updates all sessions which need it. */ public function tick() : void{ foreach($this->sessions as $k => $session){ $session->tick(); if(!$session->isConnected()){ unset($this->sessions[$k]); } } } /** * Terminates all connected sessions with the given reason. */ public function close(string $reason = "") : void{ foreach($this->sessions as $session){ $session->disconnect($reason); } $this->sessions = []; } }