function start()
 {
     $configFile = $this->request->getPostStrict('configFile');
     $spectate = $this->request->getPostStrict('spectate');
     list($options, $account, $system, $authLevel, $isLan) = $this->fetchAndAssertConfig(_('starting it'));
     $spectate = \DedicatedManager\Services\Spectate::fromArray($spectate);
     switch ($spectate->method) {
         case 'managed':
             try {
                 list($rpcHost, $rpcPort, $rpcPass) = explode(':', $spectate->managed, 3);
                 $connection = \Maniaplanet\DedicatedServer\Connection::factory($rpcHost, $rpcPort, 5, 'SuperAdmin', $rpcPass);
                 $info = $connection->getSystemInfo();
                 $gameServer = $info->publishedIp . ':' . $info->port;
                 $password = $connection->getServerPasswordForSpectator();
             } catch (\Exception $e) {
                 $errors[] = _('Cannot retrieve server connection');
             }
             break;
         case 'ip':
             $gameServer = $spectate->ip . ':' . $spectate->port;
             $password = $spectate->password;
             break;
         case 'login':
             $gameServer = $spectate->login;
             $password = $spectate->password;
             break;
     }
     $this->session->set('configFile', $configFile);
     $this->session->set('spectate', $spectate);
     $errors = array();
     if (strpbrk($configFile, '\\/:*?"<>|')) {
         $errors[] = _('The server config filename must not contain any of the following characters: \\ / : * ? " < > |');
     }
     if (!$errors) {
         try {
             $error = _('An error appeared while writing the server configuration file');
             $service = new \DedicatedManager\Services\ConfigFileService();
             $service->save($configFile, $options, $account, $system, $authLevel);
             $error = _('An error appeared while starting the server');
             $service = new \DedicatedManager\Services\ServerService();
             $server = new \DedicatedManager\Services\Server();
             $server->rpcHost = '127.0.0.1';
             $server->rpcPort = $service->startRelay($configFile, $gameServer, $password, $isLan);
             $server->rpcPassword = $authLevel->superAdmin;
             $service->register($server);
         } catch (\Exception $e) {
             \ManiaLib\Application\ErrorHandling::logException($e);
             $errors[] = $error;
         }
     }
     if ($errors) {
         $this->session->set('error', $errors);
         $this->request->redirectArgList('../spectate');
     }
     $this->session->set('success', _('Your relay server has been successfully started'));
     $this->goHome();
 }
 protected function doRegister(\DedicatedManager\Services\Server $server)
 {
     $service = new \DedicatedManager\Services\ServerService();
     try {
         $service->register($server);
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
Esempio n. 3
0
 /**
  * @redirect
  */
 function setConfig($options, $rpcPassword, $connectionRates)
 {
     $options = \DedicatedManager\Services\ServerOptions::fromArray($options);
     $options->callVoteRatio = $options->callVoteRatio < 0 ? $options->callVoteRatio : $options->callVoteRatio / 100;
     $options->nextCallVoteTimeOut = $options->nextCallVoteTimeOut * 1000;
     $service = new \DedicatedManager\Services\ConfigFileService();
     if ($errors = $service->validate($options)) {
         $this->session->set('error', $errors);
         $this->request->redirectArgList('../config', 'host', 'port');
     }
     $optionsCur = $this->server->connection->getServerOptions();
     $options->nextVehicleNetQuality = $optionsCur->nextVehicleNetQuality;
     $options->nextUseChangingValidationSeed = $optionsCur->nextUseChangingValidationSeed;
     try {
         $options->ensureCast();
         $this->server->connection->setServerOptions($options->toArray());
         $this->server->connection->disableHorns($options->disableHorns);
         $this->server->connection->setConnectionRates((int) $connectionRates['download'], (int) $connectionRates['upload']);
         if ($rpcPassword != $this->server->rpcPassword) {
             $this->server->connection->changeAuthPassword('SuperAdmin', $rpcPassword);
             $this->server->closeConnection();
             $this->server->rpcPassword = $rpcPassword;
             $service = new \DedicatedManager\Services\ServerService();
             $service->register($this->server);
         }
         $this->session->set('success', _('Configuration successfully changed'));
     } catch (\Exception $e) {
         \ManiaLib\Application\ErrorHandling::logException($e);
         $this->session->set('error', _('An error occured while changing server configuration'));
     }
     $this->request->redirectArgList('../config', 'host', 'port');
 }
 function doQuickStart()
 {
     $configFile = $this->request->getPostStrict('configFile');
     $matchFile = $this->request->getPostStrict('matchFile');
     $serverName = $this->request->getPost('serverName', '');
     $login = $this->request->getPost('login', '');
     $password = $this->request->getPost('password', '');
     $title = $this->request->getPost('title', null);
     $isLan = $this->request->getPost('isLan', false);
     $startManialive = $this->request->getPost('startManialive', false);
     $manialiveConfig = $this->request->getPost('manialiveConfig', '');
     $options = array();
     if ($serverName) {
         $options['servername'] = $serverName;
     }
     if ($login) {
         $options['login'] = $login;
     }
     if ($password) {
         $options['password'] = $password;
     }
     if ($title) {
         $options['title'] = $title;
     }
     $errors = array();
     try {
         $configService = new \DedicatedManager\Services\ConfigFileService();
         list(, , , $authLevel) = $configService->get($configFile);
         $error = _('An error appeared while starting the server.');
         $service = new \DedicatedManager\Services\ServerService();
         $server = new \DedicatedManager\Services\Server();
         $server->rpcHost = '127.0.0.1';
         $server->rpcPort = $service->start($configFile, $matchFile, (bool) $isLan, $options);
         $server->rpcPassword = $authLevel->superAdmin;
         $service->register($server);
         if ($startManialive && $manialiveConfig) {
             usleep(200);
             $service = new \DedicatedManager\Services\ManialiveService();
             $service->start($manialiveConfig, array('address' => $server->rpcHost, 'rpcport' => $server->rpcPort, 'password' => $server->rpcPassword));
         }
     } catch (\Exception $e) {
         \ManiaLib\Application\ErrorHandling::logException($e);
         $errors[] = $error;
     }
     if ($errors) {
         $this->session->set('error', $errors);
         $this->request->redirectArgList('../quickStart');
     }
     $this->session->set('success', _('Your server has been successfully started'));
     $this->goHome();
 }