]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Convert more modules
[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 "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18 #include "hashcomp.h"
19 #include "configreader.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(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                                         if (CHANOPS_EXEMPT(ServerInstance, 'N') && curr->GetStatus(user) == STATUS_OP)
90                                                 continue;
91
92                                         user->WriteServ("447 %s :Can't change nickname while on %s (+N is set)", user->nick, curr->name);
93                                         return 1;
94                                 }
95                         }
96                 }
97
98                 return 0;
99         }
100 };
101
102 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
103
104 class ModuleNoNickChangeFactory : public ModuleFactory
105 {
106  public:
107         ModuleNoNickChangeFactory()
108         {
109         }
110         
111         ~ModuleNoNickChangeFactory()
112         {
113         }
114         
115         virtual Module * CreateModule(InspIRCd* Me)
116         {
117                 return new ModuleNoNickChange(Me);
118         }
119         
120 };
121
122
123 extern "C" DllExport void * init_module( void )
124 {
125         return new ModuleNoNickChangeFactory;
126 }
127