]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonicks.cpp
...because every now and again, i have to do a massive commit.
[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_COMMON | 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                 if (isdigit(newnick[0])) /* don't even think about touching a switch to uid! */
80                         return MOD_RES_PASSTHRU;
81
82                 // Allow forced nick changes.
83                 if (ServerInstance->NICKForced.get(user))
84                         return MOD_RES_PASSTHRU;
85
86                 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
87                 {
88                         Channel* curr = *i;
89
90                         ModResult res;
91                         FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,curr,"nonick"));
92
93                         if (res == MOD_RES_ALLOW)
94                                 continue;
95
96                         if (override && IS_OPER(user))
97                                 continue;
98
99                         if (!curr->GetExtBanStatus(user, 'N').check(!curr->IsModeSet('N')))
100                         {
101                                 user->WriteNumeric(ERR_CANTCHANGENICK, "%s :Can't change nickname while on %s (+N is set)",
102                                         user->nick.c_str(), curr->name.c_str());
103                                 return MOD_RES_DENY;
104                         }
105                 }
106
107                 return MOD_RES_PASSTHRU;
108         }
109
110         virtual void OnRehash(User* user)
111         {
112                 ConfigReader Conf;
113                 override = Conf.ReadFlag("nonicks", "operoverride", "no", 0);
114         }
115 };
116
117 MODULE_INIT(ModuleNoNickChange)