3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

utils.TS6UIDGenerator: initialize SID variable once per instance

This commit is contained in:
James Lu 2015-06-22 16:51:42 -07:00
parent f37af68e3f
commit 28e7b52ef4
2 changed files with 6 additions and 5 deletions

View File

@ -23,8 +23,8 @@ def spawnClient(irc, nick, ident, host, modes=[], server=None, *args):
# We need a separate UID generator instance for every PseudoServer
# we spawn. Otherwise, things won't wrap around properly.
if server not in uidgen:
uidgen[server] = utils.TS6UIDGenerator()
uid = uidgen[server].next_uid(server)
uidgen[server] = utils.TS6UIDGenerator(server)
uid = uidgen[server].next_uid()
ts = int(time.time())
if modes:
modes = utils.joinModes(modes)

View File

@ -10,12 +10,13 @@ class TS6UIDGenerator():
https://github.com/inspircd/inspircd/blob/f449c6b296ab/src/server.cpp#L85-L156
"""
def __init__(self):
def __init__(self, sid):
# TS6 UIDs are 6 characters in length (9 including the SID).
# They wrap from ABCDEFGHIJKLMNOPQRSTUVWXYZ -> 0123456789 -> wrap around:
# (e.g. AAAAAA, AAAAAB ..., AAAAA8, AAAAA9, AAAABA)
self.allowedchars = string.ascii_uppercase + string.digits
self.uidchars = [self.allowedchars[0]]*6
self.sid = sid
def increment(self, pos=5):
# If we're at the last character in the list of allowed ones, reset
@ -29,8 +30,8 @@ class TS6UIDGenerator():
idx = self.allowedchars.find(self.uidchars[pos])
self.uidchars[pos] = self.allowedchars[idx+1]
def next_uid(self, sid):
uid = sid + ''.join(self.uidchars)
def next_uid(self):
uid = self.sid + ''.join(self.uidchars)
self.increment()
return uid