]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
456d835806ce32d6bec354478e4f58250fa71184
[user/henk/code/inspircd.git] / src / modules / m_nonicks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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(InspIRCd* Instance, Module* Creator) : ModeHandler(Creator, '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  public:
50         ModuleNoNickChange(InspIRCd* Me) : Module(Me), nn(Me, this)
51         {
52                 ServerInstance->Modes->AddMode(&nn);
53                 Implementation eventlist[] = { I_OnUserPreNick, I_On005Numeric };
54                 ServerInstance->Modules->Attach(eventlist, this, 2);
55         }
56
57         virtual ~ModuleNoNickChange()
58         {
59                 ServerInstance->Modes->DelMode(&nn);
60         }
61
62         virtual Version GetVersion()
63         {
64                 return Version("Provides support for channel mode +N & extban +b N: which prevents nick changes on channel", VF_COMMON | VF_VENDOR, API_VERSION);
65         }
66
67
68         virtual void On005Numeric(std::string &output)
69         {
70                 ServerInstance->AddExtBanChar('N');
71         }
72
73         virtual ModResult OnUserPreNick(User* user, const std::string &newnick)
74         {
75                 if (!IS_LOCAL(user))
76                         return MOD_RES_PASSTHRU;
77
78                 if (isdigit(newnick[0])) /* don't even think about touching a switch to uid! */
79                         return MOD_RES_PASSTHRU;
80
81                 // Allow forced nick changes.
82                 if (User::NICKForced.get(user))
83                         return MOD_RES_PASSTHRU;
84
85                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
86                 {
87                         Channel* curr = *i;
88
89                         if (CHANOPS_EXEMPT(ServerInstance, 'N') && curr->GetPrefixValue(user) == OP_VALUE)
90                                 continue;
91
92                         if (!curr->GetExtBanStatus(user, 'N').check(!curr->IsModeSet('N')))
93                         {
94                                 user->WriteNumeric(ERR_CANTCHANGENICK, "%s :Can't change nickname while on %s (+N is set)",
95                                         user->nick.c_str(), curr->name.c_str());
96                                 return MOD_RES_DENY;
97                         }
98                 }
99
100                 return MOD_RES_PASSTHRU;
101         }
102 };
103
104 MODULE_INIT(ModuleNoNickChange)