From 852bd74c3bd2353e5d15a1d2fcda3d79ccdb60da Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 28 Jul 2016 21:49:16 -0700 Subject: [PATCH] core: enumerate our server after calling proto.connect() This gives protocol modules a chance to manipulate their SID before it's added to the internal server list, replacing hacks previously used by the Nefarious and Clientbot modules. This is the first step to sid-less servers :) --- classes.py | 10 +++++++--- protocols/clientbot.py | 7 ++----- protocols/nefarious.py | 7 ++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/classes.py b/classes.py index 3ea0669..84f41c6 100644 --- a/classes.py +++ b/classes.py @@ -116,9 +116,7 @@ class Irc(): # Intialize the server, channel, and user indexes to be populated by # our protocol module. For the server index, we can add ourselves right # now. - self.servers = {self.sid: IrcServer(None, self.serverdata['hostname'], - internal=True, desc=self.serverdata.get('serverdesc') - or self.botdata['serverdesc'])} + self.servers = {} self.users = {} self.channels = structures.KeyedDefaultdict(IrcChannel) @@ -277,6 +275,12 @@ class Irc(): # All our checks passed, get the protocol module to connect # and run the listen loop. 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') + or self.botdata['serverdesc']) + log.info('(%s) Starting ping schedulers....', self.name) self.schedulePing() log.info('(%s) Server ready; listening for data.', self.name) diff --git a/protocols/clientbot.py b/protocols/clientbot.py index 125ffaf..e54b0fa 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -49,11 +49,8 @@ class ClientbotWrapperProtocol(Protocol): # TODO: fetch channel/user/prefix modes from RPL_ISUPPORT. #self.irc.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'} - # HACK: Replace the SID from the config options with our own. - old_sid = self.irc.sid - self.irc.sid = sid = self.sidgen.next_uid() - self.irc.servers[sid] = self.irc.servers[old_sid] - del self.irc.servers[old_sid] + # Enumerate our own server + self.irc.sid = self.sidgen.next_sid() # Clear states from last connect self.who_received.clear() diff --git a/protocols/nefarious.py b/protocols/nefarious.py index 546da3d..3b2574f 100644 --- a/protocols/nefarious.py +++ b/protocols/nefarious.py @@ -718,11 +718,8 @@ class P10Protocol(IRCS2SProtocol): name = self.irc.serverdata["hostname"] - # HACK: Encode our SID everywhere, and replace it in the IrcServer index. - old_sid = self.irc.sid - self.irc.sid = sid = p10b64encode(self.irc.serverdata["sid"]) - self.irc.servers[sid] = self.irc.servers[old_sid] - del self.irc.servers[old_sid] + # Encode our SID using P10 Base64. + self.irc.sid = p10b64encode(self.irc.serverdata["sid"]) desc = self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']