11
11
class Source (ProtocolBase ):
12
12
"""Source Engine Query Protocol"""
13
13
full_name = 'Source Engine Query Protocol'
14
- _challenge = ''
15
14
16
15
class __RequestHeader ():
17
16
A2S_INFO = b'\x54 Source Engine Query\0 '
@@ -39,7 +38,7 @@ async def get_info(self) -> dict:
39
38
See: https://developer.valvesoftware.com/wiki/Server_queries#A2S_INFO
40
39
"""
41
40
response_data = await self .__connect_and_send_challenge (self .__RequestHeader .A2S_INFO )
42
-
41
+
43
42
br = BinaryReader (response_data )
44
43
header = br .read_byte ()
45
44
@@ -192,14 +191,12 @@ async def __connect_and_send_challenge(self, header: __RequestHeader) -> bytes:
192
191
with SocketAsync () as sock :
193
192
sock .settimeout (self ._timeout )
194
193
await sock .connect ((self ._address , self ._query_port ))
195
-
194
+
196
195
# Send and receive
197
196
request_base = b'\xFF \xFF \xFF \xFF ' + header
198
197
request_data = request_base
199
198
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 :
203
200
request_data += b'\xFF \xFF \xFF \xFF '
204
201
205
202
sock .send (request_data )
@@ -209,10 +206,10 @@ async def __connect_and_send_challenge(self, header: __RequestHeader) -> bytes:
209
206
210
207
# The server may reply with a challenge
211
208
if header == self .__ResponseHeader .S2C_CHALLENGE :
212
- self . _challenge = br .read ()
213
-
209
+ challenge = br .read ()
210
+
214
211
# Send the challenge and receive
215
- sock .send (request_base + self . _challenge )
212
+ sock .send (request_base + challenge )
216
213
response_data = await self .__receive (sock )
217
214
218
215
return response_data
@@ -465,7 +462,7 @@ class AuthenticationException(Exception):
465
462
import json
466
463
467
464
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 )
469
466
info = await source .get_info ()
470
467
players = await source .get_players ()
471
468
rules = await source .get_rules ()
0 commit comments