| Category: | CGI |
| Author/Contact Info | djw djw@gibfest.org http://www.gibfest.org/ |
| Description: | A CGI tool used for monitoring your Counter-Strike Server in Linux. Uses a program called 'Qstat*' which provides the query to the server. Although I tried to run the query myself using Half-Life's network query info, it was returning some funky stuff. So instead of re-inventing the wheel I justed used Qstat. Anyhow it sorts by frags, into a swanky little table. You can see it working at http://www.gibfest.org/. Enjoy, djw * Qstat homepage & creator: http://www.activesw.com/people/steve/qstat.html, Steve Jankowski |
#!/usr/bin/perl -w
use strict;
my(@status, $line1, $line2, @final);
my($mapname, $players_on, %hash, $hostname);
my($server_ip, $status, $frags, $player_name);
$server_ip = "204.112.131.22";
@status = ();
@final = ();
$line1 = "";
$line2 = "";
$status = `qstat -P -cn -tsw -hls $server_ip`;
$frags = 0;
$player_name = "";
%hash = ();
###########################
# split up @status, then #
# take off last two lines.#
# One for use later, and #
# one because its not #
# what we need. Put into #
# @final. #
###########################
@status = split(/\n/, $status);
@final = reverse(@status);
$line1 = pop(@final);
$line2 = pop(@final);
###########################
# brab the stuff we need #
# from the second line #
###########################
($hostname) = $line2 =~ /cstrike\s(.+)/;
($mapname) = $line2 =~ /\s(\w+)\s/;
($players_on) = $line2 =~ /\s(\w.*?)\s/;
##################################
# The rest of what we need is in #
# @final. Each line containts #
# player name, frags, and time #
# on the server. I scrapped the #
# time online. #
##################################
foreach (@final) {
($frags, $player_name) = /^\W+(\s\d|\d\d)\s\w+\s\d+:\d+:\d+\s(
+.+)/;
$hash{$player_name} = $frags;
}
#################################################
# Below is some html that goes along with my #
# site design. Basically creates a small table #
# with hostname, gametype (cstrike), mapname #
# players on, server ip:port, and a url to the #
# stats page. #
#################################################
print "Content=type:text/html\n\n";
print qq!<html><head><title>Counterstrike</title><META HTTP-EQUIV=Refr
+esh
CONTENT=10; URL=http://www.gibfest.org/hlstatus.shtml></head>
<body
bgcolor="#000000" leftmargin="0" topmargin="0" bottombargin="0"
marginwidth="0" marginheight="0" link="#fffffe" vlink="#fffffe"
alink="#fffffe" text="#fffffe">
!;
print "<img src=http://www.gibfest.org/cs_logo.jpg border=0 align=righ
+t valign=top>";
print "<table border=0 cellpadding=0 cellspacing=0 width=220><tr><td
bgcolor=#000000><font size=1 face=arial>Host: $hostname</font></td></t
+r></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> cstrike</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>.: Players On :. </font></td>";
print "<td width=130 align=left bgcolor=#23343E><font face=arial size=
+1> $players_on</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> $server_ip:27015</font></td>";
print "</tr><tr>";
print "<td width=80 align=right bgcolor=#2F545B><font face=arial size=
+1>.: Stats :. </font></td>";
print "<td width=130 align=left bgcolor=#23343E><font face=arial size=
+1> cs.gibfest.org</font></td>";
print "</tr></tr>";
print "</table>";
print "<pre>";
print "<font face=arial size=1>";
#######################################
# Start of a new table that will hold #
# our wonderful player data. #
#######################################
print "<br><table border=0 cellpadding=0 cellspacing=1
width=300 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 siz
+e=1>.: Frags :.</font></th>";
############################
# This if statement prints #
# out table rows and data #
# which containts player #
# name and frags. Again, #
# This is formatted to fit #
# my design. #
############################
if (%hash) {
foreach $player_name (sort { $hash{$b} <=> $hash{$a} }keys %hash) {
print "<tr>
<td bgcolor=#2F545B width=225 align=middle><font size=1face=arial>$pla
+yer_name</font></td>
<td bgcolor=#23343E width=75 align=middle><font size=1 face=arial>$has
+h{$player_name}</font></td>
</tr>";
}
print "</table></body></html>";
#############################
# If nobody is online then #
# print out a message #
#############################
} else {
print "<tr></td>There are no players on $hostname</td></tr>";
print "</table></body></html>";
}
|
|
|
|---|