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