From 27f69fdc424fc1c934a4a994731f412118f4c051 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sun, 6 Dec 2015 11:14:17 +0100 Subject: Add m_ircv3_echomessage which implements the IRCv3.2 echo-message extension --- src/modules/m_ircv3_echomessage.cpp | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/modules/m_ircv3_echomessage.cpp (limited to 'src/modules') diff --git a/src/modules/m_ircv3_echomessage.cpp b/src/modules/m_ircv3_echomessage.cpp new file mode 100644 index 000000000..8773d7187 --- /dev/null +++ b/src/modules/m_ircv3_echomessage.cpp @@ -0,0 +1,70 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2015 Attila Molnar + * Copyright (C) 2013-2015 Peter Powell + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "inspircd.h" +#include "modules/cap.h" + +static const char* MessageTypeStringSp[] = { "PRIVMSG ", "NOTICE " }; + +class ModuleIRCv3EchoMessage : public Module +{ + Cap::Capability cap; + + public: + ModuleIRCv3EchoMessage() + : cap(this, "echo-message") + { + } + + void OnUserMessage(User* user, void* dest, int target_type, const std::string& text, char status, const CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + { + if (!cap.get(user)) + return; + + std::string msg = MessageTypeStringSp[msgtype]; + if (target_type == TYPE_USER) + { + User* destuser = static_cast(dest); + msg.append(destuser->nick); + } + else if (target_type == TYPE_CHANNEL) + { + if (status) + msg.push_back(status); + + Channel* chan = static_cast(dest); + msg.append(chan->name); + } + else + { + const char* servername = static_cast(dest); + msg.append(servername); + } + msg.append(" :").append(text); + user->WriteFrom(user, msg); + } + + Version GetVersion() CXX11_OVERRIDE + { + return Version("Provides the echo-message IRCv3.2 extension", VF_VENDOR); + } +}; + +MODULE_INIT(ModuleIRCv3EchoMessage) -- cgit v1.3.1-10-gc9f91 From fd87f9f073dff6e2f21a92c96144fb6c0a46e8e3 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sun, 6 Dec 2015 11:24:39 +0100 Subject: Add minimum channel rank and exception list parameters to the OnUserInvite hook --- include/modules.h | 4 +++- src/coremods/core_channel/cmd_invite.cpp | 13 ++++++++++--- src/modules.cpp | 2 +- src/modules/m_spanningtree/main.cpp | 2 +- src/modules/m_spanningtree/main.h | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src/modules') diff --git a/include/modules.h b/include/modules.h index 93e5c05a0..526c283b2 100644 --- a/include/modules.h +++ b/include/modules.h @@ -487,8 +487,10 @@ class CoreExport Module : public classbase, public usecountbase * @param dest The user being invited * @param channel The channel the user is being invited to * @param timeout The time the invite will expire (0 == never) + * @param notifyrank Rank required to get an invite announcement (if enabled) + * @param notifyexcepts List of users to not send the default NOTICE invite announcement to */ - virtual void OnUserInvite(User* source,User* dest,Channel* channel, time_t timeout); + virtual void OnUserInvite(User* source, User* dest, Channel* channel, time_t timeout, unsigned int notifyrank, CUList& notifyexcepts); /** Called whenever a user is about to PRIVMSG A user or a channel, before any processing is done. * Returning any nonzero value from this function stops the process immediately, causing no diff --git a/src/coremods/core_channel/cmd_invite.cpp b/src/coremods/core_channel/cmd_invite.cpp index 55ed33f7f..c1f1b00c7 100644 --- a/src/coremods/core_channel/cmd_invite.cpp +++ b/src/coremods/core_channel/cmd_invite.cpp @@ -123,17 +123,23 @@ CmdResult CommandInvite::Handle (const std::vector& parameters, Use } char prefix = 0; + unsigned int minrank = 0; switch (ServerInstance->Config->AnnounceInvites) { case ServerConfig::INVITE_ANNOUNCE_OPS: { prefix = '@'; + minrank = OP_VALUE; break; } case ServerConfig::INVITE_ANNOUNCE_DYNAMIC: { PrefixMode* mh = ServerInstance->Modes->FindPrefixMode('h'); - prefix = (mh && mh->name == "halfop" ? mh->GetPrefix() : '@'); + if ((mh) && (mh->name == "halfop")) + { + prefix = mh->GetPrefix(); + minrank = mh->GetPrefixRank(); + } break; } default: @@ -141,10 +147,11 @@ CmdResult CommandInvite::Handle (const std::vector& parameters, Use } } - FOREACH_MOD(OnUserInvite, (user, u, c, timeout)); + CUList excepts; + FOREACH_MOD(OnUserInvite, (user, u, c, timeout, minrank, excepts)); if (ServerInstance->Config->AnnounceInvites != ServerConfig::INVITE_ANNOUNCE_NONE) - c->WriteAllExceptSender(user, true, prefix, "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str()); + c->WriteAllExcept(user, true, prefix, excepts, "NOTICE %s :*** %s invited %s into the channel", c->name.c_str(), user->nick.c_str(), u->nick.c_str()); } else if (IS_LOCAL(user)) { diff --git a/src/modules.cpp b/src/modules.cpp index d77221c39..292986df5 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -114,7 +114,7 @@ ModResult Module::OnPreTopicChange(User*, Channel*, const std::string&) { Detach ModResult Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { DetachEvent(I_OnPassCompare); return MOD_RES_PASSTHRU; } void Module::OnPostConnect(User*) { DetachEvent(I_OnPostConnect); } void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { DetachEvent(I_OnUserMessage); } -void Module::OnUserInvite(User*, User*, Channel*, time_t) { DetachEvent(I_OnUserInvite); } +void Module::OnUserInvite(User*, User*, Channel*, time_t, unsigned int, CUList&) { DetachEvent(I_OnUserInvite); } void Module::OnPostTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPostTopicChange); } void Module::OnSyncUser(User*, ProtocolInterface::Server&) { DetachEvent(I_OnSyncUser); } void Module::OnSyncChannel(Channel*, ProtocolInterface::Server&) { DetachEvent(I_OnSyncChannel); } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 98cf3188f..4e45b4fe8 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -358,7 +358,7 @@ ModResult ModuleSpanningTree::HandleConnect(const std::vector& para return MOD_RES_DENY; } -void ModuleSpanningTree::OnUserInvite(User* source,User* dest,Channel* channel, time_t expiry) +void ModuleSpanningTree::OnUserInvite(User* source, User* dest, Channel* channel, time_t expiry, unsigned int notifyrank, CUList& notifyexcepts) { if (IS_LOCAL(source)) { diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 9fde32cad..d29609a35 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -149,7 +149,7 @@ class ModuleSpanningTree : public Module ModResult OnPreCommand(std::string &command, std::vector& parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE; void OnPostCommand(Command*, const std::vector& parameters, LocalUser* user, CmdResult result, const std::string& original_line) CXX11_OVERRIDE; void OnUserConnect(LocalUser* source) CXX11_OVERRIDE; - void OnUserInvite(User* source,User* dest,Channel* channel, time_t) CXX11_OVERRIDE; + void OnUserInvite(User* source, User* dest, Channel* channel, time_t timeout, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE; void OnPostTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE; void OnUserMessage(User* user, void* dest, int target_type, const std::string& text, char status, const CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE; void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE; -- cgit v1.3.1-10-gc9f91 From f9f59c2706f965f7f753271f54536cf0531a2ba8 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sun, 6 Dec 2015 11:30:13 +0100 Subject: Add m_ircv3_invitenotify which implements the IRCv3.2 invite-notify extension --- docs/conf/modules.conf.example | 6 ++++ src/modules/m_ircv3_invitenotify.cpp | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/modules/m_ircv3_invitenotify.cpp (limited to 'src/modules') diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index 1270f242b..dddd6b91f 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -988,6 +988,12 @@ # were applied to them. # +#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# +# IRCv3 invite-notify module: Provides the invite-notify IRCv3.2 +# extension which notifies supporting clients when a user invites +# another user into a channel. This respects . +# + #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Join flood module: Adds support for join flood protection +j X:Y. # Closes the channel for 60 seconds if X users join in Y seconds. diff --git a/src/modules/m_ircv3_invitenotify.cpp b/src/modules/m_ircv3_invitenotify.cpp new file mode 100644 index 000000000..3783ff33c --- /dev/null +++ b/src/modules/m_ircv3_invitenotify.cpp @@ -0,0 +1,68 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2015 Attila Molnar + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "inspircd.h" +#include "modules/cap.h" + +class ModuleIRCv3InviteNotify : public Module +{ + Cap::Capability cap; + + public: + ModuleIRCv3InviteNotify() + : cap(this, "invite-notify") + { + } + + void OnUserInvite(User* source, User* dest, Channel* chan, time_t expiry, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE + { + std::string msg = "INVITE "; + msg.append(dest->nick).append(1, ' ').append(chan->name); + const Channel::MemberMap& users = chan->GetUsers(); + for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i) + { + User* user = i->first; + // Skip members who don't use this extension or were excluded by other modules + if ((!cap.get(user)) || (notifyexcepts.count(user))) + continue; + + Membership* memb = i->second; + // Check whether the member has a high enough rank to see the notification + if (memb->getRank() < notifyrank) + continue; + + // Send and add the user to the exceptions so they won't get the NOTICE invite announcement message + user->WriteFrom(source, msg); + notifyexcepts.insert(user); + } + } + + void Prioritize() CXX11_OVERRIDE + { + // Prioritize after all modules to see all excepted users + ServerInstance->Modules.SetPriority(this, I_OnUserInvite, PRIORITY_LAST); + } + + Version GetVersion() CXX11_OVERRIDE + { + return Version("Provides the invite-notify IRCv3.2 extension", VF_VENDOR); + } +}; + +MODULE_INIT(ModuleIRCv3InviteNotify) -- cgit v1.3.1-10-gc9f91