rendered paste body<?php
// Output page header
$xname = "Server Name";
$xsettings = "Settings";
$xwebsite = "Website";
$xipaddress = "IP Address";
$xversion = "Version";
$xplayers = "Players";
$page_title = "Online Server Browser";
$fileUrl = 'http://wrtlprnft.ath.cx/serverlist/serverxml.php';
$AgetHeaders = @get_headers($fileUrl);
if (preg_match("|200|", $AgetHeaders[0])) {
function colourize($string){
$string= '0xffffff' . $string;
$string= htmlspecialchars($string, ENT_QUOTES);
foreach(explode("0x",$string) as $code) {
if(empty($code)) continue;
$str.= '<span style="color:#' . substr($code,0,6).';">' . substr($code,6).'</span>';
}
$str=strip_tags($str, '<span>');
return $str;
}
function get_server_list($stripcolors = false) {
global $get_server_list_servers;
$get_server_list_servers = array();
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "get_server_list_start_element", "get_server_list_end_element");
if(!xml_parse($xml_parser, file_get_contents( 'http://wrtlprnft.ath.cx/serverlist/serverxml.php' . ($stripcolors ? '?stripcolors' : '')), true)) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
return $get_server_list_servers;
}
function get_server_list_start_element($parser, $name, $attrs) {
global $get_server_list_servers;
switch($name) {
case 'SERVERS':
$get_server_list_servers[0] = $attrs['AGE'];
break;
case 'SERVER':
$server = array();
foreach($attrs as $name => $value) {
$server[strtolower($name)] = $value;
}
$server['players'] = array();
$get_server_list_servers[] = $server;
break;
case 'PLAYER':
if(count($get_server_list_servers) == 0) {
die('Error in XML file: Player start tag without Server start tag');
}
$get_server_list_servers[count($get_server_list_servers) - 1]['players'][] = $attrs['NAME'];
break;
}
}
function get_server_list_end_element($parser, $name) {
}
$serverlist=get_server_list(false);
$age=$serverlist['0'];
unset($serverlist['0']);
//print_r(get_server_list(true));
//print('<pre>');
//print_r($serverlist);
//print('</pre>');
function sabsi ($array, $index, $order='asc', $natsort=FALSE, $case_sensitive=FALSE) {
if(is_array($array) && count($array)>0) {
foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
if(!$natsort) ($order=='asc')? asort($temp) : arsort($temp);
else {
($case_sensitive)? natsort($temp) : natcasesort($temp);
if($order!='asc') $temp=array_reverse($temp,TRUE);
}
foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key];
return $sorted;
}
return $array;
}
if (isset($_REQUEST['sort']))
$sort=$_REQUEST['sort'];
else
$sort="numplayers";
if (isset($_REQUEST['ascdesc']))
$ascdesc=$_REQUEST['ascdesc'];
else
$ascdesc="desc";
$total_players=0;
$total_slots=0;
$total_servers=0;
$serverlist = sabsi($serverlist, $sort, $ascdesc, true);
/*print('<pre>');
print_r($serverlist);
print('</pre>'); */
$table='<table align="center" background="./images/grid.png">';
foreach ( $serverlist as $server ){
$description=($server['description']=="")?'<span style="color:#ffffff;">No Description.</span>':colourize(mb_convert_encoding($server['description'], "ISO-8859-1", "UTF-8"));
$table .='<table background="./images/grid.png" width="100%" style="border: 1px #555555 solid; border-collapse: collapse;
border-spacing: 0px;"><tr>
<td><th>' . $xname . '</th></td><td style="width: 1000px; padding:6px;"><b>' . colourize(mb_convert_encoding($server['name'], "ISO-8859-1", "UTF-8")) . ' <span style="color:#ffffff;">(' . $server['numplayers'] . '/' . $server['maxplayers'] . ')</span></b></td></tr>
<tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;"><td><th>' . $xplayers . '</th></td><td colspan="4" style="padding:6px;">
';
$total_players+=$server['numplayers'];
$total_slots+=$server['maxplayers'];
$total_servers++;
if ( count( $server['players'] ) ==0 ){
$table .= '<span style="color:#ffffff;">No Online Players.</span></td></tr><tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th><img src="http://durkadurkaland.com/templates/fisubice/images/icon_down_arrow.gif"><img src="http://durkadurkaland.com/templates/fisubice/images/icon_down_arrow.gif"><img src="http://durkadurkaland.com/templates/fisubice/images/icon_down_arrow.gif"></th></td><td colspan="4" style="padding:6px;"><font color="#ff8888">Click here to view more server details.</font></td></tr><tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th>' . $xsettings . '</th></td><td colspan="4" style="padding:6px;">' . $description . '</td></tr>
<tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th>' . $xwebsite . '</th></td><td colspan="4" style="padding:6px;"><a href="' . $server['url'] . '">' . colourize($server['url']) . '</a></td></tr>
<tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th>' . $xipaddress . '</th></td><td colspan="4" style="padding:6px;">' . colourize($server['ip']) . '<span style="color:#ffffff;">:</span>' . colourize($server['port']) . '</td></tr>
<tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th>' . $xversion . '</th></td><td colspan="4" style="padding:6px;">' . colourize($server['version']) . '</td></tr><hr>';
} else {
$i=count( $server['players'] );
foreach ( $server['players'] as $onlineplayer ){
$table .= colourize(mb_convert_encoding($onlineplayer, "ISO-8859-1", "UTF-8"));
$i--;
if ($i != 0)
$table .= '<span style="color:#ffffff;">, </span>';
else
$table .= '<span style="color:#ffffff;">.</span></td></tr><tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th><img src="http://durkadurkaland.com/templates/fisubice/images/icon_down_arrow.gif"><img src="http://durkadurkaland.com/templates/fisubice/images/icon_down_arrow.gif"><img src="http://durkadurkaland.com/templates/fisubice/images/icon_down_arrow.gif"></th></td><td colspan="4" style="padding:6px;"><font color="#ff8888">Click here to view more server details.</font></td></tr>
<tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th>' . $xsettings . '</th></td><td colspan="4" style="padding:6px;">' . $description . '</td></tr>
<tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th>' . $xwebsite . '</th></td><td colspan="4" style="padding:6px;"><a href="' . $server['url'] . '">' . colourize($server['url']) . '</a></td></tr>
<tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th>' . $xipaddress . '</th></td><td colspan="4" style="padding:6px;">' . colourize($server['ip']) . '<span style="color:#ffffff;">:</span>' . colourize($server['port']) . '</td></tr>
<tr style="border-top: 1px #555555 solid;border-bottom: 1px #555555 solid;">
<td><th>' . $xversion . '</th></td><td colspan="4" style="padding:6px;">' . colourize($server['version']) . '</td></tr><hr>';
}
}
$table .='</table>';
}
$table .= '</table>';
print ('<table align="center">
<tr>
<th align="right"><b>Players Online:</b></th>
<th align="right"><b>' . $total_players . '</b></th>
</tr>
<tr>
<th align="right"><b>Servers Online:</b></th>
<th align="right"><b>' . $total_servers . '</b></th>
</tr>
<tr>
<th align="right"><b>Data Age in Seconds:</b></th>
<th align="right"><b>' . $age . '</b></th>
</tr>
</table>
');
?>
<br>
<table align=center border=0 cellpadding=2 cellspacing=1 class="forumline">
<tr>
<td class="cat">Sort Field:</td>
<td class="cat"><form method="get" action=<?php print($_SERVER['_FILE_']); ?>>
<select name="sort">
<option value="numplayers" <?php ($sort=="numplayers")?print"selected":print""?>>numplayers
<option value="maxplayers" <?php ($sort=="maxplayers")?print"selected":print""?>>maxplayers
<option value="name" <?php ($sort=="name")?print"selected":print""?>>name
<option value="ip" <?php ($sort=="ip")?print"selected":print""?>>ip
<option value="url" <?php ($sort=="url")?print"selected":print""?>>url
<option value="version" <?php ($sort=="version")?print"selected":print""?>>version
</select></td>
<td class="cat"><select name="ascdesc">
<option value="asc" <?php ($ascdesc=="asc")?print"selected":print""?>>asc
<option value="desc" <?php ($ascdesc=="desc")?print"selected":print""?>>desc
</select></td>
<td class="cat"><input type="submit" value="Go!"></input></form></td>
</tr>
</table>
<?php
} else {
$players .= 'Online Server Browser Disabled.';
}
print $table;
?>