def submit_game_settings(): game_vs_human = str(request.form['gameVsHuman']) == 'True' if game_vs_human: RANDOM = 0 WHITE = 1 BLACK = 2 host_plays_as = -1 try: host_plays_as = int(request.form['hostPlaysAs']) # time_limit = int(request.form['timeLimit']) time_limit = 0 # not supporting time limits for now except ValueError: return render_template('createGame.html', gameVsHuman=True, showErrorMessage=True, showPasswordErrorMessage=False) if host_plays_as not in {RANDOM, WHITE, BLACK}: return render_template('createGame.html', gameVsHuman=True, showErrorMessage=True, showPasswordErrorMessage=False) if time_limit not in app_constants.SUPPORTED_TIME_LIMITS: return render_template('createGame.html', gameVsHuman=True, showErrorMessage=True, showPasswordErrorMessage=False) if host_plays_as == RANDOM: host_plays_as = random.randint(WHITE, BLACK) game_password = '' if 'gamePassword' in request.form: game_password = str(request.form['gamePassword']) if len(game_password) > 0 and not game_password.isalnum(): return render_template('createGame.html', gameVsHuman=True, showErrorMessage=False, showPasswordErrorMessage=True) db_util = DBUtil(get_db_connection()) host_user_id = session[SessionKeys.USER_ID] host_playing_white = host_plays_as == WHITE external_game_id = db_util.create_pvp_game(host_user_id, host_playing_white, game_password) session[SessionKeys.ACTIVE_GAME_ID] = external_game_id session[SessionKeys.IS_GAME_HOST] = True session[SessionKeys.IS_PLAYING_WHITE] = host_plays_as == WHITE get_logger().debug( "PVP game with external ID: " + external_game_id + " has been created. Returning 'Waiting for opponent' page") return redirect(URLs.WAIT_FOR_OPP_PAGE) else: # handle case for playing vs computer, raise exception 404 for now raise Exception( "temporary exception, doesn't support vs. computer games for now" )