import misc cgitb.enable() fields = cgi.FieldStorage() name = fields.getvalue("name") hash = fields.getvalue("hash") gameID = fields.getvalue("gameID") if None in {name, hash, gameID}: misc.fail("Missing parameters, one of (name, hash, gameID") games = misc.load_games() found = misc.find_game(games, gameID) if found is None: misc.fail("No game by that ID found") if found.player_1 == name and found.player_1_hash == hash: found.game_state = "X-1" elif found.player_2 == name and found.player_2_hash == hash: found.game_state = "X-2" else: misc.fail("name or hash incorrect for given game") misc.save_games(games) misc.succeed("Left game")
name, hash, gameID, x, y = (fields.getvalue("name"), fields.getvalue("hash"), fields.getvalue("gameID"), fields.getvalue("x"), fields.getvalue("y")) if None in {name, hash, gameID, x, y}: misc.fail("Missing parameters, one of (name, hash, x, y}") try: x = int(x) y = int(y) except ValueError: misc.fail("coordinates must be integers") games = misc.load_games() game = misc.find_game(games, gameID) player = misc.validate_player(game, name, hash) opponent = 2 if player == 1 else 1 board = misc.get_boards(gameID)[opponent - 1] if player is None: misc.fail("Invalid name/hash/gameID") if player == 1 and game.waiting_for != 1 \ or player == 2 and game.waiting_for != 2: misc.fail("It is not your turn") if game.game_state != "G": misc.fail("The game is not in progress") if board[y][x] % misc.SHOT == 0: misc.fail("You've already shot that square")
def obscure(board2): return [ [obscureCell(cell) for cell in line] for line in board2 ] cgitb.enable() fields = cgi.FieldStorage() name, hash, gameID = (fields.getvalue("name"), fields.getvalue("hash"), fields.getvalue("gameID")) if None in {name, hash, gameID}: misc.fail("Missing fields, one of (name, hash, gameID)") game = misc.find_game(misc.load_games(), gameID) if game is None: misc.fail("No game found") validated_player_id = misc.validate_player(game, name, hash) try: board1, board2 = misc.get_boards(gameID) your_board = board1 if validated_player_id == 1 else board2 opponent_board = obscure(board2 if validated_player_id == 1 else board1) except: your_board, opponent_board = [[]], [[]] misc.succeed("Game state loaded", game=game.to_personalized_dict(validated_player_id), your_board=your_board, opponent_board=opponent_board, validated_player_id=validated_player_id)