def kill(): try: msg = request.json["msg"].upper() killer = Player.all().filter('username ='******'game =', game)\ .filter('killer =', killer)\ .filter('is_complete =', False).get() if msg == old_game_history_success.confirm_msg: will_be_last_kill = None if GameHistory.all().filter("game =", game).filter("is_complete =", False).count() == 2: will_be_last_kill = True old_target = old_game_history_success.target old_game_history_success.is_complete = True old_game_history_success.put() old_game_history_failure = GameHistory.all()\ .filter('game =', game)\ .filter('killer =', old_target)\ .filter('is_complete =', False).get() old_game_history_failure.is_complete = True old_game_history_failure.put() if will_be_last_kill: game_player = GamePlayer.all().filter('game =', game).filter('player =', killer).get() game_player.is_winner = True game_player.put() return jsonify({"success": True, "info": "Your enemy has been slain! "}) new_target = old_game_history_failure.target GameHistory(killer=killer, target=new_target, game=game, is_complete=False, confirm_msg=msg_generator()).put() return jsonify({"success": True, "info": "Your enemy has been slain! "}) else: return jsonify({"success": False, "info": "The message is incorrect. Are you trying to game the system?!"}) except: # TODO: please handle exceptions in a more proper way return jsonify({"success": False, "info": "Something is fundamentally wrong. ", "Data received by server": str(request.data)})
def get_player(player_id): player = Player.get_by_id(player_id) game_players = GamePlayer.all().filter('player =', player) games = [game_player.game for game_player in game_players] info = {} for game in games: info[str(game.key().id())] = to_dict(game) return jsonify(**info)
def get_game_status(): info = {"target": None, "in_game": False, "game_exists": False, "msg": None, "player_exists": False, "game_completed": False, "time_left": None} try: game = Game.get_by_id(int(request.args["game_id"])) if game is None: info["msg"] = "Game does not exists. " return jsonify(info) info["game_exists"] = True killer = Player.all().filter('username ='******'game =', game).filter('player =', killer).get() if player_in is None: info["msg"] = "Player trying to kill is not in this game. " return jsonify(info) info["in_game"] = True if GameHistory.all().filter("game =", game).filter("is_complete =", False).count() == 0: info["game_completed"] = True game_player = GamePlayer.all().filter('game =', game).filter('is_winner =', True).get() info["winner_name"] = str(game_player.player.username) return jsonify(info) to_kill_game_history = GameHistory.all().filter('killer =', killer).filter('game =', game).filter('is_complete', False).get() be_killed_game_history = GameHistory.all().filter('target =', killer).filter('game =', game).filter('is_complete', False).get() if to_kill_game_history is None: return jsonify(info) else: info["time_left"] = to_kill_game_history.assign_date + timedelta(hours=1) info["target"] = to_kill_game_history.target.username info["msg"] = be_killed_game_history.confirm_msg return jsonify(info) except: # info["time_left"] = str(datetime.datetime.now()) info["msg"] = "Something is fundamentally wrong. " return jsonify(info)