Exemplo n.º 1
0
 def __init__(self,
              addr,
              port=27015,
              check_freq=5,
              threshold_time=30,
              check_key="game_directory",
              check_value=""):
     Thread.__init__(self)
     self.addr = addr
     self.port = port
     self.check_key = check_key
     self.check_value = check_value
     self.query = SRCDS(addr, port=port)
     self.active = True
     self.check_freq = check_freq
     self.threshold_time = threshold_time
     self.enabled = False
     self.last_check = 0
     self.last_ok = time.time()
     self.alerted = False
Exemplo n.º 2
0
    def status(self, irc, msg, args):
        """Checks the status of the TF2 server."""

        ip_port = self.registryValue('IP')
        if ':' in ip_port:
            ip, port = ip_port.split(':', 1)
        else:
            ip = ip_port
            port = 27015

        rcon_password = self.registryValue('rconPassword')

        rcon = SRCDS(ip, port, rcon_password, timeout=2.0)
        server_details = rcon.details()

        players = server_details.get('current_playercount', 0)
        if players == 0:
            template = """Nobody's playing because the server's stuck on {current_map}.  Maybe change to a map that doesn't suck."""
        elif players == 1:
            template = """One lone soul running around {current_map}.  Probably Nimbus."""
        else:
            template = """{current_playercount} dudes on {current_map}.  Stop f*****g around on IRC and go join them."""

        irc.reply(template.format(**server_details))
Exemplo n.º 3
0
 def __init__(self, addr, port=27015, check_freq=5, threshold_time=30,
              check_key="game_directory", check_value=""):
     Thread.__init__(self)
     self.addr = addr
     self.port = port
     self.check_key = check_key
     self.check_value = check_value
     self.query = SRCDS(addr, port=port)
     self.active = True
     self.check_freq = check_freq
     self.threshold_time = threshold_time
     self.enabled = False
     self.last_check = 0
     self.last_ok = time.time()
     self.alerted = False
Exemplo n.º 4
0
class SRCDSMonitorThread(Thread):
    def __init__(self,
                 addr,
                 port=27015,
                 check_freq=5,
                 threshold_time=30,
                 check_key="game_directory",
                 check_value=""):
        Thread.__init__(self)
        self.addr = addr
        self.port = port
        self.check_key = check_key
        self.check_value = check_value
        self.query = SRCDS(addr, port=port)
        self.active = True
        self.check_freq = check_freq
        self.threshold_time = threshold_time
        self.enabled = False
        self.last_check = 0
        self.last_ok = time.time()
        self.alerted = False

    def run(self):
        while self.active:
            now = time.time()
            if self.enabled:
                if self.last_check < now - self.check_freq:
                    self.last_check = now
                    try:
                        details = self.query.details()
                        if self.check_key in details and \
                            details[self.check_key] == self.check_value:
                            self.last_ok = time.time()
                            self.alerted = False
                        else:
                            logging.debug("{0}:{1}: check key ({2}) differs as '{3}'" \
                                .format(self.addr, self.port, self.check_key,
                                details[self.check_key] if self.check_key in details else "N/A"))
                    except socket.error, e:
                        logging.debug("{0}:{1}: not responding".format(
                            self.addr, self.port))
                    except Exception, e:
                        logging.debug("{0}:{1}: unknown monitoring error: {3!s}" \
                            .format(self.addr, self.port, e))
                if self.last_ok < now - self.threshold_time and not self.alerted:
                    self.alerted = True
                    self.on_alert()
            time.sleep(1)
Exemplo n.º 5
0
class SRCDSMonitorThread(Thread):
    def __init__(self, addr, port=27015, check_freq=5, threshold_time=30,
                 check_key="game_directory", check_value=""):
        Thread.__init__(self)
        self.addr = addr
        self.port = port
        self.check_key = check_key
        self.check_value = check_value
        self.query = SRCDS(addr, port=port)
        self.active = True
        self.check_freq = check_freq
        self.threshold_time = threshold_time
        self.enabled = False
        self.last_check = 0
        self.last_ok = time.time()
        self.alerted = False
    def run(self):
        while self.active:
            now = time.time()
            if self.enabled:
                if self.last_check < now - self.check_freq:
                    self.last_check = now
                    try:
                        details = self.query.details()
                        if self.check_key in details and \
                            details[self.check_key] == self.check_value:
                            self.last_ok = time.time()
                            self.alerted = False
                        else:
                            logging.debug("{0}:{1}: check key ({2}) differs as '{3}'" \
                                .format(self.addr, self.port, self.check_key,
                                details[self.check_key] if self.check_key in details else "N/A"))
                    except socket.error, e:
                        logging.debug("{0}:{1}: not responding".format(self.addr, self.port))
                    except Exception, e:
                        logging.debug("{0}:{1}: unknown monitoring error: {3!s}" \
                            .format(self.addr, self.port, e))
                if self.last_ok < now - self.threshold_time and not self.alerted:
                    self.alerted = True
                    self.on_alert()
            time.sleep(1)
Exemplo n.º 6
0
        template = defineTemplate(commonCursor, str(server['id']))

        type = defineType(commonCursor, str(template['id']))

        serverID = str(server['id'])
        serverIP = str(server['address'])
        serverPort = int(server['port'])

        logPrint('OK', "Проверка сервера %s #%s %s:%s" % (template['longname'], serverID, serverIP, serverPort))

        try:
            if type['name'] == 'srcds':
                sq = SourceQuery.SourceQuery(serverIP, serverPort)
                info = sq.info()
            elif type['name'] == 'hlds':
                sq = SRCDS(serverIP, serverPort)
                info = sq.details()
            elif type['name'] == 'cod':
                sq = getCodServerInfo(serverIP, serverPort)
            elif type['name'] == 'voice':
                numVoice += 1
                sq = False
            else:
                sq = False
        except:
            logPrint('WARN', '  >>>> Не удалось подключиться к серверу %s:%s' % (serverIP, serverPort))
            numErrors += 1
            crashedServers.append(server)

            continue
Exemplo n.º 7
0
#!/usr/bin/env python

from SRCDS import SRCDS

# Login to our server
# serverAddress = socket.gethostbyname(socket.gethostname())
serverAddress = "192.168.0.11"

server = SRCDS(serverAddress, 27015, "macondo")
print server.nplayers()

# try:
# server = SRCDS(serverAddress, 27015, "macondo")
# print "[SRCDS] Reloading sourcemod"
# server.say("[SRCDS] Reloading sourcemod")
# server.rcon_command("sm plugins unload_all")
# server.rcon_command("sm plugins refresh")
# print "[SRCDS] Reload completed"
# server.say("probando")
# server.players
# except:
# print "[SRCDS] Could not connect to server ", serverAddress
# print "end of script"
Exemplo n.º 8
0
from SRCDS import SRCDS

s = SRCDS('192.168.1.136', rconpass='******')

print s.status()


def command(cmd):
    return s._any_rcon_response(cmd)

print command('help kickid')
print command('status')
Exemplo n.º 9
0
#!/usr/bin/env python

from SRCDS import SRCDS

#Login to our server
#serverAddress = socket.gethostbyname(socket.gethostname())
serverAddress = "192.168.0.11"

server = SRCDS(serverAddress, 27015, "macondo")
print server.nplayers()

#try:
	#server = SRCDS(serverAddress, 27015, "macondo")
	#print "[SRCDS] Reloading sourcemod"
	#server.say("[SRCDS] Reloading sourcemod")
	#server.rcon_command("sm plugins unload_all")
	#server.rcon_command("sm plugins refresh")
	#print "[SRCDS] Reload completed"
	#server.say("probando")
	#server.players
#except:
	#print "[SRCDS] Could not connect to server ", serverAddress
#print "end of script"