]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
Add RAWIO log level which is more verbose than DEBUG
[user/henk/code/inspircd.git] / src / modules / m_nonicks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 & extban +b N: which prevents nick changes on channel */
17
18 class NoNicks : public ModeHandler
19 {
20  public:
21         NoNicks(Module* Creator) : ModeHandler(Creator, "nonick", 'N', PARAM_NONE, MODETYPE_CHANNEL) { }
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         bool override;
50  public:
51         ModuleNoNickChange() : nn(this)
52         {
53                 OnRehash(NULL);
54                 ServerInstance->Modes->AddMode(&nn);
55                 Implementation eventlist[] = { I_OnUserPreNick, I_On005Numeric, I_OnRehash };
56                 ServerInstance->Modules->Attach(eventlist, this, 3);
57         }
58
59         virtual ~ModuleNoNickChange()
60         {
61         }
62
63         virtual Version GetVersion()
64         {
65                 return Version("Provides support for channel mode +N & extban +b N: which prevents nick changes on channel", VF_VENDOR);
66         }
67
68
69         virtual void On005Numeric(std::string &output)
70         {
71                 ServerInstance->AddExtBanChar('N');
72         }
73
74         virtual ModResult OnUserPreNick(User* user, const std::string &newnick)
75         {
76                 if (!IS_LOCAL(user))
77                         return MOD_RES_PASSTHRU;
78
79                 // Allow forced nick changes.
80                 if (ServerInstance->NICKForced.get(user))
81                         return MOD_RES_PASSTHRU;
82
83                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
84                 {
85                         Channel* curr = *i;
86
87                         ModResult res = ServerInstance->OnCheckExemption(user,curr,"nonick");
88
89                         if (res == MOD_RES_ALLOW)
90                                 continue;
91
92                         if (override && IS_OPER(user))
93                                 continue;
94
95                         if (!curr->GetExtBanStatus(user, 'N').check(!curr->IsModeSet('N')))
96                         {
97                                 user->WriteNumeric(ERR_CANTCHANGENICK, "%s :Can't change nickname while on %s (+N is set)",
98                                         user->nick.c_str(), curr->name.c_str());
99                                 return MOD_RES_DENY;
100                         }
101                 }
102
103                 return MOD_RES_PASSTHRU;
104         }
105
106         virtual void OnRehash(User* user)
107         {
108                 ConfigReader Conf;
109                 override = Conf.ReadFlag("nonicks", "operoverride", "no", 0);
110         }
111 };
112
113 MODULE_INIT(ModuleNoNickChange)