]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_exemptchanops.cpp
Make OnChannelRestrictionApply take a User* instead of a Membership* [jackmcbarn]
[user/henk/code/inspircd.git] / src / modules / m_exemptchanops.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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 #define _CRT_SECURE_NO_DEPRECATE
15 #define _SCL_SECURE_NO_DEPRECATE
16
17 #include "inspircd.h"
18 #include "u_listmode.h"
19
20 /* $ModDesc: Provides the ability to allow channel operators to be exempt from certain modes. */
21 /* $ModDep: ../../include/u_listmode.h */
22
23 /** Handles channel mode +X
24  */
25 class ExemptChanOps : public ListModeBase
26 {
27  public:
28         ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false, "exemptchanops") { }
29
30         virtual bool ValidateParam(User* user, Channel* chan, std::string &word)
31         {
32                 if ((word.length() > 35) || (word.empty()))
33                 {
34                         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"));
35                         return false;
36                 }
37
38                 return true;
39         }
40
41         virtual bool TellListTooLong(User* user, Channel* chan, std::string &word)
42         {
43                 user->WriteNumeric(959, "%s %s %s :Channel exemptchanops list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
44                 return true;
45         }
46
47         virtual void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
48         {
49                 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());
50         }
51
52         virtual void TellNotSet(User* user, Channel* chan, std::string &word)
53         {
54                 user->WriteNumeric(958, "%s %s :No such exemptchanops word is set",user->nick.c_str(), chan->name.c_str());
55         }
56 };
57
58 class ModuleExemptChanOps : public Module
59 {
60         ExemptChanOps ec;
61         std::string alwaysexempt, neverexempt;
62
63  public:
64
65         ModuleExemptChanOps()
66                 : ec(this)
67         {
68                 if (!ServerInstance->Modes->AddMode(&ec))
69                         throw ModuleException("Could not add new modes!");
70
71                 ec.DoImplements(this);
72                 Implementation eventlist[] = { I_OnChannelDelete, I_OnChannelRestrictionApply, I_OnRehash, I_OnSyncChannel };
73                 ServerInstance->Modules->Attach(eventlist, this, 4);
74
75                 OnRehash(NULL);
76                 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
77         }
78
79         virtual Version GetVersion()
80         {
81                 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR|VF_COMMON,API_VERSION);
82         }
83
84         virtual void OnRehash(User* user)
85         {
86                 ConfigReader Conf;
87                 alwaysexempt = Conf.ReadValue("exemptchanops", "alwaysexempt", 0);
88                 neverexempt = Conf.ReadValue("exemptchanops", "neverexempt", 0);
89                 ec.DoRehash();
90         }
91
92         virtual void OnCleanup(int target_type, void* item)
93         {
94                 ec.DoCleanup(target_type, item);
95         }
96
97         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
98         {
99                 ec.DoSyncChannel(chan, proto, opaque);
100         }
101
102         virtual ModResult OnChannelRestrictionApply(User* user, Channel* chan, const char* restriction)
103         {
104                 irc::spacesepstream allowstream(alwaysexempt), denystream(neverexempt);
105                 std::string current;
106
107                 if (chan->GetPrefixValue(user) != OP_VALUE)
108                         return MOD_RES_PASSTHRU; // They're not opped, so we don't exempt them
109                 while(denystream.GetToken(current))
110                         if (!strcasecmp(restriction, current.c_str())) return MOD_RES_PASSTHRU; // This mode is set to never allow exemptions in the config
111                 while(allowstream.GetToken(current))
112                         if (!strcasecmp(restriction, current.c_str())) return MOD_RES_ALLOW; // This mode is set to always allow exemptions in the config
113
114                 modelist* list = ec.extItem.get(chan);
115
116                 if (!list) return MOD_RES_PASSTHRU;
117                 for (modelist::iterator i = list->begin(); i != list->end(); ++i)
118                         if (!strcasecmp(restriction, i->mask.c_str()))
119                                 return MOD_RES_ALLOW; //  They're opped, and the channel lets ops bypass this mode.  Allow regardless of restrictions
120
121                 return MOD_RES_PASSTHRU;
122         }
123
124         virtual ~ModuleExemptChanOps()
125         {
126                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
127         }
128 };
129
130 MODULE_INIT(ModuleExemptChanOps)