From 3af6afdc003323f52326f88acaf6c3bb4d536ad4 Mon Sep 17 00:00:00 2001 From: anitejb <41495799+anitejb@users.noreply.github.com> Date: Thu, 11 Nov 2021 18:10:02 -0500 Subject: [PATCH 1/3] multiplayer support: refactor victim rescue flow --- main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 3d69f77..9a2eda9 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,7 @@ from rich.console import Console ping_freq, ping_wait = 25, 60 -player_limit = 1 +player_limit = 2 console = Console() @@ -52,7 +52,7 @@ executor = concurrent.futures.ThreadPoolExecutor(max_workers=20) -cred = credentials.Certificate(eval(os.environ["FIREBASE_AUTH"])) +cred = credentials.Certificate(os.environ["FIREBASE_AUTH"]) initialize_app(cred, {"databaseURL": os.environ["FIREBASE_URL"]}) ref = db.reference("/") @@ -139,8 +139,14 @@ async def rescue_attempt_handler(sid, message): loop.run_in_executor(executor, save_data, sid, message) -@sio.on("rescue_success") -async def rescue_success_handler(sid, message): +@sio.on("rescue") +async def rescue_handler(sid, message): + console.print(message, sid, style="bold blue") + await sio.emit("rescue_success", message, room=message["rm_id"]) + + +@sio.on("rescue_displayed") +async def rescue_displayed_handler(sid, message): console.print(message, sid, style="bold blue") loop = asyncio.get_event_loop() loop.run_in_executor(executor, save_data, sid, message) From 2a6a3ec060045cd1a3a0aa821c21c5d77136a98a Mon Sep 17 00:00:00 2001 From: anitejb <41495799+anitejb@users.noreply.github.com> Date: Mon, 13 Dec 2021 14:31:05 -0500 Subject: [PATCH 2/3] add json.loads to replace previously removed eval --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9a2eda9..47885ae 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import asyncio import concurrent.futures import datetime +import json import os import sys from hashlib import sha1 @@ -52,7 +53,7 @@ executor = concurrent.futures.ThreadPoolExecutor(max_workers=20) -cred = credentials.Certificate(os.environ["FIREBASE_AUTH"]) +cred = credentials.Certificate(json.loads(os.environ["FIREBASE_AUTH"])) initialize_app(cred, {"databaseURL": os.environ["FIREBASE_URL"]}) ref = db.reference("/") From efe08c3d9e8461866910092a40b4cad224aad738 Mon Sep 17 00:00:00 2001 From: Chirag Date: Mon, 20 Dec 2021 09:28:51 -0600 Subject: [PATCH 3/3] Change the json.loads to previous version of eval and keep the player limit to one --- main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 47885ae..1634d67 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,6 @@ import asyncio import concurrent.futures import datetime -import json import os import sys from hashlib import sha1 @@ -16,7 +15,7 @@ from rich.console import Console ping_freq, ping_wait = 25, 60 -player_limit = 2 +player_limit = 1 console = Console() @@ -53,7 +52,7 @@ executor = concurrent.futures.ThreadPoolExecutor(max_workers=20) -cred = credentials.Certificate(json.loads(os.environ["FIREBASE_AUTH"])) +cred = credentials.Certificate(eval(os.environ["FIREBASE_AUTH"])) initialize_app(cred, {"databaseURL": os.environ["FIREBASE_URL"]}) ref = db.reference("/")