2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2014-2015 Attila Molnar <attilamolnar@hush.com>
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.
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
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/>.
21 #include "core_channel.h"
25 class CoreModChannel : public Module
27 Invite::APIImpl invapi;
28 CommandInvite cmdinvite;
31 CommandNames cmdnames;
32 CommandTopic cmdtopic;
34 ModResult IsInvited(User* user, Channel* chan)
36 LocalUser* localuser = IS_LOCAL(user);
37 if ((localuser) && (invapi.IsInvited(localuser, chan)))
39 return MOD_RES_PASSTHRU;
45 , cmdinvite(this, invapi), cmdjoin(this), cmdkick(this), cmdnames(this), cmdtopic(this)
49 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
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));
57 for (unsigned int i = 0; i < sizeof(events)/sizeof(Implementation); i++)
58 ServerInstance->Modules.Detach(events[i], this);
62 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
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)
69 const unsigned int limit = (*iter)->GetLowerLimit();
70 limits[limit].push_back((*iter)->GetModeChar());
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)
78 buffer.push_back(',');
80 buffer.append(iter->second);
81 buffer.push_back(':');
82 buffer.append(ConvToStr(iter->first));
86 void OnPostJoin(Membership* memb) CXX11_OVERRIDE
88 Channel* const chan = memb->chan;
89 LocalUser* const localuser = IS_LOCAL(memb->user);
92 // Remove existing invite, if any
93 invapi.Remove(localuser, chan);
96 Topic::ShowTopic(localuser, chan);
98 // Show all members of the channel, including invisible (+i) users
99 cmdnames.SendNames(localuser, chan, true);
103 ModResult OnCheckKey(User* user, Channel* chan, const std::string& keygiven) CXX11_OVERRIDE
105 // Hook only runs when being invited bypasses +bkl
106 return IsInvited(user, chan);
109 ModResult OnCheckChannelBan(User* user, Channel* chan) CXX11_OVERRIDE
111 // Hook only runs when being invited bypasses +bkl
112 return IsInvited(user, chan);
115 ModResult OnCheckLimit(User* user, Channel* chan) CXX11_OVERRIDE
117 // Hook only runs when being invited bypasses +bkl
118 return IsInvited(user, chan);
121 ModResult OnCheckInvite(User* user, Channel* chan) CXX11_OVERRIDE
124 return IsInvited(user, chan);
127 void OnUserDisconnect(LocalUser* user) CXX11_OVERRIDE
129 invapi.RemoveAll(user);
132 void OnChannelDelete(Channel* chan) CXX11_OVERRIDE
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);
138 void Prioritize() CXX11_OVERRIDE
140 ServerInstance->Modules.SetPriority(this, I_OnPostJoin, PRIORITY_FIRST);
143 Version GetVersion() CXX11_OVERRIDE
145 return Version("Provides the INVITE, JOIN, KICK, NAMES, and TOPIC commands", VF_VENDOR|VF_CORE);
149 MODULE_INIT(CoreModChannel)