/** * Intialise le client du serveur courant * * @param bool $fullInit -> Intialisation complète ? oui par défaut. * Si non, ça ne recupère aucune info de base, seulement la connexion * au serveur dédié et son authentication. * @return bool */ public static function initialize($fullInit = true) { global $client; $out = false; if (isset($_SESSION['adminserv']['sid'])) { // CONSTANTS define('USER_ADMINLEVEL', $_SESSION['adminserv']['adminlevel']); define('SERVER_ID', $_SESSION['adminserv']['sid']); define('SERVER_NAME', $_SESSION['adminserv']['name']); define('SERVER_ADDR', ServerConfig::$SERVERS[SERVER_NAME]['address']); define('SERVER_XMLRPC_PORT', ServerConfig::$SERVERS[SERVER_NAME]['port']); define('SERVER_MATCHSET', ServerConfig::$SERVERS[SERVER_NAME]['matchsettings']); define('SERVER_MAPS_BASEPATH', isset(ServerConfig::$SERVERS[SERVER_NAME]['mapsbasepath']) ? ServerConfig::$SERVERS[SERVER_NAME]['mapsbasepath'] : ''); define('SERVER_ADMINLEVEL', serialize(ServerConfig::$SERVERS[SERVER_NAME]['adminlevel'])); // CONNEXION $client = new IXR_ClientMulticall_Gbx(); if (!$client->InitWithIp(SERVER_ADDR, SERVER_XMLRPC_PORT, AdminServConfig::SERVER_CONNECTION_TIMEOUT)) { Utils::redirection(false, '?error=' . urlencode(Utils::t('The server is not accessible.'))); } else { if (!AdminServAdminLevel::userAllowed(USER_ADMINLEVEL)) { Utils::redirection(false, '?error=' . urlencode(Utils::t('You are not allowed at this admin level'))); } else { if (!$client->query('Authenticate', AdminServAdminLevel::getType(), $_SESSION['adminserv']['password'])) { Utils::redirection(false, '?error=' . urlencode(Utils::t('The password doesn\'t match to the server.'))); } else { if ($fullInit) { $client->addCall('SetApiVersion', array(date('Y-m-d'))); $client->addCall('GetVersion'); $client->addCall('GetSystemInfo'); $client->addCall('IsRelayServer'); if (!$client->multiquery()) { self::error(); } else { $queriesData = $client->getMultiqueryResponse(); // Version $getVersion = $queriesData['GetVersion']; define('SERVER_VERSION_NAME', $getVersion['Name']); define('SERVER_VERSION', $getVersion['Version']); define('SERVER_BUILD', $getVersion['Build']); if (SERVER_VERSION_NAME == 'ManiaPlanet') { define('API_VERSION', $getVersion['ApiVersion']); } // SystemInfo $getSystemInfo = $queriesData['GetSystemInfo']; define('SERVER_LOGIN', $getSystemInfo['ServerLogin']); define('SERVER_PUBLISHED_IP', $getSystemInfo['PublishedIp']); define('SERVER_PORT', $getSystemInfo['Port']); define('SERVER_P2P_PORT', $getSystemInfo['P2PPort']); if (SERVER_VERSION_NAME == 'ManiaPlanet') { define('SERVER_TITLE', $getSystemInfo['TitleId']); define('IS_SERVER', $getSystemInfo['IsServer']); define('IS_DEDICATED', $getSystemInfo['IsDedicated']); } // Relay define('IS_RELAY', $queriesData['IsRelayServer']); // Protocole : tmtp ou maniaplanet if (SERVER_VERSION_NAME == 'ManiaPlanet') { TmNick::$linkProtocol = 'maniaplanet'; } define('LINK_PROTOCOL', TmNick::$linkProtocol); // Mode d'affichage : detail ou simple if (isset($_SESSION['adminserv']['mode']['general'])) { define('USER_MODE_GENERAL', $_SESSION['adminserv']['mode']['general']); } else { define('USER_MODE_GENERAL', 'simple'); } if (isset($_SESSION['adminserv']['mode']['maps'])) { define('USER_MODE_MAPS', $_SESSION['adminserv']['mode']['maps']); } else { define('USER_MODE_MAPS', 'simple'); } // TmForever if (SERVER_VERSION_NAME == 'TmForever') { array_shift(ExtensionConfig::$GAMEMODES); $stuntsGameMode = array_pop(ExtensionConfig::$GAMEMODES); $CupGameMode = array_pop(ExtensionConfig::$GAMEMODES); ExtensionConfig::$GAMEMODES[4] = $stuntsGameMode; ExtensionConfig::$GAMEMODES[5] = $CupGameMode; } $out = true; } } else { $out = true; } } } } } return $out; }
} else { return 1; } } // DATA $out = array(); if (class_exists('ServerConfig')) { if (isset(ServerConfig::$SERVERS) && count(ServerConfig::$SERVERS) > 0 && !isset(ServerConfig::$SERVERS['new server name']) && !isset(ServerConfig::$SERVERS[''])) { $serverId = 0; foreach (ServerConfig::$SERVERS as $serverName => $serverValues) { // Connexion $client = new IXR_ClientMulticall_Gbx(); if (!$client->InitWithIp($serverValues['address'], $serverValues['port'])) { $out['servers'][$serverId]['error'] = Utils::t('Offline server.'); } else { if (!$client->query('Authenticate', $LEVEL, $PASSW)) { $out['servers'][$serverId]['error'] = Utils::t('Authentication error.'); } else { // Connecté sur $client->query('GetVersion'); $version = $client->getResponse(); $out['servers'][$serverId]['version']['name'] = $version['Name']; // Protocole : tmtp ou maniaplanet $linkProtocol = 'maniaplanet'; if ($version['Name'] == 'TmForever') { $linkProtocol = 'tmtp'; } $out['servers'][$serverId]['version']['protocol'] = $linkProtocol; // Jeu if ($version['Name'] == 'TmForever') { $queryName = array('getMapInfo' => 'GetCurrentChallengeInfo');