Skip to content

Commit

Permalink
[Fix] Source protocol skip non´challenge response
Browse files Browse the repository at this point in the history
  • Loading branch information
bumbummen99 committed Nov 29, 2024
1 parent 10f6071 commit 39c4e54
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/GameQ/Helpers/Arr/Recursively.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

/**
* This helper contains functions to work with arrays.
*
* @mixin \GameQ\Helpers\Arr
*
* @package GameQ\Helpers
*/
Expand Down
1 change: 0 additions & 1 deletion src/GameQ/Protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ public function hasChallenge()
*/
public function challengeParseAndApply(Buffer $challenge_buffer)
{

return true;
}

Expand Down
6 changes: 5 additions & 1 deletion src/GameQ/Protocols/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ class Source extends Protocol
public function challengeParseAndApply(Buffer $challenge_buffer)
{
// Skip the header
$challenge_buffer->skip(5);
$challenge_buffer->skip(4);

if ($challenge_buffer->read() !== "\x41") {
return true;
}

// Apply the challenge and return
return $this->challengeApply($challenge_buffer->read(4));
Expand Down
21 changes: 20 additions & 1 deletion tests/Protocols/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,33 @@ public function testChallengeapply()
$packets[\GameQ\Protocol::PACKET_RULES] = "\xFF\xFF\xFF\xFF\x56test";

// Create a fake buffer
$challenge_buffer = new \GameQ\Buffer("\xFF\xFF\xFF\xFF\xFFtest");
$challenge_buffer = new \GameQ\Buffer("\xFF\xFF\xFF\xFF\x41test");

// Apply the challenge
$this->stub->challengeParseAndApply($challenge_buffer);

$this->assertEquals($packets, $this->stub->getPacket());
}

/**
* Test that the challenge application is skipped if packet is not a challenge
*/
public function testSkipChallengeApply()
{
$packets = $this->packets;

// Set what the packets should look like
$packets[\GameQ\Protocol::PACKET_DETAILS] = "\xFF\xFF\xFF\xFFTSource Engine Query\x00%s";
$packets[\GameQ\Protocol::PACKET_PLAYERS] = "\xFF\xFF\xFF\xFF\x55%s";
$packets[\GameQ\Protocol::PACKET_RULES] = "\xFF\xFF\xFF\xFF\x56%s";

// Create a fake buffer
$challenge_buffer = new \GameQ\Buffer("\xFF\xFF\xFF\xFF\xFFtest");

$this->stub->challengeParseAndApply($challenge_buffer);
$this->assertEquals($packets, $this->stub->getPacket());
}

/**
* Test invalid packet type without debug
*/
Expand Down

0 comments on commit 39c4e54

Please sign in to comment.