]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_exemptchanops.cpp
Update m_exemptchanops to allow users to specify the status required for the exemption
[user/henk/code/inspircd.git] / src / modules / m_exemptchanops.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 #include "u_listmode.h"
16
17 /* $ModDesc: Provides the ability to allow channel operators to be exempt from certain modes. */
18
19 /** Handles channel mode +X
20  */
21 class ExemptChanOps : public ListModeBase
22 {
23  public:
24         ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false, "exemptchanops") { }
25
26         bool ValidateParam(User* user, Channel* chan, std::string &word)
27         {
28                 if ((word.length() > 35) || (word.empty()))
29                 {
30                         user->WriteNumeric(955, "%s %s %s :word is too %s for exemptchanops list",user->nick.c_str(), chan->name.c_str(), word.c_str(), (word.empty() ? "short" : "long"));
31                         return false;
32                 }
33
34                 return true;
35         }
36
37         bool TellListTooLong(User* user, Channel* chan, std::string &word)
38         {
39                 user->WriteNumeric(959, "%s %s %s :Channel exemptchanops list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
40                 return true;
41         }
42
43         void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
44         {
45                 user->WriteNumeric(957, "%s %s :The word %s is already on the exemptchanops list",user->nick.c_str(), chan->name.c_str(), word.c_str());
46         }
47
48         void TellNotSet(User* user, Channel* chan, std::string &word)
49         {
50                 user->WriteNumeric(958, "%s %s :No such exemptchanops word is set",user->nick.c_str(), chan->name.c_str());
51         }
52 };
53
54 class ModuleExemptChanOps : public Module
55 {
56         ExemptChanOps ec;
57         std::string defaults;
58
59  public:
60
61         ModuleExemptChanOps() : ec(this)
62         {
63         }
64
65         void init()
66         {
67                 ServerInstance->Modules->AddService(ec);
68                 ec.DoImplements(this);
69                 Implementation eventlist[] = { I_OnChannelDelete, I_OnChannelRestrictionApply, I_OnRehash, I_OnSyncChannel };
70                 ServerInstance->Modules->Attach(eventlist, this, 4);
71
72                 OnRehash(NULL);
73         }
74
75         Version GetVersion()
76         {
77                 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR);
78         }
79
80         void OnRehash(User* user)
81         {
82                 defaults = ServerInstance->Config->ConfValue("exemptchanops")->getString("defaults");
83                 ec.DoRehash();
84         }
85
86         void OnCleanup(int target_type, void* item)
87         {
88                 ec.DoCleanup(target_type, item);
89         }
90
91         void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
92         {
93                 ec.DoSyncChannel(chan, proto, opaque);
94         }
95
96         ModResult OnChannelRestrictionApply(User* user, Channel* chan, const char* restriction)
97         {
98                 unsigned int mypfx = chan->GetPrefixValue(user);
99                 irc::spacesepstream defaultstream(defaults);
100                 char minmode = 0;
101                 std::string current;
102
103                 while (defaultstream.GetToken(current))
104                 {
105                         std::string::size_type pos = current.find(':');
106                         if (pos == std::string::npos)
107                                 continue;
108                         if (current.substr(pos+1) == restriction)
109                                 minmode = current[0];
110                 }
111                 modelist* list = ec.extItem.get(chan);
112
113                 if (list)
114                 {
115                         for (modelist::iterator i = list->begin(); i != list->end(); ++i)
116                         {
117                                 std::string::size_type pos = i->mask.find(':');
118                                 if (pos == std::string::npos)
119                                         continue;
120                                 if (i->mask.substr(pos+1) == restriction)
121                                         minmode = i->mask[0];
122                         }
123                 }
124
125                 ModeHandler* mh = ServerInstance->Modes->FindMode(minmode, MODETYPE_CHANNEL);
126                 if (mh && mypfx >= mh->GetPrefixRank())
127                         return MOD_RES_ALLOW;
128                 return MOD_RES_PASSTHRU;
129         }
130 };
131
132 MODULE_INIT(ModuleExemptChanOps)