def submit_pvp_game_credentials(): if SessionKeys.ACTIVE_GAME_ID in session: return redirect(URLs.HOME_PAGE) if request.form['gameID'] is None or request.form['password'] is None: return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=True) submitted_game_id = str(request.form['gameID']) submitted_pass = str(request.form['password']) if submitted_game_id == '' or not submitted_game_id.isalnum(): return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=True) if submitted_pass != '' and not submitted_pass.isalnum(): return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=True) db_util = DBUtil(get_db_connection()) game_status = db_util.get_game_status(submitted_game_id) if game_status is None or game_status != GameStatus.WAITING_FOR_OPPONENT: return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=True) actual_pass = db_util.get_pvp_game_pass(submitted_game_id) if actual_pass is None or actual_pass != submitted_pass: return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=True) else: is_playing_white = db_util.set_pvp_game_active( submitted_game_id, session[SessionKeys.USER_ID]) session[SessionKeys.ACTIVE_GAME_ID] = submitted_game_id session[SessionKeys.IS_GAME_HOST] = False session[SessionKeys.IS_PLAYING_WHITE] = is_playing_white return redirect(URLs.HOME_PAGE)
def get_join_pvp_game_page(): if request.args.get('gameID') is not None: game_id = str(request.args.get('gameID')) if game_id != '' and not game_id.isalnum(): return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=True) db_util = DBUtil(get_db_connection()) game_status = db_util.get_game_status(game_id) if game_status is None or game_status != GameStatus.WAITING_FOR_OPPONENT: return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=True) password = db_util.get_pvp_game_pass(game_id) if password is None: return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=True) if password == '': is_playing_white = db_util.set_pvp_game_active( game_id, session[SessionKeys.USER_ID]) session[SessionKeys.ACTIVE_GAME_ID] = game_id session[SessionKeys.IS_GAME_HOST] = False session[SessionKeys.IS_PLAYING_WHITE] = is_playing_white return redirect(URLs.HOME_PAGE) else: return render_template('joinGame.html', prefilledID=game_id, showUnsuccessfulMessage=False) else: return render_template('joinGame.html', prefilled_id='', showUnsuccessfulMessage=False)