]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_autoop.cpp
Some more text fixes and improvements (#1618).
[user/henk/code/inspircd.git] / src / modules / m_autoop.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2011 Jackmcbarn <jackmcbarn@jackmcbarn.no-ip.org>
5  *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "listmode.h"
23
24 /** Handles +w channel mode
25  */
26 class AutoOpList : public ListModeBase
27 {
28  public:
29         AutoOpList(Module* Creator)
30                 : ListModeBase(Creator, "autoop", 'w', "End of Channel Access List", 910, 911, true)
31         {
32                 ranktoset = ranktounset = OP_VALUE;
33                 tidy = false;
34         }
35
36         PrefixMode* FindMode(const std::string& mid)
37         {
38                 if (mid.length() == 1)
39                         return ServerInstance->Modes->FindPrefixMode(mid[0]);
40
41                 ModeHandler* mh = ServerInstance->Modes->FindMode(mid, MODETYPE_CHANNEL);
42                 return mh ? mh->IsPrefixMode() : NULL;
43         }
44
45         ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE
46         {
47                 std::string::size_type pos = parameter.find(':');
48                 if (pos == 0 || pos == std::string::npos)
49                         return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
50                 unsigned int mylevel = channel->GetPrefixValue(source);
51                 std::string mid(parameter, 0, pos);
52                 PrefixMode* mh = FindMode(mid);
53
54                 if (adding && !mh)
55                 {
56                         source->WriteNumeric(ERR_UNKNOWNMODE, mid, InspIRCd::Format("Cannot find prefix mode '%s' for autoop", mid.c_str()));
57                         return MOD_RES_DENY;
58                 }
59                 else if (!mh)
60                         return MOD_RES_PASSTHRU;
61
62                 std::string dummy;
63                 if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY)
64                         return MOD_RES_DENY;
65                 if (mh->GetLevelRequired(true) > mylevel)
66                 {
67                         source->WriteNumeric(ERR_CHANOPRIVSNEEDED, channel->name, InspIRCd::Format("You must be able to set mode '%s' to include it in an autoop", mid.c_str()));
68                         return MOD_RES_DENY;
69                 }
70                 return MOD_RES_PASSTHRU;
71         }
72 };
73
74 class ModuleAutoOp : public Module
75 {
76         AutoOpList mh;
77
78  public:
79         ModuleAutoOp() : mh(this)
80         {
81         }
82
83         void OnPostJoin(Membership *memb) CXX11_OVERRIDE
84         {
85                 if (!IS_LOCAL(memb->user))
86                         return;
87
88                 ListModeBase::ModeList* list = mh.GetList(memb->chan);
89                 if (list)
90                 {
91                         Modes::ChangeList changelist;
92                         for (ListModeBase::ModeList::iterator it = list->begin(); it != list->end(); it++)
93                         {
94                                 std::string::size_type colon = it->mask.find(':');
95                                 if (colon == std::string::npos)
96                                         continue;
97                                 if (memb->chan->CheckBan(memb->user, it->mask.substr(colon+1)))
98                                 {
99                                         PrefixMode* given = mh.FindMode(it->mask.substr(0, colon));
100                                         if (given)
101                                                 changelist.push_add(given, memb->user->nick);
102                                 }
103                         }
104                         ServerInstance->Modes->Process(ServerInstance->FakeClient, memb->chan, NULL, changelist);
105                 }
106         }
107
108         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
109         {
110                 mh.DoRehash();
111         }
112
113         Version GetVersion() CXX11_OVERRIDE
114         {
115                 return Version("Provides channel mode +w, basic channel access controls", VF_VENDOR);
116         }
117 };
118
119 MODULE_INIT(ModuleAutoOp)