From 359132045d9ffc0e3a7264be29e3cadc25596e2f Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 29 Jan 2017 19:49:37 -0800 Subject: [PATCH] protocols: allow forwarding NOTICE from servers (#384) --- docs/technical/pmodule-spec.md | 9 +++++++-- protocols/nefarious.py | 7 ++++--- protocols/ts6_common.py | 7 ++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/technical/pmodule-spec.md b/docs/technical/pmodule-spec.md index ea82c81..95f0f41 100644 --- a/docs/technical/pmodule-spec.md +++ b/docs/technical/pmodule-spec.md @@ -1,6 +1,6 @@ # PyLink Protocol Module Specification -***Last updated for 1.0-beta1+ (2017-01-09).*** +***Last updated for 1.2-dev (2017-01-29).*** In PyLink, each protocol module is a file consisting of a protocol class (e.g. `InspIRCdProtocol`), and a global `Class` attribute set equal to it (e.g. `Class = InspIRCdProtocol`). These classes are usually based off boilerplate classes such as `classes.Protocol`, `protocols.ircs2s_common.IRCS2SProtocol`, or other protocol module classes that share functionality with it. @@ -66,7 +66,7 @@ internals](https://github.com/GLolol/PyLink/blob/1.0-beta1/classes.py#L474-L483) - **`nick`**`(self, source, newnick)` - Changes the nick of a PyLink client. -- **`notice`**`(self, source, target, text)` - Sends a NOTICE from a PyLink client. +- **`notice`**`(self, source, target, text)` - Sends a NOTICE from a PyLink client or server. - **`numeric`**`(self, source, numeric, target, text)` - Sends a raw numeric `numeric` with `text` from the `source` server to `target`. @@ -158,3 +158,8 @@ When a certain mode (e.g. owner) isn't supported on a network, the key still exi Starting with PyLink 0.10.x, protocol modules can specify which config values within a server block they need in order to work. This is done by adjusting the `self.conf_keys` attribute, usually in the protocol module's `__init__()` method. The default set, defined in [`Classes.Protocol`](https://github.com/GLolol/PyLink/blob/1.0-beta1/classes.py#L1202-L1204), includes `{'ip', 'port', 'hostname', 'sid', 'sidrange', 'protocol', 'sendpass', 'recvpass'}`. Should any of these keys be missing from a server block, PyLink will bail with a configuration error. As an example, one protocol module that tweaks this is [`Clientbot`](https://github.com/GLolol/PyLink/blob/1.0-beta1/protocols/clientbot.py#L17-L18), which removes all options except `ip`, `protocol`, and `port`. + +## Changes +* 2017-01-29 (1.2-dev) + - NOTICE can now be sent from servers. + - This section was added. diff --git a/protocols/nefarious.py b/protocols/nefarious.py index 6a88e31..b4e7e9b 100644 --- a/protocols/nefarious.py +++ b/protocols/nefarious.py @@ -455,9 +455,10 @@ class P10Protocol(IRCS2SProtocol): self._send(source, '%s %s %s' % (numeric, target, text)) def notice(self, numeric, target, text): - """Sends a NOTICE from a PyLink client.""" - if not self.irc.isInternalClient(numeric): - raise LookupError('No such PyLink client exists.') + """Sends a NOTICE from a PyLink client or server.""" + if (not self.irc.isInternalClient(numeric)) and \ + (not self.irc.isInternalServer(numeric)): + raise LookupError('No such PyLink client/server exists.') self._send(numeric, 'O %s :%s' % (target, text)) diff --git a/protocols/ts6_common.py b/protocols/ts6_common.py index 996a5a3..de73667 100644 --- a/protocols/ts6_common.py +++ b/protocols/ts6_common.py @@ -229,9 +229,10 @@ class TS6BaseProtocol(IRCS2SProtocol): self._send(numeric, 'PRIVMSG %s :%s' % (target, text)) def notice(self, numeric, target, text): - """Sends a NOTICE from a PyLink client.""" - if not self.irc.isInternalClient(numeric): - raise LookupError('No such PyLink client exists.') + """Sends a NOTICE from a PyLink client or server.""" + if (not self.irc.isInternalClient(numeric)) and \ + (not self.irc.isInternalServer(numeric)): + raise LookupError('No such PyLink client/server exists.') # Mangle message targets for IRCds that require it. target = self._expandPUID(target)