2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2014-2015 Attila Molnar <attilamolnar@hush.com>
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.
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
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/>.
23 class CoreExport ParamModeBase : public ModeHandler
26 virtual void OnUnsetInternal(User* source, Channel* chan) = 0;
29 ParamModeBase(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps)
30 : ModeHandler(Creator, Name, modeletter, ps, MODETYPE_CHANNEL, MC_PARAM) { }
32 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& param, bool adding) CXX11_OVERRIDE;
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;
41 /** Defines a parameter mode
43 * ExtItemT = Type of the extension item used to store the parameter
45 * When unsetting the mode, the extension is automatically unset.
47 template <typename T, typename ExtItemT>
48 class ParamMode : public ParamModeBase
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
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)
65 void OnUnsetInternal(User* source, Channel* chan) CXX11_OVERRIDE
67 this->OnUnset(source, chan);
71 void GetParameter(Channel* chan, std::string& out) CXX11_OVERRIDE
73 T* mh = static_cast<T*>(this);
74 mh->SerializeParam(chan, ext.get(chan), out);