InspIRCd  3.0
parammode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2018-2019 Sadie Powell <[email protected]>
5  * Copyright (C) 2014-2015 Attila Molnar <[email protected]>
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 
47 template <typename T, typename ExtItemT>
48 class ParamMode : public ParamModeBase
49 {
50  public:
51  ExtItemT ext;
52 
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 };
ModeHandler::OnModeChange
virtual ModeAction OnModeChange(User *source, User *dest, Channel *channel, std::string &parameter, bool adding)
Definition: mode.cpp:82
ExtensionItem
Definition: extensible.h:35
ParamMode::ParamMode
ParamMode(Module *Creator, const std::string &Name, char modeletter, ParamSpec ps=PARAM_SETONLY)
Definition: parammode.h:59
ParamMode
Definition: parammode.h:48
Channel
Definition: channels.h:40
Module
Definition: modules.h:247
User
Definition: users.h:233
ModeHandler::ModeHandler
ModeHandler(Module *me, const std::string &name, char modeletter, ParamSpec params, ModeType type, Class mclass=MC_OTHER)
Definition: mode.cpp:33
ParamModeBase
Definition: parammode.h:23
ModeHandler
Definition: mode.h:99