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 support for the +w channel mode, autoop list */
19 /** Handles +w channel mode
21 class AutoOpList : public ListModeBase
24 AutoOpList(Module* Creator) : ListModeBase(Creator, "autoop", 'w', "End of Channel Access List", 910, 911, true)
26 levelrequired = OP_VALUE;
30 ModeHandler* FindMode(const std::string& mid)
32 if (mid.length() == 1)
33 return ServerInstance->Modes->FindMode(mid[0], MODETYPE_CHANNEL);
34 for(char c='A'; c < 'z'; c++)
36 ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL);
37 if (mh && mh->name == mid)
43 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
45 std::string::size_type pos = parameter.find(':');
46 if (pos == 0 || pos == std::string::npos)
47 return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
48 unsigned int mylevel = channel->GetPrefixValue(source);
49 std::string mid = parameter.substr(0, pos);
50 ModeHandler* mh = FindMode(mid);
52 if (adding && (!mh || !mh->GetPrefixRank()))
54 source->WriteNumeric(415, "%s %s :Cannot find prefix mode '%s' for autoop",
55 source->nick.c_str(), mid.c_str(), mid.c_str());
59 return MOD_RES_PASSTHRU;
62 if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY)
64 if (mh->GetLevelRequired() > mylevel)
66 source->WriteNumeric(482, "%s %s :You must be able to set mode '%s' to include it in an autoop",
67 source->nick.c_str(), channel->name.c_str(), mid.c_str());
70 return MOD_RES_PASSTHRU;
74 class ModuleAutoOp : public Module
79 ModuleAutoOp() : mh(this)
81 ServerInstance->Modules->AddService(mh);
82 mh.DoImplements(this);
84 Implementation list[] = { I_OnPostJoin, };
85 ServerInstance->Modules->Attach(list, this, 1);
88 void OnPostJoin(Membership *memb)
90 if (!IS_LOCAL(memb->user))
93 modelist* list = mh.extItem.get(memb->chan);
96 std::string modeline("+");
97 std::vector<std::string> modechange;
98 modechange.push_back(memb->chan->name);
99 for (modelist::iterator it = list->begin(); it != list->end(); it++)
101 std::string::size_type colon = it->mask.find(':');
102 if (colon == std::string::npos)
104 if (memb->chan->CheckBan(memb->user, it->mask.substr(colon+1)))
106 ModeHandler* given = mh.FindMode(it->mask.substr(0, colon));
107 if (given && given->GetPrefixRank())
108 modeline.push_back(given->GetModeChar());
111 modechange.push_back(modeline);
112 for(std::string::size_type i = modeline.length(); i > 1; --i) // we use "i > 1" instead of "i" so we skip the +
113 modechange.push_back(memb->user->nick);
114 if(modechange.size() >= 3)
115 ServerInstance->SendMode(modechange,ServerInstance->FakeClient);
119 void OnCleanup(int target_type, void* item)
121 mh.DoCleanup(target_type, item);
124 void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
126 mh.DoSyncChannel(chan, proto, opaque);
129 void OnRehash(User* user)
136 return Version("Provides support for the +w channel mode", VF_VENDOR);
140 MODULE_INIT(ModuleAutoOp)