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

protocols: migrate to irc.parseModes/applyModes (#199)

This commit is contained in:
James Lu 2016-04-24 21:43:52 -07:00
parent 84822fb1d6
commit a8fc9428cf
5 changed files with 58 additions and 58 deletions

View File

@ -111,7 +111,7 @@ class HybridProtocol(TS6Protocol):
raw_modes = utils.joinModes(modes)
u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable)
utils.applyModes(self.irc, uid, modes)
self.irc.applyModes(uid, modes)
self.irc.servers[server].users.add(uid)
self._send(server, "UID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
"* :{realname}".format(ts=ts, host=host,
@ -182,9 +182,9 @@ class HybridProtocol(TS6Protocol):
self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, host, ip)
parsedmodes = utils.parseModes(self.irc, uid, [modes])
parsedmodes = self.irc.parseModes(uid, [modes])
log.debug('(%s) handle_uid: Applying modes %s for %s', self.irc.name, parsedmodes, uid)
utils.applyModes(self.irc, uid, parsedmodes)
self.irc.applyModes(uid, parsedmodes)
self.irc.servers[numeric].users.add(uid)
# Call the OPERED UP hook if +o is being added to the mode list.
@ -221,7 +221,7 @@ class HybridProtocol(TS6Protocol):
target = args[0]
ts = args[1]
modes = args[2:]
parsedmodes = utils.parseModes(self.irc, target, modes)
parsedmodes = self.irc.parseModes(target, modes)
for modepair in parsedmodes:
if modepair[0] == '+d':
@ -259,7 +259,7 @@ class HybridProtocol(TS6Protocol):
parsedmodes.remove(modepair)
if parsedmodes:
utils.applyModes(self.irc, target, parsedmodes)
self.irc.applyModes(target, parsedmodes)
return {'target': target, 'modes': parsedmodes}

View File

@ -59,7 +59,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
utils.applyModes(self.irc, uid, modes)
self.irc.applyModes(uid, modes)
self.irc.servers[server].users.add(uid)
self._send(server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}"
@ -132,7 +132,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
log.debug("(%s) sjoin: KeyError trying to add %r to %r's channel list?", self.irc.name, channel, user)
if ts <= orig_ts:
# Only save our prefix modes in the channel state if our TS is lower than or equal to theirs.
utils.applyModes(self.irc, channel, changedmodes)
self.irc.applyModes(channel, changedmodes)
namelist = ' '.join(namelist)
self._send(server, "FJOIN {channel} {ts} {modes} :{users}".format(
ts=ts, users=namelist, channel=channel,
@ -177,7 +177,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
# https://github.com/inspircd/inspircd/blob/master/src/modules/m_spanningtree/opertype.cpp#L26-L28
# Servers need a special command to set umode +o on people.
self._operUp(target)
utils.applyModes(self.irc, target, modes)
self.irc.applyModes(target, modes)
joinedmodes = utils.joinModes(modes)
if utils.isChannel(target):
ts = ts or self.irc.channels[utils.toLower(self.irc, target)].ts
@ -491,8 +491,8 @@ class InspIRCdProtocol(TS6BaseProtocol):
self.updateTS(channel, their_ts)
modestring = args[2:-1] or args[2]
parsedmodes = utils.parseModes(self.irc, channel, modestring)
utils.applyModes(self.irc, channel, parsedmodes)
parsedmodes = self.irc.parseModes(channel, modestring)
self.irc.applyModes(channel, parsedmodes)
namelist = []
for user in userlist:
modeprefix, user = user.split(',', 1)
@ -506,7 +506,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
namelist.append(user)
self.irc.users[user].channels.add(channel)
if their_ts <= our_ts:
utils.applyModes(self.irc, channel, [('+%s' % mode, user) for mode in modeprefix])
self.irc.applyModes(channel, [('+%s' % mode, user) for mode in modeprefix])
self.irc.channels[channel].users.add(user)
return {'channel': channel, 'users': namelist, 'modes': parsedmodes, 'ts': their_ts}
@ -516,9 +516,9 @@ class InspIRCdProtocol(TS6BaseProtocol):
uid, ts, nick, realhost, host, ident, ip = args[0:7]
realname = args[-1]
self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip)
parsedmodes = utils.parseModes(self.irc, uid, [args[8], args[9]])
parsedmodes = self.irc.parseModes(uid, [args[8], args[9]])
log.debug('Applying modes %s for %s', parsedmodes, uid)
utils.applyModes(self.irc, uid, parsedmodes)
self.irc.applyModes(uid, parsedmodes)
self.irc.servers[numeric].users.add(uid)
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
@ -555,8 +555,8 @@ class InspIRCdProtocol(TS6BaseProtocol):
channel = utils.toLower(self.irc, args[0])
oldobj = self.irc.channels[channel].deepcopy()
modes = args[2:]
changedmodes = utils.parseModes(self.irc, channel, modes)
utils.applyModes(self.irc, channel, changedmodes)
changedmodes = self.irc.parseModes(channel, modes)
self.irc.applyModes(channel, changedmodes)
ts = int(args[1])
return {'target': channel, 'modes': changedmodes, 'ts': ts,
'oldchan': oldobj}
@ -568,8 +568,8 @@ class InspIRCdProtocol(TS6BaseProtocol):
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc
target = args[0]
modestrings = args[1:]
changedmodes = utils.parseModes(self.irc, target, modestrings)
utils.applyModes(self.irc, target, changedmodes)
changedmodes = self.irc.parseModes(target, modestrings)
self.irc.applyModes(target, changedmodes)
return {'target': target, 'modes': changedmodes}
def handle_idle(self, numeric, command, args):
@ -636,7 +636,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
# <- :70MAAAAAB OPERTYPE Network_Owner
omode = [('+o', None)]
self.irc.users[numeric].opertype = opertype = args[0].replace("_", " ")
utils.applyModes(self.irc, numeric, omode)
self.irc.applyModes(numeric, omode)
# OPERTYPE is essentially umode +o and metadata in one command;
# we'll call that too.
self.irc.callHooks([numeric, 'CLIENT_OPERED', {'text': opertype}])

View File

@ -270,7 +270,7 @@ class P10Protocol(Protocol):
opertype=opertype)
# Fill in modes and add it to our users index
utils.applyModes(self.irc, uid, modes)
self.irc.applyModes(uid, modes)
self.irc.servers[server].users.add(uid)
# Encode IPs when sending
@ -377,7 +377,7 @@ class P10Protocol(Protocol):
(not self.irc.isInternalServer(numeric)):
raise LookupError('No such PyLink client/server exists.')
utils.applyModes(self.irc, target, modes)
self.irc.applyModes(target, modes)
modes = list(modes)
# According to the P10 specification:
@ -533,7 +533,7 @@ class P10Protocol(Protocol):
if ts <= orig_ts:
# Only save our prefix modes in the channel state if our TS is lower than or equal to theirs.
utils.applyModes(self.irc, channel, changedmodes)
self.irc.applyModes(channel, changedmodes)
def spawnServer(self, name, sid=None, uplink=None, desc=None, endburst_delay=0):
"""
@ -623,7 +623,7 @@ class P10Protocol(Protocol):
self._send(self.irc.sid, 'FA %s %s' % (target, text))
# Save the host change as a user mode (this is what P10 does),
# so further host checks work.
utils.applyModes(self.irc, target, [('+f', text)])
self.irc.applyModes(target, [('+f', text)])
# P10 cloaks aren't as simple as just replacing the displayed host with the one we're
# sending. Check for cloak changes properly.
@ -786,8 +786,8 @@ class P10Protocol(Protocol):
# parameters attached.
if args[5].startswith('+'):
modes = args[5:-3]
parsedmodes = utils.parseModes(self.irc, uid, modes)
utils.applyModes(self.irc, uid, parsedmodes)
parsedmodes = self.irc.parseModes(uid, modes)
self.irc.applyModes(uid, parsedmodes)
for modepair in parsedmodes:
if modepair[0][-1] == 'r':
@ -952,7 +952,7 @@ class P10Protocol(Protocol):
# If no modes are given, this will simply be empty.
modestring = args[2:-1]
if modestring:
parsedmodes = utils.parseModes(self.irc, channel, modestring)
parsedmodes = self.irc.parseModes(channel, modestring)
else:
parsedmodes = []
@ -960,7 +960,7 @@ class P10Protocol(Protocol):
parsedmodes.extend(bans)
if parsedmodes:
utils.applyModes(self.irc, channel, parsedmodes)
self.irc.applyModes(channel, parsedmodes)
namelist = []
log.debug('(%s) handle_sjoin: got userlist %r for %r', self.irc.name, userlist, channel)
@ -991,7 +991,7 @@ class P10Protocol(Protocol):
self.irc.users[user].channels.add(channel)
if their_ts <= our_ts:
utils.applyModes(self.irc, channel, [('+%s' % mode, user) for mode in prefixes])
self.irc.applyModes(channel, [('+%s' % mode, user) for mode in prefixes])
self.irc.channels[channel].users.add(user)
@ -1060,8 +1060,8 @@ class P10Protocol(Protocol):
target = utils.toLower(self.irc, target)
modestrings = args[1:]
changedmodes = utils.parseModes(self.irc, target, modestrings)
utils.applyModes(self.irc, target, changedmodes)
changedmodes = self.irc.parseModes(target, modestrings)
self.irc.applyModes(target, changedmodes)
# Call the CLIENT_OPERED hook if +o is being set.
if ('+o', None) in changedmodes and target in self.irc.users:
@ -1236,7 +1236,7 @@ class P10Protocol(Protocol):
# Mode does not take an argument when unsetting.
changedmodes.append(('-%s' % modechar, None))
utils.applyModes(self.irc, channel, changedmodes)
self.irc.applyModes(channel, changedmodes)
return {'target': channel, 'modes': changedmodes, 'oldchan': oldobj}
def handle_account(self, numeric, command, args):
@ -1281,7 +1281,7 @@ class P10Protocol(Protocol):
text = args[1]
# Assume a usermode +f change, and then update the cloak checking.
utils.applyModes(self.irc, target, [('+f', text)])
self.irc.applyModes(target, [('+f', text)])
self.checkCloakChange(target)
# We don't need to send any hooks here, checkCloakChange does that for us.

View File

@ -54,7 +54,7 @@ class TS6Protocol(TS6BaseProtocol):
u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
utils.applyModes(self.irc, uid, modes)
self.irc.applyModes(uid, modes)
self.irc.servers[server].users.add(uid)
self._send(server, "EUID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
@ -139,7 +139,7 @@ class TS6Protocol(TS6BaseProtocol):
self.irc.channels[channel].users.update(uids)
if ts <= orig_ts:
# Only save our prefix modes in the channel state if our TS is lower than or equal to theirs.
utils.applyModes(self.irc, channel, changedmodes)
self.irc.applyModes(channel, changedmodes)
def mode(self, numeric, target, modes, ts=None):
"""Sends mode changes from a PyLink client/server."""
@ -150,7 +150,7 @@ class TS6Protocol(TS6BaseProtocol):
(not self.irc.isInternalServer(numeric)):
raise LookupError('No such PyLink client/server exists.')
utils.applyModes(self.irc, target, modes)
self.irc.applyModes(target, modes)
modes = list(modes)
if utils.isChannel(target):
@ -427,8 +427,8 @@ class TS6Protocol(TS6BaseProtocol):
self.updateTS(channel, their_ts)
modestring = args[2:-1] or args[2]
parsedmodes = utils.parseModes(self.irc, channel, modestring)
utils.applyModes(self.irc, channel, parsedmodes)
parsedmodes = self.irc.parseModes(channel, modestring)
self.irc.applyModes(channel, parsedmodes)
namelist = []
log.debug('(%s) handle_sjoin: got userlist %r for %r', self.irc.name, userlist, channel)
for userpair in userlist:
@ -455,7 +455,7 @@ class TS6Protocol(TS6BaseProtocol):
namelist.append(user)
self.irc.users[user].channels.add(channel)
if their_ts <= our_ts:
utils.applyModes(self.irc, channel, [('+%s' % mode, user) for mode in finalprefix])
self.irc.applyModes(channel, [('+%s' % mode, user) for mode in finalprefix])
self.irc.channels[channel].users.add(user)
return {'channel': channel, 'users': namelist, 'modes': parsedmodes, 'ts': their_ts}
@ -502,9 +502,9 @@ class TS6Protocol(TS6BaseProtocol):
self.irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip)
parsedmodes = utils.parseModes(self.irc, uid, [modes])
parsedmodes = self.irc.parseModes(uid, [modes])
log.debug('Applying modes %s for %s', parsedmodes, uid)
utils.applyModes(self.irc, uid, parsedmodes)
self.irc.applyModes(uid, parsedmodes)
self.irc.servers[numeric].users.add(uid)
# Call the OPERED UP hook if +o is being added to the mode list.
@ -563,8 +563,8 @@ class TS6Protocol(TS6BaseProtocol):
channel = utils.toLower(self.irc, args[1])
oldobj = self.irc.channels[channel].deepcopy()
modes = args[2:]
changedmodes = utils.parseModes(self.irc, channel, modes)
utils.applyModes(self.irc, channel, changedmodes)
changedmodes = self.irc.parseModes(channel, modes)
self.irc.applyModes(channel, changedmodes)
ts = int(args[0])
return {'target': channel, 'modes': changedmodes, 'ts': ts,
'oldchan': oldobj}
@ -574,8 +574,8 @@ class TS6Protocol(TS6BaseProtocol):
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc
target = args[0]
modestrings = args[1:]
changedmodes = utils.parseModes(self.irc, target, modestrings)
utils.applyModes(self.irc, target, changedmodes)
changedmodes = self.irc.parseModes(target, modestrings)
self.irc.applyModes(target, changedmodes)
# Call the OPERED UP hook if +o is being set.
if ('+o', None) in changedmodes:
otype = 'Server Administrator' if ('a', None) in self.irc.users[target].modes else 'IRC Operator'
@ -621,7 +621,7 @@ class TS6Protocol(TS6BaseProtocol):
modes = []
for ban in args[-1].split():
modes.append(('+%s' % mode, ban))
utils.applyModes(self.irc, channel, modes)
self.irc.applyModes(channel, modes)
return {'target': channel, 'modes': modes, 'ts': ts}
def handle_whois(self, numeric, command, args):

View File

@ -83,7 +83,7 @@ class UnrealProtocol(TS6BaseProtocol):
raw_modes = utils.joinModes(modes)
u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
utils.applyModes(self.irc, uid, modes)
self.irc.applyModes(uid, modes)
self.irc.servers[server].users.add(uid)
# UnrealIRCd requires encoding the IP by first packing it into a binary format,
@ -180,7 +180,7 @@ class UnrealProtocol(TS6BaseProtocol):
self.irc.channels[channel].users.update(uids)
if ts <= orig_ts:
# Only save our prefix modes in the channel state if our TS is lower than or equal to theirs.
utils.applyModes(self.irc, channel, changedmodes)
self.irc.applyModes(channel, changedmodes)
def ping(self, source=None, target=None):
"""Sends a PING to a target server. Periodic PINGs are sent to our uplink
@ -215,7 +215,7 @@ class UnrealProtocol(TS6BaseProtocol):
(not self.irc.isInternalServer(numeric)):
raise LookupError('No such PyLink client/server exists.')
utils.applyModes(self.irc, target, modes)
self.irc.applyModes(target, modes)
joinedmodes = utils.joinModes(modes)
if utils.isChannel(target):
# The MODE command is used for channel mode changes only
@ -378,8 +378,8 @@ class UnrealProtocol(TS6BaseProtocol):
self.irc.servers[numeric].users.add(uid)
# Handle user modes
parsedmodes = utils.parseModes(self.irc, uid, [modestring])
utils.applyModes(self.irc, uid, parsedmodes)
parsedmodes = self.irc.parseModes(uid, [modestring])
self.irc.applyModes(uid, parsedmodes)
# The cloaked (+x) host is completely separate from the displayed host
# and real host in that it is ONLY shown if the user is +x (cloak mode
@ -574,7 +574,7 @@ class UnrealProtocol(TS6BaseProtocol):
self.irc.users[user].channels.add(channel)
# Only merge the remote's prefix modes if their TS is smaller or equal to ours.
if their_ts <= our_ts:
utils.applyModes(self.irc, channel, [('+%s' % mode, user) for mode in finalprefix])
self.irc.applyModes(channel, [('+%s' % mode, user) for mode in finalprefix])
self.irc.channels[channel].users.add(user)
return {'channel': channel, 'users': namelist, 'modes': self.irc.channels[channel].modes, 'ts': their_ts}
@ -636,9 +636,9 @@ class UnrealProtocol(TS6BaseProtocol):
channel = utils.toLower(self.irc, args[0])
oldobj = self.irc.channels[channel].deepcopy()
modes = list(filter(None, args[1:])) # normalize whitespace
parsedmodes = utils.parseModes(self.irc, channel, modes)
parsedmodes = self.irc.parseModes(channel, modes)
if parsedmodes:
utils.applyModes(self.irc, channel, parsedmodes)
self.irc.applyModes(channel, parsedmodes)
if numeric in self.irc.servers and args[-1].isdigit():
# Sender is a server AND last arg is number. Perform TS updates.
their_ts = int(args[-1])
@ -690,8 +690,8 @@ class UnrealProtocol(TS6BaseProtocol):
target = self._getUid(args[0])
modes = args[1:]
parsedmodes = utils.parseModes(self.irc, target, modes)
utils.applyModes(self.irc, target, parsedmodes)
parsedmodes = self.irc.parseModes(target, modes)
self.irc.applyModes(target, parsedmodes)
# If +x/-x is being set, update cloaked host info.
self.checkCloakChange(target, parsedmodes)
@ -732,8 +732,8 @@ class UnrealProtocol(TS6BaseProtocol):
def handle_umode2(self, numeric, command, args):
"""Handles UMODE2, used to set user modes on oneself."""
# <- :GL UMODE2 +W
parsedmodes = utils.parseModes(self.irc, numeric, args)
utils.applyModes(self.irc, numeric, parsedmodes)
parsedmodes = self.irc.parseModes(numeric, args)
self.irc.applyModes(numeric, parsedmodes)
if ('+o', None) in parsedmodes:
# If +o being set, call the CLIENT_OPERED internal hook.
@ -784,7 +784,7 @@ class UnrealProtocol(TS6BaseProtocol):
# When SETHOST or CHGHOST is used, modes +xt are implicitly set on the
# target.
utils.applyModes(self.irc, numeric, [('+x', None), ('+t', None)])
self.irc.applyModes(numeric, [('+x', None), ('+t', None)])
return {'target': numeric, 'newhost': newhost}
@ -809,7 +809,7 @@ class UnrealProtocol(TS6BaseProtocol):
# When SETHOST or CHGHOST is used, modes +xt are implicitly set on the
# target.
utils.applyModes(self.irc, target, [('+x', None), ('+t', None)])
self.irc.applyModes(target, [('+x', None), ('+t', None)])
return {'target': target, 'newhost': newhost}