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 class CustomPrefixMode : public PrefixMode
25 reference<ConfigTag> tag;
28 CustomPrefixMode(Module* parent, ConfigTag* Tag)
29 : PrefixMode(parent, Tag->getString("name"), 0, Tag->getInt("rank"))
32 std::string v = tag->getString("prefix");
33 prefix = v.c_str()[0];
34 v = tag->getString("letter");
36 levelrequired = tag->getInt("ranktoset", prefixrank);
37 depriv = tag->getBool("depriv", true);
40 ModResult AccessCheck(User* src, Channel*, std::string& value, bool adding)
42 if (!adding && src->nick == value && depriv)
44 return MOD_RES_PASSTHRU;
48 class ModuleCustomPrefix : public Module
50 std::vector<CustomPrefixMode*> modes;
52 void init() CXX11_OVERRIDE
54 ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix");
55 while (tags.first != tags.second)
57 ConfigTag* tag = tags.first->second;
59 CustomPrefixMode* mh = new CustomPrefixMode(this, tag);
61 if (mh->GetPrefixRank() == 0)
62 throw ModuleException("Rank must be specified for prefix at " + tag->getTagLocation());
63 if (!isalpha(mh->GetModeChar()))
64 throw ModuleException("Mode must be a letter for prefix at " + tag->getTagLocation());
67 ServerInstance->Modules->AddService(*mh);
69 catch (ModuleException& e)
71 throw ModuleException(e.GetReason() + " (while creating mode from " + tag->getTagLocation() + ")");
78 stdalgo::delete_all(modes);
81 Version GetVersion() CXX11_OVERRIDE
83 return Version("Provides custom prefix channel modes", VF_VENDOR);
87 MODULE_INIT(ModuleCustomPrefix)