GameQuery |
GameQueryThe GameQuery package is meant to be used as a class factory for creating server monitors with the Monitor static method, called from the base class. // include the base class using an absolute path The base class, as the name implies, can also be extended for implementing new query protocols. require_once("GameQuery.php"); Each extension of this class is meant to cover an individual protocol by reimplementing the following functions. The remaining functions (some public, some protected, and some private) are fully implemented in this class and are not meant to be overridden in any extensions. Additionally, the displaying of query data is handled using specially constructed PHP template files, by using specially provided variables. // the entire query data structure is provided in this variable Summary
Global ConstantsThese go in the global scope, rather than the scope of the base class, and affect general error-handling and reporting behavior of the library classes. Enabling these facilities simply requires defining the appropriate constants as true values. By default, these are defined as false when the base class file is loaded.
Member Variables
Member Constants
Monitor
Factory for creating monitor instances (also known as monitor objects) using the given protocol. This is intended to be called as a static method of the base class. Note that, if caching is enabled and a new enough cache file is found for the given combination of host and protocol, the cached query data will be used instead of performing a new query. Parameters
ReturnsAn object of the extended class for the given protocol. supported_protocols
Method for returning all protocols found in the include_path, as an array. This can be invoked as either a static class method, or as an object method. It should be noted that the path of the current classfile is added to the include_path if necessary. // invoking as a static method ParametersNone ReturnsAn array of viable supported_protocols (extending classes implementing a specific protocol). supported_templates
Method for returning all templates found in the include_path, as an array. This can be invoked as either a static class method, or as an object method. It should be noted that the path of the current classfile is added to the include_path if necessary. // invoking as a static method ParametersNone ReturnsAn array of viable supported_templates (scripts displaying information specific to a protocol and/or gametype). __construct
Constructor, implemented by base class, to be inherited and used by extender classes. Initializes values, executes queries of game server, and processes responses using inherited member methods. Should not be invoked directly, see Monitor static method. Parameters
Reimplemented MethodsThese methods, hollowly defined in the base class, are meant to be reimplemented in the extending classes to accomodate differing protocols and games. The exceptions to this are the _communicate and _validate methods, the standard implementations of which should suit most protocools. _communicate
Internal method for the gory details of sending request strings and recieving response strings through direct socket communications. By default, it is implemented as a one-to-one protocol of sending a request and getting a usable response via a UDP socket. While this is sufficient for many protocols, some require more complex logic, such as challenge-response systems, and yet others may not use UDP communications. Parameters
ReturnsAn array of strings containing server response data. _request
Internal method for constructing request strings that will be sent to the host server. Typically, any variations in the way request strings are built would be due to the options passed to the Monitor method. By default, it is unimplemented (returns NULL). Since this is heavily protocol-dependant, it must be implemented in the extending protocol class, and should return a string or array of strings. Parameters
ReturnsA string or array of strings containing server request data. _response
Internal method for parsing response strings that will be sent to the host server. By default, it is unimplemented (returns NULL). Since this is heavily protocol-dependant, it must be implemented in the extending protocol class. Parameters
ReturnsA nested array structure derived from the server response data. _validate
Internal method for validating that a host string is suitable for the current protocol and breaking it down into a dns/ip address and port number. It can be reimplemented on a per-protocol or per-game basis, if needed. By default, it simply expects the address and portnumber seperated with a colon. // both of these are potentially valid However, some games use a fixed query port, so this method could be implemented, for example, to match an address and discard any given port, in favor of the default. // default port is 6969 Parameters
ReturnsAn array of strings containing the dns/ip address and the port number. get_template
Public method for displaying a processed query in an aesthetically pleasing format. This can be used for displaying server status in HTML, XML, YAML, plain text, etc. Changing how it displays is as simple as editing the template file. Essentially, a template is a normal PHP file, given the special variables $_GAMEQUERY (which contains the query data structure) and $_TEMPLATEFILE (hich contains the template filename). $monitor->get_template(''); In the base class, this simply returns NULL since it is protocol- and game-specific. It is meant to be reimplemented on a per-game basis. Parameters
ReturnsA string containing HTML-formatted query data. supported_configs
Method for returning an array of configuration directives supported by the current class, where the key is a directive name, and the value is a brief description of the directive. In the base class, this returns an array of base-class specific configuration directives. Each overriding protocol class that implements its own directives should also include the directives of its parents. // example implementation of an overriden ::supported_configs() ParametersNone ReturnsAn associative array where each key is a config directive, and each value is a brief description of that directive. add_include_paths
Private method for adding new directories to the include_path. This is meant for internal use within the base class. Parameters
ReturnsBoolean true on success, or false on failure. get_include_delimiter
Private method for calculating the include_path delimiter character, which varies depending on the host operating system. This is meant for internal use within the base class. ParametersNone ReturnsString containing the delimiter character. include_capture
Private method for including and executing a PHP file within a confined scope (providing it the parsed query as a data structure), and caputuring and returning the output. Parameters
ReturnsString containing output of given template _unpack_float32
Static method for removing and returning a 32-bit (4 byte) float from an array of bytes. $bytes = array( \x5D, \x0A, \x12, \x44 ); Parameters
ReturnsAn integer on success, or NULL on error. _unpack_int16
Static method for removing and returning a 16-bit (2 byte) integer from an array of bytes. $bytes = array( \x80, \x00 ); Parameters
ReturnsAn integer on success, or NULL on error. _unpack_int32
Static method for removing and returning a 32-bit (4 byte) integer from an array of bytes. $bytes = array( \xFF, \xFF, \x00, \x00 ); Parameters
ReturnsAn integer on success, or NULL on error. _unpack_byte
Static method for removing and returning the numeric ordinal of a byte from an array of bytes. $bytes = array( \x20 ); Parameters
ReturnsAn integer on success, or NULL on error. _unpack_cstring
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 ); Parameters
ReturnsA string on success, or NULL on error. _unpack_fstring
Static method for removing and returning a fixed-length string from an array of bytes. $bytes = array( \x66, \x69, \x78, \x65, \x64, \x20, \x6c, \x65, \x6e, \x67, \x74, \x68 ); Parameters
ReturnsA string on success, or NULL on error. |
Factory for creating monitor instances (also known as monitor objects) using the given protocol.
public static function Monitor( $protocol = NULL, $host = NULL, $options = array() )
Method for returning all protocols found in the include_path, as an array.
public function supported_protocols()
Method for returning all templates found in the include_path, as an array.
public function supported_templates()
Constructor, implemented by base class, to be inherited and used by extender classes.
public function __construct( $hostarg = NULL, $options = NULL )
Member method for returning the raw response string(s) from a query.
public function get_raw()
Method for returning response data after it has been broken down into a structure (typically composed of nested arrays).
public function get_struct()
Internal method for the gory details of sending request strings and recieving response strings through direct socket communications.
protected function _communicate( $requests = array() )
Internal method for constructing request strings that will be sent to the host server.
protected function _request( $options = NULL )
Internal method for parsing response strings that will be sent to the host server.
protected function _response( $response = NULL )
Internal method for validating that a host string is suitable for the current protocol and breaking it down into a dns/ip address and port number.
protected function _validate( $hostname = NULL )
Public method for displaying a processed query in an aesthetically pleasing format.
public function get_template( $template = NULL )
Method for returning an array of configuration directives supported by the current class, where the key is a directive name, and the value is a brief description of the directive.
public function supported_configs()
Private method for adding new directories to the include_path.
protected function add_include_paths( $paths = NULL )
Private method for calculating the include_path delimiter character, which varies depending on the host operating system.
protected function get_include_delimiter()
Private method for retrieving seperated paths from the include_path.
protected function get_include_paths()
Private method for including and executing a PHP file within a confined scope (providing it the parsed query as a data structure), and caputuring and returning the output.
protected function include_capture( $_TEMPLATEFILE = NULL, $_GAMEQUERY = NULL )
Static method for removing and returning a 32-bit (4 byte) float from an array of bytes.
protected function _unpack_float32( & $arr = NULL )
Static method for removing and returning a 16-bit (2 byte) integer from an array of bytes.
protected function _unpack_int16( & $arr = NULL )
Static method for removing and returning a 32-bit (4 byte) integer from an array of bytes.
protected function _unpack_int32( & $arr = NULL )
Static method for removing and returning the numeric ordinal of a byte from an array of bytes.
protected function _unpack_byte( & $arr = NULL )
Static method for removing and returning a null-terminated string (aka c-string) from an array of bytes.
protected function _unpack_cstring( & $arr = NULL )
Static method for removing and returning a fixed-length string from an array of bytes.
protected function _unpack_fstring( & $arr = NULL, $len = 0 )