]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Merge pull request #1271 from SaberUK/master+exemption
[user/henk/code/inspircd.git] / src / modules / m_nonicks.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
5  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6  *   Copyright (C) 2004, 2006 Craig Edwards <craigedwards@brainbox.cc>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23 #include "modules/exemption.h"
24
25 class NoNicks : public SimpleChannelModeHandler
26 {
27  public:
28         NoNicks(Module* Creator) : SimpleChannelModeHandler(Creator, "nonick", 'N') { }
29 };
30
31 class ModuleNoNickChange : public Module
32 {
33         CheckExemption::EventProvider exemptionprov;
34         NoNicks nn;
35         bool override;
36  public:
37         ModuleNoNickChange()
38                 : exemptionprov(this)
39                 , nn(this)
40         {
41         }
42
43         Version GetVersion() CXX11_OVERRIDE
44         {
45                 return Version("Provides support for channel mode +N & extban +b N: which prevents nick changes on channel", VF_VENDOR);
46         }
47
48         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
49         {
50                 tokens["EXTBAN"].push_back('N');
51         }
52
53         ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
54         {
55                 for (User::ChanList::iterator i = user->chans.begin(); i != user->chans.end(); i++)
56                 {
57                         Channel* curr = (*i)->chan;
58
59                         ModResult res;
60                         FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (user, curr, "nonick"));
61
62                         if (res == MOD_RES_ALLOW)
63                                 continue;
64
65                         if (override && user->IsOper())
66                                 continue;
67
68                         if (!curr->GetExtBanStatus(user, 'N').check(!curr->IsModeSet(nn)))
69                         {
70                                 user->WriteNumeric(ERR_CANTCHANGENICK, InspIRCd::Format("Can't change nickname while on %s (+N is set)",
71                                         curr->name.c_str()));
72                                 return MOD_RES_DENY;
73                         }
74                 }
75
76                 return MOD_RES_PASSTHRU;
77         }
78
79         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
80         {
81                 override = ServerInstance->Config->ConfValue("nonicks")->getBool("operoverride", false);
82         }
83 };
84
85 MODULE_INIT(ModuleNoNickChange)