<?php
/*
Okay. This is the hacked-up version of the livestatus script we use a dontcamp.com.
It should work once you plug in the right ip and port below. I don't intend this script
to be a normal package deal with support and all that. I still don't have enough time to
devote to getting this all polished and gift-wrapped. I tried to take out all the stylesheet
and link references to dontcamp.com that I could, so it should work alright.
That all said, if you aren't a php guy, this script should work for you. If you are a PHP guy,
I apologize for the lack of comments, and wish you luck on tearing this down and rebuilding it
should you choose to do so. Hopefully it's nice to your error logs.
BF:V support is very easy to add, if we're calling this a 1.0, it'll be in 1.1.
--dst
*/
//The Variables
//The page output is template-ish at the bottom for easier customization of the final product.
//Team names. Team 1 is red, Team 2 is blue.
$t1name = 'Axis';
$t2name = 'Allies';
//Your game server IP
$bfip = '192.168.1.2';
//Your game server's GameSpy query port, default 23000 for BF1942
$bfport = '23000';
//How many seconds to wait for the query to return.
//Might need to be set higher for slower connections.
$timeout = '2';
//How often you'd like the page to autorefresh, in seconds.
//Delete all the lines with $refresh in it to make it not auto-refresh.
$refresh = '60';
//A few different options passable through the browser address.
//Adding ?debug=1 will spit out the arrays of data from the server
//The sort variable is handled via the script, so click around to figure it out.
if (!array_key_exists('sort', $_REQUEST)) $sort = 'score'; else $sort = $_REQUEST['sort'];
if (!array_key_exists('debug', $_GET)) $debug = '0'; else $debug = $_GET['debug'];
//Function Definitions
function stripquotes($string) {
$string = trim($string, "\"");
return $string;
}
function superstrip ($str) {
$str = ereg_replace('<[^>]*>|\([^)]*\)|\{[^}]*\}|\[[^]]*\]|\|[^|]*\|', '', $str);
$str = ereg_replace('[^[:alnum:]]', '', $str);
$str = strtolower($str);
return $str;
}
function cleanascii ($string) {
$count = strlen($string);
$i = '0';
$newstring = '';
while ($i < $count) {
$astring[] = $string{$i};
$i++;
}
foreach ($astring as $value) {
$ord = ord($value);
$good = "&#$ord;";
$value = ereg_replace("[^[:alnum:][:punct:][:space:]]|<|>|\"|\'|&", $good, $value);
$newstring .= $value;
}
return $newstring;
}
//The part that gathers and chews UDP data aka unreliable world
$socket = fsockopen("udp://$bfip", $bfport);
fwrite($socket, "\\info\\");
$buffer = "";
$sockstatus = socket_get_status($socket);
while ( substr($buffer,-7) != "\final\\" && !$sockstatus['timed_out'] ) {
socket_set_timeout($socket, $timeout);
$buffer .= fread($socket,1);
$sockstatus = socket_get_status($socket);
}
$pair = explode("\\", $buffer);
for ($i=1; $i<count($pair)-2; $i++) { // -2 because the last pair is "final"
if ( $pair[$i] != "queryid" ) {
$info[$pair[$i]] = $pair[$i+1];
}
$i++;
}
if ($sockstatus['timed_out'] == 1) {
$error = 'Server is temporarily down or changing maps.';
unset($sockstatus['timed_out']); }
$socket = fsockopen("udp://$bfip", $bfport);
fwrite($socket, "\\players\\");
$buffer = "";
$sockstatus = socket_get_status($socket);
while ( substr($buffer,-7) != "\final\\" && !$sockstatus['timed_out']) {
socket_set_timeout($socket, $timeout);
$buffer .= fread($socket,1);
$sockstatus = socket_get_status($socket);
}
$pair = explode("\\", $buffer);
reset($pair);
each($pair);
for ($i=1; $i<count($pair)-2; $i++) { // -2 because the last pair is "final"
each($pair);
for ($i=1; $i<count($pair)-2; $i++) { // -2 because the last pair is "final"
each($pair);
for ($i=1; $i<count($pair)-2; $i++) { // -2 because the last pair is "final"
$array = each($pair);
$rule = $array[1];
if ( $rule != "queryid" ) {
$array = each($pair);
$value = $array[1];
$array = explode("_", $rule);
//Dupe name prevention:
if ($array[1] < @$info['numplayers'] && $array[0] != "teamname") {
$game[$array[0]]['p'.$array[1]] = $value; }
} else {
each($pair); }
$i++;
}
fclose($socket);
//Content Generation
if (@$info && @$info['numplayers'] == 0) {
$error = 'Server is empty or changing maps.';
unset($info);
}
if (@$game['error']) {
$error = $game['error'];
}
if ($info['tickets2'] > $info['tickets1']) {
$tickets = $info['tickets2'] - $info['tickets1'];
if ($tickets == '1') $tickets = "<b>$tickets</b> ticket";
else $tickets = "<b>$tickets</b> tickets";
$twinning = "<b>$t2name</b> is currently winning by $tickets."; }
elseif ($info['tickets1'] > $info['tickets2']) {
$tickets = $info['tickets1'] - $info['tickets2'];
if ($tickets == '1') $tickets = "<b>$tickets</b> ticket";
else $tickets = "<b>$tickets</b> tickets";
$twinning = "<b>$t1name</b> is currently winning by $tickets."; }
else {
$twinning = "The teams are currently tied at <b class=highlight>{$info['tickets1']}</b> tickets"; };
switch ($sort) {
case 'score':
@array_multisort($game['score'], SORT_DESC, $game['kills'], SORT_DESC, $game['deaths'], SORT_ASC);
$sortprint = 'score'; break;
case 'kills':
@array_multisort($game['kills'], SORT_DESC, $game['score'], SORT_DESC, $game['deaths'], SORT_ASC);
$sortprint = 'kills'; break;
case 'deaths':
@array_multisort($game['deaths'], SORT_DESC, $game['kills'], SORT_DESC, $game['score'], SORT_DESC);
$sortprint = 'deaths'; break;
case 'ping':
@array_multisort($game['ping'], SORT_ASC, $game['score'], SORT_DESC, $game['kills'], SORT_DESC, $game['deaths'], SORT_ASC);
$sortprint = 'ping'; break;
case 'lowername':
foreach ($game['playername'] as $key => $value) {
$value = html_entity_decode($value);
$game['lowername'][$key] = superstrip($value); }
array_multisort($game['lowername'], SORT_ASC, SORT_STRING, $game['score'], SORT_DESC, $game['kills'], SORT_DESC, $game['deaths'], SORT_ASC);
$sortprint = 'player name'; break; }
if (@$game[$sort]) foreach ($game[$sort] as $player => $crap) {
$playername = &$game['playername'][$player];
if ($stripout) $playername = superstrip($playername);
$keyhash = &$game['keyhash'][$player];
$score = &$game['score'][$player];
$kills = &$game['kills'][$player];
$deaths = &$game['deaths'][$player];
$ping = &$game['ping'][$player];
$team = &$game['team'][$player];
$playername = cleanascii($playername);
$listadd = "\t<tr>
<td><a href=\"$link$keyhash\"$color>$playername</a></TD>
<td align=center>$score</TD>
<td align=center>$kills</TD>
<td align=center>$deaths</TD>
<td align=center>$ping</TD>
</tr>\n";
if ($team == 1) {
$t1list .= $listadd;
$t1score += $score;
$t1kills += $kills;
$t1deaths += $deaths;
$t1ping += $ping;
$t1++;
}
if ($team == 2) {
$t2list .= $listadd;
$t2score += $score;
$t2kills += $kills;
$t2deaths += eaths;
$t2ping += $ping;
$t2++;
}
$numplayers++;
}
if ($small == 1) echo("<center><table border=0 width=640>");
if ($small != 1) {
//Page output goes here
?>
<html>
<head>
<title><?=$info['hostname'];?> Live Server Status</title>
<meta http-equiv='refresh' content='<?=$refresh;?>'>
</head>
<body>
<div align=center>
<table border=0 width=600>
<tr><td colspan=2 align=center>
<h1><?=$info['hostname'];?> Server Status:</h1>
There are <b><?=$info['numplayers'];?></b> out of <b><?=$info['maxplayers'];?></b> players currently playing.<br><br>
The current map is <?= ucwords($info['mapname']);?></span></b></a>.<br><?=$twinning?>
</td></tr>
<tr><td colspan=2><hr width=96%></td></tr>
<tr><td valign=top width=50%>
<TABLE border=0 cellspacing=0 cellpadding=1 width=100%>
<TR><td height="17" valign=bottom bgcolor="#847D49"><?=$t2name;?> Team</TD>
<td colspan=4 nowrap bgcolor="#847D49">Tickets: <b><?=$info['tickets2'];?></b></td></tr>
<TR><td width="60%" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=lowername"><b class=x-small> Players: <?=$t2;?></b></a></TD>
<td width="10%" align="center" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=score"><img src="/images/status/score.jpg" alt="Sort by Score" title="Sort by Score" border=0></a></TD>
<td width="10%" align="center" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=kills"><img src="/images/status/kills.jpg" alt="Sort by Kills" title="Sort by Kills" border=0></a></TD>
<td width="10%" align="center" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=deaths"><img src="/images/status/deaths.jpg" alt="Sort by Deaths" title="Sort by Deaths" border=0></a></TD>
<td width="10%" align="center" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=ping"><img src="/images/status/ping.jpg" alt="Sort by Ping" title="Sort by Ping" border=0></a></TD></TR>
<?=$t2list;?></table>
</td>
<td valign=top width=50%>
<TABLE border=0 cellspacing=0 cellpadding=1 width=100%>
<TR><td height="17" valign=bottom bgcolor="#847D49"><?=$t1name;?> Team</TD>
<td colspan=4 nowrap bgcolor="#847D49">Tickets: <b><?=$info['tickets1'];?></b></td></tr>
<TR><td width="60%" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=lowername"><b class=x-small> Players: <?=$t1;?></b></a></TD>
<td width="10%" align="center" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=score"><img src="/images/status/score.jpg" alt="Sort by Score" title="Sort by Score" border=0></a></TD>
<td width="10%" align="center" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=kills"><img src="/images/status/kills.jpg" alt="Sort by Kills" title="Sort by Kills" border=0></TD>
<td width="10%" align="center" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=deaths"><img src="/images/status/deaths.jpg" alt="Sort by Deaths" title="Sort by Deaths" border=0></a></TD>
<td width="10%" align="center" bgcolor="#847D49"><a href="<?=$_SERVER['SCRIPT_NAME'];?>?sort=ping"><img src="/images/status/ping.jpg" alt="Sort by Ping" title="Sort by Ping" border=0></a></TD></TR>
<?=$t1list;?></table></tr>
<tr>
<td valign=top width=50%>
<TABLE border=0 cellspacing=0 cellpadding=1 width=100%>
<TR><td width='60%'></TD>
<td align='center'><?=$t2score;?></TD>
<td align='center'><?=$t2kills;?></TD>
<td align='center'><?=$t2deaths;?></TD>
<td align='center'><? if ($t2 > 0) echo intval($t2ping/$t2);?></TD></TR>
</TABLE></td>
<td valign=top width=50%>
<TABLE border=0 cellspacing=0 cellpadding=1 width=100%>
<TR><td width='60%'></TD>
<td align='center'><?=$t1score;?></TD>
<td align='center'><?=$t1kills;?></TD>
<td align='center'><?=$t1deaths;?></TD>
<td align='center'><? if ($t1 > 0) echo intval($t1ping/$t1);?></TD></TR>
</TABLE></td></tr>
<tr><td colspan=2><hr width=96%></td></tr>
<tr><td colspan=2 align=center>
Page generated <?=date("l F dS, Y");?> at <?=date("g:i:s T");?>.</td></tr>
</table>
</center>
</body>
</html>
<?
}
if ($debug == 1) {
echo("<pre>");
echo("Sorted Player List<br>");
echo print_r($game);
echo("<br>--<br>");
echo("Server Info<br>");
echo print_r($info);
echo("<br>--<br>");
echo("</pre>");
}
?>