Skip to content

Commit 77d8a3a

Browse files
committed
Add support for games that use old method for getting challenges
1 parent 980bbc1 commit 77d8a3a

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The class also allows you to query servers using RCON although this only works f
1818
* [Dino D-Day](http://store.steampowered.com/app/70000/)
1919
* [Nuclear Dawn](http://store.steampowered.com/app/17710/)
2020
* [Call of Duty: Modern Warfare 3](http://store.steampowered.com/app/115300/)
21+
* [Starbound](http://store.steampowered.com/app/211820/) *(use SetUseOldGetChallengeMethod method after connecting)*
2122
* [Arma 3](http://store.steampowered.com/app/107410/) *(add +1 to the server port, their implementation also violates Source query protocol spec.)*
2223
* [Minecraft](http://www.minecraft.net/) **(RCON ONLY!)**
2324
* *and many other games that implement Source Query Protocol*

SourceQuery/SourceQuery.class.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class SourceQuery
4444
const A2S_INFO = 0x54;
4545
const A2S_PLAYER = 0x55;
4646
const A2S_RULES = 0x56;
47+
const A2S_SERVERQUERY_GETCHALLENGE = 0x57;
4748

4849
/**
4950
* Packets received
@@ -103,6 +104,13 @@ class SourceQuery
103104
*/
104105
private $Challenge;
105106

107+
/**
108+
* Use old method for getting challenge number
109+
*
110+
* @var bool
111+
*/
112+
private $UseOldGetChallengeMethod;
113+
106114
public function __construct( )
107115
{
108116
$this->Buffer = new SourceQueryBuffer( );
@@ -158,6 +166,22 @@ public function Connect( $Ip, $Port, $Timeout = 3, $Engine = self :: SOURCE )
158166
}
159167
}
160168

169+
/**
170+
* Forces GetChallenge to use old method for challenge retrieval because some games use outdated protocol (e.g Starbound)
171+
*
172+
* @param bool $Value Set to true to force old method
173+
*
174+
* @returns bool Previous value
175+
*/
176+
public function SetUseOldGetChallengeMethod( $Value )
177+
{
178+
$Previous = $this->UseOldGetChallengeMethod;
179+
180+
$this->UseOldGetChallengeMethod = $Value === true;
181+
182+
return $Previous;
183+
}
184+
161185
/**
162186
* Closes all open connections
163187
*/
@@ -464,6 +488,11 @@ private function GetChallenge( $Header, $ExpectedResult )
464488
return self :: GETCHALLENGE_ALL_CLEAR;
465489
}
466490

491+
if( $this->UseOldGetChallengeMethod )
492+
{
493+
$Header = self :: A2S_SERVERQUERY_GETCHALLENGE;
494+
}
495+
467496
$this->Socket->Write( $Header, 0xFFFFFFFF );
468497
$this->Socket->Read( );
469498

View.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Edit this ->
55
define( 'SQ_SERVER_ADDR', 'localhost' );
66
define( 'SQ_SERVER_PORT', 27015 );
7-
define( 'SQ_TIMEOUT', 1 );
7+
define( 'SQ_TIMEOUT', 3 );
88
define( 'SQ_ENGINE', SourceQuery :: SOURCE );
99
// Edit this <-
1010

@@ -19,6 +19,7 @@
1919
try
2020
{
2121
$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );
22+
//$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound
2223

2324
$Info = $Query->GetInfo( );
2425
$Players = $Query->GetPlayers( );
@@ -39,7 +40,7 @@
3940
<meta charset="utf-8">
4041
<title>Source Query PHP Class</title>
4142

42-
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
43+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
4344
<style type="text/css">
4445
.jumbotron {
4546
margin-top: 30px;
@@ -141,7 +142,7 @@
141142
<?php endforeach; ?>
142143
<?php else: ?>
143144
<tr>
144-
<td>No players in da house</td>
145+
<td colspan="3">No players received</td>
145146
</tr>
146147
<?php endif; ?>
147148
</tbody>
@@ -164,6 +165,10 @@
164165
<td><?php echo htmlspecialchars( $Value ); ?></td>
165166
</tr>
166167
<?php endforeach; ?>
168+
<?php else: ?>
169+
<tr>
170+
<td colspan="2">No rules received</td>
171+
</tr>
167172
<?php endif; ?>
168173
</tbody>
169174
</table>

0 commit comments

Comments
 (0)