From 3a8d3d146c92ccaa494ca2896d26bddca7c65c4d Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 12 Sep 2015 16:02:51 -0700 Subject: [PATCH] protocols: make "uidgen" a protocol instance attribute --- classes.py | 3 --- protocols/inspircd.py | 9 ++++----- protocols/ts6.py | 9 ++++----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/classes.py b/classes.py index 2432ff6..1211088 100644 --- a/classes.py +++ b/classes.py @@ -57,9 +57,6 @@ class Irc(): self.uplink = None self.start_ts = int(time.time()) - # UID generators, for servers that need it - self.uidgen = {} - def __init__(self, netname, proto): # Initialize some variables self.name = netname.lower() diff --git a/protocols/inspircd.py b/protocols/inspircd.py index 63c0cb0..f118ba9 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -25,6 +25,7 @@ class InspIRCdProtocol(TS6BaseProtocol): 'FTOPIC': 'TOPIC', 'OPERTYPE': 'MODE', 'FHOST': 'CHGHOST', 'FIDENT': 'CHGIDENT', 'FNAME': 'CHGNAME'} self.sidgen = utils.TS6SIDGenerator(self.irc.serverdata["sidrange"]) + self.uidgen = {} def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(), server=None, ip='0.0.0.0', realname=None, ts=None, opertype=None): @@ -35,11 +36,9 @@ class InspIRCdProtocol(TS6BaseProtocol): server = server or self.irc.sid if not utils.isInternalServer(self.irc, server): raise ValueError('Server %r is not a PyLink internal PseudoServer!' % server) - # We need a separate UID generator instance for every PseudoServer - # we spawn. Otherwise, things won't wrap around properly. - if server not in self.irc.uidgen: - self.irc.uidgen[server] = utils.TS6UIDGenerator(server) - uid = self.irc.uidgen[server].next_uid() + # Create an UIDGenerator instance for every SID, so that each gets + # distinct values. + uid = self.uidgen.setdefault(server, utils.TS6UIDGenerator(server)).next_uid() ts = ts or int(time.time()) realname = realname or self.irc.botdata['realname'] realhost = realhost or host diff --git a/protocols/ts6.py b/protocols/ts6.py index 6b65807..c2b7b6b 100644 --- a/protocols/ts6.py +++ b/protocols/ts6.py @@ -18,6 +18,7 @@ class TS6Protocol(TS6BaseProtocol): self.casemapping = 'rfc1459' self.hook_map = {'SJOIN': 'JOIN', 'TB': 'TOPIC', 'TMODE': 'MODE', 'BMASK': 'MODE'} self.sidgen = utils.TS6SIDGenerator(self.irc.serverdata["sidrange"]) + self.uidgen = {} def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(), server=None, ip='0.0.0.0', realname=None, ts=None, opertype=None): @@ -28,11 +29,9 @@ class TS6Protocol(TS6BaseProtocol): server = server or self.irc.sid if not utils.isInternalServer(self.irc, server): raise ValueError('Server %r is not a PyLink internal PseudoServer!' % server) - # We need a separate UID generator instance for every PseudoServer - # we spawn. Otherwise, things won't wrap around properly. - if server not in self.irc.uidgen: - self.irc.uidgen[server] = utils.TS6UIDGenerator(server) - uid = self.irc.uidgen[server].next_uid() + # Create an UIDGenerator instance for every SID, so that each gets + # distinct values. + uid = self.uidgen.setdefault(server, utils.TS6UIDGenerator(server)).next_uid() # EUID: # parameters: nickname, hopcount, nickTS, umodes, username, # visible hostname, IP address, UID, real hostname, account name, gecos