Skip to content

Commit e0010c1

Browse files
Fix source query issue
1 parent 3583a2b commit e0010c1

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

opengsq/protocols/source.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
class Source(ProtocolBase):
1212
"""Source Engine Query Protocol"""
1313
full_name = 'Source Engine Query Protocol'
14-
_challenge = ''
1514

1615
class __RequestHeader():
1716
A2S_INFO = b'\x54Source Engine Query\0'
@@ -39,7 +38,7 @@ async def get_info(self) -> dict:
3938
See: https://developer.valvesoftware.com/wiki/Server_queries#A2S_INFO
4039
"""
4140
response_data = await self.__connect_and_send_challenge(self.__RequestHeader.A2S_INFO)
42-
41+
4342
br = BinaryReader(response_data)
4443
header = br.read_byte()
4544

@@ -192,14 +191,12 @@ async def __connect_and_send_challenge(self, header: __RequestHeader) -> bytes:
192191
with SocketAsync() as sock:
193192
sock.settimeout(self._timeout)
194193
await sock.connect((self._address, self._query_port))
195-
194+
196195
# Send and receive
197196
request_base = b'\xFF\xFF\xFF\xFF' + header
198197
request_data = request_base
199198

200-
if len(self._challenge) > 0:
201-
request_data += self._challenge
202-
elif header != self.__RequestHeader.A2S_INFO:
199+
if header != self.__RequestHeader.A2S_INFO:
203200
request_data += b'\xFF\xFF\xFF\xFF'
204201

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

210207
# The server may reply with a challenge
211208
if header == self.__ResponseHeader.S2C_CHALLENGE:
212-
self._challenge = br.read()
213-
209+
challenge = br.read()
210+
214211
# Send the challenge and receive
215-
sock.send(request_base + self._challenge)
212+
sock.send(request_base + challenge)
216213
response_data = await self.__receive(sock)
217214

218215
return response_data
@@ -465,7 +462,7 @@ class AuthenticationException(Exception):
465462
import json
466463

467464
async def main_async():
468-
source = Source(address='45.147.5.5', query_port=27015, timeout=5.0)
465+
source = Source(address='209.205.114.187', query_port=27015, timeout=5.0)
469466
info = await source.get_info()
470467
players = await source.get_players()
471468
rules = await source.get_rules()

opengsq/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.2.0'
1+
__version__ = '1.2.1'

0 commit comments

Comments
 (0)