fix(pterodactyl): only json.loads() once in the websocket handling code
This commit is contained in:
parent
e2389cec08
commit
0496454030
1 changed files with 6 additions and 7 deletions
|
@ -33,24 +33,23 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
||||||
coginstance.websocket = websocket
|
coginstance.websocket = websocket
|
||||||
|
|
||||||
while True: # pylint: disable=too-many-nested-blocks
|
while True: # pylint: disable=too-many-nested-blocks
|
||||||
message = await websocket.recv()
|
message = json.loads(await websocket.recv())
|
||||||
if json.loads(message)['event'] in ('token expiring', 'token expired'):
|
if message['event'] in ('token expiring', 'token expired'):
|
||||||
logger.info("Received token expiring/expired event. Refreshing token.")
|
logger.info("Received token expiring/expired event. Refreshing token.")
|
||||||
websocket_credentials = await retrieve_websocket_credentials(coginstance)
|
websocket_credentials = await retrieve_websocket_credentials(coginstance)
|
||||||
auth_message = json.dumps({"event": "auth", "args": [websocket_credentials['data']['token']]})
|
auth_message = json.dumps({"event": "auth", "args": [websocket_credentials['data']['token']]})
|
||||||
await websocket.send(auth_message)
|
await websocket.send(auth_message)
|
||||||
logger.info("Authentication message sent")
|
logger.info("Authentication message sent")
|
||||||
|
|
||||||
if json.loads(message)['event'] == 'auth success':
|
if message['event'] == 'auth success':
|
||||||
logger.info("WebSocket authentication successful")
|
logger.info("WebSocket authentication successful")
|
||||||
|
|
||||||
if json.loads(message)['event'] == 'console output' and await config.console_channel() is not None:
|
if message['event'] == 'console output' and await config.console_channel() is not None:
|
||||||
msg = json.loads(message)['args'][0]
|
|
||||||
regex_blacklist: dict = await config.regex_blacklist()
|
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):
|
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:
|
if await config.mask_ip() is True:
|
||||||
content = mask_ip(content)
|
content = mask_ip(content)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue