diff --git a/src/GameQ/Helpers/Arr/Recursively.php b/src/GameQ/Helpers/Arr/Recursively.php index c280476a..09553961 100644 --- a/src/GameQ/Helpers/Arr/Recursively.php +++ b/src/GameQ/Helpers/Arr/Recursively.php @@ -25,6 +25,8 @@ /** * This helper contains functions to work with arrays. + * + * @mixin \GameQ\Helpers\Arr * * @package GameQ\Helpers */ diff --git a/src/GameQ/Protocol.php b/src/GameQ/Protocol.php index 0c38f474..dcfd9e91 100644 --- a/src/GameQ/Protocol.php +++ b/src/GameQ/Protocol.php @@ -440,7 +440,6 @@ public function hasChallenge() */ public function challengeParseAndApply(Buffer $challenge_buffer) { - return true; } diff --git a/src/GameQ/Protocols/Source.php b/src/GameQ/Protocols/Source.php index adf940a1..027700c6 100644 --- a/src/GameQ/Protocols/Source.php +++ b/src/GameQ/Protocols/Source.php @@ -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)); diff --git a/tests/Protocols/Source.php b/tests/Protocols/Source.php index 98566493..defd9eb3 100644 --- a/tests/Protocols/Source.php +++ b/tests/Protocols/Source.php @@ -72,7 +72,7 @@ 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); @@ -80,6 +80,25 @@ public function testChallengeapply() $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 */