Example #1
0
 function onInit()
 {
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
     $this->serverStatus = $this->connection->getStatus();
     $players = $this->connection->getPlayerList(-1, 0);
     foreach ($players as $player) {
         try {
             $details = $this->connection->getDetailedPlayerInfo($player->login);
             foreach ($details as $key => $value) {
                 if ($value) {
                     $player->{$key} = $value;
                 }
             }
             if ($player->spectatorStatus % 10 == 0) {
                 $this->players[$player->login] = $player;
             } else {
                 $this->spectators[$player->login] = $player;
             }
         } catch (\Exception $e) {
         }
     }
     try {
         $this->maps = $this->connection->getMapList(-1, 0);
         $this->currentMap = $this->connection->getCurrentMapInfo();
         if (isset($this->maps[$this->connection->getNextMapIndex()])) {
             $this->nextMap = $this->maps[$this->connection->getNextMapIndex()];
         } else {
             $this->nextMap = null;
         }
     } catch (\Exception $e) {
         $this->maps = array();
         $this->nextMap = null;
         $this->currentMap = null;
     }
     $this->server = $this->connection->getServerOptions();
     $this->gameInfos = $this->connection->getCurrentGameInfo();
     try {
         $this->serverLogin = $this->connection->getSystemInfo()->serverLogin;
     } catch (\Exception $e) {
         $this->serverLogin = null;
     }
 }