def req_server_info():
    """ Always retrieve as much server information as possible. """
    status_dict = {}

    # Open the server.cfg file up.
    if not os.path.exists(servercfg_filename):
        print "No CFG!"
        return False


    # For each server, loop through status.
    with open(servercfg_filename) as serverlist:
        servers = dict( eval( serverlist.read() ) )
        for server in servers.keys():
            ip = servers[server]['ip']
            port = servers[server]['port']
            livestatus = SQ(ip, port)
            try:
                status_dict[server] = livestatus.info()
            except socket_error as serr:
                if serr.errno == errno.ECONNREFUSED:
                    status_dict[server] = {'error': True}
            try:
                status_dict[server]['gamename'] = servers[server]['name']
                status_dict[server]['ip'] = ip
                status_dict[server]['port'] = port
            except KeyError:
                pass

    return status_dict
Exemple #2
0
 def __init__(self, address, port, rcon_pass, local_port=17105):
     self.network_ip = network_ip()
     self.public_ip = public_ip()
     self.query = SourceQuery(address, port)
     self.srcon = SourceRcon(address, port, rcon_pass)
     self.logger = SourceLogListener((self.network_ip, local_port), (address, port), PugServerLogParser(self))
     self.rcon('logaddress_add "{0}:{1}"'.format(self.public_ip, local_port))
Exemple #3
0
def index():
    servers = []
    for server in SERVERS:
        try:
            s = SourceQuery(server[0], server[1])
            servers.append({
                'server': {
                    'address': server[0],
                    'port': server[1]
                    },
                'info': s.info(),
                'players': s.player()
            })
        except Exception as e:
            print(server)
            logger.error(e)

    return render_template('index.html', servers=servers)
Exemple #4
0
def root(function=None):
    response = {
        'data': {}
    }

    if not request.json:
        record_query(request, NOT_VALID_JSON)
        return json.jsonify(NOT_VALID_JSON)

    if 'data' not in request.json.keys():
        record_query(request, MISSING_DATA)
        return json.jsonify(MISSING_DATA)

    try:
        ip, port = request.json['data'].split(':')
    except:
        record_query(request, NOT_VALID_JSON)
        return json.jsonify(NOT_VALID_JSON)

    try:
        s = SourceQuery(ip, int(port))
        servername = '{}:{}'.format(ip, port)

        if function == 'all':
            response['data'][servername] = s.info()
            response['data'][servername]['players'] = s.player()
        elif function == 'serverinfo':
            response['data'][servername] = s.info()
        elif function == 'playerinfo':
            response['data'][servername] = s.player()
        elif function == 'ping':
            response['data'][servername] = s.ping()
        elif function == 'rules':
            s.timeout = 10
            response['data'][servername] = s.rules()
        else:
            record_query(request, ENDPOINT_NOT_FOUND)
            return json.jsonify(ENDPOINT_NOT_FOUND)

        response['status'] = 'success'
        record_query(request, None)
        return json.jsonify(response)
    except Exception:
        record_query(request, NO_RESPONSE)
        return json.jsonify(NO_RESPONSE)
Exemple #5
0
class PugServer(object):
    def __init__(self, address, port, rcon_pass, local_port=17105):
        self.network_ip = network_ip()
        self.public_ip = public_ip()
        self.query = SourceQuery(address, port)
        self.srcon = SourceRcon(address, port, rcon_pass)
        self.logger = SourceLogListener((self.network_ip, local_port), (address, port), PugServerLogParser(self))
        self.rcon('logaddress_add "{0}:{1}"'.format(self.public_ip, local_port))

    def connect(self):
        self.query.connect()
        self.srcon.connect()

    def disconnect(self):
        self.query.disconnect()
        self.srcon.disconnect()

    def info(self):
        return self.query.info()

    def player(self):
        return self.query.player()

    def rules(self):
        return self.query.rules()

    def rcon(self, command):
        return self.srcon.rcon(command)[:-1]

    def cevo(self):
        stopwatch_maps = ['cp_dustbowl', 'cp_egypt', 'cp_gorge', 'cp_gravelpit', 'cp_junction', 'cp_steel']
        map = self.info()['map']
        if map.startswith('ctf_'):
            file = 'cevo_ctf.cfg'
        elif map.startswith('koth_'):
            file = 'cevo_koth.cfg'
        elif map in stopwatch_maps:
            file = 'cevo_stopwatch.cfg'
        else:
            file = 'cevo_push.cfg'
        return self.rcon('exec "{0}"'.format(file))

    def changelevel(self, map):
        result = self.rcon('changelevel "{0}"'.format(map))
        return "No such map" not in result

    def status(self):
        return self.rcon('status')