]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_ircv3_invitenotify.cpp
bcb6f51d548f9a538e4dd2f4cdc0e92cbbd37f31
[user/henk/code/inspircd.git] / src / modules / m_ircv3_invitenotify.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "modules/cap.h"
22
23 class ModuleIRCv3InviteNotify : public Module
24 {
25         Cap::Capability cap;
26
27  public:
28         ModuleIRCv3InviteNotify()
29                 : cap(this, "invite-notify")
30         {
31         }
32
33         void OnUserInvite(User* source, User* dest, Channel* chan, time_t expiry, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE
34         {
35                 ClientProtocol::Messages::Invite invitemsg(source, dest, chan);
36                 ClientProtocol::Event inviteevent(ServerInstance->GetRFCEvents().invite, invitemsg);
37                 const Channel::MemberMap& users = chan->GetUsers();
38                 for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
39                 {
40                         User* user = i->first;
41                         // Skip members who don't use this extension or were excluded by other modules
42                         if ((!cap.get(user)) || (notifyexcepts.count(user)))
43                                 continue;
44
45                         Membership* memb = i->second;
46                         // Check whether the member has a high enough rank to see the notification
47                         if (memb->getRank() < notifyrank)
48                                 continue;
49
50                         // Caps are only set on local users
51                         LocalUser* const localuser = static_cast<LocalUser*>(user);
52                         // Send and add the user to the exceptions so they won't get the NOTICE invite announcement message
53                         localuser->Send(inviteevent);
54                         notifyexcepts.insert(user);
55                 }
56         }
57
58         void Prioritize() CXX11_OVERRIDE
59         {
60                 // Prioritize after all modules to see all excepted users
61                 ServerInstance->Modules.SetPriority(this, I_OnUserInvite, PRIORITY_LAST);
62         }
63
64         Version GetVersion() CXX11_OVERRIDE
65         {
66                 return Version("Provides the invite-notify IRCv3.2 extension", VF_VENDOR);
67         }
68 };
69
70 MODULE_INIT(ModuleIRCv3InviteNotify)