Example #1
0
def match_rcon(matchid):
    match = Match.query.get_or_404(matchid)

    command = request.values.get('command')
    server = GameServer.query.get_or_404(match.server_id)
    owns_server = util.is_server_owner(g.user, server)
    is_sadmin = g.user.super_admin
    # Check to see if user owns server.
    if not owns_server:
        if not is_sadmin:
            raise BadRequestError('You are not the server owner.')

    if command:
        try:
            rcon_response = server.send_rcon_command(command,
                                                     raise_errors=True)
            if rcon_response:
                rcon_response = Markup(rcon_response.replace('\n', '<br>'))
            else:
                rcon_response = 'No output'
            flash(rcon_response)
            # Store the command.
            match_audit.create(g.user.id, matchid, datetime.now(), command)
            db.session.commit()
        except util.RconError as e:
            print(e)
            flash('Failed to send command: ' + str(e))

    return redirect('/match/{}'.format(matchid))
Example #2
0
def match(matchid):
    match = Match.query.get_or_404(matchid)
    # Begin Private/Public Match Implementation

    vetoes = Veto.query.filter_by(match_id=matchid)
    if match.server_id:
        server = GameServer.query.get_or_404(match.server_id)
    else:
        server = None
    team1 = Team.query.get_or_404(match.team1_id)
    team2 = Team.query.get_or_404(match.team2_id)
    check_private_or_public(match, team1, team2)

    map_stat_list = match.map_stats.all()
    completed = match.winner
    try:
        if server is not None and (completed is None and match.cancelled == 0):
            password = server.receive_rcon_value('sv_password')
            connect_string = str("steam://connect/") + str(server.ip_string) + str(":") + \
                str(server.port) + str("/") + str(password)
            gotv_port = server.receive_rcon_value('tv_port')
            gotv_string = str("steam://connect/") + str(server.ip_string) + str(":") + \
                str(gotv_port)
        else:
            connect_string = None
            gotv_string = None
    except util.RconError as e:
        connect_string = None
        gotv_string = None
        app.logger.info(
            'Attempted to connect to server {}, but it is offline'.format(
                server.ip_string))

    is_match_owner = False
    is_server_op = False
    has_admin_access = False
    has_super_admin_access = False
    if g.user:
        is_match_owner = (g.user.id == match.user_id)
        has_admin_access = (config_setting('ADMINS_ACCESS_ALL_MATCHES')
                            and g.user.admin)
        has_super_admin_access = g.user.super_admin
        is_server_op = util.is_server_owner(g.user, server)
    return render_template('match.html',
                           user=g.user,
                           admin_access=has_admin_access,
                           match=match,
                           team1=team1,
                           team2=team2,
                           map_stat_list=map_stat_list,
                           completed=completed,
                           connect_string=connect_string,
                           gotv_string=gotv_string,
                           super_admin_access=has_super_admin_access,
                           vetoes=vetoes,
                           server_owner=is_server_op,
                           match_owner=is_match_owner)
Example #3
0
def server_edit(serverid):
    server = GameServer.query.get_or_404(serverid)
    is_owner = (g.user and (util.is_server_owner(g.user, server)))
    is_sadmin = (g.user and util.is_super_admin(g.user))
    app.logger.info("Owner: {} Sadmin: {}".format(is_owner, is_sadmin))
    if not is_owner:
        if not is_sadmin:
            raise BadRequestError('You do not have access to this server.')

    # Attempt encryption/decryption
    rconDecrypt = util.decrypt(dbKey, server.rcon_password)
    form = ServerForm(request.form,
                      display_name=server.display_name,
                      ip_string=server.ip_string,
                      port=server.port,
                      rcon_password=server.rcon_password
                      if rconDecrypt is None else rconDecrypt,
                      public_server=server.public_server)

    if request.method == 'POST':
        if form.validate():
            mock = app.config['TESTING']
            data = form.data
            if not mock:
                encRcon = util.encrypt(dbKey, str(data['rcon_password']))
            else:
                encRcon = data['rcon_password']
            server.display_name = data['display_name']
            server.ip_string = data['ip_string']
            server.port = data['port']
            server.rcon_password = encRcon
            server.public_server = (data['public_server']
                                    and util.is_admin(g.user))

            if mock or util.check_server_connection(server, dbKey):
                db.session.commit()
                return redirect('/myservers')
            else:
                db.session.remove()
                flash('Failed to connect to server')

        else:
            flash_errors(form)

    return render_template('server_create.html',
                           user=g.user,
                           form=form,
                           edit=True,
                           is_admin=util.is_admin(g.user),
                           is_sadmin=util.is_super_admin(g.user))