diff --git a/docs/.gitignore b/docs/.gitignore index a7952c5..049a3c6 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,3 +1,2 @@ -modules.rst -opengsq.protocols.rst -opengsq.rst +*.rst +!index.rst diff --git a/opengsq/protocols/quake3.py b/opengsq/protocols/quake3.py index f8656dd..f480429 100644 --- a/opengsq/protocols/quake3.py +++ b/opengsq/protocols/quake3.py @@ -1,5 +1,6 @@ import re +from opengsq.responses.quake2 import Status from opengsq.binary_reader import BinaryReader from opengsq.protocols.quake2 import Quake2 from opengsq.exceptions import InvalidPacketException @@ -52,31 +53,20 @@ async def get_info(self, strip_color=True) -> dict: return info - async def get_status(self, strip_color=True) -> dict: - """ - Asynchronously retrieves the status of the game server. The status includes information about the server and players. - - :param strip_color: A boolean indicating whether to strip color codes from the status. - :return: A dictionary containing the status of the game server. - """ + async def get_status(self, strip_color=True) -> Status: br = await self._get_response_binary_reader() - status = { - "info": self._parse_info(br), - "players": self._parse_players(br), - } + status = Status(info=self._parse_info(br), players=self._parse_players(br)) if not strip_color: return status - if "sv_hostname" in status["info"]: - status["info"]["sv_hostname"] = Quake3.strip_colors( - status["info"]["sv_hostname"] - ) + if "sv_hostname" in status.info: + status.info["sv_hostname"] = Quake3.strip_colors(status.info["sv_hostname"]) - for player in status["players"]: - if "name" in player: - player["name"] = Quake3.strip_colors(player["name"]) + for player in status.players: + if player.name: + player.name = Quake3.strip_colors(player.name) return status @@ -96,10 +86,10 @@ def strip_colors(text: str) -> str: import json async def main_async(): - quake3 = Quake3(host="85.10.197.106", port=27960, timeout=5.0) + quake3 = Quake3(host="108.61.18.110", port=27960, timeout=5.0) info = await quake3.get_info() status = await quake3.get_status() - print(json.dumps(info, indent=None) + "\n") - print(json.dumps(status, indent=None) + "\n") + print(json.dumps(info, indent=None, default=lambda o: o.__dict__) + "\n") + print(json.dumps(status, indent=None, default=lambda o: o.__dict__) + "\n") asyncio.run(main_async()) diff --git a/tests/protocols/result_handler.py b/tests/protocols/result_handler.py index b0a7fe5..e6b9628 100644 --- a/tests/protocols/result_handler.py +++ b/tests/protocols/result_handler.py @@ -20,13 +20,13 @@ async def save_result(self, function_name, result, is_json=True): if self.enable_save: if is_json: - if is_dataclass(result): - result = asdict(result) - elif isinstance(result, list): - # set asdict to all items - result = [asdict(item) for item in result if is_dataclass(item)] + # if is_dataclass(result): + # result = asdict(result) + # elif isinstance(result, list): + # # set asdict to all items + # result = [asdict(item) for item in result if is_dataclass(item)] - result = json.dumps(result, indent=4, ensure_ascii=False) + result = json.dumps(result, indent=4, ensure_ascii=False, default=lambda o: o.__dict__) with open(os.path.join(self.__protocol_path, f'{function_name}.{(is_json and "json" or "txt")}'), 'w', encoding='utf-8') as f: print(result, file=f) diff --git a/tests/protocols/test_doom3.py b/tests/protocols/test_doom3.py index 5764548..765fcc3 100644 --- a/tests/protocols/test_doom3.py +++ b/tests/protocols/test_doom3.py @@ -9,7 +9,7 @@ # handler.enable_save = True # Quake 4 -doom3 = Doom3(host='88.99.0.7', port=28007) +doom3 = Doom3(host='178.162.135.83', port=27735) @pytest.mark.asyncio async def test_get_info(): diff --git a/tests/protocols/test_minecraft.py b/tests/protocols/test_minecraft.py index 6f462ee..cf2e4f2 100644 --- a/tests/protocols/test_minecraft.py +++ b/tests/protocols/test_minecraft.py @@ -9,7 +9,7 @@ # handler.enable_save = True # Minecraft -test = Minecraft(host='valistar.site', port=25565) +test = Minecraft(host='mc.goldcraft.ir', port=25565) @pytest.mark.asyncio async def test_get_status():