bad socketio bad

This commit is contained in:
EvilMuffinHa 2020-10-15 10:42:59 -04:00
parent 124cb54b74
commit b6912248a4
6 changed files with 32 additions and 16 deletions

1
.gitignore vendored
View File

@ -133,5 +133,4 @@ dmypy.json
# jetbrains folder # jetbrains folder
.idea/ .idea/
qbBuzzer.iml qbBuzzer.iml
test/

View File

@ -6,7 +6,7 @@ WORKDIR /root/
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
WORKDIR /root/src WORKDIR /root/
CMD [ "python", "app.py" ] # CMD [ "python", "app.py" ]
# CMD [ "gunicorn", "-b", "0.0.0.0:25565","--workers", "3", "--timeout", "86400", "src.app:app" ] CMD [ "gunicorn", "-b", "0.0.0.0:25565","--workers", "3", "--timeout", "86400", "-k", "eventlet", "src.app:app" ]

View File

@ -1 +1 @@
web: gunicorn src.app:app web: gunicorn -w 1 -k eventlet src.app:app

View File

@ -1,15 +1,24 @@
certifi==2020.6.20
chardet==3.0.4
click==7.1.2 click==7.1.2
dnspython==1.16.0
eventlet==0.28.0
Flask==1.1.2 Flask==1.1.2
Flask-SocketIO==4.3.1 Flask-SocketIO==4.3.1
Flask-WTF==0.14.3 Flask-WTF==0.14.3
greenlet==0.4.17
gunicorn==20.0.4 gunicorn==20.0.4
idna==2.10
itsdangerous==1.1.0 itsdangerous==1.1.0
Jinja2==2.11.2 Jinja2==2.11.2
MarkupSafe==1.1.1 MarkupSafe==1.1.1
monotonic==1.5
pycryptodome==3.9.8 pycryptodome==3.9.8
python-dotenv==0.14.0 python-dotenv==0.14.0
python-engineio==3.13.2 python-engineio==3.13.2
python-socketio==4.6.0 python-socketio==4.6.0
requests==2.24.0
six==1.15.0 six==1.15.0
urllib3==1.25.10
Werkzeug==1.0.1 Werkzeug==1.0.1
WTForms==2.3.3 WTForms==2.3.3

3
run.sh Executable file
View File

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

View File

@ -1,9 +1,9 @@
from flask import * from flask import *
from random import randint as rint from random import randint as rint
from config import Config from src.config import Config
from host import HostForm from src.host import HostForm
from join import JoinForm from src.join import JoinForm
from sec import gencode, dohash, whitelist from src.sec import gencode, dohash, whitelist
from logging.config import dictConfig from logging.config import dictConfig
from flask_socketio import SocketIO, emit, join_room, leave_room from flask_socketio import SocketIO, emit, join_room, leave_room
import json import json
@ -12,7 +12,7 @@ from dotenv import load_dotenv
load_dotenv() load_dotenv()
# Loading logging preferences # Loading logging preferences
with open("logger.json", "r") as f: with open("src/logger.json", "r") as f:
dconf = json.load(f) dconf = json.load(f)
# Establishing logger # Establishing logger
@ -46,7 +46,7 @@ def host():
hash = dohash(hostcode) hash = dohash(hostcode)
resp = redirect(url_for("play", hash=hash)) resp = redirect(url_for("play", hash=hash))
resp.set_cookie("_gid", str(hostcode)) 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) tmp = json.load(f)
games[hash] = tmp games[hash] = tmp
games[hash]["hostcode"] = hostcode games[hash]["hostcode"] = hostcode
@ -59,7 +59,7 @@ def host():
session.permanent = True session.permanent = True
return resp return resp
with open("templates/games.json", "r") as f: with open("src/templates/games.json", "r") as f:
tmp = json.load(f) tmp = json.load(f)
default = [tmp["tossup"], tmp["bonus"], tmp["power"], tmp["negs"]] default = [tmp["tossup"], tmp["bonus"], tmp["power"], tmp["negs"]]
return render_template('host.html', title="Host Game", version=str(version), form=form, default=default) 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') @socketio.on('join')
def on_join(data): def on_join(data):
room = data['room'] room = data['room']
if room not in games.keys():
return render_template('gamenotfound.html', title="Join Game", version=str(version))
username = "" username = ""
if "username" in data.keys(): if "username" in data.keys():
username = data['username'] username = data['username']
@ -138,10 +140,7 @@ def on_join(data):
if dohash(gid) == room: if dohash(gid) == room:
username = "host" username = "host"
join_room(str(room)) join_room(str(room))
try: msg = {"locked": games[room]["locked"], "players": games[room]["players"]}
msg = {"locked": games[room]["locked"], "players": games[room]["players"]}
except KeyError:
return render_template('gamenotfound.html', title="Join Game", version=str(version))
emit('player_join_event', msg, room=room) emit('player_join_event', msg, room=room)
@ -150,6 +149,8 @@ def on_join(data):
def host_msg(data): def host_msg(data):
room = data["room"] room = data["room"]
gid = data["_gid"] 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 if dohash(gid) != room: # Check if the host is really the host
return return
msg = data["data"] msg = data["data"]
@ -203,6 +204,8 @@ def host_msg(data):
@socketio.on('buzz') @socketio.on('buzz')
def buzz(data): def buzz(data):
room = data["room"] 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"]: if not games[room]["locked"]:
games[room]["buzzed"] = data["username"] games[room]["buzzed"] = data["username"]
emit("buzz_event", data, room=room) # Just send it back emit("buzz_event", data, room=room) # Just send it back
@ -213,6 +216,8 @@ def buzz(data):
@socketio.on('leave') @socketio.on('leave')
def on_leave(data): def on_leave(data):
room = data['room'] room = data['room']
if room not in games.keys():
return render_template('gamenotfound.html', title="Join Game", version=str(version))
username = "" username = ""
if "username" in data.keys(): if "username" in data.keys():
username = data['username'] username = data['username']