Hide<?
include_once("mysql.php");
class CURL {
var $callback = false;
function setCallback($func_name) {
$this->callback = $func_name;
}
function doRequest($method, $url, $vars) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 7);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
//curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_TIMEOUT, 1);
//curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($fh, CURLOPT_REFERER, 'http://knl/');
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
//curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
$data = curl_exec($ch);
curl_close($ch);
if ($data) {
if ($this->callback)
{
$callback = $this->callback;
$this->callback = false;
return call_user_func($callback, $data);
} else {
return $data;
}
} else {
return curl_error($ch);
}
}
function get($url) {
return $this->doRequest('GET', $url, 'NULL');
}
function post($url, $vars) {
return $this->doRequest('POST', $url, $vars);
}
}
if (!function_exists('array_combine')) {
function array_combine($a, $b) {
$c = array();
if (is_array($a) && is_array($b))
while (list(, $va) = each($a))
if (list(, $vb) = each($b))
$c[$va] = $vb;
else
break 1;
return $c;
}
}
function doPost($uri,$postdata,$host){
$da = fsockopen($host, 80, $errno, $errstr);
if (!$da) {
echo "$errstr ($errno)<br/>\n";
echo $da;
}
else {
$salida ="POST $uri HTTP/1.1\r\n";
$salida.="Host: $host\r\n";
$salida.="User-Agent: PHP Script\r\n";
$salida.="Content-Type: application/x-www-form-urlencoded\r\n";
$salida.="Content-Length: ".strlen($postdata)."\r\n";
$salida.="Connection: close\r\n\r\n";
$salida.=$postdata;
fwrite($da, $salida);
while (!feof($da))
$response.=fgets($da, 128);
$response=split("\r\n\r\n",$response);
$header=$response[0];
$responsecontent=$response[1];
if(!(strpos($header,"Transfer-Encoding: chunked")===false)){
$aux=split("\r\n",$responsecontent);
for($i=0;$i<count($aux);$i++)
if($i==0 || ($i%2==0))
$aux[$i]="";
$responsecontent=implode("",$aux);
}//if
return chop($responsecontent);
}//else
}//function-doPost
$ar_complete=array();
$ar_keys=array();
$ar_items=array();
function myarray(&$item)
{
global $ar_keys;
global $ar_items;
$tmp_ar=split("=",$item);
$ar_keys[]=$tmp_ar[0];
$ar_items[]=$tmp_ar[1];
}
function print_rf($str)
{
echo("<pre>");
print_r($str);
echo("</pre>");
}
$result = mysql_query ("SELECT login,gamecity_url FROM ".ST_TABLE, $LINK) or die("index.php -> err ".mysql_error($LINK));
if ($row->gamecity=="")
{
$gamecity="http://emeraldscity.combats.com";
} else {
$gamecity=$row->gamecity_url;
}
$curl=new CURL;
for ($i = 0; $i < mysql_num_rows ($result); $i++) {
$row = mysql_fetch_object ($result);
//$url=$gamecity."/inf.pl?login=".$row->login."&short=1";
//$p_url=parse_url($gamecity);
$contents=$curl->post($gamecity."/inf.pl","login=".$row->login."&short=1");
//$contents = @doPost("/inf.pl","login=".$row->login."&short=1",$p_url[host]);
if (stristr($contents,"[503]")) break;
if (stristr($contents,"The document has moved")) {
sleep(3);
$host=stristr($contents,"http://");
$host=str_replace("\n","",$host);
$host=str_replace("\r","",$host);
$host=str_replace(" ","",$host);
$pos = strpos($host, '"', 1);
$url=substr($host, 0, $pos);
$p_url=parse_url($url);
$contents =$curl->post("http://".$p_url[host]."/inf.pl","login=".$row->login."&short=1");
//$contents = @doPost("/inf.pl","login=".$row->login."&short=1",$p_url[host]);
}
$ar=$ar_complete=$ar_keys=$ar_items=array();
$ar=split("\n",$contents);
array_walk($ar,'myarray');
$ar_complete = array_combine ( $ar_keys, $ar_items );
$login=$row->login;
if (!array_key_exists("login_online", $ar_complete)) {
mysql_query ("UPDATE `".ST_TABLE."` SET login_online='0' WHERE login='$login'") or die("update.php -> err ".mysql_error($LINK)."\n");
mysql_query ("UPDATE `".ST_TABLE."` SET room_name='' WHERE login='$login'") or die("update.php -> err ".mysql_error($LINK))."\n";
}
foreach ($ar_complete as $key => $value) {
//print_rf($ar_complete);
//echo("UPDATE ".ST_TABLE." SET ".$key."='".$value."' WHERE login='$login'");
//exit;
if (($row->key)!=$value) {
//print_rf($row->$key);
// print_rf($value);
//print_rf ("UPDATE `".ST_TABLE."` SET "$key"='"$value"' WHERE login='".$login."'\n");
mysql_query ("UPDATE ".ST_TABLE." SET ".$key."='".$value."' WHERE login='".$login."'") or die("update.php -> err ".mysql_error($LINK)."\n");
//exit;
}
}
//set_time_limit(0);
sleep (3);
}
mysql_free_result ($result);
?>