Skip to content

Commit

Permalink
Fix source query issue
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Oct 28, 2022
1 parent 3583a2b commit e0010c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions opengsq/protocols/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
class Source(ProtocolBase):
"""Source Engine Query Protocol"""
full_name = 'Source Engine Query Protocol'
_challenge = ''

class __RequestHeader():
A2S_INFO = b'\x54Source Engine Query\0'
Expand Down Expand Up @@ -39,7 +38,7 @@ async def get_info(self) -> dict:
See: https://developer.valvesoftware.com/wiki/Server_queries#A2S_INFO
"""
response_data = await self.__connect_and_send_challenge(self.__RequestHeader.A2S_INFO)

br = BinaryReader(response_data)
header = br.read_byte()

Expand Down Expand Up @@ -192,14 +191,12 @@ async def __connect_and_send_challenge(self, header: __RequestHeader) -> bytes:
with SocketAsync() as sock:
sock.settimeout(self._timeout)
await sock.connect((self._address, self._query_port))

# Send and receive
request_base = b'\xFF\xFF\xFF\xFF' + header
request_data = request_base

if len(self._challenge) > 0:
request_data += self._challenge
elif header != self.__RequestHeader.A2S_INFO:
if header != self.__RequestHeader.A2S_INFO:
request_data += b'\xFF\xFF\xFF\xFF'

sock.send(request_data)
Expand All @@ -209,10 +206,10 @@ async def __connect_and_send_challenge(self, header: __RequestHeader) -> bytes:

# The server may reply with a challenge
if header == self.__ResponseHeader.S2C_CHALLENGE:
self._challenge = br.read()
challenge = br.read()

# Send the challenge and receive
sock.send(request_base + self._challenge)
sock.send(request_base + challenge)
response_data = await self.__receive(sock)

return response_data
Expand Down Expand Up @@ -465,7 +462,7 @@ class AuthenticationException(Exception):
import json

async def main_async():
source = Source(address='45.147.5.5', query_port=27015, timeout=5.0)
source = Source(address='209.205.114.187', query_port=27015, timeout=5.0)
info = await source.get_info()
players = await source.get_players()
rules = await source.get_rules()
Expand Down
2 changes: 1 addition & 1 deletion opengsq/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.0'
__version__ = '1.2.1'

0 comments on commit e0010c1

Please sign in to comment.