<?php header('Content-type: text/html', TRUE);
?>
<?php
?>
<?php
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n";
echo "<?xml-stylesheet href=\"style.css\" type=\"text/css\"?>\n";
?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>gsQuery Example</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<!--
To use this example simply add the following params to the URI:
host: The game server's hostname or IP
queryport: The game server's queryport
protocol: The protocol to use (currently gameSpy, hlife, q3a, vietkong, rvnshld, armyGame)
Example:
http:
Note: You have to adjust the path in the include statment if you want to use the example outside of the gsQuery example directory
-->
<div id="basicInfo" class="block">
<?php
if(isset($_GET['debug'])) {
error_reporting(E_ALL);
}
if(isset($_GET['url'])) {
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR .'..'.
DIRECTORY_SEPARATOR .'src'.
DIRECTORY_SEPARATOR .'gsQuery.php';
$gameserver=gsQuery::unserializeFromURL($_GET['url']);
if(!$gameserver) {
echo 'Could not fetch the serialized object.';
}
} else {
$gameserver=queryServer($_GET['host'], $_GET['queryport'], $_GET['protocol']);
}
if(!$gameserver) { echo '</div></body></html>'; exit(0); }
$version = $gameserver->version;
basicInfo($gameserver);
?>
</div>
<div id="players" class="block">
<?php players($gameserver); ?>
</div>
<div id="rules" class="block">
<?php rules($gameserver); ?>
</div>
<div id="debug" class="block">
<?php if(isset($_GET['debug'])) { debugInfo($gameserver); } ?>
</div>
<div id="footer">
<a href="http://validator.w3.org/check/referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31" width="88"/></a>
<a href="http://jigsaw.w3.org/css-validator/">
<img style="border:0;width:88px;height:31px"
src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="Valid CSS!"/></a>
<p>
Powered by <a href="http://www.gsquery.org">gsQuery</a>
<?php echo $version; ?>
</p>
</div>
</body>
</html>
<?php
function queryServer($address, $port, $protocol)
{
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR .'..'.
DIRECTORY_SEPARATOR .'src'.
DIRECTORY_SEPARATOR .'gsQuery.php';
if(!$address && !$port && !$protocol) {
echo "No parameters given\n";
return FALSE;
}
$gameserver=gsQuery::createInstance($protocol, $address, $port);
if(!$gameserver) {
echo "<h1>Could not instantiate gsQuery class. Does the protocol you've specified exist?</h1>\n";
return FALSE;
}
if(!$gameserver->query_server(TRUE, TRUE)) {
echo '<h1>Error: '. ($gameserver->errstr ? $gameserver->errstr : 'Could not query the server / No response received') ."</h1>\n";
if(array_key_exists('debug', $_GET) && $_GET['debug']) {
debugInfo($gameserver);
}
return FALSE;
}
return $gameserver;
}
function basicInfo($gameserver)
{
echo '<table><caption>Generic</caption>';
echo "<tr><td>Servername:</td><td>".$gameserver->htmlize($gameserver->servertitle)."</td></tr>\n";
if($gameserver->gameversion!="") {
echo "<tr><td>Version:</td><td>".htmlentities($gameserver->gameversion)."</td></tr>\n";
}
echo "<tr><td>Players/Max Players:</td><td>".htmlentities($gameserver->numplayers)."/".htmlentities($gameserver->maxplayers)."</td></tr>\n";
echo "<tr><td>Mapname/Maptitle:</td><td>".htmlentities($gameserver->mapname);
if($gameserver->maptitle) {
echo " / ".htmlentities($gameserver->maptitle)."</td></tr>\n";
} else {
echo "</td></tr>";
}
echo "<tr><td>Gametype:</td><td>".htmlentities($gameserver->gametype)."</td></tr>\n";
echo "</table>";
}
function players($gameserver)
{
if(!count($gameserver->players)) {
echo "No Players";
return FALSE;
}
$result="<table><caption>Players</caption>\n<tr>";
foreach($gameserver->playerkeys as $key => $value) {
if($value) {
$result.="<th>".$key."</th>\n";
}
}
$result.="</tr>";
foreach($gameserver->players as $player) {
$result.="<tr>";
foreach($gameserver->playerkeys as $key => $value) {
if($value) {
$result.="<td class=\"player".htmlentities($key)."\">".$gameserver->htmlize($player[$key])."</td>\n";
}
}
$result.="</tr>\n";
}
$result.="</table>";
echo $result;
}
function rules($gameserver)
{
if(!count($gameserver->rules)) {
echo "No rules";
return FALSE;
}
$result="<table><caption>Rules</caption><tr><th>Key</th><th>Value</th></tr>\n";
foreach($gameserver->rules as $key => $value) {
$result.="<tr><td class=\"rulekey\">".$key."</td><td>".$value."</td></tr>\n";
}
$result.="</table>";
echo $result;
}
function debugInfo($gameserver)
{
$dumps = $gameserver->getDebugDumps(TRUE);
echo "<table><caption>Debug</caption><tr><th>Send</th><th>Received</th></tr>\n";
foreach ($dumps as $curDebug) {
echo "<tr><td>".$curDebug[0]."</td><td>".$curDebug[1]."</td></tr>\n";
}
echo "</table>";
}
?>