InspIRCd  3.0
listmode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  *
6  * This file is part of InspIRCd. InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 #pragma once
21 
24 class CoreExport ListModeBase : public ModeHandler
25 {
26  public:
29  struct ListItem
30  {
31  std::string setter;
32  std::string mask;
33  time_t time;
34  ListItem(const std::string& Mask, const std::string& Setter, time_t Time)
35  : setter(Setter), mask(Mask), time(Time) { }
36  };
37 
40  typedef std::vector<ListItem> ModeList;
41 
42  private:
43  class ChanData
44  {
45  public:
46  ModeList list;
47  int maxitems;
48 
49  ChanData() : maxitems(-1) { }
50  };
51 
54  struct ListLimit
55  {
56  std::string mask;
57  unsigned int limit;
58  ListLimit(const std::string& Mask, unsigned int Limit) : mask(Mask), limit(Limit) { }
59  bool operator==(const ListLimit& other) const { return (this->mask == other.mask && this->limit == other.limit); }
60  };
61 
64  typedef std::vector<ListLimit> limitlist;
65 
67  static const unsigned int DEFAULT_LIST_SIZE = 100;
68 
73  unsigned int FindLimit(const std::string& channame);
74 
83  unsigned int GetLimitInternal(const std::string& channame, ChanData* cd);
84 
85  protected:
88  unsigned int listnumeric;
91  unsigned int endoflistnumeric;
94  std::string endofliststring;
97  bool tidy;
100  std::string configtag;
104  limitlist chanlimits;
105 
109 
110  public:
121  ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag = "banlist");
122 
127  unsigned int GetLimit(Channel* channel);
128 
131  unsigned int GetLowerLimit();
132 
137  ModeList* GetList(Channel* channel);
138 
144  virtual void DisplayList(User* user, Channel* channel);
145 
152  virtual void DisplayEmptyList(User* user, Channel* channel);
153 
161  virtual void RemoveMode(Channel* channel, Modes::ChangeList& changelist);
162 
165  void DoRehash();
166 
170  virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding);
171 
179  virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
180 
187  virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
188 
195  virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
196 
203  virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
204 };
205 
207 {
208  ChanData* cd = extItem.get(channel);
209  if (!cd)
210  return NULL;
211 
212  return &cd->list;
213 }
Definition: mode.h:95
std::vector< ListItem > ModeList
Definition: listmode.h:40
Definition: listmode.h:29
limitlist chanlimits
Definition: listmode.h:104
std::string endofliststring
Definition: listmode.h:94
unsigned int endoflistnumeric
Definition: listmode.h:91
Definition: users.h:224
std::string configtag
Definition: listmode.h:100
bool tidy
Definition: listmode.h:97
Definition: modules.h:245
SimpleExtItem< ChanData > extItem
Definition: listmode.h:108
ModeList * GetList(Channel *channel)
Definition: listmode.h:206
unsigned int listnumeric
Definition: listmode.h:88
Definition: listmode.h:24
Definition: modechange.h:51
Definition: channels.h:37