]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Remove global namespacing, makes modules compile FASTAH. Also massive update on heade...
[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 unreal-style GLOBOPS and umode +g */
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                 irc::string server = user->server;
82                 irc::string me = ServerInstance->Config->ServerName;
83                 if (server == me)
84                 {
85                         for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
86                         {
87                                 chanrec* curr = i->first;
88                                 if ((curr->IsModeSet('N')) && (!*user->oper))
89                                 {
90                                         // don't allow the nickchange, theyre on at least one channel with +N set
91                                         // and theyre not an oper
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                 return 0;
98         }
99 };
100
101 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
102
103 class ModuleNoNickChangeFactory : public ModuleFactory
104 {
105  public:
106         ModuleNoNickChangeFactory()
107         {
108         }
109         
110         ~ModuleNoNickChangeFactory()
111         {
112         }
113         
114         virtual Module * CreateModule(InspIRCd* Me)
115         {
116                 return new ModuleNoNickChange(Me);
117         }
118         
119 };
120
121
122 extern "C" void * init_module( void )
123 {
124         return new ModuleNoNickChangeFactory;
125 }
126