are you looking into doing it for PHP/ Perl or something else?
if php here's an example getstatus function which u can use:
Code:
function getstatus($server, $port = 29070)
{
if (!($fd = @fsockopen("udp://$server", $port, $errno, $errstr, 3)))
return FALSE;
stream_set_timeout($fd, 3, 0);
# challenge?
fwrite($fd, "\xff\xff\xff\xffgetstatus " . rand());
# getstatus reply should always come as a single (possibly
# fragmented) datagram
if (!($buf = @fread($fd, 4096))) {
echo("Server is not responding<br>\n");
return FALSE;
}
$parts = explode("\n", $buf);
if ($parts[0] != "\xff\xff\xff\xffstatusResponse") {
echo("bad response<br>\n");
return FALSE;
}
# build an array of all the serverinfo keys
$infostring = explode("\\", $parts[1]);
array_shift($infostring);
$side = 0;
while (list($idx, $str) = each($infostring)) {
if ($side == 0)
$key = $str;
else
$info[$key] = $str;
$side ^= 1;
}
# build an array of all the players
# start by shifting off the response header and the serverinfo
array_shift($parts);
array_shift($parts);
# and then looping through what's left
while (list($idx, $str) = each($parts)) {
if ($str == "")
break;
$playerparts = explode("\"", $str);
$playerinfo = $playerparts[0];
$name = $playerparts[1];
$scoreping = explode(" ", $playerinfo);
$score = $scoreping[0];
$ping = $scoreping[1];
$playerlist[$idx]['slot'] = $slot;
$playerlist[$idx]['team'] = $team;
$playerlist[$idx]['score'] = $score;
$playerlist[$idx]['ping'] = $ping;
$playerlist[$idx]['name'] = $name;
}
return array(info => $info, players => $playerlist);
}
u basically call something like this above all the printing stuff:
Code:
$ip = "your.ip.goes.here";
$port = "29070";
$status = getstatus($ip, $port);
to get a cvar u would do something like this:
Code:
<?php printf("%s", $status['info']['sv_hostname']); ?>
because there isnt another easy way to do this here's my example way of getting player count (not sure its 100% correct)
Code:
<?php
if ($status['players']) {
uasort($status['players'], sort_by_score_desc);
$playercount=0;
while (list($idx, $curplayer) = each($status['players'])) {
$playercount++;
}
$status['info']['sv_currentclients']=$playercount;
}
?>
(just print out the sv_currentclients cvar if u use this method)
basically this is how i print out players:
Code:
<table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000" width="100%">
<tr>
<td align="left"><font size="2" color="#EEEEEE"><b><u>Players</u></b></font></td>
<td width="30" align="center"><font size="2" color="#EEEEEE"><b><u>Score</u></b></font></td>
<td width="30" align="center"><font size="2" color="#EEEEEE"><b><u>Ping</u></b></font></td>
</tr>
<?php
if ($status['players']) {
uasort($status['players'], sort_by_score_desc);
while (list($idx, $curplayer) = each($status['players'])) {
printf(" <tr>\n<td align=left><font size=2>%s</font></td><td width=30 align=center><font size=2>%d</font></td><td width=30 align=center><font size=2>%d</font></td></tr>\n",
$curplayer['name'],
$curplayer['score'],
$curplayer['ping']);
}
}
?>
</table>
now,,, you might want to colorize say the hostname or player names so:
Code:
<?php
$osp_colors = array(
0 => "#666666", // to show black text on black bg...
//0 => "#000000",
1 => "#ff0000",
2 => "#00ff00",
3 => "#ffff00",
4 => "#0000ff",
5 => "#00ffff",
6 => "#ff00ff",
7 => "#ffffff", // maybe change this if you use a white bg
8 => "#ff7f00",
9 => "#7f7f7f",
10 => "#bfbfbf",
11 => "#bfbfbf",
12 => "#007f00",
13 => "#7f7f00",
14 => "#00007f",
15 => "#7f0000",
16 => "#7f3f00",
17 => "#ff9919",
18 => "#007f7f",
19 => "#7f007f",
20 => "#007fff",
21 => "#7f00ff",
22 => "#3399cc",
23 => "#ccffcc",
24 => "#006633",
25 => "#ff0033",
26 => "#b21919",
27 => "#993300",
28 => "#cc9933",
29 => "#999933",
30 => "#ffffbf",
31 => "#ffff7f"
);
function colorize($text)
{
global $osp_colors;
$curcolor = -1;
$nextcolor = 7;
for ($x = 0; $x < strlen($text); $x++) {
if ($text[$x] == '^' && $text[$x + 1] != '^') {
$nextcolor = (ord($text[$x + 1]) + 16) & 31;
$x++;
continue;
}
if ($curcolor != $nextcolor) {
if ($curcolor != -1)
$buf .= "</font>";
$curcolor = $nextcolor;
$buf .= sprintf("<font color=\"%s\">", $osp_colors[$curcolor]);
}
//$chars = "¤";
$buf .= htmlspecialchars($text[$x]);
}
if ($curcolor != -1)
$buf .= "</font>";
return $buf;
}
just do something like this:
Code:
<?php printf("%s", colorize($status['info']['sv_hostname'])); ?>