InspIRCd  3.0
listmode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2018 B00mX0r <[email protected]>
5  * Copyright (C) 2013-2014 Attila Molnar <[email protected]>
6  * Copyright (C) 2013, 2017-2019 Sadie Powell <[email protected]>
7  *
8  * This file is part of InspIRCd. InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #pragma once
23 
26 class CoreExport ListModeBase : public ModeHandler
27 {
28  public:
31  struct ListItem
32  {
33  std::string setter;
34  std::string mask;
35  time_t time;
36  ListItem(const std::string& Mask, const std::string& Setter, time_t Time)
37  : setter(Setter), mask(Mask), time(Time) { }
38  };
39 
42  typedef std::vector<ListItem> ModeList;
43 
44  private:
45  class ChanData
46  {
47  public:
48  ModeList list;
49  int maxitems;
50 
51  ChanData() : maxitems(-1) { }
52  };
53 
56  struct ListLimit
57  {
58  std::string mask;
59  unsigned int limit;
60  ListLimit(const std::string& Mask, unsigned int Limit) : mask(Mask), limit(Limit) { }
61  bool operator==(const ListLimit& other) const { return (this->mask == other.mask && this->limit == other.limit); }
62  };
63 
66  typedef std::vector<ListLimit> limitlist;
67 
69  static const unsigned int DEFAULT_LIST_SIZE = 100;
70 
75  unsigned int FindLimit(const std::string& channame);
76 
85  unsigned int GetLimitInternal(const std::string& channame, ChanData* cd);
86 
87  protected:
90  unsigned int listnumeric;
91 
94  unsigned int endoflistnumeric;
95 
98  std::string endofliststring;
99 
102  bool tidy;
103 
107  limitlist chanlimits;
108 
112 
113  public:
123  ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string& eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy);
124 
126  bool HasVariableLength() const { return chanlimits.size() > 1; }
127 
132  unsigned int GetLimit(Channel* channel);
133 
136  unsigned int GetLowerLimit();
137 
142  ModeList* GetList(Channel* channel);
143 
149  void DisplayList(User* user, Channel* channel) CXX11_OVERRIDE;
150 
157  void DisplayEmptyList(User* user, Channel* channel) CXX11_OVERRIDE;
158 
166  void RemoveMode(Channel* channel, Modes::ChangeList& changelist) CXX11_OVERRIDE;
167 
170  void DoRehash();
171 
175  ModeAction OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
176 
184  virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
185 
193  virtual void OnParameterMissing(User* user, User* dest, Channel* channel) CXX11_OVERRIDE;
194 
201  virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
202 
209  virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
210 
217  virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
218 };
219 
221 {
222  ChanData* cd = extItem.get(channel);
223  if (!cd)
224  return NULL;
225 
226  return &cd->list;
227 }
ListModeBase::GetList
ModeList * GetList(Channel *channel)
Definition: listmode.h:220
ModeHandler::OnModeChange
virtual ModeAction OnModeChange(User *source, User *dest, Channel *channel, std::string &parameter, bool adding)
Definition: mode.cpp:82
ListModeBase::endoflistnumeric
unsigned int endoflistnumeric
Definition: listmode.h:94
Modes::ChangeList
Definition: modechange.h:52
ModeHandler::RemoveMode
void RemoveMode(User *user)
Definition: mode.cpp:839
ModeHandler::DisplayEmptyList
virtual void DisplayEmptyList(User *user, Channel *channel)
Definition: mode.cpp:91
ListModeBase::endofliststring
std::string endofliststring
Definition: listmode.h:98
ListModeBase::ModeList
std::vector< ListItem > ModeList
Definition: listmode.h:42
ListModeBase::chanlimits
limitlist chanlimits
Definition: listmode.h:107
ListModeBase::ListItem
Definition: listmode.h:31
ModeHandler::DisplayList
virtual void DisplayList(User *user, Channel *channel)
Definition: mode.cpp:87
ListModeBase::listnumeric
unsigned int listnumeric
Definition: listmode.h:90
ModeHandler::OnParameterMissing
virtual void OnParameterMissing(User *user, User *dest, Channel *channel)
Definition: mode.cpp:95
Channel
Definition: channels.h:40
ListModeBase::tidy
bool tidy
Definition: listmode.h:102
ListModeBase::extItem
SimpleExtItem< ChanData > extItem
Definition: listmode.h:111
ListModeBase
Definition: listmode.h:26
SimpleExtItem< ChanData >
Module
Definition: modules.h:247
User
Definition: users.h:233
ListModeBase::HasVariableLength
bool HasVariableLength() const
Definition: listmode.h:126
ModeHandler
Definition: mode.h:99