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 /* $ModDesc: Provides support for the +w channel mode, autoop list */
26 /** Handles +w channel mode
28 class AutoOpList : public ListModeBase
31 AutoOpList(Module* Creator) : ListModeBase(Creator, "autoop", 'w', "End of Channel Access List", 910, 911, true)
33 levelrequired = OP_VALUE;
37 ModeHandler* FindMode(const std::string& mid)
39 if (mid.length() == 1)
40 return ServerInstance->Modes->FindMode(mid[0], MODETYPE_CHANNEL);
41 for(char c='A'; c < 'z'; c++)
43 ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL);
44 if (mh && mh->name == mid)
50 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
52 std::string::size_type pos = parameter.find(':');
53 if (pos == 0 || pos == std::string::npos)
54 return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
55 unsigned int mylevel = channel->GetPrefixValue(source);
56 std::string mid = parameter.substr(0, pos);
57 ModeHandler* mh = FindMode(mid);
59 if (adding && (!mh || !mh->GetPrefixRank()))
61 source->WriteNumeric(415, "%s %s :Cannot find prefix mode '%s' for autoop",
62 source->nick.c_str(), mid.c_str(), mid.c_str());
66 return MOD_RES_PASSTHRU;
69 if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY)
71 if (mh->GetLevelRequired() > mylevel)
73 source->WriteNumeric(482, "%s %s :You must be able to set mode '%s' to include it in an autoop",
74 source->nick.c_str(), channel->name.c_str(), mid.c_str());
77 return MOD_RES_PASSTHRU;
81 class ModuleAutoOp : public Module
86 ModuleAutoOp() : mh(this)
90 void init() CXX11_OVERRIDE
92 ServerInstance->Modules->AddService(mh);
93 mh.DoImplements(this);
95 Implementation list[] = { I_OnPostJoin, };
96 ServerInstance->Modules->Attach(list, this, sizeof(list)/sizeof(Implementation));
99 void OnPostJoin(Membership *memb) CXX11_OVERRIDE
101 if (!IS_LOCAL(memb->user))
104 ListModeBase::ModeList* list = mh.GetList(memb->chan);
107 std::string modeline("+");
108 std::vector<std::string> modechange;
109 modechange.push_back(memb->chan->name);
110 for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
112 std::string::size_type colon = it->mask.find(':');
113 if (colon == std::string::npos)
115 if (memb->chan->CheckBan(memb->user, it->mask.substr(colon+1)))
117 ModeHandler* given = mh.FindMode(it->mask.substr(0, colon));
118 if (given && given->GetPrefixRank())
119 modeline.push_back(given->GetModeChar());
122 modechange.push_back(modeline);
123 for(std::string::size_type i = modeline.length(); i > 1; --i) // we use "i > 1" instead of "i" so we skip the +
124 modechange.push_back(memb->user->nick);
125 if(modechange.size() >= 3)
126 ServerInstance->SendGlobalMode(modechange, ServerInstance->FakeClient);
130 void OnSyncChannel(Channel* chan, Module* proto, void* opaque) CXX11_OVERRIDE
132 mh.DoSyncChannel(chan, proto, opaque);
135 void OnRehash(User* user) CXX11_OVERRIDE
140 Version GetVersion() CXX11_OVERRIDE
142 return Version("Provides support for the +w channel mode", VF_VENDOR);
146 MODULE_INIT(ModuleAutoOp)