-
-
Save Marlinc/e3d099ac41226cd91f37e358a56d3283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre> | |
<?php | |
$server = array(); | |
$server['tw-stats'] = '94.198.82.205'; | |
if (isset($_GET['type'])) { | |
if ($_GET['type'] == 'player') { | |
if (($_GET['user']) && ($_GET['world'])) { | |
echo "START:\n"; | |
if ($_GET['world'] == 'nls1') $fp = fsockopen('212.72.179.47', 80, $errno, $errstr,2); | |
else $fp = fsockopen($server['tw-stats'], 80, $errno, $errstr,2); | |
if (isset($_GET['max'])) $max = (int)$_GET['max']; | |
else $max = 10; | |
if (!$fp) { | |
echo "ERR:102,".$errno.",".$errstr."\n"; | |
exit(); | |
} | |
if ($_GET['world'] == 'nls1') { | |
$data = 'name='.urlencode($_GET['user']); | |
fwrite($fp, "POST /guest.php?screen=ranking&mode=player&search HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nls1.tribalwars.nl\r\n"); | |
fwrite($fp, "Referer: http://mchosts.co.cc/mirc/tw-parser.php?type=player&user=".urlencode($_GET['user'])."&world=nls1\r\n"); | |
fwrite($fp, "Content-type: application/x-www-form-urlencoded\r\n"); | |
fwrite($fp, "Content-length: ". strlen($data) ."\r\n"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
fwrite($fp, $data); | |
} | |
else { | |
fwrite($fp, "GET /nl".(int)$_GET['world']."/index.php?page=rankings&mode=players&searchstring=".urlencode($_GET['user'])." HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nl.twstats.com\r\n"); | |
fwrite($fp, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
} | |
$nr = 0; | |
$datanr = 0; | |
$td_first = true; | |
while (!feof($fp)) { | |
$data = fgets($fp, 512); | |
if ($_GET['world'] == 'nls1') { | |
if (strstr($data,'</td><td valign="top"><table id="player_ranking_table" class="vis">')) $liststart = true; | |
elseif ((isset($liststart)) && ($liststart)) { | |
$dataexp = explode('>',$data); | |
if (strstr($data,'</table><table class="vis" width="100%"><tr>')) $liststart = false; | |
elseif (strstr($data,'<tr><th width="60">Rang</th><th width="180">Naam</th><th width="100">Stam</th>')) { } | |
elseif (strstr($data,'<th width="60">Punten</th><th>Dorpen</th><th>Puntengemiddelde dorp</th></tr>')) { } | |
elseif (strstr($data,'</tr>')) { | |
if ((isset($ready)) && ($ready)) $nr++; | |
$td_first = true; | |
$ready = false; | |
} | |
elseif (strstr($data,'<tr class="lit">')) { $ready = true; } | |
elseif (strstr($data,'<td><a href="/guest.php?screen=info_player&id=')) { | |
if ((isset($ready)) && ($ready)) { | |
$id[$nr]['id'] = str_replace(array('<a href="/guest.php?screen=info_player&id=','"'),'',$dataexp[1]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[2]); | |
} | |
} | |
elseif (strstr($data,'<td><a href="/guest.php?screen=info_ally&id=')) { | |
if ((isset($ready)) && ($ready)) { | |
$id[$nr]['tribeid'] = str_replace(array('<a href="/guest.php?screen=info_ally&id=','"'),'',$dataexp[1]); | |
$id[$nr]['tribename'] = str_replace('</a','',$dataexp[2]); | |
} | |
} | |
elseif ((strstr($data,'<td>')) && (strstr($data,'</td>')) && ($td_first)) { | |
if ((isset($ready)) && ($ready)) { | |
$id[$nr]['rank'] = str_replace(array('<td>','</td>',"\n","\r"),'',$data); | |
} | |
$td_first = false; | |
} | |
elseif (strstr($data,'<span class="grey">')) { | |
$dataexp = explode('>',str_replace(array('<span class="grey">','</span>'),'',$data)); | |
if ((isset($ready)) && ($ready)) { | |
$id[$nr]['points'] = str_replace(array('</td','.'),'',$dataexp[1]); | |
$id[$nr]['villages'] = str_replace(array('</td','.'),'',$dataexp[3]); | |
$id[$nr]['gemvillages'] = str_replace(array('</td','.'),'',$dataexp[5]); | |
} | |
} | |
else { | |
$datanr++; | |
} | |
} | |
} | |
else { | |
if ((strstr($data,'<tr class="row_a">')) || (strstr($data,'<tr class="row_b">'))) { | |
$dataexp = explode('>',$data); | |
if ($nr < $max) { | |
if (count($dataexp) == 19) { | |
$id[$nr]['rank'] = str_replace('</td','',$dataexp[2]); | |
$id[$nr]['id'] = str_replace(array('<a href="index.php?page=player&id=','"'),'',$dataexp[4]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[5]); | |
$id[$nr]['tribeid'] = str_replace(array('<a href="index.php?page=tribe&id=','"'),'',$dataexp[8]); | |
$id[$nr]['tribename'] = str_replace('</a','',$dataexp[9]); | |
$id[$nr]['points'] = str_replace(array('</td',','),'',$dataexp[12]); | |
$id[$nr]['villages'] = str_replace('</td','',$dataexp[14]); | |
$id[$nr]['gemvillages'] = str_replace(array('</td',','),'',$dataexp[16]); | |
} | |
else { | |
$id[$nr]['rank'] = str_replace('</td','',$dataexp[2]); | |
$id[$nr]['id'] = str_replace(array('<a href="index.php?page=player&id=','"'),'',$dataexp[4]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[5]); | |
$id[$nr]['tribeid'] = 0; | |
$id[$nr]['tribename'] = 'NONE'; | |
$id[$nr]['points'] = str_replace(array('</td',','),'',$dataexp[10]); | |
$id[$nr]['villages'] = str_replace('</td','',$dataexp[12]); | |
$id[$nr]['gemvillages'] = str_replace(array('</td',','),'',$dataexp[14]); | |
} | |
} | |
$nr++; | |
} | |
} | |
} | |
if (isset($id)) { | |
foreach ($id as $nr => $data) { | |
$data['worlds'] = 'NL'.(int)$_GET['world']; | |
if ($_GET['world'] == 'nls1') { | |
$data['joined'] = 0; | |
$data['bestrank'] = array('ts' => 0,'rank' => 0); | |
$data['mostpoints'] = array('ts' => 0,'points' => 0); | |
$data['mostvillages'] = array('ts' => 0,'villages' => 0); | |
$data['worlds'] = '-'; | |
} | |
else { | |
$fp2 = fsockopen($server['tw-stats'], 80, $errno, $errstr,1); | |
if (!$fp2) { | |
echo "ERR:103,".$errno.",".$errstr."\n"; | |
} | |
else { | |
fwrite($fp2, "GET /nl".(int)$_GET['world']."/index.php?page=player&id=".(int)$data['id']." HTTP/1.1\r\n"); | |
fwrite($fp2, "Host: nl.twstats.com\r\n"); | |
fwrite($fp2, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp2, "Connection: Close\r\n"); | |
fwrite($fp2, "\r\n"); | |
$nr2 = 0; | |
while (!feof($fp2)) { | |
$data2 = fgets($fp2, 1024); | |
if (strstr($data2,'<tr><th width="50%">')) { | |
$data2exp = explode('>',$data2); | |
if ($nr2 == 7) $data['joined'] = strtotime(str_replace('</td','',$data2exp[4])); | |
if ($nr2 == 8) $data['bestrank'] = array('ts' => strtotime(str_replace('</span','',$data2exp[7])),'rank' => str_replace('</span','',$data2exp[5])); | |
if ($nr2 == 9) $data['mostpoints'] = array('ts' => strtotime(str_replace('</span','',$data2exp[7])),'points' => str_replace(array('</span',','),'',$data2exp[5])); | |
if ($nr2 == 10) $data['mostvillages'] = array('ts' => strtotime(str_replace('</span','',$data2exp[7])),'villages' => str_replace(array('</span',','),'',$data2exp[5])); | |
$nr2++; | |
} | |
if (strstr($data2,'<span class="world" style="padding-right: 6px">')) { | |
$data2exp = explode('>',strip_tags($data2,'<a>')); | |
foreach ($data2exp as $nr3 => $w) { | |
if ($nr3 & 1) $data['worlds'] = $data['worlds'].'-'.str_replace('</a','',$w); | |
} | |
} | |
} | |
} | |
} | |
if ($nr < 10) $nr = '0'.$nr; | |
$results[$data['name']] = $data; | |
} | |
ksort($results); | |
//print_r($results); | |
$nr = 0; | |
foreach ($results as $name => $data) { | |
if ($nr < 10) $nr = '0'.$nr; | |
echo "DATA".$nr.":".$data['rank'].",".$data['id'].",".$data['name'].",".$data['tribeid'].",".$data['tribename'].",".$data['points'].",".$data['villages'].",".$data['gemvillages'].",".$data['joined'].",".$data['bestrank']['ts'].",".$data['bestrank']['rank'].",".$data['mostpoints']['ts'].",".$data['mostpoints']['points'].",".$data['mostvillages']['ts'].",".$data['mostvillages']['villages'].",".$data['worlds']."\n"; | |
$nr++; | |
} | |
} | |
else echo "ERR:101\n"; | |
echo "END:\n"; | |
} | |
else { | |
echo "Please specify a nickname and world!\n\rtw-parser.php?type=player&user=peter&world=5\n"; | |
} | |
} | |
elseif ($_GET['type'] == 'playerod') { | |
if (($_GET['user']) && ($_GET['world'])) { | |
echo "START:\n"; | |
$fp = fsockopen($server['tw-stats'], 80, $errno, $errstr,2); | |
if (!$fp) { | |
echo "ERR:102,".$errno.",".$errstr."\n"; | |
exit(); | |
} | |
fwrite($fp, "GET /nl".(int)$_GET['world']."/index.php?page=rankings&mode=playersod&searchstring=".urlencode($_GET['user'])." HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nl.twstats.com\r\n"); | |
fwrite($fp, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
$nr = 0; | |
while (!feof($fp)) { | |
$data = fgets($fp, 512); | |
if ((strstr($data,'<tr class="row_a">')) || (strstr($data,'<tr class="row_b">'))) { | |
$dataexp = explode('>',$data); | |
if (count($dataexp) == 23) { | |
$id[$nr]['rank'] = str_replace('</td','',$dataexp[10]); | |
$id[$nr]['id'] = str_replace(array('<a href="index.php?page=player&id=','"'),'',$dataexp[2]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[3]); | |
$id[$nr]['tribeid'] = str_replace(array('<a href="index.php?page=tribe&id=','"'),'',$dataexp[6]); | |
$id[$nr]['tribename'] = str_replace('</a','',$dataexp[7]); | |
$id[$nr]['score'] = str_replace(array('</td',','),'',$dataexp[12]); | |
$id[$nr]['attrank'] = str_replace(array('</td',','),'',$dataexp[14]); | |
$id[$nr]['attscore'] = str_replace(array('</td',','),'',$dataexp[16]); | |
$id[$nr]['defrank'] = str_replace(array('</td',','),'',$dataexp[18]); | |
$id[$nr]['defscore'] = str_replace(array('</td',','),'',$dataexp[20]); | |
} | |
else { | |
$id[$nr]['rank'] = str_replace('</td','',$dataexp[8]); | |
$id[$nr]['id'] = str_replace(array('<a href="index.php?page=player&id=','"'),'',$dataexp[2]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[3]); | |
$id[$nr]['tribeid'] = 0; | |
$id[$nr]['tribename'] = 'NONE'; | |
$id[$nr]['score'] = str_replace(array('</td',','),'',$dataexp[10]); | |
$id[$nr]['attrank'] = str_replace(array('</td',','),'',$dataexp[12]); | |
$id[$nr]['attscore'] = str_replace(array('</td',','),'',$dataexp[14]); | |
$id[$nr]['defrank'] = str_replace(array('</td',','),'',$dataexp[16]); | |
$id[$nr]['defscore'] = str_replace(array('</td',','),'',$dataexp[18]); | |
} | |
$nr++; | |
} | |
} | |
if (isset($id)) { | |
foreach ($id as $nr => $data) { | |
if ($nr < 10) $nr = '0'.$nr; | |
echo "DATA".$nr.":".$data['rank'].",".$data['id'].",".$data['name'].",".$data['tribeid'].",".$data['tribename'].",".$data['score'].",".$data['attrank'].",".$data['attscore'].",".$data['defrank'].",".$data['defscore']."\n"; | |
} | |
} | |
else echo "ERR:101\n"; | |
echo "END:\n"; | |
} | |
else { | |
echo "Please specify a nickname and world!\n\rtw-parser.php?type=playerod&user=peter&world=5\n"; | |
} | |
} | |
elseif ($_GET['type'] == 'tribeod') { | |
if (($_GET['tribe']) && ($_GET['world'])) { | |
echo "START:\n"; | |
$fp = fsockopen($server['tw-stats'], 80, $errno, $errstr,2); | |
if (!$fp) { | |
echo "ERR:102,".$errno.",".$errstr."\n\r"; | |
exit(); | |
} | |
fwrite($fp, "GET /nl".(int)$_GET['world']."/index.php?page=rankings&mode=tribesod&searchstring=".urlencode($_GET['tribe'])." HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nl.twstats.com\r\n"); | |
fwrite($fp, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
$nr = 0; | |
while (!feof($fp)) { | |
$data = fgets($fp, 512); | |
if ((strstr($data,'<tr class="row_a">')) || (strstr($data,'<tr class="row_b">'))) { | |
$dataexp = explode('>',$data); | |
$id[$nr]['rank'] = str_replace('</td','',$dataexp[8]); | |
$id[$nr]['id'] = str_replace(array('<a href="index.php?page=tribe&id=','"'),'',$dataexp[2]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[3]); | |
$id[$nr]['members'] = str_replace(array('</td',','),'',$dataexp[6]); | |
$id[$nr]['score'] = str_replace(array('</td',','),'',$dataexp[10]); | |
$id[$nr]['attrank'] = str_replace(array('</td',','),'',$dataexp[12]); | |
$id[$nr]['attscore'] = str_replace(array('</td',','),'',$dataexp[14]); | |
$id[$nr]['defrank'] = str_replace(array('</td',','),'',$dataexp[16]); | |
$id[$nr]['defscore'] = str_replace(array('</td',','),'',$dataexp[18]); | |
$nr++; | |
} | |
} | |
if (isset($id)) { | |
foreach ($id as $nr => $data) { | |
if ($nr < 10) $nr = '0'.$nr; | |
echo "DATA".$nr.":".$data['rank'].",".$data['id'].",".$data['name'].",".$data['members'].",".$data['score'].",".$data['attrank'].",".$data['attscore'].",".$data['defrank'].",".$data['defscore']."\n"; | |
} | |
} | |
else echo "ERR:101\n"; | |
echo "END:\n"; | |
} | |
else { | |
echo "Please specify a nickname and world!\n\rtw-parser.php?type=playerod&user=peter&world=5\n"; | |
} | |
} | |
elseif ($_GET['type'] == 'top') { | |
if (($_GET['ranks']) && ($_GET['world'])) { | |
echo "START:\n"; | |
if ($_GET['world'] == 'nls1') $fp = fsockopen('212.72.179.47', 80, $errno, $errstr,2); | |
else $fp = fsockopen($server['tw-stats'], 80, $errno, $errstr,2); | |
if (!$fp) { | |
echo "ERR:102,".$errno.",".$errstr."\n"; | |
exit(); | |
} | |
if ($_GET['world'] == 'nls1') { | |
fwrite($fp, "GET /guest.php?screen=ranking&mode=player HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nls1.tribalwars.nl\r\n"); | |
fwrite($fp, "Referer: http://mchosts.co.cc/mirc/tw-parser.php?type=top&ranks=".(int)$_GET['ranks']."&world=nls1\r\n"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
} | |
else { | |
fwrite($fp, "GET /nl".(int)$_GET['world']."/index.php?page=rankings&mode=players HTTP/1.1\r\n"); | |
fwrite($fp, "Referer: http://mchosts.co.cc/mirc/tw-parser.php?type=top&ranks=".(int)$_GET['ranks']."&world=nls1\r\n"); | |
fwrite($fp, "Host: nl.twstats.com\r\n"); | |
fwrite($fp, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
} | |
$nr = 0; | |
$datanr = 0; | |
$td_first = true; | |
while (!feof($fp)) { | |
$data = fgets($fp, 512); | |
if ($_GET['world'] == 'nls1') { | |
if (strstr($data,'</td><td valign="top"><table id="player_ranking_table" class="vis">')) $liststart = true; | |
elseif ((isset($liststart)) && ($liststart)) { | |
$dataexp = explode('>',$data); | |
if (strstr($data,'</table><table class="vis" width="100%"><tr>')) $liststart = false; | |
elseif (strstr($data,'<tr><th width="60">Rang</th><th width="180">Naam</th><th width="100">Stam</th>')) { } | |
elseif (strstr($data,'<th width="60">Punten</th><th>Dorpen</th><th>Puntengemiddelde dorp</th></tr>')) { } | |
elseif (strstr($data,'</tr>')) { $nr++; $td_first = true; } | |
elseif (strstr($data,'<td><a href="/guest.php?screen=info_player&id=')) { | |
$id[$nr]['id'] = str_replace(array('<a href="/guest.php?screen=info_player&id=','"'),'',$dataexp[1]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[2]); | |
} | |
elseif (strstr($data,'<td><a href="/guest.php?screen=info_ally&id=')) { | |
$id[$nr]['tribeid'] = str_replace(array('<a href="/guest.php?screen=info_ally&id=','"'),'',$dataexp[1]); | |
$id[$nr]['tribename'] = str_replace('</a','',$dataexp[2]); | |
} | |
elseif ((strstr($data,'<td>')) && (strstr($data,'</td>')) && ($td_first)) { | |
$id[$nr]['rank'] = str_replace(array('<td>','</td>',"\n","\r"),'',$data); | |
$td_first = false; | |
} | |
elseif (strstr($data,'<span class="grey">')) { | |
$dataexp = explode('>',str_replace(array('<span class="grey">','</span>'),'',$data)); | |
$id[$nr]['points'] = str_replace(array('</td','.'),'',$dataexp[1]); | |
$id[$nr]['villages'] = str_replace(array('</td','.'),'',$dataexp[3]); | |
$id[$nr]['gemvillages'] = str_replace(array('</td','.'),'',$dataexp[5]); | |
} | |
else { | |
$datanr++; | |
} | |
} | |
} | |
else { | |
if ((strstr($data,'<tr class="row_a">')) || (strstr($data,'<tr class="row_b">'))) { | |
$dataexp = explode('>',$data); | |
if (count($dataexp) == 19) { | |
$id[$nr]['rank'] = str_replace('</td','',$dataexp[2]); | |
$id[$nr]['id'] = str_replace(array('<a href="index.php?page=player&id=','"'),'',$dataexp[4]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[5]); | |
$id[$nr]['tribeid'] = str_replace(array('<a href="index.php?page=tribe&id=','"'),'',$dataexp[8]); | |
$id[$nr]['tribename'] = str_replace('</a','',$dataexp[9]); | |
$id[$nr]['points'] = str_replace(array('</td',','),'',$dataexp[12]); | |
$id[$nr]['villages'] = str_replace('</td','',$dataexp[14]); | |
$id[$nr]['gemvillages'] = str_replace(array('</td',','),'',$dataexp[16]); | |
} | |
else { | |
$id[$nr]['rank'] = str_replace('</td','',$dataexp[2]); | |
$id[$nr]['id'] = str_replace(array('<a href="index.php?page=player&id=','"'),'',$dataexp[4]); | |
$id[$nr]['name'] = str_replace('</a','',$dataexp[5]); | |
$id[$nr]['tribeid'] = 0; | |
$id[$nr]['tribename'] = 'NONE'; | |
$id[$nr]['points'] = str_replace(array('</td',','),'',$dataexp[10]); | |
$id[$nr]['villages'] = str_replace('</td','',$dataexp[12]); | |
$id[$nr]['gemvillages'] = str_replace(array('</td',','),'',$dataexp[14]); | |
} | |
$nr++; | |
} | |
} | |
} | |
if (isset($id)) { | |
foreach ($id as $nr => $data) { | |
if ($nr < (int)$_GET['ranks']) { | |
if ($nr < 10) $nr = '0'.$nr; | |
echo "DATA".$nr.":".$data['rank'].",".$data['id'].",".$data['name'].",".$data['tribeid'].",".$data['tribename'].",".$data['points'].",".$data['villages'].",".$data['gemvillages']."\n"; | |
} | |
} | |
} | |
else echo "ERR:101\n"; | |
echo "END:\n"; | |
} | |
else { | |
echo "Please specify a amount of ranks and a world!\n\rtw-parser.php?type=top&ranks=7&world=5\n"; | |
echo "The total of ranks may not be higher then 19! we start counting at 0\n"; | |
} | |
} | |
elseif ($_GET['type'] == 'search') { | |
if (($_GET['string'])) { | |
echo "START:\n"; | |
$fp = fsockopen($server['tw-stats'], 80, $errno, $errstr,2); | |
$fp2 = fsockopen($server['tw-stats'], 80, $errno2, $errstr2,2); | |
if (!$fp) { | |
echo "ERR:102,".$errno.",".$errstr."\n"; | |
exit(); | |
} | |
if (!$fp2) { | |
echo "ERR:102,".$errno.",".$errstr."\n"; | |
exit(); | |
} | |
fwrite($fp, "GET /index.php?page=search&type=player&name=".urlencode($_GET['string'])." HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nl.twstats.com\r\n"); | |
fwrite($fp, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
fwrite($fp2, "GET /index.php?page=search&type=tribe&name=".urlencode($_GET['string'])." HTTP/1.1\r\n"); | |
fwrite($fp2, "Host: nl.twstats.com\r\n"); | |
fwrite($fp2, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp2, "Connection: Close\r\n"); | |
fwrite($fp2, "\r\n"); | |
$nr = 0; | |
while (!feof($fp)) { | |
$data = fgets($fp, 512); | |
if ((strstr($data,'<tr class="row_a">')) || (strstr($data,'<tr class="row_b">'))) { | |
$dataexp = explode('>',str_replace(array('<tr><th width="30">Wereld</th><th>Rang</th><th>Speler</th><th>Punten</th><th>Dorpen</th><th>Stam</th></tr>'),'',$data)); | |
$userid[$nr]['world'] = str_replace('</span','',$dataexp[3]); | |
$userid[$nr]['rank'] = str_replace('</td','',$dataexp[6]); | |
$userid[$nr]['id'] = str_replace(array('<a href=','/index.php?page=player&id=',strtolower($userid[$nr]['world']),'"'),'',$dataexp[8]); | |
$userid[$nr]['name'] = str_replace('</a','',$dataexp[9]); | |
$userid[$nr]['points'] = str_replace(array('</td',','),'',$dataexp[12]); | |
$userid[$nr]['villages'] = str_replace(array('td>',','),'',$dataexp[14]); | |
$userid[$nr]['tribeid'] = str_replace(array('<a href=','/index.php?page=tribe&id=',strtolower($userid[$nr]['world']),'"'),'',$dataexp[16]); | |
$userid[$nr]['tribename'] = str_replace('</a','',$dataexp[17]); | |
if (!$userid[$nr]['tribename']) $userid[$nr]['tribename'] = 'NONE'; | |
$nr++; | |
} | |
} | |
$nr = 0; | |
while (!feof($fp2)) { | |
$data = fgets($fp2, 512); | |
if ((strstr($data,'<tr class="row_a">')) || (strstr($data,'<tr class="row_b">'))) { | |
$dataexp = explode('>',str_replace(array('<tr><th width="30">Wereld</th><th>Stam</th><th>Leden</th><th>Rang</th><th>Dorpen</th><th>Punten</th></tr>'),'',$data)); | |
$tribeid[$nr]['world'] = str_replace('</span','',$dataexp[3]); | |
$tribeid[$nr]['rank'] = str_replace('</td','',$dataexp[12]); | |
$tribeid[$nr]['tribeid'] = str_replace(array('<a href=','/index.php?page=tribe&id=',strtolower($tribeid[$nr]['world']),'"'),'',$dataexp[6]); | |
$tribeid[$nr]['tribename'] = str_replace('</a','',$dataexp[7]); | |
$tribeid[$nr]['points'] = str_replace(array('</td',','),'',$dataexp[16]); | |
$tribeid[$nr]['villages'] = str_replace(array('</td',','),'',$dataexp[14]); | |
$tribeid[$nr]['members'] = str_replace(array('</td',','),'',$dataexp[10]); | |
$nr++; | |
} | |
} | |
if (isset($userid)) { | |
foreach ($userid as $nr => $data) { | |
if ($nr < 10) $nr = '0'.$nr; | |
echo "USERDATA".$nr.":".$data['rank'].",".$data['id'].",".$data['name'].",".$data['tribeid'].",".$data['tribename'].",".$data['points'].",".$data['world']."\n"; | |
} | |
} | |
if (isset($tribeid)) { | |
foreach ($tribeid as $nr => $data) { | |
if ($nr < 10) $nr = '0'.$nr; | |
echo "TRIBEDATA".$nr.":".$data['rank'].",".$data['tribeid'].",".$data['tribename'].",".$data['points'].",".$data['villages'].",".$data['members'].",".$data['world']."\n"; | |
} | |
} | |
if ((!isset($userid)) && (!isset($tribeid))) echo "ERR:101\n"; | |
echo "END:\n"; | |
} | |
else { | |
echo "Please specify a searchstring!\n\rtw-parser.php?type=search&string=peter\n"; | |
} | |
} | |
elseif ($_GET['type'] == 'tribe') { | |
if (($_GET['tribe']) && ($_GET['world'])) { | |
echo "START:\n"; | |
if ($_GET['world'] == 'nls1') $fp = fsockopen('212.72.179.47', 80, $errno, $errstr,2); | |
else $fp = fsockopen($server['tw-stats'], 80, $errno, $errstr,2); | |
if (isset($_GET['max'])) $max = (int)$_GET['max']; | |
else $max = 10; | |
if (!$fp) { | |
echo "ERR:102,".$errno.",".$errstr."\n"; | |
exit(); | |
} | |
if ($_GET['world'] == 'nls1') { | |
$data = 'name='.urlencode($_GET['tribe']); | |
fwrite($fp, "POST /guest.php?screen=ranking&mode=ally&search HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nls1.tribalwars.nl\r\n"); | |
fwrite($fp, "Referer: http://mchosts.co.cc/mirc/tw-parser.php?type=tribe&tribe=".urlencode($_GET['tribe'])."&world=nls1\r\n"); | |
fwrite($fp, "Content-type: application/x-www-form-urlencoded\r\n"); | |
fwrite($fp, "Content-length: ". strlen($data) ."\r\n"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
fwrite($fp, $data); | |
} | |
else { | |
fwrite($fp, "GET /nl".(int)$_GET['world']."/index.php?page=rankings&mode=tribes&searchstring=".urlencode($_GET['tribe'])." HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nl.twstats.com\r\n"); | |
fwrite($fp, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
} | |
$nr = 0; | |
$nri = 0; | |
$datanr = 0; | |
$td_first = true; | |
while (!feof($fp)) { | |
$data = fgets($fp, 512); | |
if ($_GET['world'] == 'nls1') { | |
if (strstr($data,'</td><td valign="top"><table id="ally_ranking_table" class="vis">')) $liststart = true; | |
elseif ((isset($liststart)) && ($liststart)) { | |
$dataexp = explode('>',$data); | |
if (strstr($data,'</table><table class="vis" width="100%"><tr>')) $liststart = false; | |
elseif (strstr($data,'<tr><th width="60">Rang</th><th width="60">Stamnaam</th><th width="120">Punten van de 7 beste spelers</th><th width="60">Puntentotaal</th><th width="100">Leden</th><th width="100">Puntengemiddelde speler</th><th width="60">Dorpen</th><th width="100">Puntengemiddelde dorp</th></tr>')) { } | |
elseif (strstr($data,'</tr>')) { | |
if ((isset($ready)) && ($ready)) $nr++; | |
$nri = 0; | |
$td_first = true; | |
$ready = false; | |
} | |
elseif (strstr($data,'<tr class="lit">')) { $ready = true; } | |
elseif (strstr($data,'<td><a href="/guest.php?screen=info_ally&id=')) { | |
if ((isset($ready)) && ($ready)) { | |
$id[$nr]['id'] = str_replace(array('<a href="/guest.php?screen=info_ally&id=','"'),'',$dataexp[1]); | |
$id[$nr]['sname'] = str_replace('</a','',$dataexp[2]); | |
} | |
} | |
elseif ((strstr($data,'<td>')) && (strstr($data,'</td>')) && ($td_first)) { | |
if ((isset($ready)) && ($ready)) { | |
$id[$nr]['rank'] = str_replace(array('<td>','</td>',"\n","\r"),'',$data); | |
} | |
$td_first = false; | |
} | |
elseif (strstr($data,'<span class="grey">')) { | |
$dataexp = explode('>',str_replace(array('<span class="grey">','</span>'),'',$data)); | |
if ((isset($ready)) && ($ready)) { | |
if ($nri == 0) { | |
$id[$nr]['points40'] = str_replace(array('</td','.'),'',$dataexp[1]); | |
$id[$nr]['points'] = str_replace(array('</td','.'),'',$dataexp[3]); | |
} | |
elseif ($nri == 1) { | |
$id[$nr]['members'] = str_replace(array('</td','.'),'',$dataexp[1]); | |
$id[$nr]['avpp'] = str_replace(array('</td','.'),'',$dataexp[3]); | |
} | |
elseif ($nri == 2) { | |
$id[$nr]['villages'] = str_replace(array('</td','.'),'',$dataexp[1]); | |
$id[$nr]['gemvillages'] = str_replace(array('</td','.'),'',$dataexp[3]); | |
} | |
$nri++; | |
} | |
} | |
else { | |
$datanr++; | |
} | |
} | |
} | |
else { | |
if ((strstr($data,'<tr class="row_a">')) || (strstr($data,'<tr class="row_b">'))) { | |
$dataexp = explode('>',$data); | |
if ($nr < $max) { | |
$id[$nr]['rank'] = str_replace('</td','',$dataexp[2]); | |
$id[$nr]['id'] = str_replace(array('<a href="index.php?page=tribe&id=','"'),'',$dataexp[4]); | |
$id[$nr]['sname'] = str_replace('</a','',$dataexp[5]); | |
$id[$nr]['points40'] = str_replace(array('</td',','),'',$dataexp[8]); | |
$id[$nr]['points'] = str_replace(array('</td',','),'',$dataexp[10]); | |
$id[$nr]['members'] = str_replace(array('</td',','),'',$dataexp[12]); | |
$id[$nr]['avpp'] = str_replace(array('</td',','),'',$dataexp[14]); | |
$id[$nr]['villages'] = str_replace(array('</td',','),'',$dataexp[16]); | |
$id[$nr]['gemvillages'] = str_replace(array('</td',','),'',$dataexp[18]); | |
} | |
$nr++; | |
} | |
} | |
} | |
if (isset($id)) { | |
foreach ($id as $nr => $data) { | |
$data['worlds'] = 'NL'.(int)$_GET['world']; | |
if ($_GET['world'] == 'nls1') { | |
$data['bestrank'] = array('ts' => 0,'rank' => 0); | |
$data['mostpoints'] = array('ts' => 0,'points' => 0); | |
$data['mostvillages'] = array('ts' => 0,'villages' => 0); | |
$data['worlds'] = '-'; | |
$data['name'] = $data['sname']; | |
} | |
else { | |
$fp2 = fsockopen($server['tw-stats'], 80, $errno, $errstr,1); | |
if (!$fp2) { | |
echo "ERR:103,".$errno.",".$errstr."\n"; | |
} | |
else { | |
fwrite($fp2, "GET /nl".(int)$_GET['world']."/index.php?page=tribe&id=".$data['id']." HTTP/1.1\r\n"); | |
fwrite($fp2, "Host: nl.twstats.com\r\n"); | |
fwrite($fp2, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp2, "Connection: Close\r\n"); | |
fwrite($fp2, "\r\n"); | |
$nr2 = 0; | |
while (!feof($fp2)) { | |
$data2 = fgets($fp2, 1024); | |
if (strstr($data2,'<tr><th width="50%">')) { | |
$data2exp = explode('>',$data2); | |
if ($nr2 == 0) { | |
$data['name'] = str_replace('</td','',$data2exp[4]); | |
} | |
if ($nr2 == 7) { | |
if (count($data2exp) == 7) $data['bestrank'] = array('ts' => 0,'rank' => 0); | |
else $data['bestrank'] = array('ts' => strtotime(str_replace('</span','',$data2exp[5])),'rank' => str_replace(array(' <span style="float: right; font-size: xx-small"','.'),'',$data2exp[4])); | |
} | |
if ($nr2 == 8) { | |
if (count($data2exp) == 7) $data['mostpoints'] = array('ts' => 0,'points' => 0); | |
else $data['mostpoints'] = array('ts' => strtotime(str_replace('</span','',$data2exp[5])),'points' => str_replace(array(' <span style="float: right; font-size: xx-small"',','),'',$data2exp[4])); | |
} | |
if ($nr2 == 9) { | |
if (count($data2exp) == 7) $data['mostvillages'] = array('ts' => 0,'villages' => 0); | |
else $data['mostvillages'] = array('ts' => strtotime(str_replace('</span','',$data2exp[5])),'villages' => str_replace(array(' <span style="float: right; font-size: xx-small"',','),'',$data2exp[4])); | |
} | |
$nr2++; | |
} | |
if (strstr($data2,'<span class="world" style="padding-right: 6px">')) { | |
$data2exp = explode('>',strip_tags($data2,'<a>')); | |
foreach ($data2exp as $nr3 => $w) { | |
if ($nr3 & 1) $data['worlds'] = $data['worlds'].'-'.str_replace('</a','',$w); | |
} | |
} | |
} | |
} | |
} | |
if ($nr < 10) $nr = '0'.$nr; | |
$results[$data['name']] = $data; | |
} | |
//ksort($results); | |
//print_r($results); | |
$nr = 0; | |
foreach ($results as $name => $data) { | |
if ($nr < 10) $nr = '0'.$nr; | |
echo "DATA".$nr.":".$data['rank'].",".$data['id'].",".$data['sname'].",".$data['points40'].",".$data['points'].",".$data['members'].",".$data['avpp'].",".$data['villages'].",".$data['gemvillages'].",".$data['bestrank']['ts'].",".$data['bestrank']['rank'].",".$data['mostpoints']['ts'].",".$data['mostpoints']['points'].",".$data['mostvillages']['ts'].",".$data['mostvillages']['villages'].",".$data['worlds'].",".$data['name']."\n"; | |
$nr++; | |
} | |
} | |
else echo "ERR:101\n"; | |
echo "END:\n"; | |
} | |
else { | |
echo "Please specify a nickname and world!\n\rtw-parser.php?type=player&user=peter&world=5\n"; | |
} | |
} | |
elseif ($_GET['type'] == 'ennoblements') { | |
$file = 'C:\\Servers\\PHP-Batch\\TW-Bot\\veroveringen-w'.(int)$_GET['world'].'.txt'; | |
if (file_exists($file)) { | |
echo "START:\n"; | |
readfile($file); | |
echo "END:\n"; | |
} | |
else { | |
echo "Please specify a world!\n\rtw-parser.php?type=ennoblements&world=5\n"; | |
} | |
} | |
elseif ($_GET['type'] == 'ennoblementsglobal') { | |
echo "START:\n"; | |
$i = 1; | |
while ($i <= 18) { | |
$worlds[$i] = @file('C:\\Servers\\PHP-Batch\\TW-Bot\\veroveringen-w'.$i.'.txt'); | |
$nr = 0; | |
if ($worlds[$i]) { | |
foreach ($worlds[$i] as $data) { | |
$dataexp = explode(',',str_replace(array("\n", "\r"), '', $data)); | |
$dataid = explode(':',$dataexp[0]); | |
if (isset($dataexp[2])) { | |
$worlds[$i][$nr] = array(); | |
$worlds[$i][$nr]['village']['id'] = $dataid[1]; | |
$worlds[$i][$nr]['village']['data'] = $dataexp[1]; | |
$worlds[$i][$nr]['ts'] = $dataexp[2]; | |
$nr++; | |
} | |
} | |
} | |
$i++; | |
} | |
$newest['ago'] = 99999; | |
$i = 1; | |
while ($i <= 18) { | |
if ($worlds[$i]) { | |
foreach ($worlds[$i] as $nr => $data) { | |
if ((time() - $data['ts']) < $newest['ago']) { | |
$newest['ago'] = (time() - $data['ts']); | |
$newest['w'] = $i; | |
$newest['id'] = $nr; | |
$newest['data'] = $data; | |
} | |
} | |
} | |
$i++; | |
} | |
echo "DATA00:".$newest['w'].",".$newest['data']['village']['id'].",".$newest['data']['village']['data'].",".$newest['data']['ts']."\n"; | |
echo "END:\n"; | |
} | |
elseif ($_GET['type'] == 'forumupdates') { | |
echo "START:\n"; | |
$fp = fsockopen('212.48.99.142', 80, $errno, $errstr,2); | |
if (!$fp) { | |
echo "ERR:102,".$errno.",".$errstr."\n"; | |
exit(); | |
} | |
fwrite($fp, "GET / HTTP/1.1\r\n"); | |
fwrite($fp, "Host: forum.tribalwars.nl\r\n"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
$info = array(); | |
$nr = 0; | |
while (!feof($fp)) { | |
$data = fgets($fp, 512); | |
if (strstr($data, '<!-- logged-in users -->')) $Box_LoggedIn = true; | |
elseif (strstr($data, '<!-- logged-in users -->')) $Box_LoggedIn = false; | |
elseif (isset($Box_LoggedIn)) { | |
if (($Box_LoggedIn) && (strstr($data, '<a href="online.php?s=')) && (strstr($data, '">')) && (!strstr($data, '<td class="alt2">'))) { | |
$dataexp = explode(' ', strip_tags($data.'</a>')); | |
$info['Online'][] = $dataexp[5]; | |
$info['Online'][] = str_replace('(', '', $dataexp[6]); | |
$info['Online'][] = $dataexp[9]; | |
} | |
elseif (($Box_LoggedIn) && (strstr($data, '<div style="white-space: nowrap">'))) { | |
$dataexp = explode(' ', strip_tags($data.'</a>')); | |
$info['Record'][] = str_replace(array(',', '.'), '', $dataexp[4]); | |
$info['Record'][] = $dataexp[6].' '.$dataexp[7].' '.$dataexp[8]; | |
$info['Record'][] = str_replace('.', '', $dataexp[12]); | |
$Box_LoggedUsers = true; | |
} | |
elseif (isset($Box_LoggedUsers)) { | |
if (($Box_LoggedUsers) && (strstr($data, '<div>'))) { | |
$dataexp = explode('<', strip_tags($data.'</a>')); | |
print_r($dataexp); | |
//echo $data; | |
} | |
elseif (($Box_LoggedUsers) && (strstr($data, '</tbody>'))) { | |
$Box_LoggedUsers = false; | |
} | |
} | |
} | |
} | |
print_r($info); | |
echo "END:\n"; | |
} | |
elseif ($_GET['type'] == 'playervillages') { | |
$fp = fsockopen($server['tw-stats'], 80, $errno, $errstr,1); | |
if (!$fp) { | |
echo "ERR:103,".$errno.",".$errstr."\n"; | |
} | |
else { | |
fwrite($fp, "GET /nl".(int)$_GET['world']."/index.php?page=player&mode=villages&id=".$_GET["id"]."&pn=-1 HTTP/1.1\r\n"); | |
fwrite($fp, "Host: nl.twstats.com\r\n"); | |
fwrite($fp, "User-Agent: Mozilla TW-Bot Parser QuakeNet #TWBot\n\r"); | |
fwrite($fp, "Connection: Close\r\n"); | |
fwrite($fp, "\r\n"); | |
$nr = 0; | |
while (!feof($fp)) { | |
$data = fgets($fp, 1024); | |
if ((strstr($data,'<tr class="row_a">')) || (strstr($data,'<tr class="row_b">'))) { | |
$dataexp = explode('<', $data); | |
$dataexp2 = explode('>', $dataexp[3]); | |
$villages[$nr]['ID'] = str_replace(array('a href="index.php?page=village&id=', '"'), '', $dataexp2[0]); | |
$villages[$nr]['Name'] = $dataexp2[1]; | |
$villages[$nr]['Points'] = str_replace(array('td>', ','), '', $dataexp[6]); | |
$villages[$nr]['XY'] = str_replace('td>', '', $dataexp[8]); | |
$villages[$nr]['Continent'] = str_replace('td>', '', $dataexp[10]); | |
$nr++; | |
} | |
} | |
print_r($villages); | |
} | |
} | |
else { | |
echo "Please specify a type!\rtw-parser.php?type=player|playerod|search|top|tribe|tribeod\n"; | |
} | |
} | |
else { | |
echo "Please specify a type!\rtw-parser.php?type=player|playerod|search|top|tribe|tribeod\n"; | |
} | |
?> | |
</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment