1
0
mirror of https://github.com/xPaw/PHP-Source-Query.git synced 2026-05-18 11:43:33 +02:00

Add support for games that use old method for getting challenges

This commit is contained in:
xPaw
2014-10-20 16:22:26 +03:00
parent 980bbc1404
commit 77d8a3aba1
3 changed files with 38 additions and 3 deletions
+1
View File
@@ -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*
+29
View File
@@ -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( );
+8 -3
View File
@@ -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 @@
<meta charset="utf-8">
<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">
.jumbotron {
margin-top: 30px;
@@ -141,7 +142,7 @@
<?php endforeach; ?>
<?php else: ?>
<tr>
<td>No players in da house</td>
<td colspan="3">No players received</td>
</tr>
<?php endif; ?>
</tbody>
@@ -164,6 +165,10 @@
<td><?php echo htmlspecialchars( $Value ); ?></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="2">No rules received</td>
</tr>
<?php endif; ?>
</tbody>
</table>