2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2011 Jackmcbarn <jackmcbarn@jackmcbarn.no-ip.org>
5 * Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** Handles +w channel mode
26 class AutoOpList : public ListModeBase
29 AutoOpList(Module* Creator) : ListModeBase(Creator, "autoop", 'w', "End of Channel Access List", 910, 911, true)
31 levelrequired = OP_VALUE;
35 PrefixMode* FindMode(const std::string& mid)
37 if (mid.length() == 1)
38 return ServerInstance->Modes->FindPrefixMode(mid[0]);
40 ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL);
41 return mh ? mh->IsPrefixMode() : NULL;
44 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
46 std::string::size_type pos = parameter.find(':');
47 if (pos == 0 || pos == std::string::npos)
48 return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
49 unsigned int mylevel = channel->GetPrefixValue(source);
50 std::string mid = parameter.substr(0, pos);
51 PrefixMode* mh = FindMode(mid);
55 source->WriteNumeric(415, "%s :Cannot find prefix mode '%s' for autoop",
56 mid.c_str(), mid.c_str());
60 return MOD_RES_PASSTHRU;
63 if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY)
65 if (mh->GetLevelRequired() > mylevel)
67 source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You must be able to set mode '%s' to include it in an autoop",
68 channel->name.c_str(), mid.c_str());
71 return MOD_RES_PASSTHRU;
75 class ModuleAutoOp : public Module
80 ModuleAutoOp() : mh(this)
84 void OnPostJoin(Membership *memb) CXX11_OVERRIDE
86 if (!IS_LOCAL(memb->user))
89 ListModeBase::ModeList* list = mh.GetList(memb->chan);
92 std::string modeline("+");
93 std::vector<std::string> modechange;
94 modechange.push_back(memb->chan->name);
95 for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
97 std::string::size_type colon = it->mask.find(':');
98 if (colon == std::string::npos)
100 if (memb->chan->CheckBan(memb->user, it->mask.substr(colon+1)))
102 PrefixMode* given = mh.FindMode(it->mask.substr(0, colon));
104 modeline.push_back(given->GetModeChar());
107 modechange.push_back(modeline);
108 for(std::string::size_type i = modeline.length(); i > 1; --i) // we use "i > 1" instead of "i" so we skip the +
109 modechange.push_back(memb->user->nick);
110 if(modechange.size() >= 3)
111 ServerInstance->Modes->Process(modechange, ServerInstance->FakeClient);
115 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
120 Version GetVersion() CXX11_OVERRIDE
122 return Version("Provides support for the +w channel mode", VF_VENDOR);
126 MODULE_INIT(ModuleAutoOp)