Query a wolfenstein (or probably q3 as well) server, and get a list of connected players, their ping, and their score.
The below link works best using IE, not sure how to make mozilla/netscape render a background the same way.
See an example at
YFB Clan Server Status
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket::INET;
use HTML::Template;
my $template = HTML::Template->new(filename => "html/rtcw_status.html"
+);
my @loop_data; #an array of hashes for each player row
my $host = "1.1.1.1"; #host that wolf is running on
my $port = "27960" #port
my $query = "\377\377\377\377getstatus\n"; #command string
my $sock = IO::Socket::INET->new( #make the connection
PeerAddr => $host,
PeerPort => $port,
Proto => "udp"
) || die "Could not connect to $host: $!"; #or tell us why not
my $response; #this is what we will get back from the server
send ($sock,$query,0)
|| die "Could not send: $!"; #send the query
recv ($sock,$response,2048,0); #read the response
my ($mapname) =
$response =~ /.+\\mapname\\([^\\]+)/; #get the mapname
my ($maxclients) =
$response =~ /.+\\sv_maxclients\\([^\\]+)/; #and the max amount
+ of client connections
my @status = split /\n/,$response; #now, split the response
shift @status; #drop the first two lines (first line is getstatusre
+sponse)
shift @status; #(second line is the "header" info
my $connected = "0";#default connected = 0
$connected = length(@status) if $status[0]; #if there is someone co
+nnected, count how many
foreach (@status) {
my ($score,$ping,$name) = split; #split the score line into app
+ropriate vars
$name =~ s/^"|"$//g; #remove the quotes
$name = parse_name($name);
my %row = ( PLAYER => $name, SCORE => $score, PING => $ping );
+#create a hash for template loop
push @loop_data,\%row; #push the hash into the template loop ar
+ray
}
#fill the template
$template->param(
MAPNAME => $mapname,
IMAGENAME => $mapname . ".jpg",
MAXCONNECTS => $maxclients,
CONNECTED => $connected,
PLAYER_SCORE => \@loop_data,
);
print "Content-type: text/html\n\n";
print $template->output;
sub parse_name { #fun names -> HTML colors
my $name = shift;
$name =~ s!\^0([^^]+)!<font color="#000000">$1</font>!g;
$name =~ s!\^1([^^]+)!<font color="#FF0000">$1</font>!g;
$name =~ s!\^2([^^]+)!<font color="#00FF00">$1</font>!g;
$name =~ s!\^3([^^]+)!<font color="#FFFF00">$1</font>!g;
$name =~ s!\^4([^^]+)!<font color="#00FFFF">$1</font>!g;
$name =~ s!\^5([^^]+)!<font color="#FF00FF">$1</font>!g;
$name =~ s!\^6([^^]+)!<font color="#FF0000">$1</font>!g;
$name =~ s!\^7([^^]+)!<font color="#FFFFFF">$1</font>!g;
return ($name);
}