Skip to content

Usage & Examples v2

Austin Bischoff edited this page Mar 6, 2014 · 21 revisions

Adding a server

When adding a server to be queried you must provide at least 2 points of information:

  • type - The type of game server. For a list of types see /examples/list.php or /gameq/protocols/*.php
  • host - The ip:port of the server. Port is the server query port and is optional. If omitted the default port for the server will be used. Valid host values: some.hostname.tld:27015, 127.0.0.1:27015, [::1]:27015. Note that IPv6 host addresses must be included in square brackets.

Optional information:

  • id - This is a unique string that gives you the ability to pull out the server information directly from the result set without having to iterate. If this is omitted the information passed in 'host' will be used.
  • options - This is an array of key, value pairs that define specific options for that specific server.

Available options:

  • client_connect_port - Allows overriding of the port used for connecting to the game server by clients. Useful for servers with non-standard port setups. This only affects the gq_joinlink return key.
  • master_server_port - Allows overriding of the default master port in Teamspeak 3

General Settings

  • timeout - Default: 3 (seconds). Amount of time a server has to respond to a query before assuming the server is offline.
  • debug - Default: FALSE. When TRUE the program will exception out if there is an error with any of the servers being queried. When FALSE any server specific exceptions are ignored and that server is assumed to be offline and returned as such.

Advanced Settings

  • stream_timeout - Default: 200000 (microseconds). This setting affects how long the stream_select() (see: http://php.net/manual/en/function.stream-select.php) waits to listen for response data before allowing the script to continue. Decreasing this value can speed up large lists but increases the amount of CPU usage the script uses.
  • write_wait - Default: 500 (microseconds). This setting affects how long the script will pause between writing packets to the server sockets. Lowering this value increases speed but also cpu usage. Setting this value very low (i.e. 0) can help with speeds of very large query lists.

Available Filters

  • normalise - Normalize all of the common data across game servers. For example this filter will always return keys such as gq_online, gq_address, gq_hostname, etc...
  • stripcolor - Used to strip special characters in a player's name which changes the color of the text within the actual game. Mainly found in Quake and Unreal based games. When this filter is applied it returns the player's name without the color codes.

Examples

<?php
$servers = array(
    array(
        'type' => 'css', // Required
        'host' => '127.0.0.1:27015', // Required
        'id' => 'my_server', // Optional
    ),
);

// Init the class, only need this once
$gq = new GameQ(); // or $gq = GameQ::factory();
$gq->setOption('timeout', 5); // Seconds
$gq->setOption('debug', TRUE);
$gq->setFilter('normalise');
$gq->addServers($servers);

$results = $gq->requestData();
print_r($results);

The above section can be written also as:

$results = GameQ::factory()
    ->setOption('timeout', 5)
    ->setOption('debug', TRUE)
    ->setFilter('normalise')
    ->addServers($servers)
    ->requestData();

print_r($results);