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
.idea/
qbBuzzer.iml
test/

View File

@ -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" ]
# CMD [ "python", "app.py" ]
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
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

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 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))
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']