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