@@ -17,39 +17,37 @@ def __init__(self, address: str, query_port: int, timeout: float = 5.0):
17
17
async def get_status (self ):
18
18
"""Retrieves information about the server including, Info, Players, and Teams."""
19
19
# Connect to remote host
20
- sock = SocketAsync ()
21
- sock .settimeout (self ._timeout )
22
- await sock .connect ((self ._address , self ._query_port ))
20
+ with SocketAsync () as sock :
21
+ sock .settimeout (self ._timeout )
22
+ await sock .connect ((self ._address , self ._query_port ))
23
23
24
- request_h = b'\xFE \xFD '
25
- timestamp = b'\x04 \x05 \x06 \x07 '
26
- challenge = b''
24
+ request_h = b'\xFE \xFD '
25
+ timestamp = b'\x04 \x05 \x06 \x07 '
26
+ challenge = b''
27
27
28
- if self .challenge :
29
- # Packet 1: Initial request - (https://wiki.unrealadmin.org/UT3_query_protocol#Packet_1:_Initial_request)
30
- sock .send (request_h + b'\x09 ' + timestamp )
28
+ if self .challenge :
29
+ # Packet 1: Initial request - (https://wiki.unrealadmin.org/UT3_query_protocol#Packet_1:_Initial_request)
30
+ sock .send (request_h + b'\x09 ' + timestamp )
31
31
32
- # Packet 2: First response - (https://wiki.unrealadmin.org/UT3_query_protocol#Packet_2:_First_response)
33
- response = await sock .recv ()
34
-
35
- if response [0 ] != 9 :
36
- raise InvalidPacketException (
37
- 'Packet header mismatch. Received: {}. Expected: {}.'
38
- .format (chr (response [0 ]), chr (9 ))
39
- )
32
+ # Packet 2: First response - (https://wiki.unrealadmin.org/UT3_query_protocol#Packet_2:_First_response)
33
+ response = await sock .recv ()
40
34
41
- # Packet 3: Second request - (http://wiki.unrealadmin.org/UT3_query_protocol#Packet_3:_Second_request)
42
- challenge = int (response [5 :].decode ('ascii' ).strip ('\x00 ' ))
43
- challenge = b'' if challenge == 0 else challenge .to_bytes (4 , 'big' , signed = True )
35
+ if response [0 ] != 9 :
36
+ raise InvalidPacketException (
37
+ 'Packet header mismatch. Received: {}. Expected: {}.'
38
+ .format (chr (response [0 ]), chr (9 ))
39
+ )
44
40
45
- request_data = request_h + b'\x00 ' + timestamp + challenge
46
- sock .send (request_data + b'\xFF \xFF \xFF \x01 ' )
41
+ # Packet 3: Second request - (http://wiki.unrealadmin.org/UT3_query_protocol#Packet_3:_Second_request)
42
+ challenge = int (response [5 :].decode ('ascii' ).strip ('\x00 ' ))
43
+ challenge = b'' if challenge == 0 else challenge .to_bytes (4 , 'big' , signed = True )
47
44
48
- # Packet 4: Server information response
49
- # (http://wiki.unrealadmin.org/UT3_query_protocol#Packet_4:_Server_information_response)
50
- response = await self .__read (sock )
45
+ request_data = request_h + b'\x00 ' + timestamp + challenge
46
+ sock .send (request_data + b'\xFF \xFF \xFF \x01 ' )
51
47
52
- sock .close ()
48
+ # Packet 4: Server information response
49
+ # (http://wiki.unrealadmin.org/UT3_query_protocol#Packet_4:_Server_information_response)
50
+ response = await self .__read (sock )
53
51
54
52
br = BinaryReader (response )
55
53
0 commit comments