second faking identities fixed

This commit is contained in:
EvilMuffinHa 2020-10-19 23:12:54 -04:00
parent f951533a18
commit 0f3ad3f71f
4 changed files with 46 additions and 25 deletions

View File

@ -23,7 +23,6 @@ app = Flask(__name__)
app.logger.info("Flask app loaded at " + __name__) app.logger.info("Flask app loaded at " + __name__)
app.config.from_object(Config) app.config.from_object(Config)
# Version allows css / js to load instead of taking hours to update even on run smh # Version allows css / js to load instead of taking hours to update even on run smh
version = rint(0, 300000000) version = rint(0, 300000000)
@ -80,8 +79,10 @@ def play(hash):
elif (not all([a in wlist for a in name])) or (len(name) > 12): elif (not all([a in wlist for a in name])) or (len(name) > 12):
return render_template('badname.html', title='Join Game', version=str(version)) return render_template('badname.html', title='Join Game', version=str(version))
else: else:
games[hash]["players"][name] = 0 player_token = gencode(128)
return render_template('play.html', version=str(version), title="Play", gamecode=hash, username=name) games[hash]["players"][name] = [0, player_token]
return render_template('play.html', version=str(version), title="Play", gamecode=hash,
username=name, token=player_token)
else: else:
return render_template('please.html', version=str(version)) return render_template('please.html', version=str(version))
else: else:
@ -129,24 +130,22 @@ socketio = SocketIO(app)
# V # V
# Checks when a player / host joins the room # Checks when a player / host joins the room
@socketio.on('join') @socketio.on('join')
def on_join(data): def on_join(data):
room = data['room'] room = data['room']
if dohash(data["_gid"]) == room:
pass
elif 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))
username = ""
if "username" in data.keys():
username = data['username']
else:
gid = data["_gid"]
if dohash(gid) == room:
username = "host"
join_room(str(room)) join_room(str(room))
msg = {"locked": games[room]["locked"], "players": games[room]["players"]} nplayers = {}
for r in games[room]["players"].keys():
nplayers[r] = games[room]["players"][r][0]
msg = {"locked": games[room]["locked"], "players": nplayers}
print(msg)
emit('player_join_event', msg, room=room) emit('player_join_event', msg, room=room)
@ -176,40 +175,55 @@ def host_msg(data):
elif "tossup" in msg.keys(): elif "tossup" in msg.keys():
if games[room]["buzzed"] == "": if games[room]["buzzed"] == "":
return return
games[room]["players"][games[room]["buzzed"]] += games[room]["tossup"] games[room]["players"][games[room]["buzzed"]][0] += games[room]["tossup"]
username = games[room]["buzzed"] username = games[room]["buzzed"]
games[room]["buzzed"] = "" games[room]["buzzed"] = ""
emit("update_score_event", {"username":username, "players": games[room]["players"]}, room=room) nplayers = {}
for r in games[room]["players"].keys():
nplayers[r] = games[room]["players"][r][0]
emit("update_score_event", {"username": username, "players": nplayers}, room=room)
emit("unlocked_event", {}, room=room) emit("unlocked_event", {}, room=room)
elif "bonus" in msg.keys(): elif "bonus" in msg.keys():
if games[room]["buzzed"] == "": if games[room]["buzzed"] == "":
return return
games[room]["players"][games[room]["buzzed"]] += games[room]["bonus"] games[room]["players"][games[room]["buzzed"]][0] += games[room]["bonus"]
username = games[room]["buzzed"] username = games[room]["buzzed"]
games[room]["buzzed"] = "" games[room]["buzzed"] = ""
emit("update_score_event", {"username":username, "players": games[room]["players"]}, room=room) nplayers = {}
for r in games[room]["players"].keys():
nplayers[r] = games[room]["players"][r][0]
emit("update_score_event", {"username": username, "players": nplayers}, room=room)
emit("unlocked_event", {}, room=room) emit("unlocked_event", {}, room=room)
elif "power" in msg.keys(): elif "power" in msg.keys():
if games[room]["buzzed"] == "": if games[room]["buzzed"] == "":
return return
games[room]["players"][games[room]["buzzed"]] += games[room]["power"] games[room]["players"][games[room]["buzzed"]][0] += games[room]["power"]
username = games[room]["buzzed"] username = games[room]["buzzed"]
games[room]["buzzed"] = "" games[room]["buzzed"] = ""
emit("update_score_event", {"username":username, "players": games[room]["players"]}, room=room) nplayers = {}
for r in games[room]["players"].keys():
nplayers[r] = games[room]["players"][r][0]
emit("update_score_event", {"username": username, "players": nplayers}, room=room)
emit("unlocked_event", {}, room=room) emit("unlocked_event", {}, room=room)
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"]] -= games[room]["negs"]
username = games[room]["buzzed"] username = games[room]["buzzed"][0]
games[room]["buzzed"] = "" games[room]["buzzed"] = ""
emit("update_score_event", {"username":username, "players": games[room]["players"]}, room=room) nplayers = {}
for r in games[room]["players"].keys():
nplayers[r] = games[room]["players"][r][0]
emit("update_score_event", {"username": username, "players": nplayers}, room=room)
emit("unlocked_event", {}, room=room) emit("unlocked_event", {}, room=room)
# When the player buzzes # When the player buzzes
@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 not games[room]["locked"]: if not games[room]["locked"]:
@ -222,6 +236,10 @@ def buzz(data):
@socketio.on('leave') @socketio.on('leave')
def on_leave(data): def on_leave(data):
room = data['room'] room = data['room']
if dohash(data["_gid"]) == room:
pass
elif 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))
username = "" username = ""

View File

@ -4,6 +4,7 @@ code = document.getElementById("code").value;
name = document.getElementById("name").value; name = document.getElementById("name").value;
kickurl = document.getElementById("kick").value; kickurl = document.getElementById("kick").value;
hostleave = document.getElementById("hostleave").value; hostleave = document.getElementById("hostleave").value;
gid = document.getElementById("gid").value;
function removeAllChildren(e) { function removeAllChildren(e) {
var child = e.lastElementChild; var child = e.lastElementChild;
@ -15,7 +16,7 @@ function removeAllChildren(e) {
socket.on("connect", function() { socket.on("connect", function() {
// when client first connects to a game // when client first connects to a game
socket.emit("join", {"username": name, "room": code, "_gid": ""}); socket.emit("join", {"username": name, "room": code, "_gid": gid});
}) })
socket.on("player_join_event", function(datas) { socket.on("player_join_event", function(datas) {
@ -135,7 +136,7 @@ function unlock() {
function buzz() { function buzz() {
// when client hits buzz // when client hits buzz
socket.emit("buzz", {"username": name, "room": code, "_gid": ""}); socket.emit("buzz", {"username": name, "room": code, "_gid": gid});
} }
$(document).on('keypress', function(e) { $(document).on('keypress', function(e) {
@ -147,6 +148,6 @@ $(document).on('keypress', function(e) {
window.onbeforeunload = function leave() { window.onbeforeunload = function leave() {
// when client leaves // when client leaves
socket.emit("leave", {"username": name, "room": code, "_gid": ""}); socket.emit("leave", {"username": name, "room": code, "_gid": gid});
} }

View File

@ -46,6 +46,7 @@ window.onbeforeunload = function leave() {
socket.on("player_join_event", function(datas) { socket.on("player_join_event", function(datas) {
data = datas["players"] data = datas["players"]
console.log(data)
div = document.getElementById("sidebar"); div = document.getElementById("sidebar");
removeAllChildren(div); removeAllChildren(div);
if (Object.keys(data).length == 0) { if (Object.keys(data).length == 0) {

View File

@ -23,6 +23,7 @@
<br><input type="hidden" id="name" name="name" value="{{ username }}"> <br><input type="hidden" id="name" name="name" value="{{ username }}">
<br><input type="hidden" id="kick" name="kick" value="{{ url_for('kick') }}"> <br><input type="hidden" id="kick" name="kick" value="{{ url_for('kick') }}">
<input type="hidden" id="hostleave" name="hostleave" value="{{ url_for('join') }}"> <input type="hidden" id="hostleave" name="hostleave" value="{{ url_for('join') }}">
<input type="hidden" id="gid" name="gid" value="{{ token }}">
<div class="sidebar" id="sidebar"> <div class="sidebar" id="sidebar">
</div> </div>
<div id="game"> <div id="game">