diff --git a/classes.py b/classes.py index 165e68f..69ed13b 100644 --- a/classes.py +++ b/classes.py @@ -44,8 +44,8 @@ class Irc(): self.loghandlers = [] self.name = netname self.conf = conf + self.sid = None self.serverdata = conf['servers'][netname] - self.sid = self.serverdata["sid"] self.botdata = conf['bot'] self.bot_clients = {} self.protoname = proto.__name__.split('.')[-1] # Remove leading pylinkirc.protocols. @@ -99,7 +99,6 @@ class Irc(): (Re)sets an IRC object to its default state. This should be called when an IRC object is first created, and on every reconnection to a network. """ - self.sid = self.serverdata["sid"] self.botdata = self.conf['bot'] self.pingfreq = self.serverdata.get('pingfreq') or 90 self.pingtimeout = self.pingfreq * 3 @@ -272,13 +271,16 @@ class Irc(): hashtype, fp) if checks_ok: - # All our checks passed, get the protocol module to connect - # and run the listen loop. + self.sid = self.serverdata.get("sid") + # All our checks passed, get the protocol module to connect and run the listen + # loop. This also updates any SID values should the protocol module do so. self.proto.connect() log.info('(%s) Enumerating our own SID %s', self.name, self.sid) - self.servers[self.sid] = IrcServer(None, self.serverdata['hostname'], - internal=True, desc=self.serverdata.get('serverdesc') + host = self.serverdata.get('hostname', world.fallback_hostname) + + self.servers[self.sid] = IrcServer(None, host, internal=True, + desc=self.serverdata.get('serverdesc') or self.botdata['serverdesc']) log.info('(%s) Starting ping schedulers....', self.name) diff --git a/coremods/service_support.py b/coremods/service_support.py index 783a1da..88fa5fa 100644 --- a/coremods/service_support.py +++ b/coremods/service_support.py @@ -27,7 +27,7 @@ def spawn_service(irc, source, command, args): ident = irc.serverdata.get("%s_ident" % name) or conf.conf.get(name, {}).get('ident') or sbot.ident or name # TODO: make this configurable? - host = irc.serverdata["hostname"] + host = irc.serverdata.get("hostname", world.fallback_hostname) # Spawning service clients with these umodes where supported. servprotect usage is a # configuration option. diff --git a/protocols/clientbot.py b/protocols/clientbot.py index e54b0fa..eb0be8d 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -11,7 +11,7 @@ class ClientbotWrapperProtocol(Protocol): super().__init__(irc) # Remove conf key checks for those not needed for Clientbot. - self.conf_keys -= {'recvpass', 'sendpass'} + self.conf_keys -= {'recvpass', 'sendpass', 'sid', 'sidrange', 'hostname'} # This is just a fallback. Actual casemapping is fetched by handle_005() self.casemapping = 'ascii' diff --git a/world.py b/world.py index 85b05aa..55e4daf 100644 --- a/world.py +++ b/world.py @@ -22,3 +22,6 @@ exttarget_handlers = {} started = threading.Event() source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!! + +# Fallback hostname used in various places internally when hostname isn't configured. +fallback_hostname = 'pylink.int'