From 43af9d1bacb9d8500654e8e71fc0e57456b4650d Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 4 Jul 2017 22:00:22 -0700 Subject: [PATCH] protocols: move ping() into IRCCommonProtocol --- protocols/inspircd.py | 8 -------- protocols/ircs2s_common.py | 15 ++++++++++++++- protocols/ts6.py | 11 ----------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/protocols/inspircd.py b/protocols/inspircd.py index ba02acb..a2e6a19 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -308,14 +308,6 @@ class InspIRCdProtocol(TS6BaseProtocol): self.call_hooks([self.sid, 'CHGNAME', {'target': target, 'newgecos': text}]) - def ping(self, source=None, target=None): - """Sends a PING to a target server. Periodic PINGs are sent to our uplink - automatically by the Irc() internals; plugins shouldn't have to use this.""" - source = source or self.sid - target = target or self.uplink - if not (target is None or source is None): - self._send_with_prefix(source, 'PING %s %s' % (source, target)) - def numeric(self, source, numeric, target, text): """Sends raw numerics from a server to a remote client.""" # InspIRCd 2.0 syntax (undocumented): diff --git a/protocols/ircs2s_common.py b/protocols/ircs2s_common.py index 0bb8bd3..6667284 100644 --- a/protocols/ircs2s_common.py +++ b/protocols/ircs2s_common.py @@ -256,7 +256,7 @@ class IRCCommonProtocol(IRCNetwork): log.debug('(%s) handle_005: got umode callerid=%r', self.name, self.umodes['callerid']) def _send_with_prefix(self, source, msg, **kwargs): - """Sends a RFC 459-style raw command from the given sender.""" + """Sends a RFC1459-style raw command from the given sender.""" self.send(':%s %s' % (self._expandPUID(source), msg), **kwargs) def _expandPUID(self, uid): @@ -358,6 +358,19 @@ class IRCS2SProtocol(IRCCommonProtocol): self._send_with_prefix(client, msg) self.handle_part(client, 'PART', [channel]) + def ping(self, source=None, target=None): + """Sends a PING to a target server. + + This is mostly used by PyLink internals to check whether the remote link is up.""" + source = source or self.sid + if source is None: # Source hasn't been initialized yet; ignore this command + return + + if target is not None: + self._send_with_prefix(source, 'PING %s %s' % (source, target)) + else: + self._send_with_prefix(source, 'PING %s' % source) + def quit(self, numeric, reason): """Quits a PyLink client.""" if self.is_internal_client(numeric): diff --git a/protocols/ts6.py b/protocols/ts6.py index 5a67e30..10943e0 100644 --- a/protocols/ts6.py +++ b/protocols/ts6.py @@ -242,17 +242,6 @@ class TS6Protocol(TS6BaseProtocol): raise NotImplementedError("Changing field %r of a client is " "unsupported by this protocol." % field) - def ping(self, source=None, target=None): - """Sends a PING to a target server. Periodic PINGs are sent to our uplink - automatically by the Irc() internals; plugins shouldn't have to use this.""" - source = source or self.sid - if source is None: - return - if target is not None: - self._send_with_prefix(source, 'PING %s %s' % (source, target)) - else: - self._send_with_prefix(source, 'PING %s' % source) - ### Core / handlers def post_connect(self):