3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 04:02:45 +01:00

protocols: Move kill() into ts6_common, and make unreal.py use it

Ref #239. protocols/unreal was hardcoding a killpath, lazy me...
This commit is contained in:
James Lu 2016-07-04 23:38:54 -07:00
parent d0b7d44f1a
commit 3457da16bd
3 changed files with 33 additions and 47 deletions

View File

@ -189,39 +189,6 @@ class TS6Protocol(TS6BaseProtocol):
joinedmodes = self.irc.joinModes(modes) joinedmodes = self.irc.joinModes(modes)
self._send(numeric, 'MODE %s %s' % (target, joinedmodes)) self._send(numeric, 'MODE %s %s' % (target, joinedmodes))
def kill(self, numeric, target, reason):
"""Sends a kill from a PyLink client/server."""
if (not self.irc.isInternalClient(numeric)) and \
(not self.irc.isInternalServer(numeric)):
raise LookupError('No such PyLink client/server exists.')
# From TS6 docs:
# KILL:
# parameters: target user, path
# The format of the path parameter is some sort of description of the source of
# the kill followed by a space and a parenthesized reason. To avoid overflow,
# it is recommended not to add anything to the path.
assert target in self.irc.users, "Unknown target %r for kill()!" % target
if numeric in self.irc.users:
# Killer was an user. Follow examples of setting the path to be "killer.host!killer.nick".
userobj = self.irc.users[numeric]
killpath = '%s!%s' % (userobj.host, userobj.nick)
elif numeric in self.irc.servers:
# Sender was a server; killpath is just its name.
killpath = self.irc.servers[numeric].name
else:
# Invalid sender?! This shouldn't happen, but make the killpath our server name anyways.
log.warning('(%s) Invalid sender %s for kill(); using our server name instead.',
self.irc.name, numeric)
killpath = self.irc.servers[self.irc.sid].name
self._send(numeric, 'KILL %s :%s (%s)' % (target, killpath, reason))
self.removeClient(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.irc.isInternalServer(numeric): if not self.irc.isInternalServer(numeric):

View File

@ -160,6 +160,39 @@ class TS6BaseProtocol(Protocol):
# handle_part() does that just fine. # handle_part() does that just fine.
self.handle_part(target, 'KICK', [channel]) self.handle_part(target, 'KICK', [channel])
def kill(self, numeric, target, reason):
"""Sends a kill from a PyLink client/server."""
if (not self.irc.isInternalClient(numeric)) and \
(not self.irc.isInternalServer(numeric)):
raise LookupError('No such PyLink client/server exists.')
# From TS6 docs:
# KILL:
# parameters: target user, path
# The format of the path parameter is some sort of description of the source of
# the kill followed by a space and a parenthesized reason. To avoid overflow,
# it is recommended not to add anything to the path.
assert target in self.irc.users, "Unknown target %r for kill()!" % target
if numeric in self.irc.users:
# Killer was an user. Follow examples of setting the path to be "killer.host!killer.nick".
userobj = self.irc.users[numeric]
killpath = '%s!%s' % (userobj.host, userobj.nick)
elif numeric in self.irc.servers:
# Sender was a server; killpath is just its name.
killpath = self.irc.servers[numeric].name
else:
# Invalid sender?! This shouldn't happen, but make the killpath our server name anyways.
log.warning('(%s) Invalid sender %s for kill(); using our server name instead.',
self.irc.name, numeric)
killpath = self.irc.servers[self.irc.sid].name
self._send(numeric, 'KILL %s :%s (%s)' % (target, killpath, reason))
self.removeClient(target)
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.irc.isInternalClient(numeric): if not self.irc.isInternalClient(numeric):

View File

@ -196,20 +196,6 @@ class UnrealProtocol(TS6BaseProtocol):
if not (target is None or source is None): if not (target is None or source is None):
self._send(source, 'PING %s %s' % (self.irc.servers[source].name, self.irc.servers[target].name)) self._send(source, 'PING %s %s' % (self.irc.servers[source].name, self.irc.servers[target].name))
def kill(self, numeric, target, reason):
"""Sends a kill from a PyLink client/server."""
# <- :GL KILL 38QAAAAAA :hidden-1C620195!GL (test)
if (not self.irc.isInternalClient(numeric)) and \
(not self.irc.isInternalServer(numeric)):
raise LookupError('No such PyLink client/server exists.')
assert target in self.irc.users, "Unknown target %r for kill()!" % target
# The killpath doesn't really matter here...
self._send(numeric, 'KILL %s :%s!PyLink (%s)' % (target, self.irc.serverdata['hostname'], reason))
self.removeClient(target)
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