1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 * ---------------------------------------------------
15 #include "u_listmode.h"
17 /* $ModDesc: Provides the ability to allow channel operators to be exempt from certain modes. */
19 /** Handles channel mode +X
21 class ExemptChanOps : public ListModeBase
24 ExemptChanOps(Module* Creator) : ListModeBase(Creator, "exemptchanops", 'X', "End of channel exemptchanops list", 954, 953, false, "exemptchanops") { }
26 bool ValidateParam(User* user, Channel* chan, std::string &word)
28 // TODO actually make sure there's a prop for this
29 if ((word.length() > 35) || (word.empty()))
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"));
38 bool TellListTooLong(User* user, Channel* chan, std::string &word)
40 user->WriteNumeric(959, "%s %s %s :Channel exemptchanops list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
44 void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
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());
49 void TellNotSet(User* user, Channel* chan, std::string &word)
51 user->WriteNumeric(958, "%s %s :No such exemptchanops word is set",user->nick.c_str(), chan->name.c_str());
55 class ModuleExemptChanOps : public Module
62 ModuleExemptChanOps() : ec(this)
68 ServerInstance->Modules->AddService(ec);
69 Implementation eventlist[] = { I_OnChannelDelete, I_OnChannelRestrictionApply, I_OnRehash, I_OnSyncChannel };
70 ServerInstance->Modules->Attach(eventlist, this, 4);
77 return Version("Provides the ability to allow channel operators to be exempt from certain modes.",VF_VENDOR);
80 void OnRehash(User* user)
82 defaults = ServerInstance->Config->ConfValue("exemptchanops")->getString("defaults");
86 void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
88 ec.DoSyncChannel(chan, proto, opaque);
91 ModeHandler* FindMode(const std::string& mid)
93 if (mid.length() == 1)
94 return ServerInstance->Modes->FindMode(mid[0], MODETYPE_CHANNEL);
95 for(char c='A'; c < 'z'; c++)
97 ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL);
98 if (mh && mh->name == mid)
104 ModResult OnChannelRestrictionApply(User* user, Channel* chan, const char* restriction)
106 unsigned int mypfx = chan->GetPrefixValue(user);
107 irc::spacesepstream defaultstream(defaults);
111 while (defaultstream.GetToken(current))
113 std::string::size_type pos = current.find(':');
114 if (pos == std::string::npos)
116 if (current.substr(0,pos) == restriction)
117 minmode = current[pos+1];
119 modelist* list = ec.extItem.get(chan);
123 for (modelist::iterator i = list->begin(); i != list->end(); ++i)
125 std::string::size_type pos = (*i).mask.find(':');
126 if (pos == std::string::npos)
128 if ((*i).mask.substr(0,pos) == restriction)
129 minmode = (*i).mask.substr(pos + 1);
133 ModeHandler* mh = FindMode(minmode);
134 if (mh && mypfx >= mh->GetPrefixRank())
135 return MOD_RES_ALLOW;
136 if (mh || minmode == "*")
138 return MOD_RES_PASSTHRU;
142 MODULE_INIT(ModuleExemptChanOps)