Skip to content

Commit bc174c3

Browse files
Resolve Source Engine Protocol issue
Correct the issue where the GetRules function doesn’t work when the data is compressed.
1 parent f4b0183 commit bc174c3

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

opengsq/binary_reader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def read_short(self, unsigned=True) -> int:
3737

3838
return data
3939

40-
def read_long(self) -> int:
41-
data = struct.unpack('<l', self.__data[self.stream_position:self.stream_position + 4])[0]
40+
def read_long(self, unsigned=False) -> int:
41+
format = 'L' if unsigned else 'l'
42+
data = struct.unpack(f'<{format}', self.__data[self.stream_position:self.stream_position + 4])[0]
4243
self.stream_position += 4
4344

4445
return data

opengsq/protocols/source.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ async def __receive(self, udpClient: UdpClient) -> bytes:
278278

279279
# Packet id
280280
id = br.read_long()
281-
is_compressed = (id & 0x80000000) < 0
281+
is_compressed = id & 0x80000000 != 0
282+
print(is_compressed)
282283

283284
# Check is GoldSource multi-packet response format
284285
if self.__is_gold_source_split(BinaryReader(br.read())):
@@ -290,15 +291,15 @@ async def __receive(self, udpClient: UdpClient) -> bytes:
290291
# The number of the packet
291292
number = br.read_byte()
292293

293-
# Packet size
294-
br.read_short()
295-
296294
if number == 0 and is_compressed:
297295
# Decompressed size
298-
br.read_long()
296+
br.read_long(unsigned=True)
299297

300298
# CRC32 sum
301-
crc32_checksum = br.read_long()
299+
crc32_checksum = br.read_long(unsigned=True)
300+
else:
301+
# Packet size
302+
br.read_short()
302303

303304
payloads[number] = br.read()
304305

@@ -377,13 +378,13 @@ async def __parse_gold_source_packet(self, udpClient: UdpClient, packets: list):
377378
import asyncio
378379

379380
async def main_async():
380-
source = Source(host="45.62.160.71", port=27015, timeout=5.0)
381-
info = await source.get_info()
382-
print(info)
381+
source = Source(host="146.19.87.161", port=27015, timeout=5.0)
382+
# info = await source.get_info()
383+
# print(info)
383384

384-
await asyncio.sleep(1)
385-
players = await source.get_players()
386-
print(players)
385+
# await asyncio.sleep(1)
386+
# players = await source.get_players()
387+
# print(players)
387388

388389
await asyncio.sleep(1)
389390
rules = await source.get_rules()

0 commit comments

Comments
 (0)