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