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