From 04964540307e1969a3a1124c40707e5d7c79ac28 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sun, 3 Mar 2024 02:01:01 -0500 Subject: [PATCH] fix(pterodactyl): only json.loads() once in the websocket handling code --- pterodactyl/websocket.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pterodactyl/websocket.py b/pterodactyl/websocket.py index 48f8799..6a5113a 100644 --- a/pterodactyl/websocket.py +++ b/pterodactyl/websocket.py @@ -33,24 +33,23 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None: coginstance.websocket = websocket while True: # pylint: disable=too-many-nested-blocks - message = await websocket.recv() - if json.loads(message)['event'] in ('token expiring', 'token expired'): + message = json.loads(await websocket.recv()) + if message['event'] in ('token expiring', 'token expired'): logger.info("Received token expiring/expired event. Refreshing token.") websocket_credentials = await retrieve_websocket_credentials(coginstance) auth_message = json.dumps({"event": "auth", "args": [websocket_credentials['data']['token']]}) await websocket.send(auth_message) logger.info("Authentication message sent") - if json.loads(message)['event'] == 'auth success': + if message['event'] == 'auth success': logger.info("WebSocket authentication successful") - if json.loads(message)['event'] == 'console output' and await config.console_channel() is not None: - msg = json.loads(message)['args'][0] + if message['event'] == 'console output' and await config.console_channel() is not None: regex_blacklist: dict = await config.regex_blacklist() - matches = [re.search(regex, msg) for regex in regex_blacklist.values()] + matches = [re.search(regex, message['args'][0]) for regex in regex_blacklist.values()] if await config.current_status() in ('running', '') and not any(matches): - content = remove_ansi_escape_codes(msg) + content = remove_ansi_escape_codes(message['args'][0]) if await config.mask_ip() is True: content = mask_ip(content)