3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-02-02 15:44:06 +01:00

protocols: migrate away from camel case

This commit is contained in:
James Lu 2017-06-29 22:56:14 -07:00
parent 3913a909ef
commit a4e321522b
9 changed files with 294 additions and 294 deletions

View File

@ -113,7 +113,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
manipulatable=manipulatable, realhost=realhost, ip=ip) manipulatable=manipulatable, realhost=realhost, ip=ip)
self.servers[server].users.add(uid) self.servers[server].users.add(uid)
self.applyModes(uid, modes) self.apply_modes(uid, modes)
return u return u
@ -128,22 +128,22 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
def away(self, source, text): def away(self, source, text):
"""STUB: sets away messages for clients internally.""" """STUB: sets away messages for clients internally."""
log.debug('(%s) away: target is %s, internal client? %s', self.name, source, self.isInternalClient(source)) log.debug('(%s) away: target is %s, internal client? %s', self.name, source, self.is_internal_client(source))
if self.users[source].away != text: if self.users[source].away != text:
if not self.isInternalClient(source): if not self.is_internal_client(source):
log.debug('(%s) away: sending AWAY hook from %s with text %r', self.name, source, text) log.debug('(%s) away: sending AWAY hook from %s with text %r', self.name, source, text)
self.callHooks([source, 'AWAY', {'text': text}]) self.call_hooks([source, 'AWAY', {'text': text}])
self.users[source].away = text self.users[source].away = text
def invite(self, client, target, channel): def invite(self, client, target, channel):
"""Invites a user to a channel.""" """Invites a user to a channel."""
self.send('INVITE %s %s' % (self.getFriendlyName(target), channel)) self.send('INVITE %s %s' % (self.get_friendly_name(target), channel))
def join(self, client, channel): def join(self, client, channel):
"""STUB: Joins a user to a channel.""" """STUB: Joins a user to a channel."""
channel = self.toLower(channel) channel = self.to_lower(channel)
# Only joins for the main PyLink client are actually forwarded. Others are ignored. # Only joins for the main PyLink client are actually forwarded. Others are ignored.
# Note: we do not automatically add our main client to the channel state, as we # Note: we do not automatically add our main client to the channel state, as we
@ -159,25 +159,25 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
self.users[client].channels.add(channel) self.users[client].channels.add(channel)
log.debug('(%s) join: faking JOIN of client %s/%s to %s', self.name, client, log.debug('(%s) join: faking JOIN of client %s/%s to %s', self.name, client,
self.getFriendlyName(client), channel) self.get_friendly_name(client), channel)
self.callHooks([client, 'CLIENTBOT_JOIN', {'channel': channel}]) self.call_hooks([client, 'CLIENTBOT_JOIN', {'channel': channel}])
def kick(self, source, channel, target, reason=''): def kick(self, source, channel, target, reason=''):
"""Sends channel kicks.""" """Sends channel kicks."""
log.debug('(%s) kick: checking if target %s (nick: %s) is an internal client? %s', log.debug('(%s) kick: checking if target %s (nick: %s) is an internal client? %s',
self.name, target, self.getFriendlyName(target), self.name, target, self.get_friendly_name(target),
self.isInternalClient(target)) self.is_internal_client(target))
if self.isInternalClient(target): if self.is_internal_client(target):
# Target was one of our virtual clients. Just remove them from the state. # Target was one of our virtual clients. Just remove them from the state.
self.handle_part(target, 'KICK', [channel, reason]) self.handle_part(target, 'KICK', [channel, reason])
# Send a KICK hook for message formatting. # Send a KICK hook for message formatting.
self.callHooks([source, 'CLIENTBOT_KICK', {'channel': channel, 'target': target, 'text': reason}]) self.call_hooks([source, 'CLIENTBOT_KICK', {'channel': channel, 'target': target, 'text': reason}])
return return
self.send('KICK %s %s :<%s> %s' % (channel, self._expandPUID(target), self.send('KICK %s %s :<%s> %s' % (channel, self._expandPUID(target),
self.getFriendlyName(source), reason)) self.get_friendly_name(source), reason))
# Don't update our state here: wait for the IRCd to send an acknowledgement instead. # Don't update our state here: wait for the IRCd to send an acknowledgement instead.
# There is essentially a 3 second wait to do this, as we send NAMES with a delay # There is essentially a 3 second wait to do this, as we send NAMES with a delay
@ -201,7 +201,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
if self.pseudoclient and self.pseudoclient.uid == source: if self.pseudoclient and self.pseudoclient.uid == source:
self.send('%s %s :%s' % (command, self._expandPUID(target), text)) self.send('%s %s :%s' % (command, self._expandPUID(target), text))
else: else:
self.callHooks([source, 'CLIENTBOT_MESSAGE', {'target': target, 'is_notice': notice, 'text': text}]) self.call_hooks([source, 'CLIENTBOT_MESSAGE', {'target': target, 'is_notice': notice, 'text': text}])
def mode(self, source, channel, modes, ts=None): def mode(self, source, channel, modes, ts=None):
"""Sends channel MODE changes.""" """Sends channel MODE changes."""
@ -212,24 +212,24 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
# with IRCd MODE acknowledgements. # with IRCd MODE acknowledgements.
# FIXME: More related safety checks should be added for this. # FIXME: More related safety checks should be added for this.
log.debug('(%s) mode: re-parsing modes %s', self.name, modes) log.debug('(%s) mode: re-parsing modes %s', self.name, modes)
joined_modes = self.joinModes(modes) joined_modes = self.join_modes(modes)
for modepair in self.parseModes(channel, joined_modes): for modepair in self.parse_modes(channel, joined_modes):
log.debug('(%s) mode: checking if %s a prefix mode: %s', self.name, modepair, self.prefixmodes) log.debug('(%s) mode: checking if %s a prefix mode: %s', self.name, modepair, self.prefixmodes)
if modepair[0][-1] in self.prefixmodes: if modepair[0][-1] in self.prefixmodes:
if self.isInternalClient(modepair[1]): if self.is_internal_client(modepair[1]):
# Ignore prefix modes for virtual internal clients. # Ignore prefix modes for virtual internal clients.
log.debug('(%s) mode: skipping virtual client prefixmode change %s', self.name, modepair) log.debug('(%s) mode: skipping virtual client prefixmode change %s', self.name, modepair)
continue continue
else: else:
# For other clients, change the mode argument to nick instead of PUID. # For other clients, change the mode argument to nick instead of PUID.
nick = self.getFriendlyName(modepair[1]) nick = self.get_friendly_name(modepair[1])
log.debug('(%s) mode: coersing mode %s argument to %s', self.name, modepair, nick) log.debug('(%s) mode: coersing mode %s argument to %s', self.name, modepair, nick)
modepair = (modepair[0], nick) modepair = (modepair[0], nick)
extmodes.append(modepair) extmodes.append(modepair)
log.debug('(%s) mode: filtered modes for %s: %s', self.name, channel, extmodes) log.debug('(%s) mode: filtered modes for %s: %s', self.name, channel, extmodes)
if extmodes: if extmodes:
self.send('MODE %s %s' % (channel, self.joinModes(extmodes))) self.send('MODE %s %s' % (channel, self.join_modes(extmodes)))
# Don't update the state here: the IRCd sill respond with a MODE reply if successful. # Don't update the state here: the IRCd sill respond with a MODE reply if successful.
def nick(self, source, newnick): def nick(self, source, newnick):
@ -238,7 +238,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
self.send('NICK :%s' % newnick) self.send('NICK :%s' % newnick)
# No state update here: the IRCd will respond with a NICK acknowledgement if the change succeeds. # No state update here: the IRCd will respond with a NICK acknowledgement if the change succeeds.
else: else:
self.callHooks([source, 'CLIENTBOT_NICK', {'newnick': newnick}]) self.call_hooks([source, 'CLIENTBOT_NICK', {'newnick': newnick}])
self.users[source].nick = newnick self.users[source].nick = newnick
def notice(self, source, target, text): def notice(self, source, target, text):
@ -251,7 +251,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
Sends PING to the uplink. Sends PING to the uplink.
""" """
if self.uplink: if self.uplink:
self.send('PING %s' % self.getFriendlyName(self.uplink)) self.send('PING %s' % self.get_friendly_name(self.uplink))
# Poll WHO periodically to figure out any ident/host/away status changes. # Poll WHO periodically to figure out any ident/host/away status changes.
for channel in self.pseudoclient.channels: for channel in self.pseudoclient.channels:
@ -266,13 +266,13 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
if self.pseudoclient and source == self.pseudoclient.uid: if self.pseudoclient and source == self.pseudoclient.uid:
self.send('PART %s :%s' % (channel, reason)) self.send('PART %s :%s' % (channel, reason))
else: else:
self.callHooks([source, 'CLIENTBOT_PART', {'channel': channel, 'text': reason}]) self.call_hooks([source, 'CLIENTBOT_PART', {'channel': channel, 'text': reason}])
def quit(self, source, reason): def quit(self, source, reason):
"""STUB: Quits a client.""" """STUB: Quits a client."""
userdata = self.users[source] userdata = self.users[source]
self._remove_client(source) self._remove_client(source)
self.callHooks([source, 'CLIENTBOT_QUIT', {'text': reason, 'userdata': userdata}]) self.call_hooks([source, 'CLIENTBOT_QUIT', {'text': reason, 'userdata': userdata}])
def sjoin(self, server, channel, users, ts=None, modes=set()): def sjoin(self, server, channel, users, ts=None, modes=set()):
"""STUB: bursts joins from a server.""" """STUB: bursts joins from a server."""
@ -288,8 +288,8 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
self.users[user].channels.add(channel) self.users[user].channels.add(channel)
self.channels[channel].users |= puids self.channels[channel].users |= puids
nicks = {self.getFriendlyName(u) for u in puids} nicks = {self.get_friendly_name(u) for u in puids}
self.callHooks([server, 'CLIENTBOT_SJOIN', {'channel': channel, 'nicks': nicks}]) self.call_hooks([server, 'CLIENTBOT_SJOIN', {'channel': channel, 'nicks': nicks}])
def squit(self, source, target, text): def squit(self, source, target, text):
"""STUB: SQUITs a server.""" """STUB: SQUITs a server."""
@ -298,7 +298,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
squit_data = self._squit(source, 'CLIENTBOT_VIRTUAL_SQUIT', [target, text]) squit_data = self._squit(source, 'CLIENTBOT_VIRTUAL_SQUIT', [target, text])
if squit_data.get('nicks'): if squit_data.get('nicks'):
self.callHooks([source, 'CLIENTBOT_SQUIT', squit_data]) self.call_hooks([source, 'CLIENTBOT_SQUIT', squit_data])
def _stub(self, *args): def _stub(self, *args):
"""Stub outgoing command function (does nothing).""" """Stub outgoing command function (does nothing)."""
@ -315,20 +315,20 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
if field == 'IDENT' and u.ident != text: if field == 'IDENT' and u.ident != text:
u.ident = text u.ident = text
if not self.isInternalClient(target): if not self.is_internal_client(target):
# We're updating the host of an external client in our state, so send the appropriate # We're updating the host of an external client in our state, so send the appropriate
# hook payloads. # hook payloads.
self.callHooks([self.sid, 'CHGIDENT', self.call_hooks([self.sid, 'CHGIDENT',
{'target': target, 'newident': text}]) {'target': target, 'newident': text}])
elif field == 'HOST' and u.host != text: elif field == 'HOST' and u.host != text:
u.host = text u.host = text
if not self.isInternalClient(target): if not self.is_internal_client(target):
self.callHooks([self.sid, 'CHGHOST', self.call_hooks([self.sid, 'CHGHOST',
{'target': target, 'newhost': text}]) {'target': target, 'newhost': text}])
elif field in ('REALNAME', 'GECOS') and u.realname != text: elif field in ('REALNAME', 'GECOS') and u.realname != text:
u.realname = text u.realname = text
if not self.isInternalClient(target): if not self.is_internal_client(target):
self.callHooks([self.sid, 'CHGNAME', self.call_hooks([self.sid, 'CHGNAME',
{'target': target, 'newgecos': text}]) {'target': target, 'newgecos': text}])
else: else:
return # Nothing changed return # Nothing changed
@ -340,8 +340,8 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
Limited (internal) nick collision checking is done here to prevent Clientbot users from Limited (internal) nick collision checking is done here to prevent Clientbot users from
being confused with virtual clients, and vice versa.""" being confused with virtual clients, and vice versa."""
self._validateNick(nick) self._validateNick(nick)
idsource = self.nickToUid(nick) idsource = self.nick_to_uid(nick)
is_internal = self.isInternalClient(idsource) is_internal = self.is_internal_client(idsource)
# If this sender isn't known or it is one of our virtual clients, spawn a new one. # If this sender isn't known or it is one of our virtual clients, spawn a new one.
# This also takes care of any nick collisions caused by new, Clientbot users # This also takes care of any nick collisions caused by new, Clientbot users
@ -349,7 +349,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
if (not idsource) or (is_internal and self.pseudoclient and idsource != self.pseudoclient.uid): if (not idsource) or (is_internal and self.pseudoclient and idsource != self.pseudoclient.uid):
if idsource: if idsource:
log.debug('(%s) Nick-colliding virtual client %s/%s', self.name, idsource, nick) log.debug('(%s) Nick-colliding virtual client %s/%s', self.name, idsource, nick)
self.callHooks([self.sid, 'CLIENTBOT_NICKCOLLIDE', {'target': idsource, 'parse_as': 'SAVE'}]) self.call_hooks([self.sid, 'CLIENTBOT_NICKCOLLIDE', {'target': idsource, 'parse_as': 'SAVE'}])
idsource = self.spawnClient(nick, ident or 'unknown', host or 'unknown', idsource = self.spawnClient(nick, ident or 'unknown', host or 'unknown',
server=self.uplink, realname=FALLBACK_REALNAME).uid server=self.uplink, realname=FALLBACK_REALNAME).uid
@ -634,9 +634,9 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
# <- :charybdis.midnight.vpn 353 ice = #test :ice @GL # <- :charybdis.midnight.vpn 353 ice = #test :ice @GL
# Mark "@"-type channels as secret automatically, per RFC2812. # Mark "@"-type channels as secret automatically, per RFC2812.
channel = self.toLower(args[2]) channel = self.to_lower(args[2])
if args[1] == '@': if args[1] == '@':
self.applyModes(channel, [('+s', None)]) self.apply_modes(channel, [('+s', None)])
names = set() names = set()
modes = set() modes = set()
@ -667,7 +667,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
# Statekeeping: make sure the channel's user list is updated! # Statekeeping: make sure the channel's user list is updated!
self.channels[channel].users |= names self.channels[channel].users |= names
self.applyModes(channel, modes) self.apply_modes(channel, modes)
log.debug('(%s) handle_353: adding users %s to %s', self.name, names, channel) log.debug('(%s) handle_353: adding users %s to %s', self.name, names, channel)
log.debug('(%s) handle_353: adding modes %s to %s', self.name, modes, channel) log.debug('(%s) handle_353: adding modes %s to %s', self.name, modes, channel)
@ -705,7 +705,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
realname = args[-1].split(' ', 1)[-1] realname = args[-1].split(' ', 1)[-1]
self._validateNick(nick) self._validateNick(nick)
uid = self.nickToUid(nick) uid = self.nick_to_uid(nick)
if uid is None: if uid is None:
log.debug("(%s) Ignoring extraneous /WHO info for %s", self.name, nick) log.debug("(%s) Ignoring extraneous /WHO info for %s", self.name, nick)
@ -732,15 +732,15 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
if self.serverdata.get('track_oper_statuses'): if self.serverdata.get('track_oper_statuses'):
if '*' in status: # Track IRCop status if '*' in status: # Track IRCop status
if not self.isOper(uid, allowAuthed=False): if not self.is_oper(uid, allowAuthed=False):
# Don't send duplicate oper ups if the target is already oper. # Don't send duplicate oper ups if the target is already oper.
self.applyModes(uid, [('+o', None)]) self.apply_modes(uid, [('+o', None)])
self.callHooks([uid, 'MODE', {'target': uid, 'modes': {('+o', None)}}]) self.call_hooks([uid, 'MODE', {'target': uid, 'modes': {('+o', None)}}])
self.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC Operator'}]) self.call_hooks([uid, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
elif self.isOper(uid, allowAuthed=False) and not self.isInternalClient(uid): elif self.is_oper(uid, allowAuthed=False) and not self.is_internal_client(uid):
# Track deopers # Track deopers
self.applyModes(uid, [('-o', None)]) self.apply_modes(uid, [('-o', None)])
self.callHooks([uid, 'MODE', {'target': uid, 'modes': {('-o', None)}}]) self.call_hooks([uid, 'MODE', {'target': uid, 'modes': {('-o', None)}}])
self.who_received.add(uid) self.who_received.add(uid)
@ -753,7 +753,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
users = self.who_received.copy() users = self.who_received.copy()
self.who_received.clear() self.who_received.clear()
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
c = self.channels[channel] c = self.channels[channel]
c.who_received = True c.who_received = True
@ -788,7 +788,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
Handles incoming JOINs. Handles incoming JOINs.
""" """
# <- :GL|!~GL@127.0.0.1 JOIN #whatever # <- :GL|!~GL@127.0.0.1 JOIN #whatever
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
self.join(source, channel) self.join(source, channel)
return {'channel': channel, 'users': [source], 'modes': self.channels[channel].modes} return {'channel': channel, 'users': [source], 'modes': self.channels[channel].modes}
@ -798,8 +798,8 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
Handles incoming KICKs. Handles incoming KICKs.
""" """
# <- :GL!~gl@127.0.0.1 KICK #whatever GL| :xd # <- :GL!~gl@127.0.0.1 KICK #whatever GL| :xd
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
target = self.nickToUid(args[1]) target = self.nick_to_uid(args[1])
try: try:
reason = args[2] reason = args[2]
@ -824,9 +824,9 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
except KeyError: except KeyError:
pass pass
if (not self.isInternalClient(source)) and not self.isInternalServer(source): if (not self.is_internal_client(source)) and not self.is_internal_server(source):
# Don't repeat hooks if we're the kicker. # Don't repeat hooks if we're the kicker.
self.callHooks([source, 'KICK', {'channel': channel, 'target': target, 'text': reason}]) self.call_hooks([source, 'KICK', {'channel': channel, 'target': target, 'text': reason}])
# Delete channels that we were kicked from, for better state keeping. # Delete channels that we were kicked from, for better state keeping.
if self.pseudoclient and target == self.pseudoclient.uid: if self.pseudoclient and target == self.pseudoclient.uid:
@ -838,16 +838,16 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
# <- :ice MODE ice :+Zi # <- :ice MODE ice :+Zi
target = args[0] target = args[0]
if utils.isChannel(target): if utils.isChannel(target):
target = self.toLower(target) target = self.to_lower(target)
oldobj = self.channels[target].deepcopy() oldobj = self.channels[target].deepcopy()
else: else:
target = self.nickToUid(target) target = self.nick_to_uid(target)
oldobj = None oldobj = None
modes = args[1:] modes = args[1:]
changedmodes = self.parseModes(target, modes) changedmodes = self.parse_modes(target, modes)
self.applyModes(target, changedmodes) self.apply_modes(target, changedmodes)
if self.isInternalClient(target): if self.is_internal_client(target):
log.debug('(%s) Suppressing MODE change hook for internal client %s', self.name, target) log.debug('(%s) Suppressing MODE change hook for internal client %s', self.name, target)
return return
if changedmodes: if changedmodes:
@ -862,15 +862,15 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
# -> MODE #test # -> MODE #test
# <- :midnight.vpn 324 GL #test +nt # <- :midnight.vpn 324 GL #test +nt
# <- :midnight.vpn 329 GL #test 1491773459 # <- :midnight.vpn 329 GL #test 1491773459
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
modes = args[2:] modes = args[2:]
log.debug('(%s) Got RPL_CHANNELMODEIS (324) modes %s for %s', self.name, modes, channel) log.debug('(%s) Got RPL_CHANNELMODEIS (324) modes %s for %s', self.name, modes, channel)
changedmodes = self.parseModes(channel, modes) changedmodes = self.parse_modes(channel, modes)
self.applyModes(channel, changedmodes) self.apply_modes(channel, changedmodes)
def handle_329(self, source, command, args): def handle_329(self, source, command, args):
"""Handles TS announcements via RPL_CREATIONTIME.""" """Handles TS announcements via RPL_CREATIONTIME."""
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
ts = int(args[2]) ts = int(args[2])
self.channels[channel].ts = ts self.channels[channel].ts = ts
@ -900,7 +900,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
Handles incoming PARTs. Handles incoming PARTs.
""" """
# <- :GL|!~GL@127.0.0.1 PART #whatever # <- :GL|!~GL@127.0.0.1 PART #whatever
channels = list(map(self.toLower, args[0].split(','))) channels = list(map(self.to_lower, args[0].split(',')))
try: try:
reason = args[1] reason = args[1]
except IndexError: except IndexError:
@ -910,7 +910,7 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
self.channels[channel].removeuser(source) self.channels[channel].removeuser(source)
self.users[source].channels -= set(channels) self.users[source].channels -= set(channels)
self.callHooks([source, 'PART', {'channels': channels, 'text': reason}]) self.call_hooks([source, 'PART', {'channels': channels, 'text': reason}])
# Clear channels that are empty, or that we're parting. # Clear channels that are empty, or that we're parting.
for channel in channels: for channel in channels:
@ -936,15 +936,15 @@ class ClientbotWrapperProtocol(IRCCommonProtocol):
# <- :sender NOTICE somenick :afasfsa # <- :sender NOTICE somenick :afasfsa
target = args[0] target = args[0]
if self.isInternalClient(source) or self.isInternalServer(source): if self.is_internal_client(source) or self.is_internal_server(source):
log.warning('(%s) Received %s to %s being routed the wrong way!', self.name, command, target) log.warning('(%s) Received %s to %s being routed the wrong way!', self.name, command, target)
return return
# We use lowercase channels internally. # We use lowercase channels internally.
if utils.isChannel(target): if utils.isChannel(target):
target = self.toLower(target) target = self.to_lower(target)
else: else:
target = self.nickToUid(target) target = self.nick_to_uid(target)
if target: if target:
return {'target': target, 'text': args[1]} return {'target': target, 'text': args[1]}
handle_notice = handle_privmsg handle_notice = handle_privmsg

View File

@ -96,7 +96,7 @@ class HybridProtocol(TS6Protocol):
""" """
server = server or self.sid server = server or self.sid
if not self.isInternalServer(server): if not self.is_internal_server(server):
raise ValueError('Server %r is not a PyLink server!' % server) raise ValueError('Server %r is not a PyLink server!' % server)
uid = self.uidgen[server].next_uid() uid = self.uidgen[server].next_uid()
@ -104,10 +104,10 @@ class HybridProtocol(TS6Protocol):
ts = ts or int(time.time()) ts = ts or int(time.time())
realname = realname or conf.conf['bot']['realname'] realname = realname or conf.conf['bot']['realname']
realhost = realhost or host realhost = realhost or host
raw_modes = self.joinModes(modes) raw_modes = self.join_modes(modes)
u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname, u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable) realhost=realhost, ip=ip, manipulatable=manipulatable)
self.applyModes(uid, modes) self.apply_modes(uid, modes)
self.servers[server].users.add(uid) self.servers[server].users.add(uid)
self._send_with_prefix(server, "UID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} " self._send_with_prefix(server, "UID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
"* :{realname}".format(ts=ts, host=host, "* :{realname}".format(ts=ts, host=host,
@ -138,7 +138,7 @@ class HybridProtocol(TS6Protocol):
def topicBurst(self, numeric, target, text): def topicBurst(self, numeric, target, text):
"""Sends a topic change from a PyLink server. This is usually used on burst.""" """Sends a topic change from a PyLink server. This is usually used on burst."""
# <- :0UY TBURST 1459308205 #testchan 1459309379 dan!~d@localhost :sdf # <- :0UY TBURST 1459308205 #testchan 1459309379 dan!~d@localhost :sdf
if not self.isInternalServer(numeric): if not self.is_internal_server(numeric):
raise LookupError('No such PyLink server exists.') raise LookupError('No such PyLink server exists.')
ts = self.channels[target].ts ts = self.channels[target].ts
@ -179,25 +179,25 @@ class HybridProtocol(TS6Protocol):
self.users[uid] = IrcUser(nick, ts, uid, numeric, ident, host, realname, host, ip) self.users[uid] = IrcUser(nick, ts, uid, numeric, ident, host, realname, host, ip)
parsedmodes = self.parseModes(uid, [modes]) parsedmodes = self.parse_modes(uid, [modes])
log.debug('(%s) handle_uid: Applying modes %s for %s', self.name, parsedmodes, uid) log.debug('(%s) handle_uid: Applying modes %s for %s', self.name, parsedmodes, uid)
self.applyModes(uid, parsedmodes) self.apply_modes(uid, parsedmodes)
self.servers[numeric].users.add(uid) self.servers[numeric].users.add(uid)
# Call the OPERED UP hook if +o is being added to the mode list. # Call the OPERED UP hook if +o is being added to the mode list.
if ('+o', None) in parsedmodes: if ('+o', None) in parsedmodes:
self.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC_Operator'}]) self.call_hooks([uid, 'CLIENT_OPERED', {'text': 'IRC_Operator'}])
# Set the account name if present # Set the account name if present
if account: if account:
self.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': account}]) self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': account}])
return {'uid': uid, 'ts': ts, 'nick': nick, 'realname': realname, 'host': host, 'ident': ident, 'ip': ip} return {'uid': uid, 'ts': ts, 'nick': nick, 'realname': realname, 'host': host, 'ident': ident, 'ip': ip}
def handle_tburst(self, numeric, command, args): def handle_tburst(self, numeric, command, args):
"""Handles incoming topic burst (TBURST) commands.""" """Handles incoming topic burst (TBURST) commands."""
# <- :0UY TBURST 1459308205 #testchan 1459309379 dan!~d@localhost :sdf # <- :0UY TBURST 1459308205 #testchan 1459309379 dan!~d@localhost :sdf
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
ts = args[2] ts = args[2]
setter = args[3] setter = args[3]
topic = args[-1] topic = args[-1]
@ -221,7 +221,7 @@ class HybridProtocol(TS6Protocol):
target = args[0] target = args[0]
ts = args[1] ts = args[1]
modes = args[2:] modes = args[2:]
parsedmodes = self.parseModes(target, modes) parsedmodes = self.parse_modes(target, modes)
for modepair in parsedmodes: for modepair in parsedmodes:
if modepair[0] == '+d': if modepair[0] == '+d':
@ -241,7 +241,7 @@ class HybridProtocol(TS6Protocol):
# Send the login hook, and remove this mode from the mode # Send the login hook, and remove this mode from the mode
# list, as it shouldn't be parsed literally. # list, as it shouldn't be parsed literally.
self.callHooks([target, 'CLIENT_SERVICES_LOGIN', {'text': account}]) self.call_hooks([target, 'CLIENT_SERVICES_LOGIN', {'text': account}])
parsedmodes.remove(modepair) parsedmodes.remove(modepair)
elif modepair[0] == '+x': elif modepair[0] == '+x':
@ -253,13 +253,13 @@ class HybridProtocol(TS6Protocol):
self.users[target].host = host self.users[target].host = host
# Propagate the hostmask change as a hook. # Propagate the hostmask change as a hook.
self.callHooks([numeric, 'CHGHOST', self.call_hooks([numeric, 'CHGHOST',
{'target': target, 'newhost': host}]) {'target': target, 'newhost': host}])
parsedmodes.remove(modepair) parsedmodes.remove(modepair)
if parsedmodes: if parsedmodes:
self.applyModes(target, parsedmodes) self.apply_modes(target, parsedmodes)
return {'target': target, 'modes': parsedmodes} return {'target': target, 'modes': parsedmodes}

View File

@ -44,7 +44,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
""" """
server = server or self.sid server = server or self.sid
if not self.isInternalServer(server): if not self.is_internal_server(server):
raise ValueError('Server %r is not a PyLink server!' % server) raise ValueError('Server %r is not a PyLink server!' % server)
uid = self.uidgen[server].next_uid() uid = self.uidgen[server].next_uid()
@ -52,11 +52,11 @@ class InspIRCdProtocol(TS6BaseProtocol):
ts = ts or int(time.time()) ts = ts or int(time.time())
realname = realname or conf.conf['bot']['realname'] realname = realname or conf.conf['bot']['realname']
realhost = realhost or host realhost = realhost or host
raw_modes = self.joinModes(modes) raw_modes = self.join_modes(modes)
u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname, u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype) realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
self.applyModes(uid, modes) self.apply_modes(uid, modes)
self.servers[server].users.add(uid) self.servers[server].users.add(uid)
self._send_with_prefix(server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}" self._send_with_prefix(server, "UID {uid} {ts} {nick} {realhost} {host} {ident} {ip}"
@ -73,10 +73,10 @@ class InspIRCdProtocol(TS6BaseProtocol):
# InspIRCd doesn't distinguish between burst joins and regular joins, # InspIRCd doesn't distinguish between burst joins and regular joins,
# so what we're actually doing here is sending FJOIN from the server, # so what we're actually doing here is sending FJOIN from the server,
# on behalf of the clients that are joining. # on behalf of the clients that are joining.
channel = self.toLower(channel) channel = self.to_lower(channel)
server = self.getServer(client) server = self.get_server(client)
if not self.isInternalServer(server): if not self.is_internal_server(server):
log.error('(%s) Error trying to join %r to %r (no such client exists)', self.name, client, channel) log.error('(%s) Error trying to join %r to %r (no such client exists)', self.name, client, channel)
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
@ -84,7 +84,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
modes = [m for m in self.channels[channel].modes if m[0] not in self.cmodes['*A']] modes = [m for m in self.channels[channel].modes if m[0] not in self.cmodes['*A']]
self._send_with_prefix(server, "FJOIN {channel} {ts} {modes} :,{uid}".format( self._send_with_prefix(server, "FJOIN {channel} {ts} {modes} :,{uid}".format(
ts=self.channels[channel].ts, uid=client, channel=channel, ts=self.channels[channel].ts, uid=client, channel=channel,
modes=self.joinModes(modes))) modes=self.join_modes(modes)))
self.channels[channel].users.add(client) self.channels[channel].users.add(client)
self.users[client].channels.add(channel) self.users[client].channels.add(channel)
@ -99,7 +99,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
sjoin('100', '#test', [('', '100AAABBC'), ('qo', 100AAABBB'), ('h', '100AAADDD')]) sjoin('100', '#test', [('', '100AAABBC'), ('qo', 100AAABBB'), ('h', '100AAADDD')])
sjoin(self.sid, '#test', [('o', self.pseudoclient.uid)]) sjoin(self.sid, '#test', [('o', self.pseudoclient.uid)])
""" """
channel = self.toLower(channel) channel = self.to_lower(channel)
server = server or self.sid server = server or self.sid
assert users, "sjoin: No users sent?" assert users, "sjoin: No users sent?"
log.debug('(%s) sjoin: got %r for users', self.name, users) log.debug('(%s) sjoin: got %r for users', self.name, users)
@ -144,14 +144,14 @@ class InspIRCdProtocol(TS6BaseProtocol):
namelist = ' '.join(namelist) namelist = ' '.join(namelist)
self._send_with_prefix(server, "FJOIN {channel} {ts} {modes} :{users}".format( self._send_with_prefix(server, "FJOIN {channel} {ts} {modes} :{users}".format(
ts=ts, users=namelist, channel=channel, ts=ts, users=namelist, channel=channel,
modes=self.joinModes(modes))) modes=self.join_modes(modes)))
self.channels[channel].users.update(uids) self.channels[channel].users.update(uids)
if banmodes: if banmodes:
# Burst ban modes if there are any. # Burst ban modes if there are any.
# <- :1ML FMODE #test 1461201525 +bb *!*@bad.user *!*@rly.bad.user # <- :1ML FMODE #test 1461201525 +bb *!*@bad.user *!*@rly.bad.user
self._send_with_prefix(server, "FMODE {channel} {ts} {modes} ".format( self._send_with_prefix(server, "FMODE {channel} {ts} {modes} ".format(
ts=ts, channel=channel, modes=self.joinModes(banmodes))) ts=ts, channel=channel, modes=self.join_modes(banmodes)))
self.updateTS(server, channel, ts, changedmodes) self.updateTS(server, channel, ts, changedmodes)
@ -194,8 +194,8 @@ class InspIRCdProtocol(TS6BaseProtocol):
# -> :9PYAAAAAA FMODE #pylink 1433653951 +os 9PYAAAAAA # -> :9PYAAAAAA FMODE #pylink 1433653951 +os 9PYAAAAAA
# -> :9PYAAAAAA MODE 9PYAAAAAA -i+w # -> :9PYAAAAAA MODE 9PYAAAAAA -i+w
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
log.debug('(%s) inspircd._send_with_prefixModes: received %r for mode list', self.name, modes) log.debug('(%s) inspircd._send_with_prefixModes: received %r for mode list', self.name, modes)
@ -203,18 +203,18 @@ class InspIRCdProtocol(TS6BaseProtocol):
# https://github.com/inspircd/inspircd/blob/master/src/modules/m_spanningtree/opertype.cpp#L26-L28 # 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. # Servers need a special command to set umode +o on people.
self._operUp(target) self._operUp(target)
self.applyModes(target, modes) self.apply_modes(target, modes)
joinedmodes = self.joinModes(modes) joinedmodes = self.join_modes(modes)
if utils.isChannel(target): if utils.isChannel(target):
ts = ts or self.channels[self.toLower(target)].ts ts = ts or self.channels[self.to_lower(target)].ts
self._send_with_prefix(numeric, 'FMODE %s %s %s' % (target, ts, joinedmodes)) self._send_with_prefix(numeric, 'FMODE %s %s %s' % (target, ts, joinedmodes))
else: else:
self._send_with_prefix(numeric, 'MODE %s %s' % (target, joinedmodes)) self._send_with_prefix(numeric, 'MODE %s %s' % (target, joinedmodes))
def kill(self, numeric, target, reason): def kill(self, numeric, target, reason):
"""Sends a kill from a PyLink client/server.""" """Sends a kill from a PyLink client/server."""
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
# InspIRCd will show the raw kill message sent from our server as the quit message. # InspIRCd will show the raw kill message sent from our server as the quit message.
@ -230,12 +230,12 @@ class InspIRCdProtocol(TS6BaseProtocol):
# We only need to call _remove_client here if the target is one of our # We only need to call _remove_client here if the target is one of our
# clients, since any remote servers will send a QUIT from # clients, since any remote servers will send a QUIT from
# their target if the command succeeds. # their target if the command succeeds.
if self.isInternalClient(target): if self.is_internal_client(target):
self._remove_client(target) self._remove_client(target)
def topicBurst(self, numeric, target, text): def topicBurst(self, numeric, target, text):
"""Sends a topic change from a PyLink server. This is usually used on burst.""" """Sends a topic change from a PyLink server. This is usually used on burst."""
if not self.isInternalServer(numeric): if not self.is_internal_server(numeric):
raise LookupError('No such PyLink server exists.') raise LookupError('No such PyLink server exists.')
ts = int(time.time()) ts = int(time.time())
servername = self.servers[numeric].name servername = self.servers[numeric].name
@ -245,13 +245,13 @@ class InspIRCdProtocol(TS6BaseProtocol):
def invite(self, numeric, target, channel): def invite(self, numeric, target, channel):
"""Sends an INVITE from a PyLink client..""" """Sends an INVITE from a PyLink client.."""
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(numeric, 'INVITE %s %s' % (target, channel)) self._send_with_prefix(numeric, 'INVITE %s %s' % (target, channel))
def knock(self, numeric, target, text): def knock(self, numeric, target, text):
"""Sends a KNOCK from a PyLink client.""" """Sends a KNOCK from a PyLink client."""
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(numeric, 'ENCAP * KNOCK %s :%s' % (target, text)) self._send_with_prefix(numeric, 'ENCAP * KNOCK %s :%s' % (target, text))
@ -263,7 +263,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
raise NotImplementedError("Changing field %r of a client is " raise NotImplementedError("Changing field %r of a client is "
"unsupported by this protocol." % field) "unsupported by this protocol." % field)
if self.isInternalClient(target): if self.is_internal_client(target):
# It is one of our clients, use FIDENT/HOST/NAME. # It is one of our clients, use FIDENT/HOST/NAME.
if field == 'IDENT': if field == 'IDENT':
self.users[target].ident = text self.users[target].ident = text
@ -285,7 +285,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
self._send_with_prefix(self.sid, 'CHGIDENT %s %s' % (target, text)) self._send_with_prefix(self.sid, 'CHGIDENT %s %s' % (target, text))
# Send hook payloads for other plugins to listen to. # Send hook payloads for other plugins to listen to.
self.callHooks([self.sid, 'CHGIDENT', self.call_hooks([self.sid, 'CHGIDENT',
{'target': target, 'newident': text}]) {'target': target, 'newident': text}])
elif field == 'HOST': elif field == 'HOST':
if 'm_chghost.so' not in self.modsupport: if 'm_chghost.so' not in self.modsupport:
@ -295,7 +295,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
self.users[target].host = text self.users[target].host = text
self._send_with_prefix(self.sid, 'CHGHOST %s %s' % (target, text)) self._send_with_prefix(self.sid, 'CHGHOST %s %s' % (target, text))
self.callHooks([self.sid, 'CHGHOST', self.call_hooks([self.sid, 'CHGHOST',
{'target': target, 'newhost': text}]) {'target': target, 'newhost': text}])
elif field in ('REALNAME', 'GECOS'): elif field in ('REALNAME', 'GECOS'):
@ -305,7 +305,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
self.users[target].realname = text self.users[target].realname = text
self._send_with_prefix(self.sid, 'CHGNAME %s :%s' % (target, text)) self._send_with_prefix(self.sid, 'CHGNAME %s :%s' % (target, text))
self.callHooks([self.sid, 'CHGNAME', self.call_hooks([self.sid, 'CHGNAME',
{'target': target, 'newgecos': text}]) {'target': target, 'newgecos': text}])
def ping(self, source=None, target=None): def ping(self, source=None, target=None):
@ -363,7 +363,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
for server in self.servers.values(): for server in self.servers.values():
if name == server.name: if name == server.name:
raise ValueError('A server named %r already exists!' % name) raise ValueError('A server named %r already exists!' % name)
if not self.isInternalServer(uplink): if not self.is_internal_server(uplink):
raise ValueError('Server %r is not a PyLink server!' % uplink) raise ValueError('Server %r is not a PyLink server!' % uplink)
if not utils.isServerName(name): if not utils.isServerName(name):
raise ValueError('Invalid server name %r' % name) raise ValueError('Invalid server name %r' % name)
@ -523,19 +523,19 @@ class InspIRCdProtocol(TS6BaseProtocol):
"""Handles incoming PING commands, so we don't time out.""" """Handles incoming PING commands, so we don't time out."""
# <- :70M PING 70M 0AL # <- :70M PING 70M 0AL
# -> :0AL PONG 0AL 70M # -> :0AL PONG 0AL 70M
if self.isInternalServer(args[1]): if self.is_internal_server(args[1]):
self._send_with_prefix(args[1], 'PONG %s %s' % (args[1], source), queue=False) self._send_with_prefix(args[1], 'PONG %s %s' % (args[1], source), queue=False)
def handle_fjoin(self, servernumeric, command, args): def handle_fjoin(self, servernumeric, command, args):
"""Handles incoming FJOIN commands (InspIRCd equivalent of JOIN/SJOIN).""" """Handles incoming FJOIN commands (InspIRCd equivalent of JOIN/SJOIN)."""
# :70M FJOIN #chat 1423790411 +AFPfjnt 6:5 7:5 9:5 :o,1SRAABIT4 v,1IOAAF53R <...> # :70M FJOIN #chat 1423790411 +AFPfjnt 6:5 7:5 9:5 :o,1SRAABIT4 v,1IOAAF53R <...>
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
chandata = self.channels[channel].deepcopy() chandata = self.channels[channel].deepcopy()
# 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()
modestring = args[2:-1] or args[2] modestring = args[2:-1] or args[2]
parsedmodes = self.parseModes(channel, modestring) parsedmodes = self.parse_modes(channel, modestring)
namelist = [] namelist = []
# Keep track of other modes that are added due to prefix modes being joined too. # Keep track of other modes that are added due to prefix modes being joined too.
@ -579,13 +579,13 @@ class InspIRCdProtocol(TS6BaseProtocol):
realname = args[-1] realname = args[-1]
self.users[uid] = userobj = IrcUser(nick, ts, uid, numeric, ident, host, realname, realhost, ip) self.users[uid] = userobj = IrcUser(nick, ts, uid, numeric, ident, host, realname, realhost, ip)
parsedmodes = self.parseModes(uid, [args[8], args[9]]) parsedmodes = self.parse_modes(uid, [args[8], args[9]])
self.applyModes(uid, parsedmodes) self.apply_modes(uid, parsedmodes)
if (self.umodes.get('servprotect'), None) in userobj.modes: if (self.umodes.get('servprotect'), None) in userobj.modes:
# Services are usually given a "Network Service" WHOIS, so # Services are usually given a "Network Service" WHOIS, so
# set that as the opertype. # set that as the opertype.
self.callHooks([uid, 'CLIENT_OPERED', {'text': 'Network Service'}]) self.call_hooks([uid, 'CLIENT_OPERED', {'text': 'Network Service'}])
self.servers[numeric].users.add(uid) self.servers[numeric].users.add(uid)
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip} return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
@ -620,11 +620,11 @@ class InspIRCdProtocol(TS6BaseProtocol):
def handle_fmode(self, numeric, command, args): def handle_fmode(self, numeric, command, args):
"""Handles the FMODE command, used for channel mode changes.""" """Handles the FMODE command, used for channel mode changes."""
# <- :70MAAAAAA FMODE #chat 1433653462 +hhT 70MAAAAAA 70MAAAAAD # <- :70MAAAAAA FMODE #chat 1433653462 +hhT 70MAAAAAA 70MAAAAAD
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
oldobj = self.channels[channel].deepcopy() oldobj = self.channels[channel].deepcopy()
modes = args[2:] modes = args[2:]
changedmodes = self.parseModes(channel, modes) changedmodes = self.parse_modes(channel, modes)
self.applyModes(channel, changedmodes) self.apply_modes(channel, changedmodes)
ts = int(args[1]) ts = int(args[1])
return {'target': channel, 'modes': changedmodes, 'ts': ts, return {'target': channel, 'modes': changedmodes, 'ts': ts,
'channeldata': oldobj} 'channeldata': oldobj}
@ -636,8 +636,8 @@ class InspIRCdProtocol(TS6BaseProtocol):
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc # <- :70MAAAAAA MODE 70MAAAAAA -i+xc
target = args[0] target = args[0]
modestrings = args[1:] modestrings = args[1:]
changedmodes = self.parseModes(target, modestrings) changedmodes = self.parse_modes(target, modestrings)
self.applyModes(target, changedmodes) self.apply_modes(target, changedmodes)
return {'target': target, 'modes': changedmodes} return {'target': target, 'modes': changedmodes}
def handle_idle(self, numeric, command, args): def handle_idle(self, numeric, command, args):
@ -662,7 +662,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
def handle_ftopic(self, numeric, command, args): def handle_ftopic(self, numeric, command, args):
"""Handles incoming FTOPIC (sets topic on burst).""" """Handles incoming FTOPIC (sets topic on burst)."""
# <- :70M FTOPIC #channel 1434510754 GLo|o|!GLolol@escape.the.dreamland.ca :Some channel topic # <- :70M FTOPIC #channel 1434510754 GLo|o|!GLolol@escape.the.dreamland.ca :Some channel topic
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
ts = args[1] ts = args[1]
setter = args[2] setter = args[2]
topic = args[-1] topic = args[-1]
@ -676,7 +676,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
def handle_knock(self, numeric, command, args): def handle_knock(self, numeric, command, args):
"""Handles channel KNOCKs.""" """Handles channel KNOCKs."""
# <- :70MAAAAAA ENCAP * KNOCK #blah :abcdefg # <- :70MAAAAAA ENCAP * KNOCK #blah :abcdefg
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
text = args[1] text = args[1]
return {'channel': channel, 'text': text} return {'channel': channel, 'text': text}
@ -693,11 +693,11 @@ class InspIRCdProtocol(TS6BaseProtocol):
# Set umode +o on the target. # Set umode +o on the target.
omode = [('+o', None)] omode = [('+o', None)]
self.applyModes(target, omode) self.apply_modes(target, omode)
# Call the CLIENT_OPERED hook that protocols use. The MODE hook # Call the CLIENT_OPERED hook that protocols use. The MODE hook
# payload is returned below. # payload is returned below.
self.callHooks([target, 'CLIENT_OPERED', {'text': opertype}]) self.call_hooks([target, 'CLIENT_OPERED', {'text': opertype}])
return {'target': target, 'modes': omode} return {'target': target, 'modes': omode}
def handle_fident(self, numeric, command, args): def handle_fident(self, numeric, command, args):
@ -752,10 +752,10 @@ class InspIRCdProtocol(TS6BaseProtocol):
# SQUIT, in order to be consistent with other IRCds which make SQUITs # SQUIT, in order to be consistent with other IRCds which make SQUITs
# implicit. # implicit.
target = self._get_SID(args[0]) target = self._get_SID(args[0])
if self.isInternalServer(target): if self.is_internal_server(target):
# The target has to be one of our servers in order to work... # The target has to be one of our servers in order to work...
uplink = self.servers[target].uplink uplink = self.servers[target].uplink
reason = 'Requested by %s' % self.getHostmask(numeric) reason = 'Requested by %s' % self.get_hostmask(numeric)
self._send_with_prefix(uplink, 'SQUIT %s :%s' % (target, reason)) self._send_with_prefix(uplink, 'SQUIT %s :%s' % (target, reason))
return self.handle_squit(numeric, 'SQUIT', [target, reason]) return self.handle_squit(numeric, 'SQUIT', [target, reason])
else: else:
@ -774,7 +774,7 @@ class InspIRCdProtocol(TS6BaseProtocol):
# <- :00A METADATA 1MLAAAJET accountname :tester # <- :00A METADATA 1MLAAAJET accountname :tester
# Sets the services login name of the client. # Sets the services login name of the client.
self.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': args[-1]}]) self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': args[-1]}])
def handle_version(self, numeric, command, args): def handle_version(self, numeric, command, args):
""" """
@ -800,20 +800,20 @@ class InspIRCdProtocol(TS6BaseProtocol):
# ENCAP -> SAKICK args: ['#test', '0ALAAAAAB', 'test'] # ENCAP -> SAKICK args: ['#test', '0ALAAAAAB', 'test']
target = args[1] target = args[1]
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
try: try:
reason = args[2] reason = args[2]
except IndexError: except IndexError:
# Kick reason is optional, strange... # Kick reason is optional, strange...
reason = self.getFriendlyName(source) reason = self.get_friendly_name(source)
if not self.isInternalClient(target): if not self.is_internal_client(target):
log.warning("(%s) Got SAKICK for client that not one of ours: %s", self.name, target) log.warning("(%s) Got SAKICK for client that not one of ours: %s", self.name, target)
return return
else: else:
# Like RSQUIT, SAKICK requires that the receiving server acknowledge that a kick has # Like RSQUIT, SAKICK requires that the receiving server acknowledge that a kick has
# happened. This comes from the server hosting the target client. # happened. This comes from the server hosting the target client.
server = self.getServer(target) server = self.get_server(target)
self.kick(server, channel, target, reason) self.kick(server, channel, target, reason)
return {'channel': channel, 'target': target, 'text': reason} return {'channel': channel, 'target': target, 'text': reason}

View File

@ -179,7 +179,7 @@ class IRCS2SProtocol(IRCCommonProtocol):
sender = self.uplink sender = self.uplink
args.insert(0, sender) args.insert(0, sender)
if self.isInternalClient(sender) or self.isInternalServer(sender): if self.is_internal_client(sender) or self.is_internal_server(sender):
log.warning("(%s) Received command %s being routed the wrong way!", self.name, command) log.warning("(%s) Received command %s being routed the wrong way!", self.name, command)
return return
@ -213,13 +213,13 @@ class IRCS2SProtocol(IRCCommonProtocol):
""" """
Nick collision checker. Nick collision checker.
""" """
uid = self.nickToUid(nick) uid = self.nick_to_uid(nick)
# If there is a nick collision, we simply alert plugins. Relay will purposely try to # If there is a nick collision, we simply alert plugins. Relay will purposely try to
# lose fights and tag nicks instead, while other plugins can choose how to handle this. # lose fights and tag nicks instead, while other plugins can choose how to handle this.
if uid: if uid:
log.info('(%s) Nick collision on %s/%s, forwarding this to plugins', self.name, log.info('(%s) Nick collision on %s/%s, forwarding this to plugins', self.name,
uid, nick) uid, nick)
self.callHooks([self.sid, 'SAVE', {'target': uid}]) self.call_hooks([self.sid, 'SAVE', {'target': uid}])
def handle_away(self, numeric, command, args): def handle_away(self, numeric, command, args):
"""Handles incoming AWAY messages.""" """Handles incoming AWAY messages."""
@ -243,7 +243,7 @@ class IRCS2SProtocol(IRCCommonProtocol):
# Note that the target is a nickname, not a numeric. # Note that the target is a nickname, not a numeric.
target = self._get_UID(args[0]) target = self._get_UID(args[0])
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
curtime = int(time.time()) curtime = int(time.time())
try: try:
@ -274,7 +274,7 @@ class IRCS2SProtocol(IRCCommonProtocol):
try: try:
# Get the nick or server name of the caller. # Get the nick or server name of the caller.
killer = self.getFriendlyName(source) killer = self.get_friendly_name(source)
except KeyError: except KeyError:
# Killer was... neither? We must have aliens or something. Fallback # Killer was... neither? We must have aliens or something. Fallback
# to the given "UID". # to the given "UID".
@ -289,7 +289,7 @@ class IRCS2SProtocol(IRCCommonProtocol):
def handle_part(self, source, command, args): def handle_part(self, source, command, args):
"""Handles incoming PART commands.""" """Handles incoming PART commands."""
channels = self.toLower(args[0]).split(',') channels = self.to_lower(args[0]).split(',')
for channel in channels: for channel in channels:
self.channels[channel].removeuser(source) self.channels[channel].removeuser(source)
@ -337,7 +337,7 @@ class IRCS2SProtocol(IRCCommonProtocol):
# Note: don't mess with the case of the channel prefix, or ~#channel # Note: don't mess with the case of the channel prefix, or ~#channel
# messages will break on RFC1459 casemapping networks (it becomes ^#channel # messages will break on RFC1459 casemapping networks (it becomes ^#channel
# instead). # instead).
target = '#'.join((split_channel[0], self.toLower(split_channel[1]))) target = '#'.join((split_channel[0], self.to_lower(split_channel[1])))
log.debug('(%s) Normalizing channel target %s to %s', self.name, args[0], target) log.debug('(%s) Normalizing channel target %s to %s', self.name, args[0], target)
return {'target': target, 'text': args[1]} return {'target': target, 'text': args[1]}

View File

@ -262,7 +262,7 @@ class P10Protocol(IRCS2SProtocol):
# -1 <fullname> # -1 <fullname>
server = server or self.sid server = server or self.sid
if not self.isInternalServer(server): if not self.is_internal_server(server):
raise ValueError('Server %r is not a PyLink server!' % server) raise ValueError('Server %r is not a PyLink server!' % server)
# Create an UIDGenerator instance for every SID, so that each gets # Create an UIDGenerator instance for every SID, so that each gets
@ -273,7 +273,7 @@ class P10Protocol(IRCS2SProtocol):
ts = ts or int(time.time()) ts = ts or int(time.time())
realname = realname or conf.conf['bot']['realname'] realname = realname or conf.conf['bot']['realname']
realhost = realhost or host realhost = realhost or host
raw_modes = self.joinModes(modes) raw_modes = self.join_modes(modes)
# Initialize an IrcUser instance # Initialize an IrcUser instance
u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname, u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname,
@ -281,7 +281,7 @@ class P10Protocol(IRCS2SProtocol):
opertype=opertype) opertype=opertype)
# Fill in modes and add it to our users index # Fill in modes and add it to our users index
self.applyModes(uid, modes) self.apply_modes(uid, modes)
self.servers[server].users.add(uid) self.servers[server].users.add(uid)
# Encode IPs when sending # Encode IPs when sending
@ -301,7 +301,7 @@ class P10Protocol(IRCS2SProtocol):
def away(self, source, text): def away(self, source, text):
"""Sends an AWAY message from a PyLink client. <text> can be an empty string """Sends an AWAY message from a PyLink client. <text> can be an empty string
to unset AWAY status.""" to unset AWAY status."""
if not self.isInternalClient(source): if not self.is_internal_client(source):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
if text: if text:
@ -315,7 +315,7 @@ class P10Protocol(IRCS2SProtocol):
# Note: we have to send a nick as the target, not a UID. # Note: we have to send a nick as the target, not a UID.
# <- ABAAA I PyLink-devel #services 1460948992 # <- ABAAA I PyLink-devel #services 1460948992
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
nick = self.users[target].nick nick = self.users[target].nick
@ -325,10 +325,10 @@ class P10Protocol(IRCS2SProtocol):
def join(self, client, channel): def join(self, client, channel):
"""Joins a PyLink client to a channel.""" """Joins a PyLink client to a channel."""
# <- ABAAB J #test3 1460744371 # <- ABAAB J #test3 1460744371
channel = self.toLower(channel) channel = self.to_lower(channel)
ts = self.channels[channel].ts ts = self.channels[channel].ts
if not self.isInternalClient(client): if not self.is_internal_client(client):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
if not self.channels[channel].users: if not self.channels[channel].users:
@ -343,11 +343,11 @@ class P10Protocol(IRCS2SProtocol):
def kick(self, numeric, channel, target, reason=None): def kick(self, numeric, channel, target, reason=None):
"""Sends kicks from a PyLink client/server.""" """Sends kicks from a PyLink client/server."""
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
channel = self.toLower(channel) channel = self.to_lower(channel)
if not reason: if not reason:
reason = 'No reason given' reason = 'No reason given'
@ -355,8 +355,8 @@ class P10Protocol(IRCS2SProtocol):
# HACK: prevent kick bounces by sending our kick through the server if # HACK: prevent kick bounces by sending our kick through the server if
# the sender isn't op. # the sender isn't op.
if numeric not in self.servers and (not cobj.isOp(numeric)) and (not cobj.isHalfop(numeric)): if numeric not in self.servers and (not cobj.isOp(numeric)) and (not cobj.isHalfop(numeric)):
reason = '(%s) %s' % (self.getFriendlyName(numeric), reason) reason = '(%s) %s' % (self.get_friendly_name(numeric), reason)
numeric = self.getServer(numeric) numeric = self.get_server(numeric)
self._send_with_prefix(numeric, 'K %s %s :%s' % (channel, target, reason)) self._send_with_prefix(numeric, 'K %s %s :%s' % (channel, target, reason))
@ -369,8 +369,8 @@ class P10Protocol(IRCS2SProtocol):
"""Sends a kill from a PyLink client/server.""" """Sends a kill from a PyLink client/server."""
# <- ABAAA D AyAAA :nefarious.midnight.vpn!GL (test) # <- ABAAA D AyAAA :nefarious.midnight.vpn!GL (test)
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
self._send_with_prefix(numeric, 'D %s :Killed (%s)' % (target, reason)) self._send_with_prefix(numeric, 'D %s :Killed (%s)' % (target, reason))
@ -381,7 +381,7 @@ class P10Protocol(IRCS2SProtocol):
def message(self, numeric, target, text): def message(self, numeric, target, text):
"""Sends a PRIVMSG from a PyLink client.""" """Sends a PRIVMSG from a PyLink client."""
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(numeric, 'P %s :%s' % (target, text)) self._send_with_prefix(numeric, 'P %s :%s' % (target, text))
@ -391,8 +391,8 @@ class P10Protocol(IRCS2SProtocol):
# <- ABAAA M GL -w # <- ABAAA M GL -w
# <- ABAAA M #test +v ABAAB 1460747615 # <- ABAAA M #test +v ABAAB 1460747615
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
modes = list(modes) modes = list(modes)
@ -404,13 +404,13 @@ class P10Protocol(IRCS2SProtocol):
is_cmode = utils.isChannel(target) is_cmode = utils.isChannel(target)
if is_cmode: if is_cmode:
# Channel mode changes have a trailing TS. User mode changes do not. # Channel mode changes have a trailing TS. User mode changes do not.
cobj = self.channels[self.toLower(target)] cobj = self.channels[self.to_lower(target)]
ts = ts or cobj.ts ts = ts or cobj.ts
# HACK: prevent mode bounces by sending our mode through the server if # HACK: prevent mode bounces by sending our mode through the server if
# the sender isn't op. # the sender isn't op.
if numeric not in self.servers and (not cobj.isOp(numeric)) and (not cobj.isHalfop(numeric)): if numeric not in self.servers and (not cobj.isOp(numeric)) and (not cobj.isHalfop(numeric)):
numeric = self.getServer(numeric) numeric = self.get_server(numeric)
# Wrap modes: start with max bufsize and subtract the lengths of the source, target, # Wrap modes: start with max bufsize and subtract the lengths of the source, target,
# mode command, and whitespace. # mode command, and whitespace.
@ -422,12 +422,12 @@ class P10Protocol(IRCS2SProtocol):
# P10 uses nicks in user MODE targets, NOT UIDs. ~GL # P10 uses nicks in user MODE targets, NOT UIDs. ~GL
real_target = self.users[target].nick real_target = self.users[target].nick
self.applyModes(target, modes) self.apply_modes(target, modes)
while modes[:12]: while modes[:12]:
joinedmodes = self.joinModes([m for m in modes[:12]]) joinedmodes = self.join_modes([m for m in modes[:12]])
if is_cmode: if is_cmode:
for wrapped_modes in self.wrapModes(modes[:12], bufsize): for wrapped_modes in self.wrap_modes(modes[:12], bufsize):
self._send_with_prefix(numeric, 'M %s %s %s' % (real_target, wrapped_modes, ts)) self._send_with_prefix(numeric, 'M %s %s %s' % (real_target, wrapped_modes, ts))
else: else:
self._send_with_prefix(numeric, 'M %s %s' % (real_target, joinedmodes)) self._send_with_prefix(numeric, 'M %s %s' % (real_target, joinedmodes))
@ -436,7 +436,7 @@ class P10Protocol(IRCS2SProtocol):
def nick(self, numeric, newnick): def nick(self, numeric, newnick):
"""Changes the nick of a PyLink client.""" """Changes the nick of a PyLink client."""
# <- ABAAA N GL_ 1460753763 # <- ABAAA N GL_ 1460753763
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(numeric, 'N %s %s' % (newnick, int(time.time()))) self._send_with_prefix(numeric, 'N %s %s' % (newnick, int(time.time())))
@ -453,17 +453,17 @@ class P10Protocol(IRCS2SProtocol):
def notice(self, numeric, target, text): def notice(self, numeric, target, text):
"""Sends a NOTICE from a PyLink client or server.""" """Sends a NOTICE from a PyLink client or server."""
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
self._send_with_prefix(numeric, 'O %s :%s' % (target, text)) self._send_with_prefix(numeric, 'O %s :%s' % (target, text))
def part(self, client, channel, reason=None): def part(self, client, channel, reason=None):
"""Sends a part from a PyLink client.""" """Sends a part from a PyLink client."""
channel = self.toLower(channel) channel = self.to_lower(channel)
if not self.isInternalClient(client): if not self.is_internal_client(client):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
msg = "L %s" % channel msg = "L %s" % channel
@ -485,7 +485,7 @@ class P10Protocol(IRCS2SProtocol):
def quit(self, numeric, reason): def quit(self, numeric, reason):
"""Quits a PyLink client.""" """Quits a PyLink client."""
if self.isInternalClient(numeric): if self.is_internal_client(numeric):
self._send_with_prefix(numeric, "Q :%s" % reason) self._send_with_prefix(numeric, "Q :%s" % reason)
self._remove_client(numeric) self._remove_client(numeric)
else: else:
@ -503,7 +503,7 @@ class P10Protocol(IRCS2SProtocol):
sjoin(self.sid, '#test', [('o', self.pseudoclient.uid)]) sjoin(self.sid, '#test', [('o', self.pseudoclient.uid)])
""" """
# <- AB B #test 1460742014 +tnl 10 ABAAB,ABAAA:o :%*!*@other.bad.host ~ *!*@bad.host # <- AB B #test 1460742014 +tnl 10 ABAAB,ABAAA:o :%*!*@other.bad.host ~ *!*@bad.host
channel = self.toLower(channel) channel = self.to_lower(channel)
server = server or self.sid server = server or self.sid
assert users, "sjoin: No users sent?" assert users, "sjoin: No users sent?"
@ -546,7 +546,7 @@ class P10Protocol(IRCS2SProtocol):
msgprefix = '{sid} B {channel} {ts} '.format(sid=server, channel=channel, ts=ts) msgprefix = '{sid} B {channel} {ts} '.format(sid=server, channel=channel, ts=ts)
if regularmodes: if regularmodes:
msgprefix += '%s ' % self.joinModes(regularmodes) msgprefix += '%s ' % self.join_modes(regularmodes)
last_prefixes = '' last_prefixes = ''
for userpair in users: for userpair in users:
@ -652,7 +652,7 @@ class P10Protocol(IRCS2SProtocol):
if name == server.name: if name == server.name:
raise ValueError('A server named %r already exists!' % name) raise ValueError('A server named %r already exists!' % name)
if not self.isInternalServer(uplink): if not self.is_internal_server(uplink):
raise ValueError('Server %r is not a PyLink server!' % uplink) raise ValueError('Server %r is not a PyLink server!' % uplink)
if not utils.isServerName(name): if not utils.isServerName(name):
raise ValueError('Invalid server name %r' % name) raise ValueError('Invalid server name %r' % name)
@ -677,10 +677,10 @@ class P10Protocol(IRCS2SProtocol):
# <- ABAAA T #test GL!~gl@nefarious.midnight.vpn 1460852591 1460855795 :blah # <- ABAAA T #test GL!~gl@nefarious.midnight.vpn 1460852591 1460855795 :blah
# First timestamp is channel creation time, second is current time, # First timestamp is channel creation time, second is current time,
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
sendername = self.getHostmask(numeric) sendername = self.get_hostmask(numeric)
creationts = self.channels[target].ts creationts = self.channels[target].ts
@ -693,7 +693,7 @@ class P10Protocol(IRCS2SProtocol):
"""Sends a TOPIC change from a PyLink server.""" """Sends a TOPIC change from a PyLink server."""
# <- AB T #test GL!~gl@nefarious.midnight.vpn 1460852591 1460855795 :blah # <- AB T #test GL!~gl@nefarious.midnight.vpn 1460852591 1460855795 :blah
if not self.isInternalServer(numeric): if not self.is_internal_server(numeric):
raise LookupError('No such PyLink server exists.') raise LookupError('No such PyLink server exists.')
sendername = self.servers[numeric].name sendername = self.servers[numeric].name
@ -711,7 +711,7 @@ class P10Protocol(IRCS2SProtocol):
ircd = self.serverdata.get('p10_ircd', 'nefarious').lower() ircd = self.serverdata.get('p10_ircd', 'nefarious').lower()
if self.isInternalClient(target): if self.is_internal_client(target):
# Host changing via SETHOST is only supported on nefarious and snircd. # Host changing via SETHOST is only supported on nefarious and snircd.
if ircd not in ('nefarious', 'snircd'): if ircd not in ('nefarious', 'snircd'):
raise NotImplementedError("Host changing for internal clients (via SETHOST) is only " raise NotImplementedError("Host changing for internal clients (via SETHOST) is only "
@ -741,7 +741,7 @@ class P10Protocol(IRCS2SProtocol):
# Save the host change as a user mode (this is what P10 does on bursts), # Save the host change as a user mode (this is what P10 does on bursts),
# so further host checks work. # so further host checks work.
self.applyModes(target, [('+f', text)]) self.apply_modes(target, [('+f', text)])
self.mode(self.sid, target, [('+x', None)]) self.mode(self.sid, target, [('+x', None)])
else: else:
raise NotImplementedError("Changing field %r of a client is " raise NotImplementedError("Changing field %r of a client is "
@ -865,18 +865,18 @@ class P10Protocol(IRCS2SProtocol):
# parameters attached. # parameters attached.
if args[5].startswith('+'): if args[5].startswith('+'):
modes = args[5:-3] modes = args[5:-3]
parsedmodes = self.parseModes(uid, modes) parsedmodes = self.parse_modes(uid, modes)
self.applyModes(uid, parsedmodes) self.apply_modes(uid, parsedmodes)
for modepair in parsedmodes: for modepair in parsedmodes:
if modepair[0][-1] == 'r': if modepair[0][-1] == 'r':
# Parse account registrations, sent as usermode "+r accountname:TS" # Parse account registrations, sent as usermode "+r accountname:TS"
accountname = modepair[1].split(':', 1)[0] accountname = modepair[1].split(':', 1)[0]
self.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}]) self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}])
# Call the OPERED UP hook if +o is being added to the mode list. # Call the OPERED UP hook if +o is being added to the mode list.
if ('+o', None) in parsedmodes: if ('+o', None) in parsedmodes:
self.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC Operator'}]) self.call_hooks([uid, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
self._check_cloak_change(uid) self._check_cloak_change(uid)
@ -947,9 +947,9 @@ class P10Protocol(IRCS2SProtocol):
# Propagate a hostname update to plugins, but only if the changed host is different. # Propagate a hostname update to plugins, but only if the changed host is different.
if newhost != uobj.host: if newhost != uobj.host:
self.callHooks([uid, 'CHGHOST', {'target': uid, 'newhost': newhost}]) self.call_hooks([uid, 'CHGHOST', {'target': uid, 'newhost': newhost}])
if ident != uobj.ident: if ident != uobj.ident:
self.callHooks([uid, 'CHGIDENT', {'target': uid, 'newident': ident}]) self.call_hooks([uid, 'CHGIDENT', {'target': uid, 'newident': ident}])
uobj.host = newhost uobj.host = newhost
uobj.ident = ident uobj.ident = ident
@ -972,7 +972,7 @@ class P10Protocol(IRCS2SProtocol):
currtime = time.time() currtime = time.time()
timediff = int(time.time() - float(orig_pingtime)) timediff = int(time.time() - float(orig_pingtime))
if self.isInternalServer(sid): if self.is_internal_server(sid):
# Only respond if the target server is ours. No forwarding is needed because # Only respond if the target server is ours. No forwarding is needed because
# no IRCds can ever connect behind us... # no IRCds can ever connect behind us...
self._send_with_prefix(self.sid, 'Z %s %s %s %s' % (target, orig_pingtime, timediff, currtime), queue=False) self._send_with_prefix(self.sid, 'Z %s %s %s %s' % (target, orig_pingtime, timediff, currtime), queue=False)
@ -1002,7 +1002,7 @@ class P10Protocol(IRCS2SProtocol):
# No useful data was sent, ignore. # No useful data was sent, ignore.
return return
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
chandata = self.channels[channel].deepcopy() chandata = self.channels[channel].deepcopy()
bans = [] bans = []
@ -1030,7 +1030,7 @@ class P10Protocol(IRCS2SProtocol):
# If no modes are given, this will simply be empty. # If no modes are given, this will simply be empty.
modestring = args[2:-1] modestring = args[2:-1]
if modestring: if modestring:
parsedmodes = self.parseModes(channel, modestring) parsedmodes = self.parse_modes(channel, modestring)
else: else:
parsedmodes = [] parsedmodes = []
@ -1100,7 +1100,7 @@ class P10Protocol(IRCS2SProtocol):
return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'} return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'}
else: else:
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
if ts: # Only update TS if one was sent. if ts: # Only update TS if one was sent.
self.updateTS(source, channel, ts) self.updateTS(source, channel, ts)
@ -1126,15 +1126,15 @@ class P10Protocol(IRCS2SProtocol):
# <- ABAAA OM #test +h ABAAA # <- ABAAA OM #test +h ABAAA
target = self._get_UID(args[0]) target = self._get_UID(args[0])
if utils.isChannel(target): if utils.isChannel(target):
target = self.toLower(target) target = self.to_lower(target)
modestrings = args[1:] modestrings = args[1:]
changedmodes = self.parseModes(target, modestrings) changedmodes = self.parse_modes(target, modestrings)
self.applyModes(target, changedmodes) self.apply_modes(target, changedmodes)
# Call the CLIENT_OPERED hook if +o is being set. # Call the CLIENT_OPERED hook if +o is being set.
if ('+o', None) in changedmodes and target in self.users: if ('+o', None) in changedmodes and target in self.users:
self.callHooks([target, 'CLIENT_OPERED', {'text': 'IRC Operator'}]) self.call_hooks([target, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
if target in self.users: if target in self.users:
# Target was a user. Check for any cloak changes. # Target was a user. Check for any cloak changes.
@ -1147,7 +1147,7 @@ class P10Protocol(IRCS2SProtocol):
def handle_kick(self, source, command, args): def handle_kick(self, source, command, args):
"""Handles incoming KICKs.""" """Handles incoming KICKs."""
# <- ABAAA K #TEST AyAAA :PyLink-devel # <- ABAAA K #TEST AyAAA :PyLink-devel
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
kicked = args[1] kicked = args[1]
self.handle_part(kicked, 'KICK', [channel, args[2]]) self.handle_part(kicked, 'KICK', [channel, args[2]])
@ -1161,7 +1161,7 @@ class P10Protocol(IRCS2SProtocol):
def handle_topic(self, source, command, args): def handle_topic(self, source, command, args):
"""Handles TOPIC changes.""" """Handles TOPIC changes."""
# <- ABAAA T #test GL!~gl@nefarious.midnight.vpn 1460852591 1460855795 :blah # <- ABAAA T #test GL!~gl@nefarious.midnight.vpn 1460852591 1460855795 :blah
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
topic = args[-1] topic = args[-1]
oldtopic = self.channels[channel].topic oldtopic = self.channels[channel].topic
@ -1174,7 +1174,7 @@ class P10Protocol(IRCS2SProtocol):
def handle_clearmode(self, numeric, command, args): def handle_clearmode(self, numeric, command, args):
"""Handles CLEARMODE, which is used to clear a channel's modes.""" """Handles CLEARMODE, which is used to clear a channel's modes."""
# <- ABAAA CM #test ovpsmikbl # <- ABAAA CM #test ovpsmikbl
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
modes = args[1] modes = args[1]
# Enumerate a list of our existing modes, including prefix modes. # Enumerate a list of our existing modes, including prefix modes.
@ -1202,7 +1202,7 @@ class P10Protocol(IRCS2SProtocol):
# Mode does not take an argument when unsetting. # Mode does not take an argument when unsetting.
changedmodes.append(('-%s' % modechar, None)) changedmodes.append(('-%s' % modechar, None))
self.applyModes(channel, changedmodes) self.apply_modes(channel, changedmodes)
return {'target': channel, 'modes': changedmodes, 'channeldata': oldobj} return {'target': channel, 'modes': changedmodes, 'channeldata': oldobj}
def handle_account(self, numeric, command, args): def handle_account(self, numeric, command, args):
@ -1236,7 +1236,7 @@ class P10Protocol(IRCS2SProtocol):
accountname = args[1] accountname = args[1]
# Call this manually because we need the UID to be the sender. # Call this manually because we need the UID to be the sender.
self.callHooks([target, 'CLIENT_SERVICES_LOGIN', {'text': accountname}]) self.call_hooks([target, 'CLIENT_SERVICES_LOGIN', {'text': accountname}])
# Check for any cloak changes now. # Check for any cloak changes now.
self._check_cloak_change(target) self._check_cloak_change(target)
@ -1247,7 +1247,7 @@ class P10Protocol(IRCS2SProtocol):
text = args[1] text = args[1]
# Assume a usermode +f change, and then update the cloak checking. # Assume a usermode +f change, and then update the cloak checking.
self.applyModes(target, [('+f', text)]) self.apply_modes(target, [('+f', text)])
self._check_cloak_change(target) self._check_cloak_change(target)
# We don't need to send any hooks here, _check_cloak_change does that for us. # We don't need to send any hooks here, _check_cloak_change does that for us.

View File

@ -54,21 +54,21 @@ class RatboxProtocol(TS6Protocol):
# UID, gecos # UID, gecos
server = server or self.sid server = server or self.sid
if not self.isInternalServer(server): if not self.is_internal_server(server):
raise ValueError('Server %r is not a PyLink server!' % server) raise ValueError('Server %r is not a PyLink server!' % server)
uid = self.uidgen[server].next_uid() uid = self.uidgen[server].next_uid()
ts = ts or int(time.time()) ts = ts or int(time.time())
realname = realname or conf.conf['bot']['realname'] realname = realname or conf.conf['bot']['realname']
raw_modes = self.joinModes(modes) raw_modes = self.join_modes(modes)
orig_realhost = realhost orig_realhost = realhost
realhost = realhost or host realhost = realhost or host
u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname, u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable) realhost=realhost, ip=ip, manipulatable=manipulatable)
self.applyModes(uid, modes) self.apply_modes(uid, modes)
self.servers[server].users.add(uid) self.servers[server].users.add(uid)
self._send_with_prefix(server, "UID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} " self._send_with_prefix(server, "UID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "

View File

@ -38,7 +38,7 @@ class TS6Protocol(TS6BaseProtocol):
""" """
server = server or self.sid server = server or self.sid
if not self.isInternalServer(server): if not self.is_internal_server(server):
raise ValueError('Server %r is not a PyLink server!' % server) raise ValueError('Server %r is not a PyLink server!' % server)
uid = self.uidgen[server].next_uid() uid = self.uidgen[server].next_uid()
@ -49,11 +49,11 @@ class TS6Protocol(TS6BaseProtocol):
ts = ts or int(time.time()) ts = ts or int(time.time())
realname = realname or conf.conf['bot']['realname'] realname = realname or conf.conf['bot']['realname']
realhost = realhost or host realhost = realhost or host
raw_modes = self.joinModes(modes) raw_modes = self.join_modes(modes)
u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname, u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype) realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
self.applyModes(uid, modes) self.apply_modes(uid, modes)
self.servers[server].users.add(uid) self.servers[server].users.add(uid)
self._send_with_prefix(server, "EUID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} " self._send_with_prefix(server, "EUID {nick} 1 {ts} {modes} {ident} {host} {ip} {uid} "
@ -66,10 +66,10 @@ class TS6Protocol(TS6BaseProtocol):
def join(self, client, channel): def join(self, client, channel):
"""Joins a PyLink client to a channel.""" """Joins a PyLink client to a channel."""
channel = self.toLower(channel) channel = self.to_lower(channel)
# JOIN: # JOIN:
# parameters: channelTS, channel, '+' (a plus sign) # parameters: channelTS, channel, '+' (a plus sign)
if not self.isInternalClient(client): if not self.is_internal_client(client):
log.error('(%s) Error trying to join %r to %r (no such client exists)', self.name, client, channel) log.error('(%s) Error trying to join %r to %r (no such client exists)', self.name, client, channel)
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(client, "JOIN {ts} {channel} +".format(ts=self.channels[channel].ts, channel=channel)) self._send_with_prefix(client, "JOIN {ts} {channel} +".format(ts=self.channels[channel].ts, channel=channel))
@ -96,7 +96,7 @@ class TS6Protocol(TS6BaseProtocol):
# their status ('@+', '@', '+' or ''), for example: # their status ('@+', '@', '+' or ''), for example:
# '@+1JJAAAAAB +2JJAAAA4C 1JJAAAADS'. All users must be behind the source server # '@+1JJAAAAAB +2JJAAAA4C 1JJAAAADS'. All users must be behind the source server
# so it is not possible to use this message to force users to join a channel. # so it is not possible to use this message to force users to join a channel.
channel = self.toLower(channel) channel = self.to_lower(channel)
server = server or self.sid server = server or self.sid
assert users, "sjoin: No users sent?" assert users, "sjoin: No users sent?"
log.debug('(%s) sjoin: got %r for users', self.name, users) log.debug('(%s) sjoin: got %r for users', self.name, users)
@ -149,7 +149,7 @@ class TS6Protocol(TS6BaseProtocol):
namelist = ' '.join(namelist) namelist = ' '.join(namelist)
self._send_with_prefix(server, "SJOIN {ts} {channel} {modes} :{users}".format( self._send_with_prefix(server, "SJOIN {ts} {channel} {modes} :{users}".format(
ts=ts, users=namelist, channel=channel, ts=ts, users=namelist, channel=channel,
modes=self.joinModes(regularmodes))) modes=self.join_modes(regularmodes)))
self.channels[channel].users.update(uids) self.channels[channel].users.update(uids)
# Now, burst bans. # Now, burst bans.
@ -172,15 +172,15 @@ class TS6Protocol(TS6BaseProtocol):
# c <- :0UYAAAAAA TMODE 0 #a +o 0T4AAAAAC # c <- :0UYAAAAAA TMODE 0 #a +o 0T4AAAAAC
# u <- :0UYAAAAAA MODE 0UYAAAAAA :-Facdefklnou # u <- :0UYAAAAAA MODE 0UYAAAAAA :-Facdefklnou
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
self.applyModes(target, modes) self.apply_modes(target, modes)
modes = list(modes) modes = list(modes)
if utils.isChannel(target): if utils.isChannel(target):
ts = ts or self.channels[self.toLower(target)].ts ts = ts or self.channels[self.to_lower(target)].ts
# TMODE: # TMODE:
# parameters: channelTS, channel, cmode changes, opt. cmode parameters... # parameters: channelTS, channel, cmode changes, opt. cmode parameters...
@ -189,15 +189,15 @@ class TS6Protocol(TS6BaseProtocol):
msgprefix = ':%s TMODE %s %s ' % (numeric, ts, target) msgprefix = ':%s TMODE %s %s ' % (numeric, ts, target)
bufsize = S2S_BUFSIZE - len(msgprefix) bufsize = S2S_BUFSIZE - len(msgprefix)
for modestr in self.wrapModes(modes, bufsize, max_modes_per_msg=10): for modestr in self.wrap_modes(modes, bufsize, max_modes_per_msg=10):
self.send(msgprefix + modestr) self.send(msgprefix + modestr)
else: else:
joinedmodes = self.joinModes(modes) joinedmodes = self.join_modes(modes)
self._send_with_prefix(numeric, 'MODE %s %s' % (target, joinedmodes)) self._send_with_prefix(numeric, 'MODE %s %s' % (target, joinedmodes))
def topicBurst(self, numeric, target, text): def topicBurst(self, numeric, target, text):
"""Sends a topic change from a PyLink server. This is usually used on burst.""" """Sends a topic change from a PyLink server. This is usually used on burst."""
if not self.isInternalServer(numeric): if not self.is_internal_server(numeric):
raise LookupError('No such PyLink server exists.') raise LookupError('No such PyLink server exists.')
# TB # TB
# capab: TB # capab: TB
@ -212,7 +212,7 @@ class TS6Protocol(TS6BaseProtocol):
def invite(self, numeric, target, channel): def invite(self, numeric, target, channel):
"""Sends an INVITE from a PyLink client..""" """Sends an INVITE from a PyLink client.."""
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(numeric, 'INVITE %s %s %s' % (target, channel, self.channels[channel].ts)) self._send_with_prefix(numeric, 'INVITE %s %s %s' % (target, channel, self.channels[channel].ts))
@ -222,7 +222,7 @@ class TS6Protocol(TS6BaseProtocol):
log.debug('(%s) knock: Dropping KNOCK to %r since the IRCd ' log.debug('(%s) knock: Dropping KNOCK to %r since the IRCd '
'doesn\'t support it.', self.name, target) 'doesn\'t support it.', self.name, target)
return return
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
# No text value is supported here; drop it. # No text value is supported here; drop it.
self._send_with_prefix(numeric, 'KNOCK %s' % target) self._send_with_prefix(numeric, 'KNOCK %s' % target)
@ -233,10 +233,10 @@ class TS6Protocol(TS6BaseProtocol):
if field == 'HOST': if field == 'HOST':
self.users[target].host = text self.users[target].host = text
self._send_with_prefix(self.sid, 'CHGHOST %s :%s' % (target, text)) self._send_with_prefix(self.sid, 'CHGHOST %s :%s' % (target, text))
if not self.isInternalClient(target): if not self.is_internal_client(target):
# If the target isn't one of our clients, send hook payload # If the target isn't one of our clients, send hook payload
# for other plugins to listen to. # for other plugins to listen to.
self.callHooks([self.sid, 'CHGHOST', self.call_hooks([self.sid, 'CHGHOST',
{'target': target, 'newhost': text}]) {'target': target, 'newhost': text}])
else: else:
raise NotImplementedError("Changing field %r of a client is " raise NotImplementedError("Changing field %r of a client is "
@ -406,7 +406,7 @@ class TS6Protocol(TS6BaseProtocol):
destination = args[1] destination = args[1]
except IndexError: except IndexError:
destination = self.sid destination = self.sid
if self.isInternalServer(destination): if self.is_internal_server(destination):
self._send_with_prefix(destination, 'PONG %s %s' % (destination, source), queue=False) self._send_with_prefix(destination, 'PONG %s %s' % (destination, source), queue=False)
if destination == self.sid and not self.has_eob: if destination == self.sid and not self.has_eob:
@ -421,12 +421,12 @@ class TS6Protocol(TS6BaseProtocol):
"""Handles incoming SJOIN commands.""" """Handles incoming SJOIN commands."""
# parameters: channelTS, channel, simple modes, opt. mode parameters..., nicklist # parameters: channelTS, channel, simple modes, opt. mode parameters..., nicklist
# <- :0UY SJOIN 1451041566 #channel +nt :@0UYAAAAAB # <- :0UY SJOIN 1451041566 #channel +nt :@0UYAAAAAB
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
chandata = self.channels[channel].deepcopy() chandata = self.channels[channel].deepcopy()
userlist = args[-1].split() userlist = args[-1].split()
modestring = args[2:-1] or args[2] modestring = args[2:-1] or args[2]
parsedmodes = self.parseModes(channel, modestring) parsedmodes = self.parse_modes(channel, modestring)
namelist = [] namelist = []
# Keep track of other modes that are added due to prefix modes being joined too. # Keep track of other modes that are added due to prefix modes being joined too.
@ -484,7 +484,7 @@ class TS6Protocol(TS6BaseProtocol):
self.users[numeric].channels.discard(channel) self.users[numeric].channels.discard(channel)
return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'} return {'channels': oldchans, 'text': 'Left all channels.', 'parse_as': 'PART'}
else: else:
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
self.updateTS(numeric, channel, ts) self.updateTS(numeric, channel, ts)
self.users[numeric].channels.add(channel) self.users[numeric].channels.add(channel)
@ -514,19 +514,19 @@ class TS6Protocol(TS6BaseProtocol):
self.users[uid] = IrcUser(nick, ts, uid, numeric, ident, host, realname, realhost, ip) self.users[uid] = IrcUser(nick, ts, uid, numeric, ident, host, realname, realhost, ip)
parsedmodes = self.parseModes(uid, [modes]) parsedmodes = self.parse_modes(uid, [modes])
log.debug('Applying modes %s for %s', parsedmodes, uid) log.debug('Applying modes %s for %s', parsedmodes, uid)
self.applyModes(uid, parsedmodes) self.apply_modes(uid, parsedmodes)
self.servers[numeric].users.add(uid) self.servers[numeric].users.add(uid)
# Call the OPERED UP hook if +o is being added to the mode list. # Call the OPERED UP hook if +o is being added to the mode list.
if ('+o', None) in parsedmodes: if ('+o', None) in parsedmodes:
otype = 'Server Administrator' if ('+a', None) in parsedmodes else 'IRC Operator' otype = 'Server Administrator' if ('+a', None) in parsedmodes else 'IRC Operator'
self.callHooks([uid, 'CLIENT_OPERED', {'text': otype}]) self.call_hooks([uid, 'CLIENT_OPERED', {'text': otype}])
# Set the accountname if present # Set the accountname if present
if accountname != "*": if accountname != "*":
self.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}]) self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}])
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip} return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
@ -587,11 +587,11 @@ class TS6Protocol(TS6BaseProtocol):
"""Handles incoming TMODE commands (channel mode change).""" """Handles incoming TMODE commands (channel mode change)."""
# <- :42XAAAAAB TMODE 1437450768 #test -c+lkC 3 agte4 # <- :42XAAAAAB TMODE 1437450768 #test -c+lkC 3 agte4
# <- :0UYAAAAAD TMODE 0 #a +h 0UYAAAAAD # <- :0UYAAAAAD TMODE 0 #a +h 0UYAAAAAD
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
oldobj = self.channels[channel].deepcopy() oldobj = self.channels[channel].deepcopy()
modes = args[2:] modes = args[2:]
changedmodes = self.parseModes(channel, modes) changedmodes = self.parse_modes(channel, modes)
self.applyModes(channel, changedmodes) self.apply_modes(channel, changedmodes)
ts = int(args[0]) ts = int(args[0])
return {'target': channel, 'modes': changedmodes, 'ts': ts, return {'target': channel, 'modes': changedmodes, 'ts': ts,
'channeldata': oldobj} 'channeldata': oldobj}
@ -601,18 +601,18 @@ class TS6Protocol(TS6BaseProtocol):
# <- :70MAAAAAA MODE 70MAAAAAA -i+xc # <- :70MAAAAAA MODE 70MAAAAAA -i+xc
target = args[0] target = args[0]
modestrings = args[1:] modestrings = args[1:]
changedmodes = self.parseModes(target, modestrings) changedmodes = self.parse_modes(target, modestrings)
self.applyModes(target, changedmodes) self.apply_modes(target, changedmodes)
# Call the OPERED UP hook if +o is being set. # Call the OPERED UP hook if +o is being set.
if ('+o', None) in changedmodes: if ('+o', None) in changedmodes:
otype = 'Server Administrator' if ('a', None) in self.users[target].modes else 'IRC Operator' otype = 'Server Administrator' if ('a', None) in self.users[target].modes else 'IRC Operator'
self.callHooks([target, 'CLIENT_OPERED', {'text': otype}]) self.call_hooks([target, 'CLIENT_OPERED', {'text': otype}])
return {'target': target, 'modes': changedmodes} return {'target': target, 'modes': changedmodes}
def handle_tb(self, numeric, command, args): def handle_tb(self, numeric, command, args):
"""Handles incoming topic burst (TB) commands.""" """Handles incoming topic burst (TB) commands."""
# <- :42X TB #chat 1467427448 GL!~gl@127.0.0.1 :test # <- :42X TB #chat 1467427448 GL!~gl@127.0.0.1 :test
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
ts = args[1] ts = args[1]
setter = args[2] setter = args[2]
topic = args[-1] topic = args[-1]
@ -624,7 +624,7 @@ class TS6Protocol(TS6BaseProtocol):
"""Handles extended topic burst (ETB).""" """Handles extended topic burst (ETB)."""
# <- :00AAAAAAC ETB 0 #test 1470021157 GL :test | abcd # <- :00AAAAAAC ETB 0 #test 1470021157 GL :test | abcd
# Same as TB, with extra TS and extensions arguments. # Same as TB, with extra TS and extensions arguments.
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
ts = args[2] ts = args[2]
setter = args[3] setter = args[3]
topic = args[-1] topic = args[-1]
@ -642,13 +642,13 @@ class TS6Protocol(TS6BaseProtocol):
"""Handles incoming BMASK commands (ban propagation on burst).""" """Handles incoming BMASK commands (ban propagation on burst)."""
# <- :42X BMASK 1424222769 #dev b :*!test@*.isp.net *!badident@* # <- :42X BMASK 1424222769 #dev b :*!test@*.isp.net *!badident@*
# This is used for propagating bans, not TMODE! # This is used for propagating bans, not TMODE!
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
mode = args[2] mode = args[2]
ts = int(args[0]) ts = int(args[0])
modes = [] modes = []
for ban in args[-1].split(): for ban in args[-1].split():
modes.append(('+%s' % mode, ban)) modes.append(('+%s' % mode, ban))
self.applyModes(channel, modes) self.apply_modes(channel, modes)
return {'target': channel, 'modes': modes, 'ts': ts} return {'target': channel, 'modes': modes, 'ts': ts}
def handle_472(self, numeric, command, args): def handle_472(self, numeric, command, args):
@ -684,7 +684,7 @@ class TS6Protocol(TS6BaseProtocol):
account = '' # No account name means a logout account = '' # No account name means a logout
uid = args[0] uid = args[0]
self.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': account}]) self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': account}])
def handle_rsfnc(self, numeric, command, args): def handle_rsfnc(self, numeric, command, args):
""" """

View File

@ -134,11 +134,11 @@ class TS6BaseProtocol(IRCS2SProtocol):
def kick(self, numeric, channel, target, reason=None): def kick(self, numeric, channel, target, reason=None):
"""Sends kicks from a PyLink client/server.""" """Sends kicks from a PyLink client/server."""
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
channel = self.toLower(channel) channel = self.to_lower(channel)
if not reason: if not reason:
reason = 'No reason given' reason = 'No reason given'
@ -155,8 +155,8 @@ class TS6BaseProtocol(IRCS2SProtocol):
def kill(self, numeric, target, reason): def kill(self, numeric, target, reason):
"""Sends a kill from a PyLink client/server.""" """Sends a kill from a PyLink client/server."""
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
# From TS6 docs: # From TS6 docs:
@ -187,7 +187,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
def nick(self, numeric, newnick): def nick(self, numeric, newnick):
"""Changes the nick of a PyLink client.""" """Changes the nick of a PyLink client."""
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(numeric, 'NICK %s %s' % (newnick, int(time.time()))) self._send_with_prefix(numeric, 'NICK %s %s' % (newnick, int(time.time())))
@ -199,8 +199,8 @@ class TS6BaseProtocol(IRCS2SProtocol):
def part(self, client, channel, reason=None): def part(self, client, channel, reason=None):
"""Sends a part from a PyLink client.""" """Sends a part from a PyLink client."""
channel = self.toLower(channel) channel = self.to_lower(channel)
if not self.isInternalClient(client): if not self.is_internal_client(client):
log.error('(%s) Error trying to part %r from %r (no such client exists)', self.name, client, channel) log.error('(%s) Error trying to part %r from %r (no such client exists)', self.name, client, channel)
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
msg = "PART %s" % channel msg = "PART %s" % channel
@ -211,7 +211,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
def quit(self, numeric, reason): def quit(self, numeric, reason):
"""Quits a PyLink client.""" """Quits a PyLink client."""
if self.isInternalClient(numeric): if self.is_internal_client(numeric):
self._send_with_prefix(numeric, "QUIT :%s" % reason) self._send_with_prefix(numeric, "QUIT :%s" % reason)
self._remove_client(numeric) self._remove_client(numeric)
else: else:
@ -219,7 +219,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
def message(self, numeric, target, text): def message(self, numeric, target, text):
"""Sends a PRIVMSG from a PyLink client.""" """Sends a PRIVMSG from a PyLink client."""
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
# Mangle message targets for IRCds that require it. # Mangle message targets for IRCds that require it.
@ -229,8 +229,8 @@ class TS6BaseProtocol(IRCS2SProtocol):
def notice(self, numeric, target, text): def notice(self, numeric, target, text):
"""Sends a NOTICE from a PyLink client or server.""" """Sends a NOTICE from a PyLink client or server."""
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
# Mangle message targets for IRCds that require it. # Mangle message targets for IRCds that require it.
@ -240,7 +240,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
def topic(self, numeric, target, text): def topic(self, numeric, target, text):
"""Sends a TOPIC change from a PyLink client.""" """Sends a TOPIC change from a PyLink client."""
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(numeric, 'TOPIC %s :%s' % (target, text)) self._send_with_prefix(numeric, 'TOPIC %s :%s' % (target, text))
self.channels[target].topic = text self.channels[target].topic = text
@ -268,7 +268,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
for server in self.servers.values(): for server in self.servers.values():
if name == server.name: if name == server.name:
raise ValueError('A server named %r already exists!' % name) raise ValueError('A server named %r already exists!' % name)
if not self.isInternalServer(uplink): if not self.is_internal_server(uplink):
raise ValueError('Server %r is not a PyLink server!' % uplink) raise ValueError('Server %r is not a PyLink server!' % uplink)
if not utils.isServerName(name): if not utils.isServerName(name):
raise ValueError('Invalid server name %r' % name) raise ValueError('Invalid server name %r' % name)
@ -296,7 +296,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
def handle_kick(self, source, command, args): def handle_kick(self, source, command, args):
"""Handles incoming KICKs.""" """Handles incoming KICKs."""
# :70MAAAAAA KICK #test 70MAAAAAA :some reason # :70MAAAAAA KICK #test 70MAAAAAA :some reason
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
kicked = self._get_UID(args[1]) kicked = self._get_UID(args[1])
try: try:
@ -343,7 +343,7 @@ class TS6BaseProtocol(IRCS2SProtocol):
"""Handles incoming TOPIC changes from clients. For topic bursts, """Handles incoming TOPIC changes from clients. For topic bursts,
TB (TS6/charybdis) and FTOPIC (InspIRCd) are used instead.""" TB (TS6/charybdis) and FTOPIC (InspIRCd) are used instead."""
# <- :70MAAAAAA TOPIC #test :test # <- :70MAAAAAA TOPIC #test :test
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
topic = args[1] topic = args[1]
oldtopic = self.channels[channel].topic oldtopic = self.channels[channel].topic

View File

@ -66,7 +66,7 @@ class UnrealProtocol(TS6BaseProtocol):
up to plugins to make sure they don't introduce anything invalid. up to plugins to make sure they don't introduce anything invalid.
""" """
server = server or self.sid server = server or self.sid
if not self.isInternalServer(server): if not self.is_internal_server(server):
raise ValueError('Server %r is not a PyLink server!' % server) raise ValueError('Server %r is not a PyLink server!' % server)
# Unreal 4.0 uses TS6-style UIDs. They don't start from AAAAAA like other IRCd's # Unreal 4.0 uses TS6-style UIDs. They don't start from AAAAAA like other IRCd's
@ -81,10 +81,10 @@ class UnrealProtocol(TS6BaseProtocol):
modes = set(modes) # Ensure type safety modes = set(modes) # Ensure type safety
modes |= {('+x', None), ('+t', None)} modes |= {('+x', None), ('+t', None)}
raw_modes = self.joinModes(modes) raw_modes = self.join_modes(modes)
u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname, u = self.users[uid] = IrcUser(nick, ts, uid, server, ident=ident, host=host, realname=realname,
realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype) realhost=realhost, ip=ip, manipulatable=manipulatable, opertype=opertype)
self.applyModes(uid, modes) self.apply_modes(uid, modes)
self.servers[server].users.add(uid) self.servers[server].users.add(uid)
# UnrealIRCd requires encoding the IP by first packing it into a binary format, # UnrealIRCd requires encoding the IP by first packing it into a binary format,
@ -116,8 +116,8 @@ class UnrealProtocol(TS6BaseProtocol):
def join(self, client, channel): def join(self, client, channel):
"""Joins a PyLink client to a channel.""" """Joins a PyLink client to a channel."""
channel = self.toLower(channel) channel = self.to_lower(channel)
if not self.isInternalClient(client): if not self.is_internal_client(client):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(client, "JOIN %s" % channel) self._send_with_prefix(client, "JOIN %s" % channel)
self.channels[channel].users.add(client) self.channels[channel].users.add(client)
@ -135,7 +135,7 @@ class UnrealProtocol(TS6BaseProtocol):
sjoin(self.sid, '#test', [('o', self.pseudoclient.uid)]) sjoin(self.sid, '#test', [('o', self.pseudoclient.uid)])
""" """
# <- :001 SJOIN 1444361345 #test :*@+1JJAAAAAB %2JJAAAA4C 1JJAAAADS # <- :001 SJOIN 1444361345 #test :*@+1JJAAAAAB %2JJAAAA4C 1JJAAAADS
channel = self.toLower(channel) channel = self.to_lower(channel)
server = server or self.sid server = server or self.sid
assert users, "sjoin: No users sent?" assert users, "sjoin: No users sent?"
if not server: if not server:
@ -189,7 +189,7 @@ class UnrealProtocol(TS6BaseProtocol):
# Modes are optional; add them if they exist # Modes are optional; add them if they exist
if modes: if modes:
sjoin_prefix += " %s" % self.joinModes(simplemodes) sjoin_prefix += " %s" % self.join_modes(simplemodes)
sjoin_prefix += " :" sjoin_prefix += " :"
# Wrap arguments to the max supported S2S line length to prevent cutoff # Wrap arguments to the max supported S2S line length to prevent cutoff
@ -212,15 +212,15 @@ class UnrealProtocol(TS6BaseProtocol):
def mode(self, numeric, target, modes, ts=None): def mode(self, numeric, target, modes, ts=None):
""" """
Sends mode changes from a PyLink client/server. The mode list should be Sends mode changes from a PyLink client/server. The mode list should be
a list of (mode, arg) tuples, i.e. the format of utils.parseModes() output. a list of (mode, arg) tuples, i.e. the format of utils.parse_modes() output.
""" """
# <- :unreal.midnight.vpn MODE #test +ntCo GL 1444361345 # <- :unreal.midnight.vpn MODE #test +ntCo GL 1444361345
if (not self.isInternalClient(numeric)) and \ if (not self.is_internal_client(numeric)) and \
(not self.isInternalServer(numeric)): (not self.is_internal_server(numeric)):
raise LookupError('No such PyLink client/server exists.') raise LookupError('No such PyLink client/server exists.')
self.applyModes(target, modes) self.apply_modes(target, modes)
if utils.isChannel(target): if utils.isChannel(target):
@ -231,7 +231,7 @@ class UnrealProtocol(TS6BaseProtocol):
modes[idx] = (mode[0], self._expandPUID(mode[1])) modes[idx] = (mode[0], self._expandPUID(mode[1]))
# The MODE command is used for channel mode changes only # The MODE command is used for channel mode changes only
ts = ts or self.channels[self.toLower(target)].ts ts = ts or self.channels[self.to_lower(target)].ts
# 7 characters for "MODE", the space between MODE and the target, the space between the # 7 characters for "MODE", the space between MODE and the target, the space between the
# target and mode list, and the space between the mode list and TS. # target and mode list, and the space between the mode list and TS.
@ -242,7 +242,7 @@ class UnrealProtocol(TS6BaseProtocol):
bufsize -= len(target) bufsize -= len(target)
# Subtract the prefix (":SID " for servers or ":SIDAAAAAA " for servers) # Subtract the prefix (":SID " for servers or ":SIDAAAAAA " for servers)
bufsize -= (5 if self.isInternalServer(numeric) else 11) bufsize -= (5 if self.is_internal_server(numeric) else 11)
# There is also an (undocumented) 15 args per line limit for MODE. The target, mode # There is also an (undocumented) 15 args per line limit for MODE. The target, mode
# characters, and TS take up three args, so we're left with 12 spaces for parameters. # characters, and TS take up three args, so we're left with 12 spaces for parameters.
@ -251,24 +251,24 @@ class UnrealProtocol(TS6BaseProtocol):
# * *** Warning! Possible desynch: MODE for channel #test ('+bbbbbbbbbbbb *!*@0.1 *!*@1.1 *!*@2.1 *!*@3.1 *!*@4.1 *!*@5.1 *!*@6.1 *!*@7.1 *!*@8.1 *!*@9.1 *!*@10.1 *!*@11.1') has fishy timestamp (12) (from pylink.local/pylink.local) # * *** Warning! Possible desynch: MODE for channel #test ('+bbbbbbbbbbbb *!*@0.1 *!*@1.1 *!*@2.1 *!*@3.1 *!*@4.1 *!*@5.1 *!*@6.1 *!*@7.1 *!*@8.1 *!*@9.1 *!*@10.1 *!*@11.1') has fishy timestamp (12) (from pylink.local/pylink.local)
# Thanks to kevin and Jobe for helping me debug this! # Thanks to kevin and Jobe for helping me debug this!
for modestring in self.wrapModes(modes, bufsize, max_modes_per_msg=12): for modestring in self.wrap_modes(modes, bufsize, max_modes_per_msg=12):
self._send_with_prefix(numeric, 'MODE %s %s %s' % (target, modestring, ts)) self._send_with_prefix(numeric, 'MODE %s %s %s' % (target, modestring, ts))
else: else:
# For user modes, the only way to set modes (for non-U:Lined servers) # For user modes, the only way to set modes (for non-U:Lined servers)
# is through UMODE2, which sets the modes on the caller. # is through UMODE2, which sets the modes on the caller.
# U:Lines can use SVSMODE/SVS2MODE, but I won't expect people to # U:Lines can use SVSMODE/SVS2MODE, but I won't expect people to
# U:Line a PyLink daemon... # U:Line a PyLink daemon...
if not self.isInternalClient(target): if not self.is_internal_client(target):
raise ProtocolError('Cannot force mode change on external clients!') raise ProtocolError('Cannot force mode change on external clients!')
# XXX: I don't expect usermode changes to ever get cut off, but length # XXX: I don't expect usermode changes to ever get cut off, but length
# checks could be added just to be safe... # checks could be added just to be safe...
joinedmodes = self.joinModes(modes) joinedmodes = self.join_modes(modes)
self._send_with_prefix(target, 'UMODE2 %s' % joinedmodes) self._send_with_prefix(target, 'UMODE2 %s' % joinedmodes)
def topicBurst(self, numeric, target, text): def topicBurst(self, numeric, target, text):
"""Sends a TOPIC change from a PyLink server.""" """Sends a TOPIC change from a PyLink server."""
if not self.isInternalServer(numeric): if not self.is_internal_server(numeric):
raise LookupError('No such PyLink server exists.') raise LookupError('No such PyLink server exists.')
self._send_with_prefix(numeric, 'TOPIC %s :%s' % (target, text)) self._send_with_prefix(numeric, 'TOPIC %s :%s' % (target, text))
self.channels[target].topic = text self.channels[target].topic = text
@ -282,7 +282,7 @@ class UnrealProtocol(TS6BaseProtocol):
raise NotImplementedError("Changing field %r of a client is " raise NotImplementedError("Changing field %r of a client is "
"unsupported by this protocol." % field) "unsupported by this protocol." % field)
if self.isInternalClient(target): if self.is_internal_client(target):
# It is one of our clients, use SETIDENT/HOST/NAME. # It is one of our clients, use SETIDENT/HOST/NAME.
if field == 'IDENT': if field == 'IDENT':
self.users[target].ident = text self.users[target].ident = text
@ -300,26 +300,26 @@ class UnrealProtocol(TS6BaseProtocol):
self._send_with_prefix(self.sid, 'CHGIDENT %s %s' % (target, text)) self._send_with_prefix(self.sid, 'CHGIDENT %s %s' % (target, text))
# Send hook payloads for other plugins to listen to. # Send hook payloads for other plugins to listen to.
self.callHooks([self.sid, 'CHGIDENT', self.call_hooks([self.sid, 'CHGIDENT',
{'target': target, 'newident': text}]) {'target': target, 'newident': text}])
elif field == 'HOST': elif field == 'HOST':
self.users[target].host = text self.users[target].host = text
self._send_with_prefix(self.sid, 'CHGHOST %s %s' % (target, text)) self._send_with_prefix(self.sid, 'CHGHOST %s %s' % (target, text))
self.callHooks([self.sid, 'CHGHOST', self.call_hooks([self.sid, 'CHGHOST',
{'target': target, 'newhost': text}]) {'target': target, 'newhost': text}])
elif field in ('REALNAME', 'GECOS'): elif field in ('REALNAME', 'GECOS'):
self.users[target].realname = text self.users[target].realname = text
self._send_with_prefix(self.sid, 'CHGNAME %s :%s' % (target, text)) self._send_with_prefix(self.sid, 'CHGNAME %s :%s' % (target, text))
self.callHooks([self.sid, 'CHGNAME', self.call_hooks([self.sid, 'CHGNAME',
{'target': target, 'newgecos': text}]) {'target': target, 'newgecos': text}])
def invite(self, numeric, target, channel): def invite(self, numeric, target, channel):
"""Sends an INVITE from a PyLink client..""" """Sends an INVITE from a PyLink client.."""
if not self.isInternalClient(numeric): if not self.is_internal_client(numeric):
raise LookupError('No such PyLink client exists.') raise LookupError('No such PyLink client exists.')
self._send_with_prefix(numeric, 'INVITE %s %s' % (target, channel)) self._send_with_prefix(numeric, 'INVITE %s %s' % (target, channel))
@ -329,8 +329,8 @@ class UnrealProtocol(TS6BaseProtocol):
# sent to all ops in a channel. # sent to all ops in a channel.
# <- :unreal.midnight.vpn NOTICE @#test :[Knock] by GL|!gl@hidden-1C620195 (test) # <- :unreal.midnight.vpn NOTICE @#test :[Knock] by GL|!gl@hidden-1C620195 (test)
assert utils.isChannel(target), "Can only knock on channels!" assert utils.isChannel(target), "Can only knock on channels!"
sender = self.getServer(numeric) sender = self.get_server(numeric)
s = '[Knock] by %s (%s)' % (self.getHostmask(numeric), text) s = '[Knock] by %s (%s)' % (self.get_hostmask(numeric), text)
self._send_with_prefix(sender, 'NOTICE @%s :%s' % (target, s)) self._send_with_prefix(sender, 'NOTICE @%s :%s' % (target, s))
### HANDLERS ### HANDLERS
@ -422,8 +422,8 @@ class UnrealProtocol(TS6BaseProtocol):
self.servers[numeric].users.add(uid) self.servers[numeric].users.add(uid)
# Handle user modes # Handle user modes
parsedmodes = self.parseModes(uid, [modestring]) parsedmodes = self.parse_modes(uid, [modestring])
self.applyModes(uid, parsedmodes) self.apply_modes(uid, parsedmodes)
# The cloaked (+x) host is completely separate from the displayed host # 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 # and real host in that it is ONLY shown if the user is +x (cloak mode
@ -432,7 +432,7 @@ class UnrealProtocol(TS6BaseProtocol):
if ('+o', None) in parsedmodes: if ('+o', None) in parsedmodes:
# If +o being set, call the CLIENT_OPERED internal hook. # If +o being set, call the CLIENT_OPERED internal hook.
self.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC Operator'}]) self.call_hooks([uid, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
if ('+x', None) not in parsedmodes: if ('+x', None) not in parsedmodes:
# If +x is not set, update to use the person's real host. # If +x is not set, update to use the person's real host.
@ -443,7 +443,7 @@ class UnrealProtocol(TS6BaseProtocol):
accountname = nick accountname = nick
if not accountname.isdigit(): if not accountname.isdigit():
self.callHooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}]) self.call_hooks([uid, 'CLIENT_SERVICES_LOGIN', {'text': accountname}])
return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip} return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip}
@ -564,7 +564,7 @@ class UnrealProtocol(TS6BaseProtocol):
else: else:
for channel in args[0].split(','): for channel in args[0].split(','):
# Normalize channel case. # Normalize channel case.
channel = self.toLower(channel) channel = self.to_lower(channel)
c = self.channels[channel] c = self.channels[channel]
@ -572,14 +572,14 @@ class UnrealProtocol(TS6BaseProtocol):
self.channels[channel].users.add(numeric) self.channels[channel].users.add(numeric)
# Call hooks manually, because one JOIN command in UnrealIRCd can # Call hooks manually, because one JOIN command in UnrealIRCd can
# have multiple channels... # have multiple channels...
self.callHooks([numeric, command, {'channel': channel, 'users': [numeric], 'modes': self.call_hooks([numeric, command, {'channel': channel, 'users': [numeric], 'modes':
c.modes, 'ts': c.ts}]) c.modes, 'ts': c.ts}])
def handle_sjoin(self, numeric, command, args): def handle_sjoin(self, numeric, command, args):
"""Handles the UnrealIRCd SJOIN command.""" """Handles the UnrealIRCd SJOIN command."""
# <- :001 SJOIN 1444361345 #test :001AAAAAA @001AAAAAB +001AAAAAC # <- :001 SJOIN 1444361345 #test :001AAAAAA @001AAAAAB +001AAAAAC
# <- :001 SJOIN 1483250129 #services +nt :+001OR9V02 @*~001DH6901 &*!*@test "*!*@blah.blah '*!*@yes.no # <- :001 SJOIN 1483250129 #services +nt :+001OR9V02 @*~001DH6901 &*!*@test "*!*@blah.blah '*!*@yes.no
channel = self.toLower(args[1]) channel = self.to_lower(args[1])
chandata = self.channels[channel].deepcopy() chandata = self.channels[channel].deepcopy()
userlist = args[-1].split() userlist = args[-1].split()
@ -599,7 +599,7 @@ class UnrealProtocol(TS6BaseProtocol):
# Strip extra spaces between the mode argument and the user list, if # Strip extra spaces between the mode argument and the user list, if
# there are any. XXX: report this as a bug in unreal's s2s protocol? # there are any. XXX: report this as a bug in unreal's s2s protocol?
modestring = [m for m in modestring if m] modestring = [m for m in modestring if m]
parsedmodes = self.parseModes(channel, modestring) parsedmodes = self.parse_modes(channel, modestring)
changedmodes = set(parsedmodes) changedmodes = set(parsedmodes)
except IndexError: except IndexError:
pass pass
@ -705,11 +705,11 @@ class UnrealProtocol(TS6BaseProtocol):
# Also, we need to get rid of that extra space following the +f argument. :| # Also, we need to get rid of that extra space following the +f argument. :|
if utils.isChannel(args[0]): if utils.isChannel(args[0]):
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
oldobj = self.channels[channel].deepcopy() oldobj = self.channels[channel].deepcopy()
modes = [arg for arg in args[1:] if arg] # normalize whitespace modes = [arg for arg in args[1:] if arg] # normalize whitespace
parsedmodes = self.parseModes(channel, modes) parsedmodes = self.parse_modes(channel, modes)
if parsedmodes: if parsedmodes:
if parsedmodes[0][0] == '+&': if parsedmodes[0][0] == '+&':
@ -720,7 +720,7 @@ class UnrealProtocol(TS6BaseProtocol):
self.name, modes, channel, self.channels[channel].ts) self.name, modes, channel, self.channels[channel].ts)
return return
self.applyModes(channel, parsedmodes) self.apply_modes(channel, parsedmodes)
if numeric in self.servers and args[-1].isdigit(): if numeric in self.servers and args[-1].isdigit():
# Sender is a server AND last arg is number. Perform TS updates. # Sender is a server AND last arg is number. Perform TS updates.
@ -763,7 +763,7 @@ class UnrealProtocol(TS6BaseProtocol):
if newhost != oldhost: if newhost != oldhost:
# Only send a payload if the old and new hosts are different. # Only send a payload if the old and new hosts are different.
self.callHooks([uid, 'SETHOST', self.call_hooks([uid, 'SETHOST',
{'target': uid, 'newhost': newhost}]) {'target': uid, 'newhost': newhost}])
def handle_svsmode(self, numeric, command, args): def handle_svsmode(self, numeric, command, args):
@ -772,8 +772,8 @@ class UnrealProtocol(TS6BaseProtocol):
target = self._get_UID(args[0]) target = self._get_UID(args[0])
modes = args[1:] modes = args[1:]
parsedmodes = self.parseModes(target, modes) parsedmodes = self.parse_modes(target, modes)
self.applyModes(target, parsedmodes) self.apply_modes(target, parsedmodes)
# If +x/-x is being set, update cloaked host info. # If +x/-x is being set, update cloaked host info.
self._check_cloak_change(target, parsedmodes) self._check_cloak_change(target, parsedmodes)
@ -818,7 +818,7 @@ class UnrealProtocol(TS6BaseProtocol):
# <- :NickServ SVS2MODE 001SALZ01 +r # <- :NickServ SVS2MODE 001SALZ01 +r
target = self._get_UID(args[0]) target = self._get_UID(args[0])
parsedmodes = self.parseModes(target, args[1:]) parsedmodes = self.parse_modes(target, args[1:])
if ('+r', None) in parsedmodes: if ('+r', None) in parsedmodes:
# Umode +r is being set (log in) # Umode +r is being set (log in)
@ -829,13 +829,13 @@ class UnrealProtocol(TS6BaseProtocol):
# If one doesn't exist, make it the same as the nick, but only if the account name # If one doesn't exist, make it the same as the nick, but only if the account name
# wasn't set already. # wasn't set already.
if not self.users[target].services_account: if not self.users[target].services_account:
account = self.getFriendlyName(target) account = self.get_friendly_name(target)
else: else:
return return
else: else:
if account.isdigit(): if account.isdigit():
# If the +d argument is a number, ignore it and set the account name to the nick. # If the +d argument is a number, ignore it and set the account name to the nick.
account = self.getFriendlyName(target) account = self.get_friendly_name(target)
elif ('-r', None) in parsedmodes: elif ('-r', None) in parsedmodes:
# Umode -r being set. # Umode -r being set.
@ -853,17 +853,17 @@ class UnrealProtocol(TS6BaseProtocol):
else: else:
return return
self.callHooks([target, 'CLIENT_SERVICES_LOGIN', {'text': account}]) self.call_hooks([target, 'CLIENT_SERVICES_LOGIN', {'text': account}])
def handle_umode2(self, numeric, command, args): def handle_umode2(self, numeric, command, args):
"""Handles UMODE2, used to set user modes on oneself.""" """Handles UMODE2, used to set user modes on oneself."""
# <- :GL UMODE2 +W # <- :GL UMODE2 +W
parsedmodes = self.parseModes(numeric, args) parsedmodes = self.parse_modes(numeric, args)
self.applyModes(numeric, parsedmodes) self.apply_modes(numeric, parsedmodes)
if ('+o', None) in parsedmodes: if ('+o', None) in parsedmodes:
# If +o being set, call the CLIENT_OPERED internal hook. # If +o being set, call the CLIENT_OPERED internal hook.
self.callHooks([numeric, 'CLIENT_OPERED', {'text': 'IRC Operator'}]) self.call_hooks([numeric, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
self._check_cloak_change(numeric, parsedmodes) self._check_cloak_change(numeric, parsedmodes)
@ -873,7 +873,7 @@ class UnrealProtocol(TS6BaseProtocol):
"""Handles the TOPIC command.""" """Handles the TOPIC command."""
# <- GL TOPIC #services GL 1444699395 :weeee # <- GL TOPIC #services GL 1444699395 :weeee
# <- TOPIC #services devel.relay 1452399682 :test # <- TOPIC #services devel.relay 1452399682 :test
channel = self.toLower(args[0]) channel = self.to_lower(args[0])
topic = args[-1] topic = args[-1]
setter = args[1] setter = args[1]
ts = args[2] ts = args[2]
@ -898,7 +898,7 @@ class UnrealProtocol(TS6BaseProtocol):
# When SETHOST or CHGHOST is used, modes +xt are implicitly set on the # When SETHOST or CHGHOST is used, modes +xt are implicitly set on the
# target. # target.
self.applyModes(numeric, [('+x', None), ('+t', None)]) self.apply_modes(numeric, [('+x', None), ('+t', None)])
return {'target': numeric, 'newhost': newhost} return {'target': numeric, 'newhost': newhost}
@ -923,7 +923,7 @@ class UnrealProtocol(TS6BaseProtocol):
# When SETHOST or CHGHOST is used, modes +xt are implicitly set on the # When SETHOST or CHGHOST is used, modes +xt are implicitly set on the
# target. # target.
self.applyModes(target, [('+x', None), ('+t', None)]) self.apply_modes(target, [('+x', None), ('+t', None)])
return {'target': target, 'newhost': newhost} return {'target': target, 'newhost': newhost}