second faking identities fixed and better leaving game

This commit is contained in:
EvilMuffinHa 2020-10-19 23:33:45 -04:00
parent 0f3ad3f71f
commit d0e89672a9

View File

@ -134,18 +134,17 @@ 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))
if dohash(data["_gid"]) == room: if dohash(data["_gid"]) == room:
pass pass
elif games[room]["players"][data['username']][1] != data['_gid']: elif games[room]["players"][data['username']][1] != data['_gid']:
return return
if room not in games.keys():
return render_template('gamenotfound.html', title="Join Game", version=str(version))
join_room(str(room)) join_room(str(room))
nplayers = {} nplayers = {}
for r in games[room]["players"].keys(): for r in games[room]["players"].keys():
nplayers[r] = games[room]["players"][r][0] nplayers[r] = games[room]["players"][r][0]
msg = {"locked": games[room]["locked"], "players": nplayers} msg = {"locked": games[room]["locked"], "players": nplayers}
print(msg)
emit('player_join_event', msg, room=room) emit('player_join_event', msg, room=room)
@ -208,8 +207,8 @@ def host_msg(data):
elif "negs" in msg.keys(): elif "negs" in msg.keys():
if games[room]["buzzed"] == "": if games[room]["buzzed"] == "":
return return
games[room]["players"][games[room]["buzzed"]] -= games[room]["negs"] games[room]["players"][games[room]["buzzed"]][0] -= games[room]["negs"]
username = games[room]["buzzed"][0] username = games[room]["buzzed"]
games[room]["buzzed"] = "" games[room]["buzzed"] = ""
nplayers = {} nplayers = {}
for r in games[room]["players"].keys(): for r in games[room]["players"].keys():
@ -222,10 +221,10 @@ def host_msg(data):
@socketio.on('buzz') @socketio.on('buzz')
def buzz(data): def buzz(data):
room = data["room"] room = data["room"]
if games[room]["players"][data["username"]][1] != data['_gid']:
return
if room not in games.keys(): if room not in games.keys():
return render_template('gamenotfound.html', title="Join Game", version=str(version)) return render_template('gamenotfound.html', title="Join Game", version=str(version))
if games[room]["players"][data["username"]][1] != data['_gid']:
return
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
@ -236,12 +235,22 @@ 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))
if "username" not in data.keys():
if dohash(data["_gid"]) == room:
app.logger.debug("Game host at " + data["_gid"] + " closed game at " + room)
leave_room(str(room))
emit('host_leave_event', {'host': 0}, room=room)
return
else:
return
if data["username"] in games[room]["players"].keys():
return # you have been kicked
if dohash(data["_gid"]) == room: if dohash(data["_gid"]) == room:
pass pass
elif games[room]["players"][data["username"]][1] != data['_gid']: elif games[room]["players"][data["username"]][1] != data['_gid']:
return return
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']