2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 /* $ModDesc: Allows custom prefix modes to be created. */
24 class CustomPrefixMode : public ModeHandler
27 reference<ConfigTag> tag;
30 CustomPrefixMode(Module* parent, ConfigTag* Tag)
31 : ModeHandler(parent, Tag->getString("name"), 0, PARAM_ALWAYS, MODETYPE_CHANNEL), tag(Tag)
34 m_paramtype = TR_NICK;
35 std::string v = tag->getString("prefix");
36 prefix = v.c_str()[0];
37 v = tag->getString("letter");
39 rank = tag->getInt("rank");
40 levelrequired = tag->getInt("ranktoset", rank);
41 depriv = tag->getBool("depriv", true);
44 unsigned int GetPrefixRank()
49 ModResult AccessCheck(User* src, Channel*, std::string& value, bool adding)
51 if (!adding && src->nick == value && depriv)
53 return MOD_RES_PASSTHRU;
56 void RemoveMode(User* user, irc::modestacker* stack)
60 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
62 return MODEACTION_ALLOW;
66 class ModuleCustomPrefix : public Module
68 std::vector<CustomPrefixMode*> modes;
70 void init() CXX11_OVERRIDE
72 ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix");
73 while (tags.first != tags.second)
75 ConfigTag* tag = tags.first->second;
77 CustomPrefixMode* mh = new CustomPrefixMode(this, tag);
80 throw ModuleException("Rank must be specified for prefix at " + tag->getTagLocation());
81 if (!isalpha(mh->GetModeChar()))
82 throw ModuleException("Mode must be a letter for prefix at " + tag->getTagLocation());
85 ServerInstance->Modules->AddService(*mh);
87 catch (ModuleException& e)
89 throw ModuleException(e.err + " (while creating mode from " + tag->getTagLocation() + ")");
96 for (std::vector<CustomPrefixMode*>::iterator i = modes.begin(); i != modes.end(); i++)
100 Version GetVersion() CXX11_OVERRIDE
102 return Version("Provides custom prefix channel modes", VF_VENDOR);
106 MODULE_INIT(ModuleCustomPrefix)