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