Jump to content

tcadmin + qstat dumper.


Monk

Recommended Posts

I think there should be another section about user contributed scripts, code, etc instead of me and others piling code in this section :)

 

Anyways, I use this to dump tcadmin game info, convert it to qstat and run our stats programs with the output. Since we have so many servers, I run this from crontab to keep my stats automatically updated.

 

I tried to make this easy to understand, easy to modify etc.

 

#!/usr/bin/perl -w

# Copyright (C) 2007 Gary Stanley <gary@velocity-servers.net>.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice(s), this list of conditions and the following disclaimer as
#    the first lines of this file unmodified other than the possible
#    addition of one or more copyright notices.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice(s), this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


require 5.008;
use DBI;
use strict;

my $version = "1.1";
my $file = "./servers.txt";
my $file2 = "./fix.txt";


my $dbh = DBI->connect('dbi:mysql:tcadmin:hostname','db_username','db_pass')
       or die "Couldn't connect to database: $DBI::errstr\n";

my $sql = "SELECT GAME_ID,SERVER_IP,SERVER_PORT from tc_services ORDER by GAME_ID";

my $sth = $dbh->prepare($sql)
       or die "Couldn't prepare query '$sql': $DBI::errstr\n";

$sth->execute || 
          die "Could not execute SQL statement ... maybe invalid?";

# Convert output to qstat type. You have to be sure you have the proper 
# gametypes in qstat.cfg otherwise you may not be able to use these.

if (-e $file2) { unlink($file2); }

while (my @row=$sth->fetchrow_array)
{
       # Make SURE you have s/\bGAMEID\b/QSTATID when editing these filters
       # XXX - There's a better way of doing this, perhaps we can just 
       # write it to a file, then do the conversions there instead of inplace editing.

       $row[0] =~ s/\bTC4875210400327\b/HLSHB/i;
       $row[0] =~ s/\bTC8644464364564\b/BF2/i;
       $row[0] =~ s/\bTC6878144563415\b/CODUO/i; 
       $row[0] =~ s/\bTC2364114757686\b/DODS/i;
       $row[0] =~ s/\bTC6040600434168\b/COD2S/i;
       $row[0] =~ s/\bTC5502614372407\b/Q4S/i;
       $row[0] =~ s/\bTC3055405514836\b/HLSP/i;

       $row[0] =~ s/\b1\b/RWS/i; 
       $row[0] =~ s/\b2\b/COD/i;
       $row[0] =~ s/\b3\b/CODUO/i;
       $row[0] =~ s/\b4\b/MAQS/i;
       $row[0] =~ s/\b6\b/A2S/i;
       $row[0] =~ s/\b7\b/HLCZ/i;
       $row[0] =~ s/\b8\b/HLNS/i;
       $row[0] =~ s/\b9\b/HLDOD/i;
       $row[0] =~ s/\b10\b/CSS/i;
       $row[0] =~ s/\b12\b/SOF2S/i;
       $row[0] =~ s/\b16\b/JK3S/i;
       $row[0] =~ s/\b17\b/JK3S/i;
       $row[0] =~ s/\b18\b/Q3S/i;
       $row[0] =~ s/\b19\b/UT2004S/i;
       $row[0] =~ s/\b26\b/A2S/i;
       $row[0] =~ s/\b27\b/HLSAD/i;
       $row[0] =~ s/\b28\b/HLSAMX/i;
       $row[0] =~ s/\b29\b/HLTV/i;
       print "$row[0] $row[1]:$row[2]\n";
       open(DAT,">>$file") || die("Cannot Open File");
       print DAT "$row[0] $row[1]:$row[2]\n";
}

# Close file handler.
close(DAT);

# Disconnect from database.
$dbh->disconnect();

&read_file;

sub read_file
{
       my $filename = "./servers.txt";
       my @lines;

       open( FILE, "< $filename" ) or die "Can't open $filename : $!";

       # This is to clean the file up, remove specific game id's, whitespaces, junk, invalid gameid's
       # You should be able to read the comments below and write your own filters 

       while( <FILE> ) {
           s/#.*//;            # ignore comments by erasing them
           
           s/^0\s.*//;         # Remove gameid's that begin with 0

           #chomp;              # remove trailing newline characters

           s/TC5783714187363.*//; # Remove gameid's that begin with this (booster)
           s/TC4031046603668.*//; # Remove AAO
           s/TC3574326174148.*//; # Remove BF2
           s/TC0351024833866.*//; # Remove ??
           s/TC1574672440873.*//; # Remove ??

           next if /^(\s)*$/;  # skip blank lines
           push @lines, $_;    # push the data line onto the array
           open(STUFF,">>$file2") || die("Cannot Open File");
           print STUFF;
       }

       close FILE;
       close STUFF;

       return \@lines;  # reference
}

Link to comment
Share on other sites

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

  • Who's Online   0 Members, 0 Anonymous, 8 Guests (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use