<?php
error_reporting(E_ALL);
require_once 'GameQ.php';
// Define your servers,
// see list.php for all supported games and identifiers.
$servers = array(
'server 1' => array('cube', 'ca.hype-clan.com', 57576),
'server 2' => array('cube', 'us.hype-clan.com', 22023),
);
// Call the class, and add your servers.
$gq = new GameQ();
$gq->addServers($servers);
// You can optionally specify some settings
$gq->setOption('timeout', 200);
// You can optionally specify some output filters,
// these will be applied to the results obtained.
$gq->setFilter('normalise');
$gq->setFilter('sortplayers', 'gq_ping');
// Send requests, and parse the data
$results = $gq->requestData();
// Some functions to print the results
function print_results($results) {
foreach ($results as $id => $data) {
printf("<h2>%s</h2>\n", $id);
print_table($data);
}
}
function print_table($data) {
$gqs = array('gq_online', 'gq_address', 'gq_port', 'gq_prot', 'gq_type');
if (!$data['gq_online']) {
printf("<p>The server did not respond within the specified time.</p>\n");
return;
}
print("<table><thead><tr><td>Variable</td><td>Value</td></tr></thead><tbody>\n");
foreach ($data as $key => $val) {
if (is_array($val)) continue;
$cls = empty($cls) ? ' class="uneven"' : '';
if (substr($key, 0, 3) == 'gq_') {
$kcls = (in_array($key, $gqs)) ? 'always' : 'normalise';
$key = sprintf("<span class=\"key-%s\">%s</span>", $kcls, $key);
}
printf("<tr%s><td>%s</td><td>%s</td></tr>\n", $cls, $key, $val);
}
print("</tbody></table>\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>GameQ - Example script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
* {
font-size: 9pt;
font-family: Verdana, sans-serif;
}
h1 {
font-size: 12pt;
}
h2 {
margin-top:2em;
font-size: 10pt;
}
table {
border: 1px solid #000;
background-color: #DDD;
border-spacing:1px 1px;
}
table thead {
font-weight: bold;
background-color: #CCC;
}
table tr.uneven td {
background-color:#FFF;
}
table td {
padding: 5px 8px;
}
table tbody {
background-color: #F9F9F9;
}
.note {
color: #333;
font-style:italic;
}
.key-always {
color:red;
font-weight:bold;
}
.key-normalise {
color:red;
}
</style>
</head>
<body>
<h1>Server Stats</h1>
<div class="note">
I fail at making this thing work so far! <br/>
<span class="key-always">Failed Attempt!</span> Time to go back and try again.
Additionally, I hope I will figure this <span class="key-normalise">STUFF</span> out as soon as I can.<br/>
I appoligize for any inconveniences!.<br/>
<br/>
</div>
<?php
print_results($results);
?>
</body>
</html>
Bookmarks