BattleField2

Summary
This class extends the base GameQuery class to implement support for the BattleField 2 query protocol (which is itself a modification of the GameSpy 2 protocol).
Internal method for the gory details of sending request strings and recieving response strings through direct socket communications.
Internal method for constructing request strings that will be sent to the host server.
Internal method for parsing response strings that will be sent to the host server.
Internal method that, given a byte array, gets concurrent name-value pairs, null-terminated, until an empty pair is reached.
Internal method that, given a byte array, gets a series of null-terminated names, and repeated sets of corresponding null-terminated values.
Static method for removing and returning a null-terminated string (aka c-string) from an array of bytes.

GQProtocol_BattleField2

This class extends the base GameQuery class to implement support for the BattleField 2 query protocol (which is itself a modification of the GameSpy 2 protocol).  It is indended to be dynamically loaded by the Monitor function defined in the base class.

// include the base class
require_once("GameQuery.php");

// create a monitor instance using this protocol
$monitor = GameQuery::Monitor('BattleField2', '99.99.99.1:9999', $options );
Summary
Internal method for the gory details of sending request strings and recieving response strings through direct socket communications.
Internal method for constructing request strings that will be sent to the host server.
Internal method for parsing response strings that will be sent to the host server.
Internal method that, given a byte array, gets concurrent name-value pairs, null-terminated, until an empty pair is reached.
Internal method that, given a byte array, gets a series of null-terminated names, and repeated sets of corresponding null-terminated values.
Static method for removing and returning a null-terminated string (aka c-string) from an array of bytes.

Member Constants

MAX_QUERY_PACKETSMaximum number of packets a query response can contain.

Reimplemented Methods

_communicate

protected function _communicate($requests =  array())

Internal method for the gory details of sending request strings and recieving response strings through direct socket communications.

For this protocol, recieves data potentially split across multiple packets via a UDP socket.  This is necessary to accomodate the potentially large amount of data sent.

Parameters

$requestsAn array of request strings to be sent to the server.

Returns

An array of strings containing server response data.

_request

protected function _request($options =  NULL)

Internal method for constructing request strings that will be sent to the host server.  Note that this protocol takes no options.

Parameters

$optionsOptional associative array of directives to control module behavior.  (Not used)

Returns

A string or array of strings containing server request data.

_response

protected function _response($response =  NULL)

Internal method for parsing response strings that will be sent to the host server.

For this protocol, data is broken into three basic sections in the top-level array.

  • server_info
  • player_info
  • team_info

Parameters

$responseUnprocessed response string.

Returns

A nested array structure derived from the server response data.

Internal Methods

_concurrent_fields

private function _concurrent_fields(&$rsp_string =  array(),
$field_type =  '')

Internal method that, given a byte array, gets concurrent name-value pairs, null-terminated, until an empty pair is reached.  This is used to parse server info for the Gamespy 2 protocol.

Parameters

$rsp_stringResponse string as an array of individual bytes.
$field_typeSection key as string.

Returns

A nested array structure of the processed name-value pairs

_nonconcurrent_fields

private function _nonconcurrent_fields(&$rsp_string =  array(),
$field_type =  '')

Internal method that, given a byte array, gets a series of null-terminated names, and repeated sets of corresponding null-terminated values.  This is used to parse player and team info for the Gamespy 2 protocol.

Parameters

$rsp_stringResponse string as an array of individual bytes.
$field_typeSection key as string.

Returns

A nested array structure of the processed name-value pairs

_unpack_cstring_reversed

function _unpack_cstring_reversed(&$arr =  NULL)

Static method for removing and returning a null-terminated string (aka c-string) from an array of bytes.  Note that the string is returned without the terminating null character.

$bytes = array( \x63, \x73, \x74, \x72, \x69, \x6e, \x67, \x00 );

// should print "cstring"
echo GameQuery::_unpack_cstring($bytes);

Parameters

$arrArray of bytes, one byte per element.

Returns

A string on success, or NULL on error.

protected function _communicate($requests =  array())
Internal method for the gory details of sending request strings and recieving response strings through direct socket communications.
protected function _request($options =  NULL)
Internal method for constructing request strings that will be sent to the host server.
protected function _response($response =  NULL)
Internal method for parsing response strings that will be sent to the host server.
private function _concurrent_fields(&$rsp_string =  array(),
$field_type =  '')
Internal method that, given a byte array, gets concurrent name-value pairs, null-terminated, until an empty pair is reached.
private function _nonconcurrent_fields(&$rsp_string =  array(),
$field_type =  '')
Internal method that, given a byte array, gets a series of null-terminated names, and repeated sets of corresponding null-terminated values.
function _unpack_cstring_reversed(&$arr =  NULL)
Static method for removing and returning a null-terminated string (aka c-string) from an array of bytes.