-
-
Notifications
You must be signed in to change notification settings - Fork 138
Usage & Examples v2
Austinb edited this page Mar 29, 2012
·
21 revisions
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 optional and if omitted the default port for the server will be used)
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.
- 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.
- 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 as plain text.
<?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);