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