]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_customprefix.cpp
Move depriv from m_customprefix into PrefixMode.
[user/henk/code/inspircd.git] / src / modules / m_customprefix.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #include "inspircd.h"
21
22 class CustomPrefixMode : public PrefixMode
23 {
24  public:
25         reference<ConfigTag> tag;
26
27         CustomPrefixMode(Module* parent, ConfigTag* Tag)
28                 : PrefixMode(parent, Tag->getString("name"), 0, Tag->getInt("rank"))
29                 , tag(Tag)
30         {
31                 std::string v = tag->getString("prefix");
32                 prefix = v.c_str()[0];
33                 v = tag->getString("letter");
34                 mode = v.c_str()[0];
35                 ranktoset = tag->getInt("ranktoset", prefixrank, prefixrank, UINT_MAX);
36                 ranktounset = tag->getInt("ranktounset", ranktoset, ranktoset, UINT_MAX);
37                 selfremove = tag->getBool("depriv", true);
38         }
39 };
40
41 class ModuleCustomPrefix : public Module
42 {
43         std::vector<CustomPrefixMode*> modes;
44  public:
45         void init() CXX11_OVERRIDE
46         {
47                 ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix");
48                 while (tags.first != tags.second)
49                 {
50                         ConfigTag* tag = tags.first->second;
51                         tags.first++;
52                         CustomPrefixMode* mh = new CustomPrefixMode(this, tag);
53                         modes.push_back(mh);
54                         if (mh->GetPrefixRank() == 0)
55                                 throw ModuleException("Rank must be specified for prefix at " + tag->getTagLocation());
56                         if (!isalpha(mh->GetModeChar()))
57                                 throw ModuleException("Mode must be a letter for prefix at " + tag->getTagLocation());
58                         try
59                         {
60                                 ServerInstance->Modules->AddService(*mh);
61                         }
62                         catch (ModuleException& e)
63                         {
64                                 throw ModuleException(e.GetReason() + " (while creating mode from " + tag->getTagLocation() + ")");
65                         }
66                 }
67         }
68
69         ~ModuleCustomPrefix()
70         {
71                 stdalgo::delete_all(modes);
72         }
73
74         Version GetVersion() CXX11_OVERRIDE
75         {
76                 return Version("Provides custom prefix channel modes", VF_VENDOR);
77         }
78 };
79
80 MODULE_INIT(ModuleCustomPrefix)