]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Just to mess with om's head, remove helperfuncs.h from everywhere
[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 <stdio.h>
20 #include <string>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24
25 #include "hashcomp.h"
26 #include "configreader.h"
27 #include "inspircd.h"
28
29 /* $ModDesc: Provides support for unreal-style GLOBOPS and umode +g */
30
31
32
33 class NoNicks : public ModeHandler
34 {
35  public:
36         NoNicks(InspIRCd* Instance) : ModeHandler(Instance, 'N', 0, 0, false, MODETYPE_CHANNEL, false) { }
37
38         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
39         {
40                 if (adding)
41                 {
42                         if (!channel->IsModeSet('N'))
43                         {
44                                 channel->SetMode('N',true);
45                                 return MODEACTION_ALLOW;
46                         }
47                 }
48                 else
49                 {
50                         if (channel->IsModeSet('N'))
51                         {
52                                 channel->SetMode('N',false);
53                                 return MODEACTION_ALLOW;
54                         }
55                 }
56
57                 return MODEACTION_DENY;
58         }
59 };
60
61 class ModuleNoNickChange : public Module
62 {
63         
64         NoNicks* nn;
65         
66  public:
67         ModuleNoNickChange(InspIRCd* Me)
68                 : Module::Module(Me)
69         {
70                 
71                 nn = new NoNicks(ServerInstance);
72                 ServerInstance->AddMode(nn, 'N');
73         }
74         
75         virtual ~ModuleNoNickChange()
76         {
77                 DELETE(nn);
78         }
79         
80         virtual Version GetVersion()
81         {
82                 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
83         }
84
85         void Implements(char* List)
86         {
87                 List[I_On005Numeric] = List[I_OnUserPreNick] = 1;
88         }
89
90         virtual void On005Numeric(std::string &output)
91         {
92                 ServerInstance->Modes->InsertMode(output,"N",4);
93         }
94         
95         virtual int OnUserPreNick(userrec* user, const std::string &newnick)
96         {
97                 irc::string server = user->server;
98                 irc::string me = ServerInstance->Config->ServerName;
99                 if (server == me)
100                 {
101                         for (std::vector<ucrec*>::iterator i = user->chans.begin(); i != user->chans.end(); i++)
102                         {
103                                 if (((ucrec*)(*i))->channel != NULL)
104                                 {
105                                         chanrec* curr = ((ucrec*)(*i))->channel;
106                                         if ((curr->IsModeSet('N')) && (!*user->oper))
107                                         {
108                                                 // don't allow the nickchange, theyre on at least one channel with +N set
109                                                 // and theyre not an oper
110                                                 user->WriteServ("447 %s :Can't change nickname while on %s (+N is set)",user->nick,curr->name);
111                                                 return 1;
112                                         }
113                                 }
114                         }
115                 }
116                 return 0;
117         }
118 };
119
120 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
121
122 class ModuleNoNickChangeFactory : public ModuleFactory
123 {
124  public:
125         ModuleNoNickChangeFactory()
126         {
127         }
128         
129         ~ModuleNoNickChangeFactory()
130         {
131         }
132         
133         virtual Module * CreateModule(InspIRCd* Me)
134         {
135                 return new ModuleNoNickChange(Me);
136         }
137         
138 };
139
140
141 extern "C" void * init_module( void )
142 {
143         return new ModuleNoNickChangeFactory;
144 }
145