]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_channel/core_channel.cpp
Merge pull request #1300 from SaberUK/master+genssl
[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 #include "listmode.h"
24
25 class CoreModChannel : public Module
26 {
27         Invite::APIImpl invapi;
28         CommandInvite cmdinvite;
29         CommandJoin cmdjoin;
30         CommandKick cmdkick;
31         CommandNames cmdnames;
32         CommandTopic cmdtopic;
33
34         ModResult IsInvited(User* user, Channel* chan)
35         {
36                 LocalUser* localuser = IS_LOCAL(user);
37                 if ((localuser) && (invapi.IsInvited(localuser, chan)))
38                         return MOD_RES_ALLOW;
39                 return MOD_RES_PASSTHRU;
40         }
41
42  public:
43         CoreModChannel()
44                 : invapi(this)
45                 , cmdinvite(this, invapi), cmdjoin(this), cmdkick(this), cmdnames(this), cmdtopic(this)
46         {
47         }
48
49         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
50         {
51                 ConfigTag* optionstag = ServerInstance->Config->ConfValue("options");
52                 Implementation events[] = { I_OnCheckKey, I_OnCheckLimit, I_OnCheckChannelBan };
53                 if (optionstag->getBool("invitebypassmodes", true))
54                         ServerInstance->Modules.Attach(events, this, sizeof(events)/sizeof(Implementation));
55                 else
56                 {
57                         for (unsigned int i = 0; i < sizeof(events)/sizeof(Implementation); i++)
58                                 ServerInstance->Modules.Detach(events[i], this);
59                 }
60         }
61
62         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
63         {
64                 // Build a map of limits to their mode character.
65                 insp::flat_map<int, std::string> limits;
66                 const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes();
67                 for (ModeParser::ListModeList::const_iterator iter = listmodes.begin(); iter != listmodes.end(); ++iter)
68                 {
69                         const unsigned int limit = (*iter)->GetLowerLimit();
70                         limits[limit].push_back((*iter)->GetModeChar());
71                 }
72
73                 // Generate the MAXLIST token from the limits map.
74                 std::string& buffer = tokens["MAXLIST"];
75                 for (insp::flat_map<int, std::string>::const_iterator iter = limits.begin(); iter != limits.end(); ++iter)
76                 {
77                         if (!buffer.empty())
78                                 buffer.push_back(',');
79
80                         buffer.append(iter->second);
81                         buffer.push_back(':');
82                         buffer.append(ConvToStr(iter->first));
83                 }
84         }
85
86         void OnPostJoin(Membership* memb) CXX11_OVERRIDE
87         {
88                 Channel* const chan = memb->chan;
89                 LocalUser* const localuser = IS_LOCAL(memb->user);
90                 if (localuser)
91                 {
92                         // Remove existing invite, if any
93                         invapi.Remove(localuser, chan);
94
95                         if (chan->topicset)
96                                 Topic::ShowTopic(localuser, chan);
97
98                         // Show all members of the channel, including invisible (+i) users
99                         cmdnames.SendNames(localuser, chan, true);
100                 }
101         }
102
103         ModResult OnCheckKey(User* user, Channel* chan, const std::string& keygiven) CXX11_OVERRIDE
104         {
105                 // Hook only runs when being invited bypasses +bkl
106                 return IsInvited(user, chan);
107         }
108
109         ModResult OnCheckChannelBan(User* user, Channel* chan) CXX11_OVERRIDE
110         {
111                 // Hook only runs when being invited bypasses +bkl
112                 return IsInvited(user, chan);
113         }
114
115         ModResult OnCheckLimit(User* user, Channel* chan) CXX11_OVERRIDE
116         {
117                 // Hook only runs when being invited bypasses +bkl
118                 return IsInvited(user, chan);
119         }
120
121         ModResult OnCheckInvite(User* user, Channel* chan) CXX11_OVERRIDE
122         {
123                 // Hook always runs
124                 return IsInvited(user, chan);
125         }
126
127         void OnUserDisconnect(LocalUser* user) CXX11_OVERRIDE
128         {
129                 invapi.RemoveAll(user);
130         }
131
132         void OnChannelDelete(Channel* chan) CXX11_OVERRIDE
133         {
134                 // Make sure the channel won't appear in invite lists from now on, don't wait for cull to unset the ext
135                 invapi.RemoveAll(chan);
136         }
137
138         void Prioritize() CXX11_OVERRIDE
139         {
140                 ServerInstance->Modules.SetPriority(this, I_OnPostJoin, PRIORITY_FIRST);
141         }
142
143         Version GetVersion() CXX11_OVERRIDE
144         {
145                 return Version("Provides the INVITE, JOIN, KICK, NAMES, and TOPIC commands", VF_VENDOR|VF_CORE);
146         }
147 };
148
149 MODULE_INIT(CoreModChannel)