Apocalypse > Games-AssaultCube > Games::AssaultCube::ServerQuery

Download:
Games-AssaultCube-0.04.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.04   Source  

NAME ^

Games::AssaultCube::ServerQuery - Queries a running AssaultCube server for information

SYNOPSIS ^

        use Games::AssaultCube::ServerQuery;
        my $query = Games::AssaultCube::ServerQuery->new( 'my.server.com' );
        #my $query = Games::AssaultCube::ServerQuery->new( 'my.server.com', 12345 );
        #my $query = Games::AssaultCube::ServerQuery->new({ server => 'foo.com', port => 12345, timeout => 5 });
        my $response = $query->run;
        if ( defined $response ) {
                print "Server is running with " . $response->players . " players\n";
        } else {
                print "Server is not responding!\n";
        }

ABSTRACT ^

This module queries a running AssaultCube server for information.

DESCRIPTION ^

This module queries a running AssaultCube server for information. This has been tested extensively on AssaultCube-1.0.2 servers, so beware if you try older/newer ones! Also, not all servers return all data, so be sure to check for it in your code...

Constructor

This module uses Moose, so you can pass either a hash, hashref, or a server/port to the constructor. Passing a string means we're passing in a server hostname/ip. If you want to specify more options, please use the hash/hashref method.

The attributes are:

server

The server hostname or ip.

port

The server port. Defaults to 28763.

WARNING: AssaultCube uses $port+1 for the query port. Please do not do pass $port+1 to the constructor, we do it internally. Maybe in the future AC will use $port+2 or another system, so let us deal with it :)

get_players

Should we also retrieve the playerlist? This is a boolean which defaults to false.

timeout

The timeout waiting for the server response in seconds. Defaults to 30.

WARNING: We use alarm() internally to do the timeout. If you used it somewhere else, it will cause conflicts and potentially render it useless. Please inform me if there's conflicts in your script and we can try to work around it.

Methods

Currently, there is only one method: run(). You call this and get the response object back. For more information please look at the Games::AssaultCube::ServerQuery::Response class. You can call run() as many times as you want, no need to re-instantiate the object for each query.

WARNING: run() will die() if errors happen. For sanity, you should wrap it in an eval.

Attributes

You can modify some attributes before calling run() on the object. They are:

port

Same as the constructor

timeout

Same as the constructor

get_players

Same as the constructor

AUTHOR ^

Apocalypse <apocal@cpan.org>

Props goes to Getty and the BS clan for the support!

This project is sponsored by http://cubestats.net

Also, thanks goes out to PxL for the initial PHP implementation which helped in unraveling the AssaultCube mess.

We also couldn't have done it without staring at the AssaultCube C++ code for hours, ha!

COPYRIGHT AND LICENSE ^

Copyright 2009 by Apocalypse

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: