diff --git a/classes.py b/classes.py index 681b25d..3ea0669 100644 --- a/classes.py +++ b/classes.py @@ -172,6 +172,13 @@ class Irc(): while True: self.aborted.clear() self.initVars() + + try: + self.proto.validateServerConf() + except AssertionError as e: + log.exception("(%s) Configuration error: %s", self.name, e) + return + ip = self.serverdata["ip"] port = self.serverdata["port"] checks_ok = True @@ -1144,6 +1151,18 @@ class Protocol(): # Lock for updateTS to make sure only one thread can change the channel TS at one time. self.ts_lock = threading.Lock() + # Lists required conf keys for the server block. + self.conf_keys = {'ip', 'port', 'hostname', 'sid', 'sidrange', 'protocol', 'sendpass', + 'recvpass'} + + def validateServerConf(self): + """Validates that the server block given contains the required keys.""" + for k in self.conf_keys: + assert k in self.irc.serverdata, "Missing option %r in server block for network %s." % (k, self.irc.name) + + port = self.irc.serverdata['port'] + assert type(port) == int and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.irc.name) + def parseArgs(self, args): """Parses a string of RFC1459-style arguments split into a list, where ":" may be used for multi-word arguments that last until the end of a line. diff --git a/conf.py b/conf.py index 37679fd..2ae379f 100644 --- a/conf.py +++ b/conf.py @@ -50,10 +50,6 @@ def validateConf(conf): for section in ('bot', 'servers', 'login', 'logging'): assert conf.get(section), "Missing %r section in config." % section - for netname, serverblock in conf['servers'].items(): - for section in ('ip', 'port', 'hostname', 'sid', 'sidrange', 'protocol'): - assert serverblock.get(section), "Missing %r in server block for %r." % (section, netname) - assert type(conf['login'].get('password')) == type(conf['login'].get('user')) == str and \ conf['login']['password'] != "changeme", "You have not set the login details correctly!" diff --git a/protocols/clientbot.py b/protocols/clientbot.py index 0017626..125ffaf 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -10,6 +10,9 @@ class ClientbotWrapperProtocol(Protocol): def __init__(self, irc): super().__init__(irc) + # Remove conf key checks for those not needed for Clientbot. + self.conf_keys -= {'recvpass', 'sendpass'} + # This is just a fallback. Actual casemapping is fetched by handle_005() self.casemapping = 'ascii' diff --git a/protocols/ircs2s_common.py b/protocols/ircs2s_common.py index 7f78724..93afdb0 100644 --- a/protocols/ircs2s_common.py +++ b/protocols/ircs2s_common.py @@ -39,7 +39,6 @@ class IRCS2SProtocol(Protocol): return {'target': killed, 'text': killmsg, 'userdata': data} - def handle_squit(self, numeric, command, args): """Handles incoming SQUITs.""" return self._squit(numeric, command, args)