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;
29 ModeHandler* FindMode(const std::string& mid)
31 if (mid.length() == 1)
32 return ServerInstance->Modes->FindMode(mid[0], MODETYPE_CHANNEL);
33 for(char c='A'; c < 'z'; c++)
35 ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL);
36 if (mh && mh->name == mid)
42 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
44 std::string::size_type pos = parameter.find(':');
45 if (pos == 0 || pos == std::string::npos)
46 return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
47 unsigned int mylevel = channel->GetPrefixValue(source);
48 std::string mid = parameter.substr(0, pos);
49 ModeHandler* mh = FindMode(mid);
51 if (adding && (!mh || !mh->GetPrefixRank()))
53 source->WriteNumeric(415, "%s %s :Cannot find prefix mode '%s' for autoop",
54 source->nick.c_str(), mid.c_str(), mid.c_str());
58 return MOD_RES_PASSTHRU;
61 if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY)
63 if (mh->GetLevelRequired() > mylevel)
65 source->WriteNumeric(482, "%s %s :You must be able to set mode '%s' to include it in an autoop",
66 source->nick.c_str(), channel->name.c_str(), mid.c_str());
69 return MOD_RES_PASSTHRU;
73 class ModuleAutoOp : public Module
78 ModuleAutoOp() : mh(this)
80 ServerInstance->Modules->AddService(mh);
81 mh.DoImplements(this);
83 Implementation list[] = { I_OnUserPreJoin, };
84 ServerInstance->Modules->Attach(list, this, 1);
87 ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
90 return MOD_RES_PASSTHRU;
92 modelist* list = mh.extItem.get(chan);
95 for (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 (chan->CheckBan(user, it->mask.substr(colon+1)))
102 ModeHandler* given = mh.FindMode(it->mask.substr(0, colon));
104 privs += given->GetModeChar();
109 return MOD_RES_PASSTHRU;
112 void OnCleanup(int target_type, void* item)
114 mh.DoCleanup(target_type, item);
117 void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
119 mh.DoSyncChannel(chan, proto, opaque);
122 void OnRehash(User* user)
129 return Version("Provides support for the +w channel mode", VF_VENDOR);
133 MODULE_INIT(ModuleAutoOp)