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

Modularize TS updating code (Closes #129)

This commit is contained in:
James Lu 2015-11-08 10:49:09 -08:00
parent 5715835bbb
commit 2eeba50a2a
3 changed files with 27 additions and 46 deletions

View File

@ -488,6 +488,18 @@ class Protocol():
log.debug('Removing client %s from self.irc.servers[%s].users', numeric, sid) log.debug('Removing client %s from self.irc.servers[%s].users', numeric, sid)
self.irc.servers[sid].users.discard(numeric) self.irc.servers[sid].users.discard(numeric)
def updateTS(self, channel, their_ts):
our_ts = self.irc.channels[channel].ts
if their_ts < our_ts:
# Channel timestamp was reset on burst
log.debug('(%s) Setting channel TS of %s to %s from %s',
self.irc.name, channel, their_ts, our_ts)
self.irc.channels[channel].ts = their_ts
# When TS is reset, clear all modes we currently have
self.irc.channels[channel].modes.clear()
for p in self.irc.channels[channel].prefixmodes.values():
p.clear()
class FakeProto(Protocol): class FakeProto(Protocol):
"""Dummy protocol module for testing purposes.""" """Dummy protocol module for testing purposes."""
def handle_events(self, data): def handle_events(self, data):

View File

@ -92,17 +92,10 @@ class InspIRCdProtocol(TS6BaseProtocol):
log.debug('(%s) sjoinServer: got %r for users', self.irc.name, users) log.debug('(%s) sjoinServer: got %r for users', self.irc.name, users)
if not server: if not server:
raise LookupError('No such PyLink PseudoClient exists.') raise LookupError('No such PyLink PseudoClient exists.')
orig_ts = self.irc.channels[channel].ts orig_ts = self.irc.channels[channel].ts
ts = ts or orig_ts self.updateTS(channel, ts or orig_ts)
if ts < orig_ts:
# If the TS we're sending is lower than the one that existing, clear the
# mode lists from our channel state and reset the timestamp.
log.debug('(%s) sjoinServer: resetting TS of %r from %s to %s (clearing modes)',
self.irc.name, channel, orig_ts, ts)
self.irc.channels[channel].ts = ts
self.irc.channels[channel].modes.clear()
for p in self.irc.channels[channel].prefixmodes.values():
p.clear()
log.debug("sending SJOIN to %s%s with ts %s (that's %r)", channel, self.irc.name, ts, log.debug("sending SJOIN to %s%s with ts %s (that's %r)", channel, self.irc.name, ts,
time.strftime("%c", time.localtime(ts))) time.strftime("%c", time.localtime(ts)))
# Strip out list-modes, they shouldn't ever be sent in FJOIN (protocol rules). # Strip out list-modes, they shouldn't ever be sent in FJOIN (protocol rules).
@ -426,16 +419,11 @@ class InspIRCdProtocol(TS6BaseProtocol):
channel = utils.toLower(self.irc, args[0]) channel = utils.toLower(self.irc, args[0])
# InspIRCd sends each channel's users in the form of 'modeprefix(es),UID' # InspIRCd sends each channel's users in the form of 'modeprefix(es),UID'
userlist = args[-1].split() userlist = args[-1].split()
our_ts = self.irc.channels[channel].ts
their_ts = int(args[1]) their_ts = int(args[1])
if their_ts < our_ts: our_ts = self.irc.channels[channel].ts
# Channel timestamp was reset on burst self.updateTS(channel, their_ts)
log.debug('(%s) Setting channel TS of %s to %s from %s',
self.irc.name, channel, their_ts, our_ts)
self.irc.channels[channel].ts = their_ts
self.irc.channels[channel].modes.clear()
for p in self.irc.channels[channel].prefixmodes.values():
p.clear()
modestring = args[2:-1] or args[2] modestring = args[2:-1] or args[2]
parsedmodes = utils.parseModes(self.irc, channel, modestring) parsedmodes = utils.parseModes(self.irc, channel, modestring)
utils.applyModes(self.irc, channel, parsedmodes) utils.applyModes(self.irc, channel, parsedmodes)

View File

@ -89,17 +89,10 @@ class TS6Protocol(TS6BaseProtocol):
log.debug('(%s) sjoinServer: got %r for users', self.irc.name, users) log.debug('(%s) sjoinServer: got %r for users', self.irc.name, users)
if not server: if not server:
raise LookupError('No such PyLink PseudoClient exists.') raise LookupError('No such PyLink PseudoClient exists.')
orig_ts = self.irc.channels[channel].ts orig_ts = self.irc.channels[channel].ts
ts = ts or orig_ts self.updateTS(channel, ts or orig_ts)
if ts < orig_ts:
# If the TS we're sending is lower than the one that existing, clear the
# mode lists from our channel state and reset the timestamp.
log.debug('(%s) sjoinServer: resetting TS of %r from %s to %s (clearing modes)',
self.irc.name, channel, orig_ts, ts)
self.irc.channels[channel].ts = ts
self.irc.channels[channel].modes.clear()
for p in self.irc.channels[channel].prefixmodes.values():
p.clear()
log.debug("(%s) sending SJOIN to %s with ts %s (that's %r)", self.irc.name, channel, ts, log.debug("(%s) sending SJOIN to %s with ts %s (that's %r)", self.irc.name, channel, ts,
time.strftime("%c", time.localtime(ts))) time.strftime("%c", time.localtime(ts)))
modes = [m for m in self.irc.channels[channel].modes if m[0] not in self.irc.cmodes['*A']] modes = [m for m in self.irc.channels[channel].modes if m[0] not in self.irc.cmodes['*A']]
@ -497,16 +490,11 @@ class TS6Protocol(TS6BaseProtocol):
# parameters: channelTS, channel, simple modes, opt. mode parameters..., nicklist # parameters: channelTS, channel, simple modes, opt. mode parameters..., nicklist
channel = utils.toLower(self.irc, args[1]) channel = utils.toLower(self.irc, args[1])
userlist = args[-1].split() userlist = args[-1].split()
our_ts = self.irc.channels[channel].ts
their_ts = int(args[0]) their_ts = int(args[0])
if their_ts < our_ts: our_ts = self.irc.channels[channel].ts
# Channel timestamp was reset on burst
log.debug('(%s) Setting channel TS of %s to %s from %s', self.updateTS(channel, their_ts)
self.irc.name, channel, their_ts, our_ts)
self.irc.channels[channel].ts = their_ts
self.irc.channels[channel].modes.clear()
for p in self.irc.channels[channel].prefixmodes.values():
p.clear()
modestring = args[2:-1] or args[2] modestring = args[2:-1] or args[2]
parsedmodes = utils.parseModes(self.irc, channel, modestring) parsedmodes = utils.parseModes(self.irc, channel, modestring)
utils.applyModes(self.irc, channel, parsedmodes) utils.applyModes(self.irc, channel, parsedmodes)
@ -548,14 +536,7 @@ class TS6Protocol(TS6BaseProtocol):
return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'} return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'}
else: else:
channel = utils.toLower(self.irc, args[1]) channel = utils.toLower(self.irc, args[1])
our_ts = self.irc.channels[channel].ts self.updateTS(channel, ts)
if ts < our_ts:
# Channel timestamp was reset on burst
log.debug('(%s) Setting channel TS of %s to %s from %s',
self.irc.name, channel, ts, our_ts)
self.irc.channels[channel].ts = ts
self.irc.channels[channel].users.add(numeric)
self.irc.users[numeric].channels.add(channel)
# We send users and modes here because SJOIN and JOIN both use one hook, # We send users and modes here because SJOIN and JOIN both use one hook,
# for simplicity's sake (with plugins). # for simplicity's sake (with plugins).
return {'channel': channel, 'users': [numeric], 'modes': return {'channel': channel, 'users': [numeric], 'modes':