Bugs bugs bugs bugs bugs bugs

I love bugs
This commit is contained in:
Michał Gdula 2023-06-26 14:15:45 +01:00
parent 28d5f140c0
commit 377f20ce10
7 changed files with 34 additions and 12 deletions

View file

@ -6,7 +6,7 @@ from werkzeug.security import check_password_hash
from werkzeug.utils import secure_filename
from .models import Scores, Sessions, Users
from .extensions import db
from .extensions import db, logger
from .config import (
GAME_VERSION,
GAME_VERSIONS,
@ -55,32 +55,34 @@ def post():
difficulty = request.form.get("difficulty", GAME_DIFFICULTY)
score = request.form.get("score", 0)
# logger.debug(f"Score upload attempt: {session_key} {version} {difficulty} {score}")
if not session_key:
return "No session key provided!"
if not score:
return "Score is not valid!"
try:
float(score)
int(difficulty)
score = float(score)
difficulty = int(difficulty)
except TypeError:
return "Invalid score and difficulty must be valid numbers!"
if int(difficulty) not in GAME_DIFFICULTIES:
if difficulty not in GAME_DIFFICULTIES:
return "Invalid difficulty!"
if version not in GAME_VERSIONS:
return "Invalid version!"
# This is a fix for a bug in the game that we dunno how to actually fix
# if score < 10:
# return "Score is impossible!"
if score < 10:
return "Score is impossible!"
session_data = Sessions.query.filter_by(auth_key=session_key).first()
if not session_data:
return "Authentication failed!"
score_upload = Scores(
score=float(score),
difficulty=int(difficulty),
score=score,
difficulty=difficulty,
version=version,
user_id=session_data.user_id,
)