3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-28 05:29:25 +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 need a separate UID generator instance for every PseudoServer
# we spawn. Otherwise, things won't wrap around properly. # we spawn. Otherwise, things won't wrap around properly.
if server not in uidgen: if server not in uidgen:
uidgen[server] = utils.TS6UIDGenerator() uidgen[server] = utils.TS6UIDGenerator(server)
uid = uidgen[server].next_uid(server) uid = uidgen[server].next_uid()
ts = int(time.time()) ts = int(time.time())
if modes: if modes:
modes = utils.joinModes(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 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). # TS6 UIDs are 6 characters in length (9 including the SID).
# They wrap from ABCDEFGHIJKLMNOPQRSTUVWXYZ -> 0123456789 -> wrap around: # They wrap from ABCDEFGHIJKLMNOPQRSTUVWXYZ -> 0123456789 -> wrap around:
# (e.g. AAAAAA, AAAAAB ..., AAAAA8, AAAAA9, AAAABA) # (e.g. AAAAAA, AAAAAB ..., AAAAA8, AAAAA9, AAAABA)
self.allowedchars = string.ascii_uppercase + string.digits self.allowedchars = string.ascii_uppercase + string.digits
self.uidchars = [self.allowedchars[0]]*6 self.uidchars = [self.allowedchars[0]]*6
self.sid = sid
def increment(self, pos=5): def increment(self, pos=5):
# If we're at the last character in the list of allowed ones, reset # 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]) idx = self.allowedchars.find(self.uidchars[pos])
self.uidchars[pos] = self.allowedchars[idx+1] self.uidchars[pos] = self.allowedchars[idx+1]
def next_uid(self, sid): def next_uid(self):
uid = sid + ''.join(self.uidchars) uid = self.sid + ''.join(self.uidchars)
self.increment() self.increment()
return uid return uid