From e5e7e3fde5467d27397bb49107cb783666490c1d Mon Sep 17 00:00:00 2001 From: xPaw Date: Fri, 6 Apr 2012 18:19:38 +0300 Subject: [PATCH] Updated readme --- README.md | 86 +++++++++++++++++++++++++++++++++++-------- SourceQuery.class.php | 9 +---- 2 files changed, 71 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d8f2e93..8ea3a0f 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,83 @@ -PHP SourceQuery -=============== +PHP Source Query +================ ### Description +This class was created to query game server which use the Source query protocol, this includes all source games, half-life 1 engine games and Call of Duty: Modern Warfare 3 -This class was created to query servers that use 'Source Query' protocol, for games like HL1, HL2, The Ship, SiN 1, Rag Doll Kung Fu and more. +The class also allows you to query servers using RCON although this only works for half-life 1 and source engine games. -This also works for **Call of Duty: Modern Warfare 3**, as it uses Source Query protocol as well. +[Minecraft](http://minecraft.net) also uses Source RCON protocol, and this means you can use this class to send commands to your minecraft server while having engine set to source. -You can find protocol specifications here: http://developer.valvesoftware.com/wiki/Server_queries +##### Protocol specifications can be found over at VDC +* https://developer.valvesoftware.com/wiki/Server_queries +* https://developer.valvesoftware.com/wiki/Source_RCON_Protocol ### Usage +You can find easy examples on how to use it in `View.php` -You can find easy examples on how to use it in `Test.php` file, or just run `view.php` +### Example +```php +Connect( 'localhost', 27015, 3, SourceQuery :: GOLDSOURCE ); + + print_r( $Query->GetInfo( ) ); + print_r( $Query->GetPlayers( ) ); + print_r( $Query->GetRules( ) ); + + $Query->SetRconPassword( 'this_is_your_leet_rcon_password' ); + echo $Query->Rcon( 'status' ); + } + catch( SQueryException $e ) + { + echo $e->getMessage( ); + } + + $Query->Disconnect( ); +?> +``` ### Functions - -Open connection to a server: `Connect( $IP, $Port );` - -Close connection: `Disconnect( );` - -Set rcon password for future use: `SetRconPassword( $RconPassword );` - -Execute Rcon command: `Rcon( $Command );` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Connect( $Ip, $Port, $Timeout, $Engine )Opens connection to a server
Disconnect( )Closes all open connections
Ping( )Ping the server to see if it exists
Warning: Source engine may not answer to this
GetInfo( )Returns server info in an array
GetPlayers( )Returns players on the server in an array
GetRules( )Returns public rules (cvars) in an array
SetRconPassword( $Password )Sets rcon password for later use with Rcon()
Rcon( $Command )Execute rcon command on the server
### License - > *This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
-> To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/* \ No newline at end of file +> To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/* diff --git a/SourceQuery.class.php b/SourceQuery.class.php index 1a1503d..74aaf06 100644 --- a/SourceQuery.class.php +++ b/SourceQuery.class.php @@ -62,19 +62,12 @@ class SourceQuery $this->Disconnect( ); } - public function Connect( $Ip, $Port, $Timeout = 3, $Engine = -1 ) + public function Connect( $Ip, $Port, $Timeout = 3, $Engine = self :: SOURCE ) { $this->Disconnect( ); $this->Buffer->Reset( ); $this->Challenge = 0; - if( $Engine == -1 ) - { - $Engine = self :: SOURCE; - - Trigger_Error( 'You should pass $Engine variable to Connect(), defaulting to Source.' ); - } - if( !$this->Socket->Open( $Ip, (int)$Port, (int)$Timeout, (int)$Engine ) ) { throw new SourceQueryException( 'Can\'t connect to the server.' );