/** * @return \ManiaLive\DedicatedApi\Connection */ protected function getServerConnection() { if ($this->connection) { return $this->connection; } $service = new \ManiaHost\Services\ServerService(); $server = end($service->getList(0, 1)); if (!$server) { throw new \Exception('No server launched'); } $config = \ManiaLive\DedicatedApi\Config::getInstance(); $config->host = $server->hostname; $config->port = $server->port; $config->user = '******'; $config->password = $server->superAdminPassword; $this->connection = \ManiaLive\DedicatedApi\Connection::getInstance(); return $this->connection; }
function checkout() { $selectedTracks = $this->session->get('selected'); $gameInfos = $this->session->get('gameInfos'); $serverOptions = $this->session->get('serverOptions'); if (!$selectedTracks) { throw new \ManiaLib\Application\UserException('You have to select maps'); } if (!$gameInfos) { throw new \ManiaLib\Application\UserException('You have to configure your server'); } if (!$serverOptions) { throw new \ManiaLib\Application\UserException('You have to configure your server'); } $service = new \ManiaHost\Services\ServerService(); if (!$service->availableCount()) { throw new \ManiaLib\Application\UserException('There is no more server available'); } $transactionService = new \ManiaHost\Services\TransactionService(); $t = $transactionService->create($this->session->login, $this->session->getStrict('duration') * \ManiaHost\Config::getInstance()->hourlyCost); $this->session->set('transaction-' . $this->session->login, $t); $url = \ManiaLib\Application\Config::getInstance()->manialink . '?&ml-forcepathinfo=%2Frent%2Ffinalize%2F' . ($t->id ? '&transaction=' . $t->id : ''); $this->request->redirectAbsolute($url); }