Skip to content

Commit

Permalink
Update protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Jan 16, 2024
1 parent 1ad02d3 commit 71f46f7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion opengsq/protocols/gamespy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion opengsq/protocols/gamespy4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
12 changes: 8 additions & 4 deletions opengsq/protocols/vcmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand All @@ -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()
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion tests/protocols/test_gamespy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 71f46f7

Please sign in to comment.