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