#!/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 :. &nbsp;</font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1> &nbsp; cstrike</font></td>"; print "</tr><tr>"; print "<td width=80 align=right bgcolor=#2F545B><font face=arial size= +1>.: Map :. &nbsp;</font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1> &nbsp; $mapname</font></td>"; print "</tr><tr>"; print "<td width=80 align=right bgcolor=#2F545B><font face=arial size= +1>.: Players On :. &nbsp;</font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1>&nbsp; $players_on</font></td>"; print "</tr><tr>"; print "<td width=80 align=right bgcolor=#2F545B><font face=arial size= +1>.: Address :. &nbsp;</font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1>&nbsp; $server_ip:27015</font></td>"; print "</tr><tr>"; print "<td width=80 align=right bgcolor=#2F545B><font face=arial size= +1>.: Stats :. &nbsp;</font></td>"; print "<td width=130 align=left bgcolor=#23343E><font face=arial size= +1>&nbsp; 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>"; }

In reply to CounterStrike Monitor by djw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.