def match_create(): if not g.user: return redirect('/login') form = MatchForm(request.form) form.add_teams(g.user) form.add_servers(g.user) form.add_seasons() if request.method == 'POST': num_matches = g.user.matches.count() max_matches = config_setting('USER_MAX_MATCHES') season_id = None if max_matches >= 0 and num_matches >= max_matches and not g.user.admin: flash('You already have the maximum number of matches ({}) created'.format( num_matches)) elif form.validate(): mock = config_setting('TESTING') server = GameServer.query.get_or_404(form.data['server_id']) match_on_server = g.user.matches.filter_by( server_id=server.id, end_time=None, cancelled=False).first() server_available = False json_reply = None if g.user.id != server.user_id and not server.public_server: server_available = False message = 'This is not your server!' elif match_on_server is not None: server_available = False message = 'Match {} is already using this server'.format( match_on_server.id) elif mock: server_available = True message = 'Success' else: json_reply, message = util.check_server_avaliability( server,dbKey) server_available = (json_reply is not None) if server_available: skip_veto = 'preset' in form.data['series_type'] try: max_maps = int(form.data['series_type'][2]) except ValueError: max_maps = 1 if form.data['season_selection'] != 0: season_id = form.data['season_selection'] match = Match.create( g.user, form.data['team1_id'], form.data['team2_id'], form.data['team1_string'], form.data['team2_string'], max_maps, skip_veto, form.data['match_title'], form.data['veto_mappool'], season_id, form.data['side_type'], form.data['veto_first'], form.data['server_id']) # Save plugin version data if we have it if json_reply and 'plugin_version' in json_reply: match.plugin_version = json_reply['plugin_version'] else: match.plugin_version = 'unknown' # ADD FORM DATA FOR EXTRA GOODIES HERE LIKE CLAN TAG ETC. # Essentially stuff that doesn't need to be stored in DB. # Force Get5 to auth on official matches. Don't raise errors # if we cannot do this. if server_available and not mock: server.send_rcon_command('get5_check_auths ' + str(int(form.data['enforce_teams'])), num_retries=2, timeout=0.75) server.in_use = True db.session.commit() app.logger.info('User {} created match {}, assigned to server {}' .format(g.user.id, match.id, server.id)) if mock or match.send_to_server(): return redirect('/mymatches') else: flash('Failed to load match configs on server') else: flash(message) else: get5.flash_errors(form) return render_template( 'match_create.html', form=form, user=g.user, teams=g.user.teams, match_text_option=config_setting('CREATE_MATCH_TITLE_TEXT'))
def match_create(): if not g.user: return redirect('/login') form = MatchForm(request.form) form.add_teams(g.user) form.add_servers(g.user) if request.method == 'POST': num_matches = g.user.matches.count() max_matches = config_setting('USER_MAX_MATCHES') if max_matches >= 0 and num_matches >= max_matches and not g.user.admin: flash('You already have the maximum number of matches ({}) created'.format( num_matches)) if form.validate(): mock = config_setting('TESTING') server = GameServer.query.get_or_404(form.data['server_id']) match_on_server = g.user.matches.filter_by( server_id=server.id, end_time=None, cancelled=False).first() server_avaliable = False json_reply = None if g.user.id != server.user_id: server_avaliable = False message = 'This is not your server!' elif match_on_server is not None: server_avaliable = False message = 'Match {} is already using this server'.format( match_on_server.id) elif mock: server_avaliable = True message = 'Success' else: json_reply, message = util.check_server_avaliability( server) server_avaliable = (json_reply is not None) if server_avaliable: skip_veto = 'preset' in form.data['series_type'] try: max_maps = int(form.data['series_type'][2]) except ValueError: max_maps = 1 match = Match.create( g.user, form.data['team1_id'], form.data['team2_id'], form.data['team1_string'], form.data['team2_string'], max_maps, skip_veto, form.data['match_title'], form.data['veto_mappool'], form.data['server_id']) # Save plugin version data if we have it if json_reply and 'plugin_version' in json_reply: match.plugin_version = json_reply['plugin_version'] else: match.plugin_version = 'unknown' server.in_use = True db.session.commit() app.logger.info('User {} created match {}, assigned to server {}' .format(g.user.id, match.id, server.id)) if mock or match.send_to_server(): return redirect('/mymatches') else: flash('Failed to load match configs on server') else: flash(message) else: get5.flash_errors(form) return render_template('match_create.html', form=form, user=g.user, teams=g.user.teams, match_text_option=config_setting('CREATE_MATCH_TITLE_TEXT'))
def match_create(): if not g.user: return redirect('/login') form = MatchForm(request.form) form.add_teams(g.user) form.add_servers(g.user) form.add_seasons() if request.method == 'POST': num_matches = g.user.matches.count() max_matches = config_setting('USER_MAX_MATCHES') season_id = None if max_matches >= 0 and num_matches >= max_matches and not ( g.user.admin or g.user.super_admin): flash( 'You already have the maximum number of matches ({}) created'. format(num_matches)) elif form.validate(): mock = config_setting('TESTING') server = GameServer.query.get_or_404(form.data['server_id']) match_on_server = g.user.matches.filter_by( server_id=server.id, end_time=None, cancelled=False).first() server_available = False json_reply = None if g.user.id != server.user_id and not server.public_server: server_available = False message = 'This is not your server!' elif match_on_server is not None: server_available = False message = 'Match {} is already using this server'.format( match_on_server.id) elif mock: server_available = True message = 'Success' else: json_reply, message = util.check_server_avaliability( server, dbKey) server_available = (json_reply is not None) if server_available: skip_veto = 'preset' in form.data['series_type'] try: max_maps = int(form.data['series_type'][2]) except ValueError: max_maps = 1 if form.data['season_selection'] != 0: season_id = form.data['season_selection'] # Series Score Feature. team1_series_score = form.data[ 'team1_series_score'] if not None else 0 team2_series_score = form.data[ 'team2_series_score'] if not None else 0 # End Series Score Feature. # Spectator Feature specList = [] if form.data['spectator_string']: for auth in form.data['spectator_string'].split(): suc, new_auth = steamid.auth_to_steam64(auth) if suc: specList.append(new_auth) if not specList: specList = None # End Spectator Feature match = Match.create( g.user, form.data['team1_id'], form.data['team2_id'], form.data['team1_string'], form.data['team2_string'], max_maps, skip_veto, form.data['match_title'], form.data['veto_mappool'], season_id, form.data['side_type'], form.data['veto_first'], form.data['server_id'], team1_series_score, team2_series_score, specList, form.data['private_match'], form.data['enforce_teams'], form.data['min_player_ready']) # Save plugin version data if we have it if json_reply and 'plugin_version' in json_reply: match.plugin_version = json_reply['plugin_version'] else: match.plugin_version = 'unknown' server.in_use = True db.session.commit() # Implement normalized spectator list. if specList: for singleAuth in specList: MatchSpectator.set_or_create(match.id, auth) app.logger.info( 'User {} created match {}, assigned to server {}'.format( g.user.id, match.id, server.id)) if mock or match.send_to_server(): return redirect('/mymatches') else: flash('Failed to load match configs on server') else: flash(message) else: get5.flash_errors(form) return render_template( 'match_create.html', form=form, user=g.user, teams=g.user.teams, match_text_option=config_setting('CREATE_MATCH_TITLE_TEXT'))
def match_create(): if not g.user: return redirect('/login') form = MatchForm(request.form) form.add_teams(g.user) form.add_servers(g.user) if request.method == 'POST': num_matches = g.user.matches.count() max_matches = config_setting('USER_MAX_MATCHES') if max_matches >= 0 and num_matches >= max_matches and not g.user.admin: flash('You already have the maximum number of matches ({}) created'.format( num_matches)) if form.validate(): mock = config_setting('TESTING') server = GameServer.query.get_or_404(form.data['server_id']) match_on_server = g.user.matches.filter_by( server_id=server.id, end_time=None, cancelled=False).first() server_avaliable = False json_reply = None if g.user.id != server.user_id and not server.public_server: server_avaliable = False message = 'This is not your server!' elif match_on_server is not None: server_avaliable = False message = 'Match {} is already using this server'.format( match_on_server.id) elif mock: server_avaliable = True message = 'Success' else: json_reply, message = util.check_server_avaliability( server) server_avaliable = (json_reply is not None) if server_avaliable: skip_veto = 'preset' in form.data['series_type'] try: max_maps = int(form.data['series_type'][2]) except ValueError: max_maps = 1 match = Match.create( g.user, form.data['team1_id'], form.data['team2_id'], form.data['team1_string'], form.data['team2_string'], max_maps, skip_veto, form.data['match_title'], form.data['veto_mappool'], form.data['server_id']) # Save plugin version data if we have it if json_reply and 'plugin_version' in json_reply: match.plugin_version = json_reply['plugin_version'] else: match.plugin_version = 'unknown' server.in_use = True db.session.commit() app.logger.info('User {} created match {}, assigned to server {}' .format(g.user.id, match.id, server.id)) if mock or match.send_to_server(): return redirect('/mymatches') else: flash('Failed to load match configs on server') else: flash(message) else: get5.flash_errors(form) return render_template( 'match_create.html', form=form, user=g.user, teams=g.user.teams, match_text_option=config_setting('CREATE_MATCH_TITLE_TEXT'))