1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #define _CRT_SECURE_NO_DEPRECATE
15 #define _SCL_SECURE_NO_DEPRECATE
18 #include "u_listmode.h"
20 /* $ModDesc: Provides the ability to allow channel operators to be exempt from certain modes. */
21 /* $ModDep: ../../include/u_listmode.h */
23 /** Handles channel mode +X
25 class ExemptChanOps : public ListModeBase
28 ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false, "exemptchanops") { }
30 virtual bool ValidateParam(User* user, Channel* chan, std::string &word)
32 if ((word.length() > 35) || (word.empty()))
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"));
41 virtual bool TellListTooLong(User* user, Channel* chan, std::string &word)
43 user->WriteNumeric(959, "%s %s %s :Channel exemptchanops list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
47 virtual void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
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());
52 virtual void TellNotSet(User* user, Channel* chan, std::string &word)
54 user->WriteNumeric(958, "%s %s :No such exemptchanops word is set",user->nick.c_str(), chan->name.c_str());
58 class ModuleExemptChanOps : public Module
61 std::string alwaysexempt, neverexempt;
68 if (!ServerInstance->Modes->AddMode(&ec))
69 throw ModuleException("Could not add new modes!");
71 ec.DoImplements(this);
72 Implementation eventlist[] = { I_OnChannelDelete, I_OnChannelRestrictionApply, I_OnRehash, I_OnSyncChannel };
73 ServerInstance->Modules->Attach(eventlist, this, 4);
76 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
79 virtual Version GetVersion()
81 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR|VF_COMMON);
84 virtual void OnRehash(User* user)
87 alwaysexempt = Conf.ReadValue("exemptchanops", "alwaysexempt", 0);
88 neverexempt = Conf.ReadValue("exemptchanops", "neverexempt", 0);
92 virtual void OnCleanup(int target_type, void* item)
94 ec.DoCleanup(target_type, item);
97 virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
99 ec.DoSyncChannel(chan, proto, opaque);
102 virtual ModResult OnChannelRestrictionApply(User* user, Channel* chan, const char* restriction)
104 irc::spacesepstream allowstream(alwaysexempt), denystream(neverexempt);
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
114 modelist* list = ec.extItem.get(chan);
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
121 return MOD_RES_PASSTHRU;
124 virtual ~ModuleExemptChanOps()
126 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
130 MODULE_INIT(ModuleExemptChanOps)