3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 13:09:23 +01:00

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 :)
This commit is contained in:
James Lu 2016-07-28 21:49:16 -07:00
parent c410de2fad
commit 852bd74c3b
3 changed files with 11 additions and 13 deletions

View File

@ -116,9 +116,7 @@ class Irc():
# Intialize the server, channel, and user indexes to be populated by # Intialize the server, channel, and user indexes to be populated by
# our protocol module. For the server index, we can add ourselves right # our protocol module. For the server index, we can add ourselves right
# now. # now.
self.servers = {self.sid: IrcServer(None, self.serverdata['hostname'], self.servers = {}
internal=True, desc=self.serverdata.get('serverdesc')
or self.botdata['serverdesc'])}
self.users = {} self.users = {}
self.channels = structures.KeyedDefaultdict(IrcChannel) self.channels = structures.KeyedDefaultdict(IrcChannel)
@ -277,6 +275,12 @@ class Irc():
# All our checks passed, get the protocol module to connect # All our checks passed, get the protocol module to connect
# and run the listen loop. # and run the listen loop.
self.proto.connect() 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) log.info('(%s) Starting ping schedulers....', self.name)
self.schedulePing() self.schedulePing()
log.info('(%s) Server ready; listening for data.', self.name) log.info('(%s) Server ready; listening for data.', self.name)

View File

@ -49,11 +49,8 @@ class ClientbotWrapperProtocol(Protocol):
# TODO: fetch channel/user/prefix modes from RPL_ISUPPORT. # TODO: fetch channel/user/prefix modes from RPL_ISUPPORT.
#self.irc.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'} #self.irc.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'}
# HACK: Replace the SID from the config options with our own. # Enumerate our own server
old_sid = self.irc.sid self.irc.sid = self.sidgen.next_sid()
self.irc.sid = sid = self.sidgen.next_uid()
self.irc.servers[sid] = self.irc.servers[old_sid]
del self.irc.servers[old_sid]
# Clear states from last connect # Clear states from last connect
self.who_received.clear() self.who_received.clear()

View File

@ -718,11 +718,8 @@ class P10Protocol(IRCS2SProtocol):
name = self.irc.serverdata["hostname"] name = self.irc.serverdata["hostname"]
# HACK: Encode our SID everywhere, and replace it in the IrcServer index. # Encode our SID using P10 Base64.
old_sid = self.irc.sid self.irc.sid = p10b64encode(self.irc.serverdata["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]
desc = self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc'] desc = self.irc.serverdata.get('serverdesc') or self.irc.botdata['serverdesc']