95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* Copyright (c) 2008-2013 GIANTS Software GmbH, Confidential, All Rights Reserved.
|
|
* Copyright (c) 2003-2013 Christian Ammann and Stefan Geiger, Confidential, All Rights Reserved.
|
|
*/
|
|
// require_once 'config.php';
|
|
|
|
$configurations = [
|
|
'server_ip' => '45.137.244.65',
|
|
'server_code' => 'H2UTei9J',
|
|
'server_port' => 8620,
|
|
'secure_server_port' => 8620,
|
|
];
|
|
|
|
foreach($configurations as $name => $val){
|
|
$configName = strtoupper($name);
|
|
define($configName,$val);
|
|
|
|
}
|
|
|
|
$dedicatedServer = 'http://'. SERVER_IP .':'. SERVER_PORT .'/feed/dedicated-server-savegame.html?code='. SERVER_CODE;
|
|
|
|
$career = $dedicatedServer.'&file=careerSavegame';
|
|
$xmlc = getServerStatsSimpleXML($career, 'careerSavegame');
|
|
|
|
$serverAddress = 'http://'. SERVER_IP .':'. SERVER_PORT .'/feed/dedicated-server-stats.xml?code='. SERVER_CODE;
|
|
$xml = getServerStatsSimpleXML($serverAddress, 'Server');
|
|
$server = $xml['game'];
|
|
|
|
$vehicles = $dedicatedServer.'&file=vehicles';
|
|
$xmlv = getServerStatsSimpleXML($vehicles,'vehicles');
|
|
|
|
$economy = $dedicatedServer.'&file=economy';
|
|
$xmls = getServerStatsSimpleXML($economy, 'economy');
|
|
|
|
function loadFileHTTPSocket($domain, $port, $path, $timeout) {
|
|
$fp = fsockopen($domain, $port, $errno, $errstr, $timeout);
|
|
|
|
if ($fp) {
|
|
// Make request
|
|
$out = "GET ". $path . " HTTP/1.0\r\n";
|
|
$out .= "Host: ". $domain . "\r\n";
|
|
$out .= "Connection: Close\r\n\r\n";
|
|
fwrite($fp, $out);
|
|
|
|
// Get response
|
|
$resp = "";
|
|
while (!feof($fp)) {
|
|
$resp .= fgets($fp, 256);
|
|
}
|
|
fclose($fp);
|
|
|
|
// Check status is 200
|
|
if(preg_match("/HTTP\/1\.\d\s(\d+)/", $resp, $matches) && $matches[1] == 200) {
|
|
// Load xml as object
|
|
$parts = explode("\r\n\r\n", $resp);
|
|
$temp = "";
|
|
for ($i=1;$i<count($parts);$i++) {
|
|
$temp .= $parts[$i];
|
|
}
|
|
return $temp;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function getServerStatsSimpleXML($url, $file = 'testing') {
|
|
|
|
$urlParts = parse_url($url);
|
|
|
|
$cacheFile = 'dedicated-server-'.$file.'.cached';
|
|
$cacheTimeout = 60*2;
|
|
|
|
if(file_exists($cacheFile) && filemtime($cacheFile) > (time() - ($cacheTimeout) + rand(0, 10))) {
|
|
$xmlStr = file_get_contents($cacheFile);
|
|
} else {
|
|
error_reporting(0);
|
|
$xmlStr = loadFileHTTPSocket($urlParts["host"], $urlParts["port"], $urlParts["path"] . "?" . $urlParts["query"], 4);
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
if ($xmlStr) {
|
|
$fp = fopen($cacheFile, "w");
|
|
fwrite($fp, $xmlStr);
|
|
fclose($fp);
|
|
}
|
|
|
|
}
|
|
|
|
return simplexml_load_string($xmlStr);
|
|
}
|
|
|
|
|
|
|
|
?>
|