» News » TomeNET monster search » TomeNET servers » Getting started » Online TomeNET Guide » Installation on Linux » Downloads » Images » Maps » FAQs and HOWTOs » Spoilers » Links » Videos
|
TomeNET Metaserver Web Interface
<?php
$page_title = 'TomeNET servers'; require('header.inc.php');
echo('<h1>TomeNET Metaserver Web Interface</h1>');
if (array_key_exists('source', $_GET)) { show_source('meta.php'); require('footer.inc.php'); die(); }
$addr = 'ovh.muuttuja.org'; $port = 8801;
$meta = ''; $servers = array();
$xml_parser = xml_parser_create(); $tag_tree = array();
function startElement($parser, $name, $attrs) { global $tag_tree, $server, $player, $game, $version; array_unshift($tag_tree, $name); switch ($name) { case 'SERVER': $server = array('url' => $attrs['URL'], 'port' => $attrs['PORT'], 'players' => array()); break; case 'PLAYER': $player = ''; break; case 'GAME': $game = ''; break; case 'VERSION': $version = ''; break; } }
function endElement($parser, $name) { global $tag_tree, $servers, $server, $player, $game, $version; array_shift($tag_tree); switch ($name) { case 'SERVER': $servers[] = $server; break; case 'PLAYER': $server['players'][] = $player; break; case 'GAME': $server['game'] = $game; break; case 'VERSION': $server['version'] = $version; break; } }
function charData($parser, $data) { global $tag_tree, $meta_name, $player, $game, $version; switch ($tag_tree[0]) { case 'META': $meta_name .= $data; break; case 'PLAYER': $player .= $data; break; case 'GAME': $game .= $data; break; case 'VERSION': $version .= $data; break; } }
$fp = fsockopen($addr, $port, $errno, $errstr, 2);
if ($fp !== FALSE) {
xml_set_element_handler($xml_parser, 'startElement', 'endElement'); xml_set_character_data_handler($xml_parser, 'charData');
xml_parse($xml_parser, '<servers>');
while (!feof($fp)) { $data = fread($fp, 8192); if (!xml_parse($xml_parser, $data)) { printf("XML error: %s at line %d\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)); } }
fclose($fp);
if (!xml_parse($xml_parser, '</servers>', TRUE)) { printf("XML error: %s at line %d\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)); }
xml_parser_free($xml_parser);
?>
<h2><?php echo(htmlentities($meta_name)); ?></h2> <table border="1" cellpadding="2" cellspacing="0"> <tr><th>Name</th><th>Port</th><th>Number of Players</th><th>Players</th><th>Game</th><th>Version</th></tr> <?php foreach ($servers as $server) { echo('<tr><td>' . htmlentities($server['url']) . '</td>'); echo('<td align="center">' . htmlentities($server['port']) . '</td>'); echo('<td align="center">' . count($server['players']) . '</td>'); if (count($server['players'])) { echo('<td align="center">' . htmlentities(implode(', ', $server['players'])) . '</td>'); } else { echo('<td align="center"> </td>'); } echo('<td align="center">' . htmlentities($server['game']) . '</td>'); echo('<td align="center">' . htmlentities($server['version']) . "</td></tr>\n"); } ?> </table> <?php } else { printf('<p>Couldn\'t connect to meta! (errno = %d, errstr = "%s")</p>', $errno, $errstr); ?> <p>Alternative server list:<br> <a href="http://www.tomenet.net/meta.php">http://www.tomenet.net/meta.php</a></p> <?php } ?> <p><a href="meta.php?source=1">Source code</a></p> <?php require('footer.inc.php'); ?>
|