public function accept(Socket $socket) { if (count($this->connections) >= $this->maxConnections) { $socket->write(['alias' => 'capacity_reached']); $socket->close(); throw new \RuntimeException('Server capacity reached'); } $player = $this->playerFactory->newSocketPlayer(sprintf('PlayerBot%d', ++$this->connectionIndex), null, 5000, $socket); $connection = $player->getConnection(); $this->connections->pushBack($connection); $this->handleSocketEvents($connection); $this->handlePlayerNameChange($connection); $this->handlePlayerConnection($connection); }