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 delete($configFiles = array(), $matchFiles = array(), $manialiveFiles = array()) { $errors = array(); $success = array(); if ($configFiles) { try { $service = new \DedicatedManager\Services\ConfigFileService(); $service->deleteList($configFiles); $success[] = _('Configuration files successfully deleted'); } catch (\Exception $e) { $errors[] = _('Error while deleting configuration files'); } } if ($matchFiles) { try { $service = new \DedicatedManager\Services\MatchSettingsFileService(); $service->deleteList($matchFiles); $success[] = _('Match settings files successfully deleted'); } catch (\Exception $e) { $errors[] = _('Error while deleting match settings files'); } } if ($manialiveFiles) { try { $service = new \DedicatedManager\Services\ManialiveFileService(); $service->deleteList($manialiveFiles); $success[] = _('ManiaLive configuration files successfully deleted'); } catch (\Exception $e) { $errors[] = _('Error while deleting ManiaLive configuration files'); } } if ($errors) { $this->session->set('error', $errors); } if ($success) { $this->session->set('success', $success); } $this->request->redirectArgList('..'); }
function setConfig() { $options = $this->request->getPostStrict('options'); $account = $this->request->getPostStrict('account'); $system = $this->request->getPostStrict('system'); $authLevel = $this->request->getPostStrict('authLevel'); $isOnline = $this->request->getPost('isOnline', 0); $options = \DedicatedManager\Services\ServerOptions::fromArray($options); $options->callVoteRatio = $options->callVoteRatio < 0 ? -1 : $options->callVoteRatio / 100; $options->nextCallVoteTimeOut = $options->nextCallVoteTimeOut * 1000; $account = \DedicatedManager\Services\Account::fromArray($account); $system = \DedicatedManager\Services\SystemConfig::fromArray($system); $authLevel = \DedicatedManager\Services\AuthorizationLevels::fromArray($authLevel); $this->session->set('options', $options); $this->session->set('account', $account); $this->session->set('system', $system); $this->session->set('authLevel', $authLevel); $this->session->set('isLan', !$isOnline); $service = new \DedicatedManager\Services\ConfigFileService(); if ($errors = $service->validate($options, $account, $system, $authLevel, !$isOnline)) { $this->session->set('error', $errors); $this->request->redirectArgList('../config'); } }
/** * @redirect */ function saveGuestlist($filename) { $service = new \DedicatedManager\Services\ConfigFileService(); $configList = $service->getList(); if (in_array($filename, $configList)) { $this->session->set('error', _('You cannot use this filename')); $this->request->redirectArgList('../guestlist', 'host', 'port'); } try { $this->server->connection->saveGuestList($filename . '.txt'); $this->session->set('success', _('Guestlist successfully saved')); } catch (\Exception $e) { \ManiaLib\Application\ErrorHandling::logException($e); $this->session->set('error', _('An error occurred while saving the guestlist')); } $this->request->redirectArgList('../guestlist/', '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(); }