]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Fix for parameters which contain a colon (which is not the first char in the string)
[user/henk/code/inspircd.git] / src / modules / m_nonicks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "hashcomp.h"
23 #include "configreader.h"
24 #include "inspircd.h"
25
26 /* $ModDesc: Provides support for unreal-style GLOBOPS and umode +g */
27
28 class NoNicks : public ModeHandler
29 {
30  public:
31         NoNicks(InspIRCd* Instance) : ModeHandler(Instance, 'N', 0, 0, false, MODETYPE_CHANNEL, false) { }
32
33         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
34         {
35                 if (adding)
36                 {
37                         if (!channel->IsModeSet('N'))
38                         {
39                                 channel->SetMode('N',true);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43                 else
44                 {
45                         if (channel->IsModeSet('N'))
46                         {
47                                 channel->SetMode('N',false);
48                                 return MODEACTION_ALLOW;
49                         }
50                 }
51
52                 return MODEACTION_DENY;
53         }
54 };
55
56 class ModuleNoNickChange : public Module
57 {
58         NoNicks* nn;
59  public:
60         ModuleNoNickChange(InspIRCd* Me)
61                 : Module::Module(Me)
62         {
63                 
64                 nn = new NoNicks(ServerInstance);
65                 ServerInstance->AddMode(nn, 'N');
66         }
67         
68         virtual ~ModuleNoNickChange()
69         {
70                 DELETE(nn);
71         }
72         
73         virtual Version GetVersion()
74         {
75                 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
76         }
77
78         void Implements(char* List)
79         {
80                 List[I_OnUserPreNick] = 1;
81         }
82
83         virtual int OnUserPreNick(userrec* user, const std::string &newnick)
84         {
85                 irc::string server = user->server;
86                 irc::string me = ServerInstance->Config->ServerName;
87                 if (server == me)
88                 {
89                         for (std::vector<ucrec*>::iterator i = user->chans.begin(); i != user->chans.end(); i++)
90                         {
91                                 if (((ucrec*)(*i))->channel != NULL)
92                                 {
93                                         chanrec* curr = ((ucrec*)(*i))->channel;
94                                         if ((curr->IsModeSet('N')) && (!*user->oper))
95                                         {
96                                                 // don't allow the nickchange, theyre on at least one channel with +N set
97                                                 // and theyre not an oper
98                                                 user->WriteServ("447 %s :Can't change nickname while on %s (+N is set)",user->nick,curr->name);
99                                                 return 1;
100                                         }
101                                 }
102                         }
103                 }
104                 return 0;
105         }
106 };
107
108 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
109
110 class ModuleNoNickChangeFactory : public ModuleFactory
111 {
112  public:
113         ModuleNoNickChangeFactory()
114         {
115         }
116         
117         ~ModuleNoNickChangeFactory()
118         {
119         }
120         
121         virtual Module * CreateModule(InspIRCd* Me)
122         {
123                 return new ModuleNoNickChange(Me);
124         }
125         
126 };
127
128
129 extern "C" void * init_module( void )
130 {
131         return new ModuleNoNickChangeFactory;
132 }
133