]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_channel/core_channel.cpp
Rewrite invite system
[user/henk/code/inspircd.git] / src / coremods / core_channel / core_channel.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2014-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 "core_channel.h"
22 #include "invite.h"
23
24 class CoreModChannel : public Module
25 {
26         Invite::APIImpl invapi;
27         CommandInvite cmdinvite;
28         CommandJoin cmdjoin;
29         CommandKick cmdkick;
30         CommandNames cmdnames;
31         CommandTopic cmdtopic;
32
33         ModResult IsInvited(User* user, Channel* chan)
34         {
35                 LocalUser* localuser = IS_LOCAL(user);
36                 if ((localuser) && (invapi.IsInvited(localuser, chan)))
37                         return MOD_RES_ALLOW;
38                 return MOD_RES_PASSTHRU;
39         }
40
41  public:
42         CoreModChannel()
43                 : invapi(this)
44                 , cmdinvite(this, invapi), cmdjoin(this), cmdkick(this), cmdnames(this), cmdtopic(this)
45         {
46         }
47
48         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
49         {
50                 ConfigTag* optionstag = ServerInstance->Config->ConfValue("options");
51                 Implementation events[] = { I_OnCheckKey, I_OnCheckLimit, I_OnCheckChannelBan };
52                 if (optionstag->getBool("invitebypassmodes", true))
53                         ServerInstance->Modules.Attach(events, this, sizeof(events)/sizeof(Implementation));
54                 else
55                 {
56                         for (unsigned int i = 0; i < sizeof(events)/sizeof(Implementation); i++)
57                                 ServerInstance->Modules.Detach(events[i], this);
58                 }
59         }
60
61         void OnPostJoin(Membership* memb) CXX11_OVERRIDE
62         {
63                 Channel* const chan = memb->chan;
64                 LocalUser* const localuser = IS_LOCAL(memb->user);
65                 if (localuser)
66                 {
67                         // Remove existing invite, if any
68                         invapi.Remove(localuser, chan);
69
70                         if (chan->topicset)
71                                 Topic::ShowTopic(localuser, chan);
72
73                         // Show all members of the channel, including invisible (+i) users
74                         cmdnames.SendNames(localuser, chan, true);
75                 }
76         }
77
78         ModResult OnCheckKey(User* user, Channel* chan, const std::string& keygiven) CXX11_OVERRIDE
79         {
80                 // Hook only runs when being invited bypasses +bkl
81                 return IsInvited(user, chan);
82         }
83
84         ModResult OnCheckChannelBan(User* user, Channel* chan) CXX11_OVERRIDE
85         {
86                 // Hook only runs when being invited bypasses +bkl
87                 return IsInvited(user, chan);
88         }
89
90         ModResult OnCheckLimit(User* user, Channel* chan) CXX11_OVERRIDE
91         {
92                 // Hook only runs when being invited bypasses +bkl
93                 return IsInvited(user, chan);
94         }
95
96         ModResult OnCheckInvite(User* user, Channel* chan) CXX11_OVERRIDE
97         {
98                 // Hook always runs
99                 return IsInvited(user, chan);
100         }
101
102         void OnUserDisconnect(LocalUser* user) CXX11_OVERRIDE
103         {
104                 invapi.RemoveAll(user);
105         }
106
107         void OnChannelDelete(Channel* chan) CXX11_OVERRIDE
108         {
109                 // Make sure the channel won't appear in invite lists from now on, don't wait for cull to unset the ext
110                 invapi.RemoveAll(chan);
111         }
112
113         void Prioritize() CXX11_OVERRIDE
114         {
115                 ServerInstance->Modules.SetPriority(this, I_OnPostJoin, PRIORITY_FIRST);
116         }
117
118         Version GetVersion() CXX11_OVERRIDE
119         {
120                 return Version("Provides the INVITE, JOIN, KICK, NAMES, and TOPIC commands", VF_VENDOR|VF_CORE);
121         }
122 };
123
124 MODULE_INIT(CoreModChannel)