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();
 }
 function start($configFile)
 {
     $config = $this->fetchAndAssertConfig(_('starting it'));
     $server = $this->session->get('server');
     $this->session->set('configFile', $configFile);
     $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\ManialiveFileService();
             $service->save($configFile, $config);
             $error = _('An error appeared while starting ManiaLive');
             $service = new \DedicatedManager\Services\ManialiveService();
             $service->start($configFile, 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('../preview');
     }
     $this->session->set('success', _('ManiaLive has been successfully started'));
     $this->backToServer();
 }
 /**
  * @redirect
  */
 function sendMessage($message, $receiver = null)
 {
     try {
         $this->server->connection->chatSendServerMessage($message, $receiver ?: null);
         $this->session->set('success', _('Your message has been sent'));
     } catch (\Exception $e) {
         \ManiaLib\Application\ErrorHandling::logException($e);
         $this->session->set('error', _('Fail to send your message'));
     }
     $this->request->redirectArgList('../chat', 'host', 'port');
 }
Beispiel #4
0
 function doUpload($file)
 {
     if (!preg_match('/(\\.map\\.gbx)$/ixu', $file)) {
         throw new \ManiaLib\Application\UserException('Please upload only maps');
     }
     try {
         $path = '$uploaded/' . $this->session->login . '/';
         $connection = $this->getServerConnection();
         $mapsPath = $connection->getMapsDirectory();
         $mapService = new \ManiaHost\Services\MapService($mapsPath);
         $maxSize = 20 * pow(2, 20) - $mapService->getSize($path, array(), null, null, null, null, true);
         $maxSize = $maxSize > pow(2, 20) ? pow(2, 20) : $maxSize;
         $data = file_get_contents('php://input', null, null, null, $maxSize);
         $connection->writeFileFromString($path . $file, $data);
         $datas = $mapService->getData($mapsPath . $path . $file);
         $map = new \ManiaHost\Services\Map();
         $map->filename = $file;
         $map->path = $path;
         foreach ($datas as $key => $value) {
             $map->{$key} = $value;
         }
         $mapService->register($map);
     } catch (\Exception $e) {
         \ManiaLib\Application\ErrorHandling::logException($e);
         $this->request->set('message', 'An error append during upload');
         $this->request->redirectArgList('../upload/', 'message');
     }
     $this->request->set('message', 'file successfully uploaded');
     $this->request->redirectArgList('../upload/', 'message');
 }
 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();
 }