From 71f46f7b7b61c470c5c226a9c07cf5f6078ff3d2 Mon Sep 17 00:00:00 2001 From: Battlefield Duck Date: Wed, 17 Jan 2024 02:11:27 +0800 Subject: [PATCH] Update protocols --- opengsq/protocols/gamespy2.py | 3 ++- opengsq/protocols/gamespy4.py | 2 +- opengsq/protocols/vcmp.py | 12 ++++++++---- tests/protocols/test_gamespy2.py | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/opengsq/protocols/gamespy2.py b/opengsq/protocols/gamespy2.py index 6581287..f0ad6c8 100644 --- a/opengsq/protocols/gamespy2.py +++ b/opengsq/protocols/gamespy2.py @@ -117,7 +117,8 @@ def __get_teams(self, br: BinaryReader) -> list: import json async def main_async(): - gs2 = GameSpy2(host='158.69.118.94', port=23000, timeout=5.0) + # bfv + gs2 = GameSpy2(host='108.61.236.22', port=23000, timeout=5.0) status = await gs2.get_status() print(json.dumps(status, indent=None) + '\n') diff --git a/opengsq/protocols/gamespy4.py b/opengsq/protocols/gamespy4.py index 519d47a..581d858 100644 --- a/opengsq/protocols/gamespy4.py +++ b/opengsq/protocols/gamespy4.py @@ -12,7 +12,7 @@ class GameSpy4(GameSpy3): import json async def main_async(): - gs4 = GameSpy4(host='188.18.10.72', port=19133, timeout=5.0) + gs4 = GameSpy4(host='play.avengetech.me', port=19132, timeout=5.0) server = await gs4.get_status() print(json.dumps(server, indent=None)) diff --git a/opengsq/protocols/vcmp.py b/opengsq/protocols/vcmp.py index ad88d91..7fcb4a2 100644 --- a/opengsq/protocols/vcmp.py +++ b/opengsq/protocols/vcmp.py @@ -14,7 +14,9 @@ class Vcmp(ProtocolBase): _response_header = b'MP04' async def get_status(self): - br = await self.__send_and_receive(b'i') + response = await self.__send_and_receive(b'i') + + br = BinaryReader(response) result = {} result['version'] = str(br.read_bytes(12).strip(b'\x00'), encoding='utf-8', errors='ignore') result['password'] = br.read_byte() @@ -28,7 +30,9 @@ async def get_status(self): async def get_players(self): """Server may not response when numplayers > 100""" - br = await self.__send_and_receive(b'c') + response = await self.__send_and_receive(b'c') + + br = BinaryReader(response) players = [] numplayers = br.read_short() @@ -52,7 +56,7 @@ async def __send_and_receive(self, data: bytes): if header != self._response_header: raise InvalidPacketException(f'Packet header mismatch. Received: {header}. Expected: {self._response_header}.') - return BinaryReader(response[len(self._response_header) + len(packet_header):]) + return response[len(self._response_header) + len(packet_header):] def __read_string(self, br: BinaryReader, read_offset=1): length = br.read_byte() if read_offset == 1 else br.read_long() @@ -64,7 +68,7 @@ def __read_string(self, br: BinaryReader, read_offset=1): import json async def main_async(): - vcmp = Vcmp(host='91.121.134.5', port=8192, timeout=5.0) + vcmp = Vcmp(host='51.178.65.136', port=8114, timeout=5.0) status = await vcmp.get_status() print(json.dumps(status, indent=None) + '\n') players = await vcmp.get_players() diff --git a/tests/protocols/test_gamespy2.py b/tests/protocols/test_gamespy2.py index b362cb9..7359f08 100644 --- a/tests/protocols/test_gamespy2.py +++ b/tests/protocols/test_gamespy2.py @@ -8,7 +8,8 @@ handler = ResultHandler(os.path.basename(__file__)[:-3]) # handler.enable_save = True -test = GameSpy2(host='89.58.8.211', port=23000) +# bfv +test = GameSpy2(host='108.61.236.22', port=23000) @pytest.mark.asyncio async def test_get_status():