]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Fix TBAN not working if the banner is owner/protected
[user/henk/code/inspircd.git] / src / modules / m_nonicks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for channel mode +N & extban +b N: which prevents nick changes on channel */
17
18 class NoNicks : public ModeHandler
19 {
20  public:
21         NoNicks(Module* Creator) : ModeHandler(Creator, "nonick", 'N', PARAM_NONE, MODETYPE_CHANNEL) { }
22
23         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
24         {
25                 if (adding)
26                 {
27                         if (!channel->IsModeSet('N'))
28                         {
29                                 channel->SetMode('N',true);
30                                 return MODEACTION_ALLOW;
31                         }
32                 }
33                 else
34                 {
35                         if (channel->IsModeSet('N'))
36                         {
37                                 channel->SetMode('N',false);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41
42                 return MODEACTION_DENY;
43         }
44 };
45
46 class ModuleNoNickChange : public Module
47 {
48         NoNicks nn;
49         bool override;
50  public:
51         ModuleNoNickChange() : nn(this)
52         {
53                 OnRehash(NULL);
54                 ServerInstance->Modes->AddMode(&nn);
55                 Implementation eventlist[] = { I_OnUserPreNick, I_On005Numeric, I_OnRehash };
56                 ServerInstance->Modules->Attach(eventlist, this, 3);
57         }
58
59         virtual ~ModuleNoNickChange()
60         {
61         }
62
63         virtual Version GetVersion()
64         {
65                 return Version("Provides support for channel mode +N & extban +b N: which prevents nick changes on channel", VF_VENDOR);
66         }
67
68
69         virtual void On005Numeric(std::string &output)
70         {
71                 ServerInstance->AddExtBanChar('N');
72         }
73
74         virtual ModResult OnUserPreNick(User* user, const std::string &newnick)
75         {
76                 if (!IS_LOCAL(user))
77                         return MOD_RES_PASSTHRU;
78
79                 // Allow forced nick changes.
80                 if (ServerInstance->NICKForced.get(user))
81                         return MOD_RES_PASSTHRU;
82
83                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
84                 {
85                         Channel* curr = *i;
86
87                         ModResult res;
88                         FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,curr,"nonick"));
89
90                         if (res == MOD_RES_ALLOW)
91                                 continue;
92
93                         if (override && IS_OPER(user))
94                                 continue;
95
96                         if (!curr->GetExtBanStatus(user, 'N').check(!curr->IsModeSet('N')))
97                         {
98                                 user->WriteNumeric(ERR_CANTCHANGENICK, "%s :Can't change nickname while on %s (+N is set)",
99                                         user->nick.c_str(), curr->name.c_str());
100                                 return MOD_RES_DENY;
101                         }
102                 }
103
104                 return MOD_RES_PASSTHRU;
105         }
106
107         virtual void OnRehash(User* user)
108         {
109                 ConfigReader Conf;
110                 override = Conf.ReadFlag("nonicks", "operoverride", "no", 0);
111         }
112 };
113
114 MODULE_INIT(ModuleNoNickChange)