]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_exemptchanops.cpp
...because every now and again, i have to do a massive commit.
[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 #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         }
77
78         virtual Version GetVersion()
79         {
80                 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR|VF_COMMON);
81         }
82
83         virtual void OnRehash(User* user)
84         {
85                 ConfigReader Conf;
86                 alwaysexempt = Conf.ReadValue("exemptchanops", "alwaysexempt", 0);
87                 neverexempt = Conf.ReadValue("exemptchanops", "neverexempt", 0);
88                 ec.DoRehash();
89         }
90
91         virtual void OnCleanup(int target_type, void* item)
92         {
93                 ec.DoCleanup(target_type, item);
94         }
95
96         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
97         {
98                 ec.DoSyncChannel(chan, proto, opaque);
99         }
100
101         virtual ModResult OnChannelRestrictionApply(User* user, Channel* chan, const char* restriction)
102         {
103                 irc::spacesepstream allowstream(alwaysexempt), denystream(neverexempt);
104                 std::string current;
105
106                 if (chan->GetPrefixValue(user) != OP_VALUE)
107                         return MOD_RES_PASSTHRU; // They're not opped, so we don't exempt them
108                 while(denystream.GetToken(current))
109                         if (!strcasecmp(restriction, current.c_str())) return MOD_RES_PASSTHRU; // This mode is set to never allow exemptions in the config
110                 while(allowstream.GetToken(current))
111                         if (!strcasecmp(restriction, current.c_str())) return MOD_RES_ALLOW; // This mode is set to always allow exemptions in the config
112
113                 modelist* list = ec.extItem.get(chan);
114
115                 if (!list) return MOD_RES_PASSTHRU;
116                 for (modelist::iterator i = list->begin(); i != list->end(); ++i)
117                         if (!strcasecmp(restriction, i->mask.c_str()))
118                                 return MOD_RES_ALLOW; //  They're opped, and the channel lets ops bypass this mode.  Allow regardless of restrictions
119
120                 return MOD_RES_PASSTHRU;
121         }
122 };
123
124 MODULE_INIT(ModuleExemptChanOps)