]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
582a87626f63c4dfc034ebbc91746150ca1c7b18
[user/henk/code/inspircd.git] / src / modules / m_nonicks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 #include <stdio.h>
18 #include <string>
19 #include "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "helperfuncs.h"
23
24 /* $ModDesc: Provides support for unreal-style GLOBOPS and umode +g */
25
26 Server *Srv;
27
28 class ModuleNoNickChange : public Module
29 {
30  public:
31         ModuleNoNickChange()
32         {
33                 Srv = new Server;
34                 
35                 Srv->AddExtendedMode('N',MT_CHANNEL,false,0,0);
36         }
37         
38         virtual ~ModuleNoNickChange()
39         {
40                 delete Srv;
41         }
42         
43         virtual Version GetVersion()
44         {
45                 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
46         }
47
48         virtual void On005Numeric(std::string &output)
49         {
50                 std::stringstream line(output);
51                 std::string temp1, temp2;
52                 while (!line.eof())
53                 {
54                         line >> temp1;
55                         if (temp1.substr(0,10) == "CHANMODES=")
56                         {
57                                 // append the chanmode to the end
58                                 temp1 = temp1.substr(10,temp1.length());
59                                 temp1 = "CHANMODES=" + temp1 + "N";
60                         }
61                         temp2 = temp2 + temp1 + " ";
62                 }
63                 if (temp2.length())
64                         output = temp2.substr(0,temp2.length()-1);
65         }
66         
67         virtual int OnUserPreNick(userrec* user, std::string newnick)
68         {
69                 if (!strcasecmp(user->server,Srv->GetServerName().c_str()))
70                 {
71                         for (int i =0; i != MAXCHANS; i++)
72                         {
73                                 if (user->chans[i].channel != NULL)
74                                 {
75                                         chanrec* curr = user->chans[i].channel;
76                                         if (curr->IsCustomModeSet('N'))
77                                         {
78                                                 if (!strchr(user->modes,'o'))
79                                                 {
80                                                         // don't allow the nickchange, theyre on at least one channel with +N set
81                                                         // and theyre not an oper
82                                                         WriteServ(user->fd,"447 %s :Can't change nickname while on %s (+N is set)",user->nick,curr->name);
83                                                         return 1;
84                                                 }
85                                         }
86                                 }
87                         }
88                 }
89                 return 0;
90         }
91         
92         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
93         {
94                 // check if this is our mode character...
95                 if ((modechar == 'N') && (type == MT_CHANNEL))
96                 {
97                         return 1;
98                 }
99                 else
100                 {
101                         return 0;
102                 }
103         }
104
105 };
106
107 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
108
109 class ModuleNoNickChangeFactory : public ModuleFactory
110 {
111  public:
112         ModuleNoNickChangeFactory()
113         {
114         }
115         
116         ~ModuleNoNickChangeFactory()
117         {
118         }
119         
120         virtual Module * CreateModule()
121         {
122                 return new ModuleNoNickChange;
123         }
124         
125 };
126
127
128 extern "C" void * init_module( void )
129 {
130         return new ModuleNoNickChangeFactory;
131 }
132