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