Example #1
0
def view_server(server=None, viewtab=None):
    if viewtab not in ['info', 'settings', 'rcon', 'edit']:
        return redirect(url_for('view_server', server=server, viewtab='info'))
    if not g.user.admin and viewtab in ['rcon', 'edit']:
        return redirect(url_for('view_server', server=server, viewtab='info'))
    server_obj = Server.get(server)
    if request.method == 'POST':
        if viewtab == 'edit':
            server_obj.name = request.form.get('name', server_obj.name)
            server_obj.port = request.form.get('port', server_obj.port)
            server_obj.type = request.form.get('servertype', server_obj.type)
            server_obj.location = request.form.get('path', server_obj.location)
            server_obj.ip = request.form.get('address', server_obj.ip)
            # Only set rcon if they specified it.
            if request.form.get('rcon', None):
                server_obj.rcon = request.form.get('rcon', server_obj.rcon)
            db.session.commit()
            flash("Server edited successfully!", category='success')
            print "In edit!"
        if viewtab == 'settings':
            if request.form['action'] == 'sendmsg' and request.form['saytext']:
                server_obj._send_rcon("sm_csay '%s: %s'" % (session['user_nick'], request.form['saytext']))
                flash("Message sent!", category='success')
            elif request.form['action'] == 'alltalk':
                server_obj = Server.get(server)
                if 'enable' in request.form:
                    flash("Alltalk temporarily Enabled!", category='success')
                    server_obj._send_rcon("sv_alltalk 1")
                else:
                    flash("Alltalk temporarily Disabled!", category='success')
                    server_obj._send_rcon("sv_alltalk 0")
            elif request.form['action'] == 'changemode':
                print server_obj.location
                if 'arena' in request.form:
                    flash("Server set to arena mode, I'll restart it for ya!", category='success')
                    # server_obj._send_rcon("sv_alltalk 1")
                else:
                    flash("Server set to normal mode, I'll restart it for ya!", category='success')
                    # server_obj._send_rcon("sv_alltalk 0")
            elif request.form['action'] == 'changepass':
                if not request.form['srvpass']:
                    server_obj._send_rcon('sv_password ""')
                    flash("Password cleared!", category='success')
                else:
                    server_obj._send_rcon("sv_password "+request.form['srvpass'])
                    flash("Password set!", category='success')
            else:
                flash(request.form, category='success')
    return render_template('view_server.html', server=Server.get(server), servers=Server.get_all(), viewtab=viewtab, lock=app.config.get('LOCKSERVERS', True))
Example #2
0
def issue_rcon_better(serverid=None):
    try:
        server = Server.get(int(serverid))
        return server._send_rcon(request.form['cmd'])
    except ValueError:
        return "Fail.", 403
    return "Whoops! Something bad happened..."
Example #3
0
def delete_server():
    try:
        if Server.delete(int(request.form['serverid'])):
            return "Success."
    except ValueError:
        return "Fail.", 403
    return "Fail.", 403
Example #4
0
def issue_rcon():
    try:
        # print request.form['userid']
        # print g.user.check_auth(request.form['userid'])
        # print request.form['cmd']
        server = Server.get(int(request.form['serverid']))
        return server._send_rcon(request.form['cmd'])
    except ValueError:
        return "Fail.", 403
    return "Whoops! Something bad happened..."
Example #5
0
def restart_status():
    '''Returns success if the server is done restarting.'''
    try:
        server = Server.get(int(request.form['serverid']))
        if time.time() < my_globals['wait_time%s' % server.id]:
            return "Fail", 403
        if server.is_restarting:
            return "Fail.", 403
    except ValueError:
        return "Fail.", 403
    return "Success"
Example #6
0
def list_maps(serverid=None):
    try:
        server = Server.get(int(serverid))
        map_list = [a.split(" ")[-1][0:-4] for a in server._send_rcon("maps *").split("\n")]
        # Pop off the first element, it's always going to be '-------------'
        map_list.pop(0)
        map_list.pop(-1)
        return json.dumps(map_list)
    except Exception:
        # Probably an RCON failure
        return "Fail.", 403
    return "Yep!"
Example #7
0
def restart_server():
    if not hasattr(g, 'wait_time'):
        g.wait_time = {}
    try:
        server = Server.get(int(request.form['serverid']))
        # TODO: Put other logic here.
        if not server.is_restarting:
            status = server.restart()
            my_globals['wait_time%s' % server.id] = time.time() + 11
            return "Success"
    except ValueError:
        return "Fail.", 403
    return "Success."
Example #8
0
def add_server():
    errors = []
    values = {}
    required = ['name', 'address', 'rcon', 'servertype', 'port', 'path']
    if request.method == 'POST':
        values['name'] = request.form['name']
        values['address'] = request.form['address']
        values['rcon'] = request.form['rcon']
        values['servertype'] = request.form['servertype']
        values['port'] = request.form['port']
        values['path'] = request.form['path']
        for key, value in values.items():
            if not value:
                errors.append(key)
        if not errors:
            success, msg = Server.create(values['name'], values['address'], values['port'], values['rcon'], values['servertype'], values['path'])
            if success:
                flash(msg, category='success')
                db.session.commit()
            else:
                flash(msg, category='error')
            return redirect(url_for('servers'))
    return render_template('add_server.html', values=values, errors=errors)
Example #9
0
def servers():
    return render_template('servers.html', servers=Server.get_all(), lock=app.config.get('LOCKSERVERS', True))