fix(pterodactyl): only json.loads() once in the websocket handling code
Some checks failed
Actions / Lint Code (Ruff & Pylint) (push) Failing after 22s
Actions / Build Documentation (MkDocs) (push) Has been cancelled

This commit is contained in:
Seaswimmer 2024-03-03 02:01:01 -05:00
parent e2389cec08
commit 0496454030
Signed by: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -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)