|
@@ -29,15 +29,19 @@ def require_player(game_id):
|
|
|
|
|
|
@game.route("", methods=["PUT"])
|
|
|
def create_game():
|
|
|
- timer = request.json.get("timer", None)
|
|
|
+ js = request.get_json()
|
|
|
+ if js is None:
|
|
|
+ abort(400)
|
|
|
+
|
|
|
+ timer = js.get("timer", None)
|
|
|
if not isinstance(timer, int) or timer <= 0:
|
|
|
abort(400)
|
|
|
|
|
|
- rounds = request.json.get("rounds", None)
|
|
|
+ rounds = js.get("rounds", None)
|
|
|
if not isinstance(rounds, int) or rounds <= 0:
|
|
|
abort(400)
|
|
|
|
|
|
- only_america = request.json.get("onlyAmerica", False)
|
|
|
+ only_america = js.get("onlyAmerica", False)
|
|
|
if not isinstance(only_america, bool):
|
|
|
abort(400)
|
|
|
|
|
@@ -85,7 +89,11 @@ def link_game(game_id):
|
|
|
if request.method == "GET":
|
|
|
return jsonify({"linkedGame": g.linked_game})
|
|
|
|
|
|
- link_id = request.json.get("linkedGame", None)
|
|
|
+ js = request.get_json()
|
|
|
+ if js is None:
|
|
|
+ abort(400)
|
|
|
+
|
|
|
+ link_id = js.get("linkedGame", None)
|
|
|
if link_id is None or db.Game.query.get(link_id) is None:
|
|
|
abort(401)
|
|
|
|
|
@@ -95,7 +103,11 @@ def link_game(game_id):
|
|
|
|
|
|
@game.route("/<game_id>/join", methods=["POST"])
|
|
|
def join(game_id):
|
|
|
- name = request.json.get("playerName", None)
|
|
|
+ js = request.get_json()
|
|
|
+ if js is None:
|
|
|
+ abort(400)
|
|
|
+
|
|
|
+ name = js.get("playerName", None)
|
|
|
if name is None:
|
|
|
abort(400)
|
|
|
|
|
@@ -140,7 +152,11 @@ def make_guess(game_id, round_num):
|
|
|
if round_num != player.get_current_round():
|
|
|
abort(409)
|
|
|
|
|
|
- timed_out = request.json.get("timeout", False)
|
|
|
+ js = request.get_json()
|
|
|
+ if js is None:
|
|
|
+ abort(400)
|
|
|
+
|
|
|
+ timed_out = js.get("timeout", False)
|
|
|
if timed_out:
|
|
|
player.add_timeout(round_num)
|
|
|
db.session.commit()
|
|
@@ -151,9 +167,9 @@ def make_guess(game_id, round_num):
|
|
|
}), 201
|
|
|
|
|
|
try:
|
|
|
- lat = float(request.json.get("lat", None))
|
|
|
- lng = float(request.json.get("lng", None))
|
|
|
- remaining = int(request.json.get("timeRemaining", None))
|
|
|
+ lat = float(js.get("lat", None))
|
|
|
+ lng = float(js.get("lng", None))
|
|
|
+ remaining = int(js.get("timeRemaining", None))
|
|
|
except ValueError:
|
|
|
abort(400)
|
|
|
|