]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Opers are not exempt from other modes, don't exempt them from +N (we may add this...
[user/henk/code/inspircd.git] / src / modules / m_nonicks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "hashcomp.h"
18 #include "configreader.h"
19 #include "inspircd.h"
20
21 /* $ModDesc: Provides support for channel mode +N which prevents nick changes on channel */
22
23 class NoNicks : public ModeHandler
24 {
25  public:
26         NoNicks(InspIRCd* Instance) : ModeHandler(Instance, 'N', 0, 0, false, MODETYPE_CHANNEL, false) { }
27
28         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
29         {
30                 if (adding)
31                 {
32                         if (!channel->IsModeSet('N'))
33                         {
34                                 channel->SetMode('N',true);
35                                 return MODEACTION_ALLOW;
36                         }
37                 }
38                 else
39                 {
40                         if (channel->IsModeSet('N'))
41                         {
42                                 channel->SetMode('N',false);
43                                 return MODEACTION_ALLOW;
44                         }
45                 }
46
47                 return MODEACTION_DENY;
48         }
49 };
50
51 class ModuleNoNickChange : public Module
52 {
53         NoNicks* nn;
54  public:
55         ModuleNoNickChange(InspIRCd* Me)
56                 : Module::Module(Me)
57         {
58                 
59                 nn = new NoNicks(ServerInstance);
60                 ServerInstance->AddMode(nn, 'N');
61         }
62         
63         virtual ~ModuleNoNickChange()
64         {
65                 ServerInstance->Modes->DelMode(nn);
66                 DELETE(nn);
67         }
68         
69         virtual Version GetVersion()
70         {
71                 return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
72         }
73
74         void Implements(char* List)
75         {
76                 List[I_OnUserPreNick] = 1;
77         }
78
79         virtual int OnUserPreNick(userrec* user, const std::string &newnick)
80         {
81                 if (IS_LOCAL(user))
82                 {
83                         for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
84                         {
85                                 chanrec* curr = i->first;
86
87                                 if (curr->IsModeSet('N'))
88                                 {
89                                         // don't allow the nickchange, theyre on at least one channel with +N set
90                                         // and theyre not an oper
91                                         user->WriteServ("447 %s :Can't change nickname while on %s (+N is set)", user->nick, curr->name);
92                                         return 1;
93                                 }
94                         }
95                 }
96                 return 0;
97         }
98 };
99
100 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
101
102 class ModuleNoNickChangeFactory : public ModuleFactory
103 {
104  public:
105         ModuleNoNickChangeFactory()
106         {
107         }
108         
109         ~ModuleNoNickChangeFactory()
110         {
111         }
112         
113         virtual Module * CreateModule(InspIRCd* Me)
114         {
115                 return new ModuleNoNickChange(Me);
116         }
117         
118 };
119
120
121 extern "C" void * init_module( void )
122 {
123         return new ModuleNoNickChangeFactory;
124 }
125