public function tryConnect()
 {
     Console::out(Console::b_green . "Dedicated server connection setup:\n");
     Console::out(Console::white . "Please enter dedicated server ip (127.0.0.1): ");
     $this->ip = $this->getInput("127.0.0.1");
     Console::out(Console::white . "Please enter dedicated xml-rpc port (5000): ");
     $this->port = (int) $this->getInput(5000);
     Console::out(Console::white . "Please enter dedicated user (SuperAdmin): ");
     $this->user = $this->getInput("SuperAdmin");
     Console::out(Console::white . "Please enter dedicated password (SuperAdmin): ");
     $this->pass = $this->getInput("SuperAdmin");
     $connection = null;
     try {
         Console::out("Trying to connect...", "Connect", Console::b_green);
         $this->connection = \Maniaplanet\DedicatedServer\Connection::factory($this->ip, $this->port, 5, $this->user, $this->pass);
         $this->connection->isRelayServer();
         Console::success();
         Console::outTm("Connected to server: " . $this->connection->getServerName() . "\n");
     } catch (\Exception $ex) {
         Console::fail();
         Console::out_error($ex->getMessage());
         Console::out("Try again (y)?");
         if ($this->getInput("y") == "y") {
             $this->tryConnect();
         } else {
             Console::out(Console::white . "Setup aborted. No config written.");
             exit(0);
         }
     }
     return;
 }
예제 #2
0
 function man($login, $commandName, $parametersCount = -2)
 {
     $commandName = strtolower($commandName);
     if ($parametersCount == -2 && isset($this->registeredCommands[$commandName])) {
         $help = array();
         $help[] = 'Available $<$o$FC4' . $commandName . '$> commands:';
         foreach ($this->registeredCommands[$commandName] as $command) {
             if (!count($command->authorizedLogin) || in_array($login, $command->authorizedLogin)) {
                 $help[] = '$<$o$FC4' . $command->name . ' (' . $command->parametersCount . ')$>' . ($command->help ? ':' . $command->help : '');
             }
         }
         $text = implode("\n", $help);
     } else {
         if (isset($this->registeredCommands[$commandName][$parametersCount])) {
             $command = $this->registeredCommands[$commandName][$parametersCount];
             if (!count($command->authorizedLogin) || in_array($login, $command->authorizedLogin)) {
                 $text = '$<$o$FC4' . $command->name . ' (' . $command->parametersCount . ')$>' . ($command->help ? ':' . $command->help : '');
             } else {
                 $text = 'This command does not exists use help to see available commands';
             }
         } else {
             $text = 'This command does not exists use help to see available commands';
         }
     }
     $this->connection->chatSendServerMessage($text, $login, true);
 }
예제 #3
0
 function kill()
 {
     if ($this->connection) {
         $this->connection->manualFlowControlEnable(false);
     }
     $this->running = false;
 }
예제 #4
0
 public function onEcho($internal, $public)
 {
     $call = explode(':', substr($internal, 1), 2);
     if (isset($call[1]) && $call[1] != $this->identifier) {
         return;
     }
     if (substr($internal, 0, 1) == '?') {
         switch ($call[0]) {
             case 'census':
                 $this->connection->dedicatedEcho($this->identifier, '!census:' . $public);
                 break;
             case 'stop':
                 \ManiaLive\Application\Application::getInstance()->kill();
                 break;
         }
     }
 }
예제 #5
0
 function onPlayerAlliesChanged($login)
 {
     try {
         $allies = $this->connection->getDetailedPlayerInfo($login)->allies;
         $this->getPlayerObject($login)->allies = $allies;
     } catch (\Exception $e) {
     }
 }
예제 #6
0
 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();
 }
예제 #7
0
 final function __construct()
 {
     $this->dependencies = array();
     $this->methods = array();
     $this->id = "\\" . get_class($this);
     $this->setVersion(1);
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
     $this->pluginHandler = PluginHandler::getInstance();
     $this->storage = Storage::getInstance();
     $this->chatCommands = array();
 }
예제 #8
0
 function fetchDetails()
 {
     $this->openConnection();
     $serverName = $this->connection->getServerName();
     if ($serverName != $this->name) {
         $service = new ServerService();
         $service->register($this);
         $this->name = $serverName;
     }
     $info = $this->connection->getSystemInfo();
     $this->login = $info->serverLogin;
     $this->titleId = $info->titleId;
     $this->joinIp = $info->publishedIp;
     $this->joinPort = $info->port;
     $this->joinPassword = $this->connection->getServerPassword();
     $this->specPassword = $this->connection->getServerPasswordForSpectator();
     $this->isRelay = $this->connection->isRelayServer();
     $this->connection = $this->connection;
 }
예제 #9
0
 function onTerminate()
 {
     if (Storage::getInstance()->serverStatus->code > Status::LAUNCHING) {
         $this->connection->sendHideManialinkPage();
     }
 }
예제 #10
0
 function status($host, $port)
 {
     $service = new \DedicatedManager\Services\ServerService();
     try {
         $server = $service->get($host, $port);
         $this->connection = \Maniaplanet\DedicatedServer\Connection::factory($server->rpcHost, $server->rpcPort, 5, 'SuperAdmin', $server->rpcPassword);
         $info = $this->connection->getSystemInfo();
         $this->response->running = $info->serverLogin;
     } catch (\Exception $e) {
         $this->response->running = 0;
     }
 }
 /**
  * @param string $host
  * @param int $port
  * @return RuleDisplayable[]
  */
 function getDedicatedMatchRules(\Maniaplanet\DedicatedServer\Connection $connection)
 {
     $gameInfo = $connection->getNextGameInfo();
     $matchRules = array();
     switch ($gameInfo->gameMode) {
         case GameInfos::GAMEMODE_SCRIPT:
             $info = $connection->getModeScriptInfo();
             $settings = $connection->getModeScriptSettings();
             foreach ($info->paramDescs as $value) {
                 $rule = new RuleDisplayable();
                 $rule->name = $value->name;
                 $rule->value = $settings[$value->name];
                 $rule->label = $value->name;
                 $rule->documentation = $value->desc;
                 if ($value->type == 'boolean') {
                     $rule->value = $rule->value == 'True';
                     $rule->inputType = 'switch';
                     $rule->inputValues = array(array('label' => _('No'), 'value' => 0), array('label' => _('Yes'), 'value' => 1));
                 }
                 $matchRules[] = $rule;
             }
             break;
         case GameInfos::GAMEMODE_ROUNDS:
             $rule = new RuleDisplayable();
             $rule->name = 'roundsPointsLimit';
             $rule->value = (int) $gameInfo->roundsPointsLimit;
             $rule->label = _('Points limit');
             $rule->documentation = _('Limit of points required to win the match.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'roundsPointsLimitNewRules';
             $rule->value = (int) $gameInfo->roundsPointsLimitNewRules;
             $rule->label = _('Points limit with new rules');
             $rule->documentation = _('Limit of points required to win the match.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'roundsUseNewRules';
             $rule->value = (int) $gameInfo->roundsUseNewRules;
             $rule->label = _('Use new rules');
             $rule->inputType = 'switch';
             $rule->inputValues = array(array('label' => _('No'), 'value' => 0), array('label' => _('Yes'), 'value' => 1));
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'roundsForcedLaps';
             $rule->value = (int) $gameInfo->roundsForcedLaps;
             $rule->label = _('Forced laps');
             $rule->documentation = _('Force the number of lap for mutlilaps maps.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'roundCustomPoints';
             $rule->value = implode(',', $connection->getRoundCustomPoints());
             $rule->label = _('Custom points');
             $rule->documentation = _('Points that will be given to players in order of arrival.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'allWarmUpDuration';
             $rule->value = (int) $gameInfo->allWarmUpDuration;
             $rule->label = _('Warm up duration');
             $rule->documentation = _('0 will disable warm-up, otherwise it\'s the number of rounds.');
             $matchRules[] = $rule;
             break;
         case GameInfos::GAMEMODE_TIMEATTACK:
             $rule = new RuleDisplayable();
             $rule->name = 'timeAttackLimit';
             $rule->value = (int) $gameInfo->timeAttackLimit;
             $rule->label = _('Time limit in millisecs');
             $rule->documentation = _('Map duration.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'timeAttackSynchStartPeriod';
             $rule->value = (int) $gameInfo->timeAttackSynchStartPeriod;
             $rule->label = _('Synchronisation period at start in millisecs');
             $rule->documentation = _('Time of player synchronisation at the beginning of the map.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'allWarmUpDuration';
             $rule->value = (int) $gameInfo->allWarmUpDuration;
             $rule->label = _('Warm up duration');
             $rule->documentation = _('0 will disable warm-up, otherwise it\'s the number of times the gold medal time).');
             $matchRules[] = $rule;
             break;
         case GameInfos::GAMEMODE_TEAM:
             $rule = new RuleDisplayable();
             $rule->name = 'teamPointsLimit';
             $rule->value = (int) $gameInfo->teamPointsLimit;
             $rule->label = _('Points limit');
             $rule->documentation = _('Limit of points required to win the match.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'teamPointsLimitNewRules';
             $rule->value = (int) $gameInfo->teamPointsLimitNewRules;
             $rule->label = _('Points limit with new rules');
             $rule->documentation = _('Limit of points required to win the match.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'teamMaxPoints';
             $rule->value = (int) $gameInfo->teamMaxPoints;
             $rule->label = _('Max points');
             $rule->documentation = _('Maximum points that a team can win.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'teamUseNewRules';
             $rule->value = (int) $gameInfo->teamUseNewRules;
             $rule->label = _('Max points');
             $rule->inputType = 'switch';
             $rule->inputValues = array(array('label' => _('No'), 'value' => 0), array('label' => _('Yes'), 'value' => 1));
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'allWarmUpDuration';
             $rule->value = (int) $gameInfo->allWarmUpDuration;
             $rule->label = _('Warm up duration');
             $rule->documentation = _('0 will disable warm-up, otherwise it\'s the number of rounds.');
             $matchRules[] = $rule;
             break;
         case GameInfos::GAMEMODE_LAPS:
             $rule = new RuleDisplayable();
             $rule->name = 'lapsNbLaps';
             $rule->value = (int) $gameInfo->lapsNbLaps;
             $rule->label = _('Laps number');
             $rule->documentation = _('Number of laps to do before finishing the race, or 0 to use map default.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'lapsTimeLimit';
             $rule->value = (int) $gameInfo->lapsTimeLimit;
             $rule->label = _('Time limit in millisecs');
             $rule->documentation = _('Time allowed for player to do this number of laps.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'allWarmUpDuration';
             $rule->value = (int) $gameInfo->allWarmUpDuration;
             $rule->label = _('Warm up duration');
             $rule->documentation = _('0 will disable warm-up, otherwise it\'s the number of times the gold medal time.');
             $matchRules[] = $rule;
             break;
         case GameInfos::GAMEMODE_CUP:
             $rule = new RuleDisplayable();
             $rule->name = 'cupPointsLimit';
             $rule->value = (int) $gameInfo->cupPointsLimit;
             $rule->label = _('Points limit');
             $rule->documentation = _('Number of point to earn before reaching the finalist status.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'cupRoundsPerMap';
             $rule->value = (int) $gameInfo->cupRoundsPerMap;
             $rule->label = _('Rounds per map');
             $rule->documentation = _('Number of rounds played per map.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'cupNbWinners';
             $rule->value = (int) $gameInfo->cupNbWinners;
             $rule->label = _('Number of winner');
             $rule->documentation = _('Number of player who has to win before the match is complete.');
             $matchRules[] = $rule;
             $rule = new RuleDisplayable();
             $rule->name = 'cupWarmUpDuration';
             $rule->value = (int) $gameInfo->cupWarmUpDuration;
             $rule->label = _('Warm up duration');
             $rule->documentation = _('0 will disable warm-up, otherwise it\'s the number of rounds.');
             $matchRules[] = $rule;
             break;
     }
     return $matchRules;
 }