2
2
from typing import List
3
3
4
4
from a2s .exceptions import BrokenMessageError
5
- from a2s .defaults import DEFAULT_TIMEOUT , DEFAULT_ENCODING
5
+ from a2s .defaults import DEFAULT_TIMEOUT , DEFAULT_ENCODING , \
6
+ DEFAULT_RETRIES
6
7
from a2s .a2sstream import request
7
8
from a2s .byteio import ByteReader
8
9
from a2s .datacls import DataclsMeta
@@ -29,19 +30,20 @@ def players(address, timeout=DEFAULT_TIMEOUT,
29
30
encoding = DEFAULT_ENCODING ):
30
31
return players_impl (address , timeout , encoding )
31
32
32
- def players_impl (address , timeout , encoding , challenge = 0 ):
33
+ def players_impl (address , timeout , encoding , challenge = 0 , retries = 0 ):
33
34
resp_data = request (
34
35
address , b"\x55 " + challenge .to_bytes (4 , "little" ), timeout )
35
36
reader = ByteReader (
36
37
io .BytesIO (resp_data ), endian = "<" , encoding = encoding )
37
38
38
39
response_type = reader .read_uint8 ()
39
40
if response_type == A2S_CHALLENGE_RESPONSE :
40
- if challenge != 0 :
41
+ if retries >= DEFAULT_RETRIES :
41
42
raise BrokenMessageError (
42
43
"Server keeps sending challenge responses" )
43
- challenge = reader .read_int32 ()
44
- return players_impl (address , timeout , encoding , challenge )
44
+ challenge = reader .read_uint32 ()
45
+ return players_impl (
46
+ address , timeout , encoding , challenge , retries + 1 )
45
47
46
48
if response_type != A2S_PLAYER_RESPONSE :
47
49
raise BrokenMessageError (
0 commit comments