3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 11:42:51 +01:00

protocols: consolidate killServer / killClient into kill()

This commit is contained in:
James Lu 2016-01-16 17:03:22 -08:00
parent 983edaf8d0
commit eef97ac035
3 changed files with 23 additions and 39 deletions

View File

@ -189,26 +189,20 @@ class InspIRCdProtocol(TS6BaseProtocol):
raise LookupError('No such PyLink server exists.')
self._sendModes(numeric, target, modes, ts=ts)
def _sendKill(self, numeric, target, reason):
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.')
self._send(numeric, 'KILL %s :%s' % (target, reason))
# We only need to call removeClient here if the target is one of our
# clients, since any remote servers will send a QUIT from
# their target if the command succeeds.
if self.irc.isInternalClient(target):
self.removeClient(target)
def killServer(self, numeric, target, reason):
"""Sends a kill from a PyLink server."""
if not self.irc.isInternalServer(numeric):
raise LookupError('No such PyLink server exists.')
self._sendKill(numeric, target, reason)
def killClient(self, numeric, target, reason):
"""Sends a kill from a PyLink client."""
if not self.irc.isInternalClient(numeric):
raise LookupError('No such PyLink client exists.')
self._sendKill(numeric, target, reason)
def topicServer(self, numeric, target, text):
"""Sends a topic change from a PyLink server. This is usually used on burst."""
if not self.irc.isInternalServer(numeric):

View File

@ -169,10 +169,13 @@ class TS6Protocol(TS6BaseProtocol):
raise LookupError('No such PyLink server exists.')
self._sendModes(numeric, target, modes, ts=ts)
def killServer(self, numeric, target, reason):
"""Sends a kill from a PyLink server."""
if not self.irc.isInternalServer(numeric):
raise LookupError('No such PyLink server exists.')
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.')
# KILL:
# parameters: target user, path
@ -180,15 +183,7 @@ class TS6Protocol(TS6BaseProtocol):
# 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 killServer!" % target
self._send(numeric, 'KILL %s :Killed (%s)' % (target, reason))
self.removeClient(target)
def killClient(self, numeric, target, reason):
"""Sends a kill from a PyLink client."""
if not self.irc.isInternalClient(numeric):
raise LookupError('No such PyLink client exists.')
assert target in self.irc.users, "Unknown target %r for killClient!" % target
assert target in self.irc.users, "Unknown target %r for kill()!" % target
self._send(numeric, 'KILL %s :Killed (%s)' % (target, reason))
self.removeClient(target)

View File

@ -176,25 +176,20 @@ class UnrealProtocol(TS6BaseProtocol):
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))
def killServer(self, numeric, target, reason):
"""Sends a kill from a PyLink server."""
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.isInternalServer(numeric):
raise LookupError('No such PyLink server exists.')
assert target in self.irc.users, "Unknown target %r for killServer!" % target
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 killClient(self, numeric, target, reason):
"""Sends a kill from a PyLink client."""
if not self.irc.isInternalClient(numeric):
raise LookupError('No such PyLink client exists.')
assert target in self.irc.users, "Unknown target %r for killClient!" % target
self._send(numeric, 'KILL %s :%s!PyLink (%s)' % (target, self.irc.serverdata['hostname'], reason))
self.removeClient(target)
def _sendModes(self, numeric, target, modes, ts=None):
"""Internal function to send mode changes from a PyLink client/server."""
# <- :unreal.midnight.vpn MODE #endlessvoid +ntCo GL 1444361345