]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
809408310de143fcf2b87270930765f3c9f4316d
[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                 std::stringstream line(output);
59                 std::string temp1, temp2;
60                 while (!line.eof())
61                 {
62                         line >> temp1;
63                         if (temp1.substr(0,10) == "CHANMODES=")
64                         {
65                                 // append the chanmode to the end
66                                 temp1 = temp1.substr(10,temp1.length());
67                                 temp1 = "CHANMODES=" + temp1 + "N";
68                         }
69                         temp2 = temp2 + temp1 + " ";
70                 }
71                 if (temp2.length())
72                         output = temp2.substr(0,temp2.length()-1);
73         }
74         
75         virtual int OnUserPreNick(userrec* user, std::string newnick)
76         {
77                 irc::string server = user->server;
78                 irc::string me = Srv->GetServerName().c_str();
79                 if (server == me)
80                 {
81                         for (unsigned int i =0; i < user->chans.size(); i++)
82                         {
83                                 if (user->chans[i].channel != NULL)
84                                 {
85                                         chanrec* curr = user->chans[i].channel;
86                                         if (curr->IsCustomModeSet('N'))
87                                         {
88                                                 if (!strchr(user->modes,'o'))
89                                                 {
90                                                         // don't allow the nickchange, theyre on at least one channel with +N set
91                                                         // and theyre not an oper
92                                                         WriteServ(user->fd,"447 %s :Can't change nickname while on %s (+N is set)",user->nick,curr->name);
93                                                         return 1;
94                                                 }
95                                         }
96                                 }
97                         }
98                 }
99                 return 0;
100         }
101         
102         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
103         {
104                 // check if this is our mode character...
105                 if ((modechar == 'N') && (type == MT_CHANNEL))
106                 {
107                         return 1;
108                 }
109                 else
110                 {
111                         return 0;
112                 }
113         }
114
115 };
116
117 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
118
119 class ModuleNoNickChangeFactory : public ModuleFactory
120 {
121  public:
122         ModuleNoNickChangeFactory()
123         {
124         }
125         
126         ~ModuleNoNickChangeFactory()
127         {
128         }
129         
130         virtual Module * CreateModule(Server* Me)
131         {
132                 return new ModuleNoNickChange(Me);
133         }
134         
135 };
136
137
138 extern "C" void * init_module( void )
139 {
140         return new ModuleNoNickChangeFactory;
141 }
142