]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
In the grand tradition of huge fucking commits:
[user/henk/code/inspircd.git] / src / modules / m_nonicks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for channel mode +N which prevents nick changes on channel */
17
18 class NoNicks : public ModeHandler
19 {
20  public:
21         NoNicks(InspIRCd* Instance) : ModeHandler(Instance, 'N', 0, 0, false, MODETYPE_CHANNEL, false) { }
22
23         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
24         {
25                 if (adding)
26                 {
27                         if (!channel->IsModeSet('N'))
28                         {
29                                 channel->SetMode('N',true);
30                                 return MODEACTION_ALLOW;
31                         }
32                 }
33                 else
34                 {
35                         if (channel->IsModeSet('N'))
36                         {
37                                 channel->SetMode('N',false);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41
42                 return MODEACTION_DENY;
43         }
44 };
45
46 class ModuleNoNickChange : public Module
47 {
48         NoNicks* nn;
49  public:
50         ModuleNoNickChange(InspIRCd* Me)
51                 : Module(Me)
52         {
53                 
54                 nn = new NoNicks(ServerInstance);
55                 ServerInstance->AddMode(nn, 'N');
56         }
57         
58         virtual ~ModuleNoNickChange()
59         {
60                 ServerInstance->Modes->DelMode(nn);
61                 DELETE(nn);
62         }
63         
64         virtual Version GetVersion()
65         {
66                 return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
67         }
68
69         void Implements(char* List)
70         {
71                 List[I_OnUserPreNick] = 1;
72         }
73
74         virtual int OnUserPreNick(User* user, const std::string &newnick)
75         {
76                 if (IS_LOCAL(user))
77                 {
78                         if (isdigit(newnick[0])) /* don't even think about touching a switch to uid! */
79                                 return 0;
80
81                         for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
82                         {
83                                 Channel* curr = i->first;
84
85                                 if (curr->IsModeSet('N'))
86                                 {
87                                         if (CHANOPS_EXEMPT(ServerInstance, 'N') && curr->GetStatus(user) == STATUS_OP)
88                                                 continue;
89
90                                         user->WriteServ("447 %s :Can't change nickname while on %s (+N is set)", user->nick, curr->name);
91                                         return 1;
92                                 }
93                         }
94                 }
95
96                 return 0;
97         }
98 };
99
100 MODULE_INIT(ModuleNoNickChange)