From a76bd8c5b26f182d8f7739acc489ea81ab3d99aa Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 12 Aug 2016 19:18:56 -0700 Subject: [PATCH] core: make hostmask fetching a shared function --- classes.py | 11 ++++++++--- coremods/service_support.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/classes.py b/classes.py index ddeb441..d36d6cd 100644 --- a/classes.py +++ b/classes.py @@ -276,7 +276,7 @@ class Irc(): self.proto.connect() log.info('(%s) Enumerating our own SID %s', self.name, self.sid) - host = self.serverdata.get('hostname', world.fallback_hostname) + host = self.hostname() self.servers[self.sid] = IrcServer(None, host, internal=True, desc=self.serverdata.get('serverdesc') @@ -810,10 +810,15 @@ class Irc(): Returns a detailed version string including the PyLink daemon version, the protocol module in use, and the server hostname. """ - fullversion = 'PyLink-%s. %s :[protocol:%s]' % (__version__, self.serverdata.get('hostname', world.fallback_hostname), - self.protoname) + fullversion = 'PyLink-%s. %s :[protocol:%s]' % (__version__, self.hostname(), self.protoname) return fullversion + def hostname(self): + """ + Returns the server hostname used by PyLink on the given server. + """ + return self.serverdata.get('hostname', world.fallback_hostname) + ### State checking functions def nickToUid(self, nick): """Looks up the UID of a user with the given nick, if one is present.""" diff --git a/coremods/service_support.py b/coremods/service_support.py index 91110dc..c10e0d3 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.get("hostname", world.fallback_hostname) + host = irc.hostname() # Spawning service clients with these umodes where supported. servprotect usage is a # configuration option.