]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Now with binary versioning goodness
[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                 ServerInstance->Modes->DelMode(nn);
71                 DELETE(nn);
72         }
73         
74         virtual Version GetVersion()
75         {
76                 return Version(1,0,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
77         }
78
79         void Implements(char* List)
80         {
81                 List[I_OnUserPreNick] = 1;
82         }
83
84         virtual int OnUserPreNick(userrec* user, const std::string &newnick)
85         {
86                 irc::string server = user->server;
87                 irc::string me = ServerInstance->Config->ServerName;
88                 if (server == me)
89                 {
90                         for (std::vector<ucrec*>::iterator i = user->chans.begin(); i != user->chans.end(); i++)
91                         {
92                                 if (((ucrec*)(*i))->channel != NULL)
93                                 {
94                                         chanrec* curr = ((ucrec*)(*i))->channel;
95                                         if ((curr->IsModeSet('N')) && (!*user->oper))
96                                         {
97                                                 // don't allow the nickchange, theyre on at least one channel with +N set
98                                                 // and theyre not an oper
99                                                 user->WriteServ("447 %s :Can't change nickname while on %s (+N is set)",user->nick,curr->name);
100                                                 return 1;
101                                         }
102                                 }
103                         }
104                 }
105                 return 0;
106         }
107 };
108
109 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
110
111 class ModuleNoNickChangeFactory : public ModuleFactory
112 {
113  public:
114         ModuleNoNickChangeFactory()
115         {
116         }
117         
118         ~ModuleNoNickChangeFactory()
119         {
120         }
121         
122         virtual Module * CreateModule(InspIRCd* Me)
123         {
124                 return new ModuleNoNickChange(Me);
125         }
126         
127 };
128
129
130 extern "C" void * init_module( void )
131 {
132         return new ModuleNoNickChangeFactory;
133 }
134