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;
27 CustomPrefixMode(Module* parent, const std::string& Name, char Letter, char Prefix, ConfigTag* Tag)
28 : PrefixMode(parent, Name, Letter, 0, Prefix)
31 prefixrank = tag->getInt("rank", 0, 0, UINT_MAX);
32 ranktoset = tag->getInt("ranktoset", prefixrank, prefixrank, UINT_MAX);
33 ranktounset = tag->getInt("ranktounset", ranktoset, ranktoset, UINT_MAX);
34 selfremove = tag->getBool("depriv", true);
38 class ModuleCustomPrefix : public Module
40 std::vector<CustomPrefixMode*> modes;
42 void init() CXX11_OVERRIDE
44 ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix");
45 for (ConfigIter iter = tags.first; iter != tags.second; ++iter)
47 ConfigTag* tag = iter->second;
49 const std::string name = tag->getString("name");
51 throw ModuleException("<customprefix:name> must be specified at " + tag->getTagLocation());
53 const std::string letter = tag->getString("letter");
54 if (letter.length() != 1)
55 throw ModuleException("<customprefix:letter> must be set to a mode character at " + tag->getTagLocation());
57 const std::string prefix = tag->getString("prefix");
58 if (prefix.length() != 1)
59 throw ModuleException("<customprefix:prefix> must be set to a mode prefix at " + tag->getTagLocation());
63 CustomPrefixMode* mh = new CustomPrefixMode(this, name, letter[0], prefix[0], tag);
64 ServerInstance->Modules->AddService(*mh);
66 catch (ModuleException& e)
68 throw ModuleException(e.GetReason() + " (while creating mode from " + tag->getTagLocation() + ")");
75 stdalgo::delete_all(modes);
78 Version GetVersion() CXX11_OVERRIDE
80 return Version("Provides custom prefix channel modes", VF_VENDOR);
84 MODULE_INIT(ModuleCustomPrefix)