]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_exemptchanops.cpp
7751153e2e78228760e5473aeb90c8fa61a6ffe3
[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                 // TODO actually make sure there's a prop for this
29                 if ((word.length() > 35) || (word.empty()))
30                 {
31                         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"));
32                         return false;
33                 }
34
35                 return true;
36         }
37
38         bool TellListTooLong(User* user, Channel* chan, std::string &word)
39         {
40                 user->WriteNumeric(959, "%s %s %s :Channel exemptchanops list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
41                 return true;
42         }
43
44         void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
45         {
46                 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());
47         }
48
49         void TellNotSet(User* user, Channel* chan, std::string &word)
50         {
51                 user->WriteNumeric(958, "%s %s :No such exemptchanops word is set",user->nick.c_str(), chan->name.c_str());
52         }
53 };
54
55 class ModuleExemptChanOps : public Module
56 {
57         ExemptChanOps ec;
58         std::string defaults;
59
60  public:
61
62         ModuleExemptChanOps() : ec(this)
63         {
64         }
65
66         void init()
67         {
68                 ServerInstance->Modules->AddService(ec);
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 OnSyncChannel(Channel* chan, Module* proto, void* opaque)
87         {
88                 ec.DoSyncChannel(chan, proto, opaque);
89         }
90
91         ModResult OnChannelRestrictionApply(User* user, Channel* chan, const char* restriction)
92         {
93                 unsigned int mypfx = chan->GetPrefixValue(user);
94                 irc::spacesepstream defaultstream(defaults);
95                 char minmode = 0;
96                 std::string current;
97
98                 while (defaultstream.GetToken(current))
99                 {
100                         std::string::size_type pos = current.find(':');
101                         if (pos == std::string::npos)
102                                 continue;
103                         if (current.substr(0,pos) == restriction)
104                                 minmode = current[pos+1];
105                 }
106                 modelist* list = ec.extItem.get(chan);
107
108                 if (list)
109                 {
110                         for (modelist::iterator i = list->begin(); i != list->end(); ++i)
111                         {
112                                 std::string::size_type pos = (*i).mask.find(':');
113                                 if (pos == std::string::npos)
114                                         continue;
115                                 if ((*i).mask.substr(0,pos) == restriction)
116                                         minmode = (*i).mask[pos+1];
117                         }
118                 }
119
120                 ModeHandler* mh = ServerInstance->Modes->FindMode(minmode, MODETYPE_CHANNEL);
121                 if (mh && mypfx >= mh->GetPrefixRank())
122                         return MOD_RES_ALLOW;
123                 if (mh || minmode == '*')
124                         return MOD_RES_DENY;
125                 return MOD_RES_PASSTHRU;
126         }
127 };
128
129 MODULE_INIT(ModuleExemptChanOps)