[cod] Server status

Kendokan kendokan at amateur-hour.net
Mon Jan 5 16:08:20 EST 2004

No, you can't query a TCP port, it must be the UDP port your server is
running on. Below is a Perl script I use for updating my server status to
my web site. I'm sure there are other query scripts around written in PHP
if you prefer to use that instead, and my script is customized to my site
so you will have to tweak the output section to suit your needs. You can
see it in action at http://amateur-hour.net near the top of the screen. I
have it run from a cron entry like:

*/1 * * * * /path/to/this/script.pl -s your.server.ip > /path/to/status.html

The script is:

#!/usr/bin/env perl

use strict;
use IO::Socket;
use Getopt::Long;

# Initialize settings and results hashes.

# Get command-line options
GetOptions (
        'server|s=s'            => \$Settings{ServerIP},
        'port|p=i'              => \$Settings{ServerPort},
        'link|l=s'              => \$Settings{Link},
        'help|h'                => \$Settings{Help}

# How many seconds before we timeout the query?
$Settings{Timeout} = 2;

# How many times should we retry the query before giving up?
$Settings{RetryCount} = 3;

# This status command if for Call of Duty servers.
$Settings{StatusCmd} = "ÿÿÿÿgetinfo\x00";

# Default to port 28960 if a port is not specified.
$Settings{ServerPort} = "28960" unless $Settings{ServerPort};

# If user asks for help, show the help text.
if ($Settings{Help}) { &PrintHelp }

# If we got an IP address and port from the command-line, query.
Otherwise, print the help text.
if ($Settings{ServerIP} && $Settings{ServerPort}) {
} else {

# This section sends the status command and returns the raw result.
sub GetStatus {

        my $Socket = new IO::Socket::INET (
                Proto           => "udp",
                PeerAddr        => $Settings{ServerIP},
                PeerPort        => $Settings{ServerPort},

        if ($Socket) {
                open (ERROR, ">/dev/null") or die $!;
                STDERR->fdopen(\*ERROR, "w") or die $!;
                $Socket->send($Settings{StatusCmd}) or next;
                $SIG{ALRM} = \&Timeout;

                eval {
                        alarm ($Settings{Timeout});
                        $Socket->recv($Info{Data},1024) or next;
                        alarm (0);
                        close $Socket;

        } else {

                close $Socket;


# This section parses the raw results from GetStatus and turns it into HTML.
sub ParseStatus {
        if ($Info{Data} =~ s/^ÿÿÿÿinfoResponse//) {

                my(@DataLeft, at DataRight);

                foreach (split(/\\/,$Info{Data})) {
                        push @DataLeft,$_;
                        push @DataRight,$_;

                shift @DataRight;

                foreach (@DataLeft) {
                        $Info{$_} = shift @DataRight;

                $Info{IP} = "$Settings{ServerIP}:$Settings{ServerPort}";
                $Info{UsedSlots} = $Info{clients};
                $Info{EmptySlots} = ($Info{sv_maxclients} - $Info{clients});
                $Info{Now} = localtime;

                # This is the HTML result.
                print "<!-- Begin codsmallstat.pl content - $Info{Now}
loop $Settings{LoopCount} -->\n";
                print "     <nobr><a class=\"servername\"
                print "     <input class=\"serverip\" type=\"text\"
readonly onFocus=\"this.select()\"
                print "     Current map: <span
                print "     <table class=\"serverplayer\"
cellspacing=\"0\" cellpadding=\"0\" border=\"0\"
width=\"100%\" title=\"$Info{clients}/$Info{sv_maxclients}
players currently active\">\n";
                print "      <tr>\n";

                while ($Info{UsedSlots} > 0) {
                        print "       <td

                while ($Info{EmptySlots} > 0) {
                        print "       <td

                print "      </tr>\n";
                print "     </table>\n";
                print "     <!-- End codsmallstat.pl content -->";

        } else {

                if ($Settings{LoopCount} < $Settings{RetryCount}) {


                } else {

                        print "<!-- Begin codsmallstat.pl content -
$Info{Now} loop $Settings{LoopCount} of
$Settings{RetryCount} -->\n";
                        print "     <b><font size=\"2\">Error getting
                        print "     <!-- End codsmallstat.pl content -->";


sub Timeout {
          die "How long can this go on?!";

sub PrintHelp {
        print "Usage: codsmallstat.pl -s [IP] -p [PORT] -l [LINK]\n";
        print "Server status script for Call of Duty servers.\n\n";
        print "  -h, --help                     display this help and
        print "  -s, --server                   IP address of game server\n";
        print "  -p, --port                     IP port of game server\n\n";
        print "Long options can be abbreviated, where such abbreviation is
not ambiguous.\n";
        print "Default values for options are indicated in square brackets
        print "codsmallstat: http://amateur-hour.net\n\n";

> Hiya,
> I want to display my server status on the website, when its on or offline
> i have a PHP script for it but it only queries tcp ports
> Does any1 knows if COD uses a tcp port and if yes what is the tcp port
> then
> thnx allot
> www.gaming-hq.com

More information about the Cod mailing list