From 77d8a3aba1d0d5ecc45f2a5ec61911738f552a0a Mon Sep 17 00:00:00 2001 From: xPaw Date: Mon, 20 Oct 2014 16:22:26 +0300 Subject: [PATCH] Add support for games that use old method for getting challenges --- README.md | 1 + SourceQuery/SourceQuery.class.php | 29 +++++++++++++++++++++++++++++ View.php | 11 ++++++++--- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1f159d8..43fda12 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ The class also allows you to query servers using RCON although this only works f * [Dino D-Day](http://store.steampowered.com/app/70000/) * [Nuclear Dawn](http://store.steampowered.com/app/17710/) * [Call of Duty: Modern Warfare 3](http://store.steampowered.com/app/115300/) +* [Starbound](http://store.steampowered.com/app/211820/) *(use SetUseOldGetChallengeMethod method after connecting)* * [Arma 3](http://store.steampowered.com/app/107410/) *(add +1 to the server port, their implementation also violates Source query protocol spec.)* * [Minecraft](http://www.minecraft.net/) **(RCON ONLY!)** * *and many other games that implement Source Query Protocol* diff --git a/SourceQuery/SourceQuery.class.php b/SourceQuery/SourceQuery.class.php index 3a1d1f5..580fedd 100644 --- a/SourceQuery/SourceQuery.class.php +++ b/SourceQuery/SourceQuery.class.php @@ -44,6 +44,7 @@ const A2S_INFO = 0x54; const A2S_PLAYER = 0x55; const A2S_RULES = 0x56; + const A2S_SERVERQUERY_GETCHALLENGE = 0x57; /** * Packets received @@ -103,6 +104,13 @@ */ private $Challenge; + /** + * Use old method for getting challenge number + * + * @var bool + */ + private $UseOldGetChallengeMethod; + public function __construct( ) { $this->Buffer = new SourceQueryBuffer( ); @@ -158,6 +166,22 @@ } } + /** + * Forces GetChallenge to use old method for challenge retrieval because some games use outdated protocol (e.g Starbound) + * + * @param bool $Value Set to true to force old method + * + * @returns bool Previous value + */ + public function SetUseOldGetChallengeMethod( $Value ) + { + $Previous = $this->UseOldGetChallengeMethod; + + $this->UseOldGetChallengeMethod = $Value === true; + + return $Previous; + } + /** * Closes all open connections */ @@ -464,6 +488,11 @@ return self :: GETCHALLENGE_ALL_CLEAR; } + if( $this->UseOldGetChallengeMethod ) + { + $Header = self :: A2S_SERVERQUERY_GETCHALLENGE; + } + $this->Socket->Write( $Header, 0xFFFFFFFF ); $this->Socket->Read( ); diff --git a/View.php b/View.php index ea56dc2..625d1a5 100644 --- a/View.php +++ b/View.php @@ -4,7 +4,7 @@ // Edit this -> define( 'SQ_SERVER_ADDR', 'localhost' ); define( 'SQ_SERVER_PORT', 27015 ); - define( 'SQ_TIMEOUT', 1 ); + define( 'SQ_TIMEOUT', 3 ); define( 'SQ_ENGINE', SourceQuery :: SOURCE ); // Edit this <- @@ -19,6 +19,7 @@ try { $Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE ); + //$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound $Info = $Query->GetInfo( ); $Players = $Query->GetPlayers( ); @@ -39,7 +40,7 @@ Source Query PHP Class - +