function onLoad() { $wsConfig = \ManiaLib\WebServices\Config::getInstance(); $this->wsClient = new TrustCircles($wsConfig->username, $wsConfig->password); if ($wsConfig->username && $wsConfig->password) { $admins = AdminGroup::get(); $this->registerChatCommand('+black', 'addToBlackList', 1, true, $admins); $this->registerChatCommand('+white', 'addToWhiteList', 1, true, $admins); $this->registerChatCommand('-black', 'removeFromBlackList', 1, true, $admins); $this->registerChatCommand('-white', 'removeFromWhiteList', 1, true, $admins); $currentBlackList = array_map(function ($player) { return $player->login; }, $this->connection->getBlackList(-1, 0)); $distantBlackList = $this->wsClient->getBlackList(); foreach (array_diff($distantBlackList, $currentBlackList) as $player) { $this->connection->blackList($player); } foreach (array_diff($currentBlackList, $distantBlackList) as $player) { $this->connection->unBlackList($player); } $this->whiteList = $this->wsClient->getWhiteList(); } foreach ((array) Config::getInstance()->rules as $rule) { $this->preparedRules[] = Rule::Prepare($rule); } foreach ($this->storage->players as $player) { $this->onPlayerConnect($player->login, false); } foreach ($this->storage->spectators as $player) { $this->onPlayerConnect($player->login, true); } $this->enableDedicatedEvents(ServerEvent::ON_PLAYER_CONNECT | ServerEvent::ON_PLAYER_DISCONNECT); }
/** * Default constructor. Children classes should, if they need to override it, * keep the same first two parameters (the API credentials) to keep the usage of the SDK simple. * * You can manage your API credentials at http://developers.trackmania.com * * @param string $username API username * @param string $password API password */ function __construct($username = null, $password = null, $slowRequestThreshold = null) { if (!function_exists('curl_init')) { trigger_error('You must activate the CURL PHP extension.', E_USER_ERROR); } if (!function_exists('json_encode')) { trigger_error('You must activate the JSON PHP extension.', E_USER_ERROR); } // If you're using ManiaLib, credentials can be automatically loaded if (!$username && !$password && class_exists('\\ManiaLib\\WebServices\\Config')) { $config = \ManiaLib\WebServices\Config::getInstance(); $username = $config->username; $password = $config->password; $slowRequestThreshold = $config->slowRequestThreshold; } $this->username = $username; $this->password = $password; $this->slowRequestThreshold = $slowRequestThreshold; }
protected function saveConfiguration(InputInterface $input, OutputInterface $output) { $output->writeln('<info>Saving your configuration in app.ini file</info>'); $applicationConfig = ApplicationConfig::getInstance(); $dedicatedManagerConfig = DedicatedManagerConfig::getInstance(); $webServicesConfig = WSConfig::getInstance(); $databaseConfig = DatabaseConfig::getInstance(); $config = "application.namespace = DedicatedManager\n"; $config .= "application.webapp = true\n"; $config .= sprintf("application.URL = '%s'\n", $applicationConfig->URL . '/'); $config .= "DedicatedManager\\Config.maniaConnect = On\n"; $config .= sprintf("DedicatedManager\\Config.dedicatedPath = '%s'\n", $dedicatedManagerConfig->dedicatedPath . '/'); foreach ($dedicatedManagerConfig->admins as $admin) { $config .= sprintf("DedicatedManager\\Config.admins[] = %s\n", $admin); } $config .= sprintf("webservices.username = '******'\n", $webServicesConfig->username); $config .= sprintf("webservices.password = '******'\n", $webServicesConfig->password); $config .= sprintf("database.host = '%s'\n", $databaseConfig->host); $config .= sprintf("database.user = '******'\n", $databaseConfig->user); $config .= sprintf("database.password = '******'\n", $databaseConfig->password); $config .= sprintf("database.database = '%s'\n", $databaseConfig->database); $config .= "database.slowQueryLog = true\n"; file_put_contents('./config/app.ini', $config); $output->writeln('<success>Your Dedicated manager is successfully configured</success>'); $output->writeln(sprintf('<success>You can now access to: %s</success>', $applicationConfig->URL)); }