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;
     }
 }
 function preFilter()
 {
     if (!$this->session->get('server')) {
         try {
             $service = new \DedicatedManager\Services\ServerService();
             $server = $service->get($this->request->get('host'), $this->request->get('port'));
             $server->fetchDetails();
             $this->session->set('server', $server);
         } catch (\Exception $e) {
             $this->session->set('error', _('You cannot start ManiaLive: unknown server'));
             $this->request->redirectArgList('/');
         }
     }
 }
Example #4
0
 function remove($host, $port)
 {
     $service = new \DedicatedManager\Services\ServerService();
     $service->delete($host, $port);
     $this->request->redirectArgList('/');
 }
Example #5
0
 /**
  * @redirect
  */
 function stop()
 {
     if (!$this->isAdmin) {
         $this->session->set('error', _('You need to be an admin to do this'));
         $this->request->redirectToReferer();
     }
     $this->server->connection->stopServer();
     $service = new \DedicatedManager\Services\ServerService();
     $service->delete($this->server->rpcHost, $this->server->rpcPort);
     $this->session->set('success', _('Server has been stopped'));
     $this->request->redirectArgList('/');
 }
 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();
 }