]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
7c13d678ae46993acf6eadd32253535926e9a869
[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 ModuleNoNickChange : public Module
30 {
31         Server *Srv;
32         
33  public:
34         ModuleNoNickChange(Server* Me)
35                 : Module::Module(Me)
36         {
37                 Srv = Me;
38                 
39                 Srv->AddExtendedMode('N',MT_CHANNEL,false,0,0);
40         }
41         
42         virtual ~ModuleNoNickChange()
43         {
44         }
45         
46         virtual Version GetVersion()
47         {
48                 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
49         }
50
51         void Implements(char* List)
52         {
53                 List[I_On005Numeric] = List[I_OnUserPreNick] = List[I_OnExtendedMode] = 1;
54         }
55
56         virtual void On005Numeric(std::string &output)
57         {
58                 InsertMode(output,"N",4);
59         }
60         
61         virtual int OnUserPreNick(userrec* user, std::string newnick)
62         {
63                 irc::string server = user->server;
64                 irc::string me = Srv->GetServerName().c_str();
65                 if (server == me)
66                 {
67                         for (unsigned int i =0; i < user->chans.size(); i++)
68                         {
69                                 if (user->chans[i].channel != NULL)
70                                 {
71                                         chanrec* curr = user->chans[i].channel;
72                                         if (curr->IsCustomModeSet('N'))
73                                         {
74                                                 if (!strchr(user->modes,'o'))
75                                                 {
76                                                         // don't allow the nickchange, theyre on at least one channel with +N set
77                                                         // and theyre not an oper
78                                                         WriteServ(user->fd,"447 %s :Can't change nickname while on %s (+N is set)",user->nick,curr->name);
79                                                         return 1;
80                                                 }
81                                         }
82                                 }
83                         }
84                 }
85                 return 0;
86         }
87         
88         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
89         {
90                 // check if this is our mode character...
91                 if ((modechar == 'N') && (type == MT_CHANNEL))
92                 {
93                         return 1;
94                 }
95                 else
96                 {
97                         return 0;
98                 }
99         }
100
101 };
102
103 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
104
105 class ModuleNoNickChangeFactory : public ModuleFactory
106 {
107  public:
108         ModuleNoNickChangeFactory()
109         {
110         }
111         
112         ~ModuleNoNickChangeFactory()
113         {
114         }
115         
116         virtual Module * CreateModule(Server* Me)
117         {
118                 return new ModuleNoNickChange(Me);
119         }
120         
121 };
122
123
124 extern "C" void * init_module( void )
125 {
126         return new ModuleNoNickChangeFactory;
127 }
128