]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/parammode.h
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / include / parammode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2014-2015 Attila Molnar <attilamolnar@hush.com>
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 #pragma once
22
23 class CoreExport ParamModeBase : public ModeHandler
24 {
25  private:
26         virtual void OnUnsetInternal(User* source, Channel* chan) = 0;
27
28  public:
29         ParamModeBase(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps)
30                 : ModeHandler(Creator, Name, modeletter, ps, MODETYPE_CHANNEL, MC_PARAM) { }
31
32         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& param, bool adding) CXX11_OVERRIDE;
33
34         // Does nothing by default
35         virtual bool IsParameterSecret() { return false; }
36         virtual void OnUnset(User* source, Channel* chan) { }
37         virtual ModeAction OnSet(User* source, Channel* chan, std::string& param) = 0;
38         virtual void GetParameter(Channel* chan, std::string& out) = 0;
39 };
40
41 /** Defines a parameter mode
42  * T = Child class
43  * ExtItemT = Type of the extension item used to store the parameter
44  *
45  * When unsetting the mode, the extension is automatically unset.
46  */
47 template <typename T, typename ExtItemT>
48 class ParamMode : public ParamModeBase
49 {
50  public:
51         ExtItemT ext;
52
53         /**
54          * @param Creator Module handling this mode
55          * @param Name The internal name of this mode
56          * @param modeletter The mode letter of this mode
57          * @param ps The parameter type of this mode, one of ParamSpec
58          */
59         ParamMode(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps = PARAM_SETONLY)
60                 : ParamModeBase(Creator, Name, modeletter, ps)
61                 , ext("parammode_" + Name, ExtensionItem::EXT_CHANNEL, Creator)
62         {
63         }
64
65         void OnUnsetInternal(User* source, Channel* chan) CXX11_OVERRIDE
66         {
67                 this->OnUnset(source, chan);
68                 ext.unset(chan);
69         }
70
71         void GetParameter(Channel* chan, std::string& out) CXX11_OVERRIDE
72         {
73                 T* mh = static_cast<T*>(this);
74                 mh->SerializeParam(chan, ext.get(chan), out);
75         }
76 };