Dark Fighter Released
 

Dark Fighter

Now Available on the App Store

 
TowerDefend is now $0.99!
 

Tower Defend - ON SALE

Price reduced to 0.99 USD!

 
Wireless Heatmap
 

Wireless Heat Map

Open Source Experiments

 

Python Quake 3 server rcon and query class

Once again, I couldn’t find a Quake 3 server query/rcon class for Python so I made one. This one is substantially better then the PHP Quake 3 rcon class that I made a few days ago. It’s called pyquake3. The features are:
* Simple interface
* Automatic retries
* Can access server variables
* Can send rcon commands
* Can collect player names, ping and frags.
* With an rcon password, can collect player ip addresses.

The Python Quake 3 project page is here and you can directly download the Python Quake 3 class here.

6 Comments

  1. Poster says:

    this will fail to work if a player has negative frags
    I think the simplest way to fix it would be to change line 38 to read:

    player_reo = re.compile(r’^(-\d+|\d+) (\d+) “(.*)”‘)

    otherwise the test on line 105 will fail

    my knowledge of regular expressions is limited there may be a more elegant way.

    I just realized that will record incorrect data is it will convert a players negative frag count to positive. Maybe you would know of a good way to fix this.

  2. Tuple says:

    To get this to work, I had to add
    # -*- coding: UTF-8 -*-
    as the first line (or second line will do if you have #!/bin/python or whatnot)

    see
    http://www.python.org/dev/peps/pep-0263/
    for details.

    I’m using python 2.5

  3. Tucker says:

    This is a nice little class. I’ve found it to very useful.
    Thanks for the effort you put into it!

  4. gengis says:

    very nice class!!!!!!
    i am not familiar with regular expression, i wanted to extend the class to get the time(played time) for each player. i gave many try but i didn’t succeed……
    any idea?

    thx

  5. Mad Professor says:

    I changed the regex as follows:

    player_reo = re.compile(r’^(-?)(\d+) (\d+) “(.*)”‘)

    This introduces a new group that can then be used to check if a minus sign was present or not. So I changed the actual application of the regex to this:

    match = self.player_reo.match(player)
    if not match:
    print ‘couldnt match’, player
    continue
    negative, frags, ping, name = match.groups()
    if negative == “-”:
    frags = “-” + frags

    Certainly not the most elegant thing to do, but at least it works. I’d be curious to see what else people come up with. The only other thing I could think of was to scrap the regex and parse it apart by hand instead, probably less code overall? Not sure… Nice module BTW, I like it. :-)

  6. Tycale says:

    The best way is : player_reo = re.compile(r’^(-?\d+) (\d+) “(.*)”‘)

Leave a Comment