User Tools

Site Tools


q3astatus

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
q3astatus [2006/10/16 23:12] 209.8.40.19q3astatus [2006/11/08 02:35] (current) – old revision restored 84.142.251.254
Line 1: Line 1:
 +====== q3astatus.php ======
 +
 +This snippet displays the current map and players on your [[quake3arena]] server on your homepage. Just include it somewhere.
 +
 +<code php>
 +<?
 +$server = "yourserver.com";
 +$port   = 27960;
 +$query  = "getstatus";
 +
 +$fp = fsockopen("udp://$server", $port, $errno, $errstr);
 +if (!$fp) {
 +   echo "ERROR: $errno - $errstr<br />\n";
 +   exit;
 +} else {
 +   fwrite($fp,"\xFF\xFF\xFF\xFF".$query);
 +   $answer = fread($fp, 10000);
 +   fclose($fp);
 +}
 +
 +$rows = split("\n",$answer);
 +
 +preg_match('#mapname\\\\(.*?)\\\\#',$rows[1],$matches);
 +$map = $matches[1];
 +?>
 +
 +<table style="background-color:#cccccc">
 +<tr>
 +  <th>Frags</th>
 +  <th>Player</th>
 +  <th>Ping</th>
 +</tr>
 +<?
 +for($i=2; $i<count($rows); $i++){
 +  list($frags,$ping,$name) = split(' ',trim($rows[$i]));
 +  $name = str_replace('"','',$name);
 +
 +  //decode colors
 +  $name = preg_replace('!(\^0)(.*?)(?=\^\d|$)!','<span style="color:black">\\2</span>',$name);
 +  $name = preg_replace('!(\^1)(.*?)(?=\^\d|$)!','<span style="color:red">\\2</span>',$name);
 +  $name = preg_replace('!(\^2)(.*?)(?=\^\d|$)!','<span style="color:green">\\2</span>',$name);
 +  $name = preg_replace('!(\^3)(.*?)(?=\^\d|$)!','<span style="color:yellow">\\2</span>',$name);
 +  $name = preg_replace('!(\^4)(.*?)(?=\^\d|$)!','<span style="color:blue">\\2</span>',$name);
 +  $name = preg_replace('!(\^5)(.*?)(?=\^\d|$)!','<span style="color:lightblue">\\2</span>',$name);
 +  $name = preg_replace('!(\^6)(.*?)(?=\^\d|$)!','<span style="color:ff00cc">\\2</span>',$name);
 +  $name = preg_replace('!(\^7)(.*?)(?=\^\d|$)!','<span style="color:white">\\2</span>',$name);
 +
 +  print "<tr>";
 +  print "<td>$frags</td>";
 +  print "<td>$name</td>";
 +  print "<td>$ping</td>";
 +  print "</tr>";
 +}
 +?>
 +<tr>
 +  <th>Map:</th>
 +  <td colspan="2"><?=$map?></td>
 +</tr>
 +</table>
 +</code>