| Category: | CGI |
| Author/Contact Info | djw gibfest.org |
| Description: | Simple script used for monitoring a Quake 3 Arena server. You can modify it to monitor any server out there. Works great as a small active desktop. On my site I have it as a separate pop-up window that is 400 x 200 in size. It is also set to refreshe the window every 10 seconds.
There is a whack of html in there that formats it according to my site's color style etc. but you can toss it out and use whatever you like. Most of this is re-used code (in fact all the perl) taken from a Quake3Arena Perlbot plugin available at http://www.gibfest.org/~spar/. Good job spar and thanks for letting me share it. Hope it's useful. |
#!/usr/bin/perl use Socket; use CGI qw(:standard); my($remote,$port,$iaddr,$paddr,$proto,$q3aquery); my($result); my($gamename,$mapname,$gametype,%p_frags,%p_ping,$p_name,@p_names,$fra +gs,$ping); my($sv_hostname,@f_result,$line); $remote = "204.112.131.22"; $port = "27960"; $q3aquery = "\377\377\377\377getstatus\n"; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname("udp"); socket(SOCK, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; send(SOCK, $q3aquery, 0) || die "send: $!"; recv(SOCK, $result, 2048, 0); ($gamename) = $result =~ m/gamename\\(.*?)\\/i; ($mapname) = $result =~ m/mapname\\(.*?)\\/i; ($gametype) = $result =~ m/g_gametype\\(\d)\\/i; ($sv_hostname) = $result =~ m/sv_hostname\\(.*?)\\/i; @f_result = split /\n/, $result; foreach $line (@f_result) { if (($frags, ,$ping, $p_name) = $line =~ m/^(\d+|-\d+)\s(\d+)\s"(. +*?)"/i) { $p_name =~ s/\^\d//g; $p_frags{$p_name} = $frags; $p_ping{$p_name} = $ping; push @p_names, $p_name; } } print "Content=type:text/html\n\n"; print qq!<html><head><title>Quake3Arena</title><META HTTP-EQUIV=Refres +h CONTENT=10; URL=http://www.gibfest.org/cgi/q3astatus.cgi></head> <body bgcolor="#000000" leftmargin="0" topmargin="0" bottombargin="0" +marginwidth="0" marginheight="0" link="#fffffe" vlink="#fffffe" alin +k="#fffffe" text="#fffffe"> !; print "<img src=http://www.gibfest.org/q3a_logo_small.gif border=0 ali +gn=right valign=top>"; print "<table border=0 cellpadding=0 cellspacing=0 width=250><tr><td bgcolor=#000000><font size=1 face=arial>Host: $sv_hostname Status</fon +t></td></tr></table>"; print "<table border=0 cellpadding=0 cellspacing=1 width=220 bgcolor=#000000><tr>"; print "<td width=80 align=right bgcolor=#2F545B><font face=arial size= +1>.: Game :. </font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1> $gamename</font></td>"; print "</tr><tr>"; print "<td width=80 align=right bgcolor=#2F545B><font face=arial size= +1>.: Map :. </font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1> $mapname</font></td>"; print "</tr><tr>"; print "<td width=80 align=right bgcolor=#2F545B><font face=arial size= +1>.: Type :. </font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1> $gametype</font></td>"; print "</tr><tr>"; print "<td width=80 align=right bgcolor=#2F545B><font face=arial size= +1>.: Address :. </font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1> 204.112.131.22</font></td>"; print "</tr></table>"; print "<br><table border=0 cellpadding=0 cellspacing=1 width=400 bgcolor=#000000>"; print "<th width=225 align=middle bgcolor=#23343E><font face=arial si +ze=1> .: Player Name :.</font></th> <th width=75 align=middle bgcolor=#2F545B><font face=arial size=1> +.: Frags :.</font></th> <th width=100 align=middle bgcolor=#23343E><font face=arial size=1 +>.: Ping :.</font></th>"; if ($#p_names <= -1) { print "<br><font size=1 face=arial>No players currently playing on + $sv_hostname.</font>"; } else { foreach $player (@p_names) { print "<tr> <td bgcolor=#2F545B width=225 align=middle><font size=1face=arial>$pla +yer</font></td> <td bgcolor=#23343E width=75 align=middle><font size=1 face=arial>$p_f +rags{$player}</font></td> <td bgcolor=#2F545B width=100 align=middle><font size=1 face=arial>$p_ +ping{$player}</font></td> </tr>"; } } print "</table></body></html>"; |
|
|
|---|