-
Notifications
You must be signed in to change notification settings - Fork 0
II. Examples
George-Cristian Tudoran edited this page Nov 12, 2023
·
9 revisions
If you are here, it means that you already followed all the steps described under chapter I. How to install this script?. Otherwise, I recommend you to start there with the tutorial.
- Query one server:
use GameServerQuery\GameServerQuery;
use GameServerQuery\Protocol\Games\Source\CounterStrikeGlobalOffensiveProtocol;
$gameServerQuery = new GameServerQuery\GameServerQuery();
$gameServerQuery->server(new CounterStrikeGlobalOffensiveProtocol, 'IP address', 27015, 27016));
$response = $gameServerQuery->process();
var_dump($response);- Query multiple servers:
use GameServerQuery\GameServerQuery;
use GameServerQuery\Protocol\Games\Source\CounterStrikeGlobalOffensiveProtocol;
use GameServerQuery\Protocol\Games\Source\ConanExilesProtocol;
$servers = [
new CounterStrikeGlobalOffensiveProtocol, 'IP address', 27015, 27016),
new ConanExilesProtocol, 'IP address2', 27015, 27017),
];
$gameServerQuery = new GameServerQuery\GameServerQuery();
$gameServerQuery->servers(...$servers);
$response = $gameServerQuery->process();
var_dump($response);- Set filter and customize it:
...
$gameQueryServer->filter(ColorStripFilter::class, [
// Note:
// If *protocols = []* -> Filter applies to all games
// If *protocols = [CounterStrikeGlobalOffensiveProtocol::class, ConanExilesProtocol::class, ...]* -> Filter applies only to those games
// If *protocols = [SourceProtocol::class]* -> Filter applies to all derived game protocols
// (e.g.: If value is *Source*, then CS, HL and all classes will apply this filter)
'protocols' => [],
// Filter sections.
// If 'sections' is an empty array, then the filter will be skipped.
'sections' => [
// [] = all keys, ['hostname', 'map', ...] - applies only to these keys, null = don't filter this section
Result::GENERAL_CATEGORY => [Result::GENERAL_HOSTNAME_SUBCATEGORY],
Result::PLAYERS_CATEGORY => [Result::PLAYERS_NAME_SUBCATEGORY],
Result::RULES_CATEGORY => null,
],
// Set extra parameters (if necessary for custom or future filters).
'options' => [],
]);
$response = $gameServerQuery->process();
var_dump($response);- Set formater to XML - Response will be formatted as XML, instead of array (default).
use GameServerQuery\Formatter\Types\XMLFormatter;
...
$gameQueryServer->formatter(XMLFormatter::class);
$response = $gameServerQuery->process();
var_dump($response);