Add support for games that use old method for getting challenges

pull/35/merge
xPaw 10 years ago
parent 980bbc1404
commit 77d8a3aba1

@ -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/) * [Dino D-Day](http://store.steampowered.com/app/70000/)
* [Nuclear Dawn](http://store.steampowered.com/app/17710/) * [Nuclear Dawn](http://store.steampowered.com/app/17710/)
* [Call of Duty: Modern Warfare 3](http://store.steampowered.com/app/115300/) * [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.)* * [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!)** * [Minecraft](http://www.minecraft.net/) **(RCON ONLY!)**
* *and many other games that implement Source Query Protocol* * *and many other games that implement Source Query Protocol*

@ -44,6 +44,7 @@
const A2S_INFO = 0x54; const A2S_INFO = 0x54;
const A2S_PLAYER = 0x55; const A2S_PLAYER = 0x55;
const A2S_RULES = 0x56; const A2S_RULES = 0x56;
const A2S_SERVERQUERY_GETCHALLENGE = 0x57;
/** /**
* Packets received * Packets received
@ -103,6 +104,13 @@
*/ */
private $Challenge; private $Challenge;
/**
* Use old method for getting challenge number
*
* @var bool
*/
private $UseOldGetChallengeMethod;
public function __construct( ) public function __construct( )
{ {
$this->Buffer = new SourceQueryBuffer( ); $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 * Closes all open connections
*/ */
@ -464,6 +488,11 @@
return self :: GETCHALLENGE_ALL_CLEAR; return self :: GETCHALLENGE_ALL_CLEAR;
} }
if( $this->UseOldGetChallengeMethod )
{
$Header = self :: A2S_SERVERQUERY_GETCHALLENGE;
}
$this->Socket->Write( $Header, 0xFFFFFFFF ); $this->Socket->Write( $Header, 0xFFFFFFFF );
$this->Socket->Read( ); $this->Socket->Read( );

@ -4,7 +4,7 @@
// Edit this -> // Edit this ->
define( 'SQ_SERVER_ADDR', 'localhost' ); define( 'SQ_SERVER_ADDR', 'localhost' );
define( 'SQ_SERVER_PORT', 27015 ); define( 'SQ_SERVER_PORT', 27015 );
define( 'SQ_TIMEOUT', 1 ); define( 'SQ_TIMEOUT', 3 );
define( 'SQ_ENGINE', SourceQuery :: SOURCE ); define( 'SQ_ENGINE', SourceQuery :: SOURCE );
// Edit this <- // Edit this <-
@ -19,6 +19,7 @@
try try
{ {
$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE ); $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( ); $Info = $Query->GetInfo( );
$Players = $Query->GetPlayers( ); $Players = $Query->GetPlayers( );
@ -39,7 +40,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>Source Query PHP Class</title> <title>Source Query PHP Class</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<style type="text/css"> <style type="text/css">
.jumbotron { .jumbotron {
margin-top: 30px; margin-top: 30px;
@ -141,7 +142,7 @@
<?php endforeach; ?> <?php endforeach; ?>
<?php else: ?> <?php else: ?>
<tr> <tr>
<td>No players in da house</td> <td colspan="3">No players received</td>
</tr> </tr>
<?php endif; ?> <?php endif; ?>
</tbody> </tbody>
@ -164,6 +165,10 @@
<td><?php echo htmlspecialchars( $Value ); ?></td> <td><?php echo htmlspecialchars( $Value ); ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="2">No rules received</td>
</tr>
<?php endif; ?> <?php endif; ?>
</tbody> </tbody>
</table> </table>

Loading…
Cancel
Save