#!/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!Counterstrike !; print ""; print "
Host: $hostname
"; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "
.: Game :.     cstrike
.: Map :.     $mapname
.: Players On :.    $players_on
.: Address :.    $server_ip:27015
.: Stats :.    cs.gibfest.org
"; print "
";
print "";

#######################################
# Start of a new table that will hold #
# our wonderful player data.          #
#######################################

print "
"; print ""; ############################ # 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 ""; } print "
.: Player Name :. .: Frags :.
$player_name $hash{$player_name}
"; ############################# # If nobody is online then # # print out a message # ############################# } else { print "There are no players on $hostname"; print ""; }