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); }

In reply to Return to Castle Wolfenstein server status by the_slycer

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.