From b6912248a491583cbefe5bde4bc280297ec2b58b Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Thu, 15 Oct 2020 10:42:59 -0400 Subject: [PATCH] bad socketio bad --- .gitignore | 1 - Dockerfile | 6 +++--- Procfile | 2 +- requirements.txt | 9 +++++++++ run.sh | 3 +++ src/app.py | 27 ++++++++++++++++----------- 6 files changed, 32 insertions(+), 16 deletions(-) create mode 100755 run.sh diff --git a/.gitignore b/.gitignore index 684c562..27f0bd5 100644 --- a/.gitignore +++ b/.gitignore @@ -133,5 +133,4 @@ dmypy.json # jetbrains folder .idea/ qbBuzzer.iml -test/ diff --git a/Dockerfile b/Dockerfile index a7a20c8..aa5f42f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ WORKDIR /root/ RUN pip install -r requirements.txt -WORKDIR /root/src +WORKDIR /root/ -CMD [ "python", "app.py" ] -# CMD [ "gunicorn", "-b", "0.0.0.0:25565","--workers", "3", "--timeout", "86400", "src.app:app" ] \ No newline at end of file +# CMD [ "python", "app.py" ] +CMD [ "gunicorn", "-b", "0.0.0.0:25565","--workers", "3", "--timeout", "86400", "-k", "eventlet", "src.app:app" ] \ No newline at end of file diff --git a/Procfile b/Procfile index 52e7aed..3b8c9e3 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn src.app:app \ No newline at end of file +web: gunicorn -w 1 -k eventlet src.app:app \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0e6243d..c2d5a17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,24 @@ +certifi==2020.6.20 +chardet==3.0.4 click==7.1.2 +dnspython==1.16.0 +eventlet==0.28.0 Flask==1.1.2 Flask-SocketIO==4.3.1 Flask-WTF==0.14.3 +greenlet==0.4.17 gunicorn==20.0.4 +idna==2.10 itsdangerous==1.1.0 Jinja2==2.11.2 MarkupSafe==1.1.1 +monotonic==1.5 pycryptodome==3.9.8 python-dotenv==0.14.0 python-engineio==3.13.2 python-socketio==4.6.0 +requests==2.24.0 six==1.15.0 +urllib3==1.25.10 Werkzeug==1.0.1 WTForms==2.3.3 diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..1e7a880 --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +source venv/bin/activate +gunicorn -b 0.0.0.0:25565 --workers 4 -k eventlet src.app:app \ No newline at end of file diff --git a/src/app.py b/src/app.py index 8486651..34b1fa4 100644 --- a/src/app.py +++ b/src/app.py @@ -1,9 +1,9 @@ from flask import * from random import randint as rint -from config import Config -from host import HostForm -from join import JoinForm -from sec import gencode, dohash, whitelist +from src.config import Config +from src.host import HostForm +from src.join import JoinForm +from src.sec import gencode, dohash, whitelist from logging.config import dictConfig from flask_socketio import SocketIO, emit, join_room, leave_room import json @@ -12,7 +12,7 @@ from dotenv import load_dotenv load_dotenv() # Loading logging preferences -with open("logger.json", "r") as f: +with open("src/logger.json", "r") as f: dconf = json.load(f) # Establishing logger @@ -46,7 +46,7 @@ def host(): hash = dohash(hostcode) resp = redirect(url_for("play", hash=hash)) resp.set_cookie("_gid", str(hostcode)) - with open("templates/games.json", "r") as f: + with open("src/templates/games.json", "r") as f: tmp = json.load(f) games[hash] = tmp games[hash]["hostcode"] = hostcode @@ -59,7 +59,7 @@ def host(): session.permanent = True return resp - with open("templates/games.json", "r") as f: + with open("src/templates/games.json", "r") as f: tmp = json.load(f) default = [tmp["tossup"], tmp["bonus"], tmp["power"], tmp["negs"]] return render_template('host.html', title="Host Game", version=str(version), form=form, default=default) @@ -130,6 +130,8 @@ socketio = SocketIO(app) @socketio.on('join') def on_join(data): room = data['room'] + if room not in games.keys(): + return render_template('gamenotfound.html', title="Join Game", version=str(version)) username = "" if "username" in data.keys(): username = data['username'] @@ -138,10 +140,7 @@ def on_join(data): if dohash(gid) == room: username = "host" join_room(str(room)) - try: - msg = {"locked": games[room]["locked"], "players": games[room]["players"]} - except KeyError: - return render_template('gamenotfound.html', title="Join Game", version=str(version)) + msg = {"locked": games[room]["locked"], "players": games[room]["players"]} emit('player_join_event', msg, room=room) @@ -150,6 +149,8 @@ def on_join(data): def host_msg(data): room = data["room"] gid = data["_gid"] + if room not in games.keys(): + return render_template('gamenotfound.html', title="Join Game", version=str(version)) if dohash(gid) != room: # Check if the host is really the host return msg = data["data"] @@ -203,6 +204,8 @@ def host_msg(data): @socketio.on('buzz') def buzz(data): room = data["room"] + if room not in games.keys(): + return render_template('gamenotfound.html', title="Join Game", version=str(version)) if not games[room]["locked"]: games[room]["buzzed"] = data["username"] emit("buzz_event", data, room=room) # Just send it back @@ -213,6 +216,8 @@ def buzz(data): @socketio.on('leave') def on_leave(data): room = data['room'] + if room not in games.keys(): + return render_template('gamenotfound.html', title="Join Game", version=str(version)) username = "" if "username" in data.keys(): username = data['username']