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

protocols: move ping() into IRCCommonProtocol

This commit is contained in:
James Lu 2017-07-04 22:00:22 -07:00
parent 276b0b251d
commit 43af9d1bac
3 changed files with 14 additions and 20 deletions

View File

@ -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):

View File

@ -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):

View File

@ -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):