Anope IRC Services  Version 2.0
modes.h
Go to the documentation of this file.
1 /* Mode support
2  *
3  * Copyright (C) 2008-2011 Adam <Adam@anope.org>
4  * Copyright (C) 2008-2014 Anope Team <team@anope.org>
5  *
6  * Please read COPYING and README for further details.
7  */
8 
9 #ifndef MODES_H
10 #define MODES_H
11 
12 #include "anope.h"
13 #include "base.h"
14 
18 {
19  /* Regular mode */
21  /* b/e/I */
23  /* k/l etc */
25  /* v/h/o/a/q */
27 };
28 
29 /* Classes of modes, Channel modes and User modes
30  */
32 {
35 };
36 
39 class CoreExport Mode : public Base
40 {
41  public:
42  /* Mode name */
44  /* Class of mode this is (user/channel) */
46  /* Mode char for this, eg 'b' */
47  char mchar;
48  /* Type of mode this is, eg MODE_LIST */
50 
57  Mode(const Anope::string &mname, ModeClass mclass, char mc, ModeType type);
58  virtual ~Mode();
59 
63  virtual bool CanSet(User *u) const;
64 };
65 
68 class CoreExport UserMode : public Mode
69 {
70  public:
75  UserMode(const Anope::string &name, char mc);
76 };
77 
79 {
80  public:
85  UserModeParam(const Anope::string &name, char mc);
86 
91  virtual bool IsValid(Anope::string &value) const { return true; }
92 };
93 
96 class CoreExport ChannelMode : public Mode
97 {
98  public:
99  /* channel modes that can posssibly unwrap this mode */
100  std::vector<ChannelMode *> listeners;
101 
106  ChannelMode(const Anope::string &name, char mc);
107 
108  bool CanSet(User *u) const anope_override;
109 
112  virtual ChannelMode *Wrap(Anope::string &param);
113 
116  ChannelMode *Unwrap(Anope::string &param);
117 
120  virtual ChannelMode *Unwrap(ChannelMode *, Anope::string &param);
121 };
122 
126 {
127  public:
132  ChannelModeList(const Anope::string &name, char mc);
133 
138  virtual bool IsValid(Anope::string &mask) const;
139 
146  virtual bool Matches(User *u, const Entry *e) { return false; }
147 
152  virtual void OnAdd(Channel *chan, const Anope::string &mask) { }
153 
158  virtual void OnDel(Channel *chan, const Anope::string &mask) { }
159 };
160 
164 {
165  public:
171  ChannelModeParam(const Anope::string &name, char mc, bool minus_no_arg = false);
172 
173  /* Should we send an arg when unsetting this mode? */
175 
180  virtual bool IsValid(Anope::string &value) const { return true; }
181 };
182 
186 {
187  public:
188  /* The symbol, eg @ % + */
189  char symbol;
190  /* The "level" of the mode, used to compare with other modes.
191  * Used so we know op > halfop > voice etc.
192  */
193  short level;
194 
201  ChannelModeStatus(const Anope::string &name, char mc, char msymbol, short mlevel);
202 };
203 
207 template<typename T>
209 {
212 
213  public:
214  ChannelModeVirtual(const Anope::string &mname, const Anope::string &basename);
215 
217 
219 
220  ChannelMode *Unwrap(ChannelMode *cm, Anope::string &param) = 0;
221 };
222 
223 /* The status a user has on a channel (+v, +h, +o) etc */
225 {
227  public:
228  ChannelStatus();
229  ChannelStatus(const Anope::string &modes);
230  void AddMode(char c);
231  void DelMode(char c);
232  bool HasMode(char c) const;
233  bool Empty() const;
234  void Clear();
235  const Anope::string &Modes() const;
236  Anope::string BuildModePrefixList() const;
237 };
238 
240 {
241  public:
242  UserModeOperOnly(const Anope::string &mname, char um) : UserMode(mname, um) { }
243 
244  bool CanSet(User *u) const anope_override;
245 };
246 
248 {
249  public:
250  UserModeNoone(const Anope::string &mname, char um) : UserMode(mname, um) { }
251 
252  bool CanSet(User *u) const anope_override;
253 };
254 
258 {
259  public:
260  ChannelModeKey(char mc) : ChannelModeParam("KEY", mc) { }
261 
262  bool IsValid(Anope::string &value) const anope_override;
263 };
264 
268 {
269  public:
270  ChannelModeOperOnly(const Anope::string &mname, char mc) : ChannelMode(mname, mc) { }
271 
272  /* Opers only */
273  bool CanSet(User *u) const anope_override;
274 };
275 
279 {
280  public:
281  ChannelModeNoone(const Anope::string &mname, char mc) : ChannelMode(mname, mc) { }
282 
283  bool CanSet(User *u) const anope_override;
284 };
285 
293 {
294  public:
295 
296  /* Number of generic channel and user modes we are tracking */
297  static unsigned GenericChannelModes;
298  static unsigned GenericUserModes;
299 
304  static bool AddUserMode(UserMode *um);
305 
310  static bool AddChannelMode(ChannelMode *cm);
311 
315  static void RemoveUserMode(UserMode *um);
316 
320  static void RemoveChannelMode(ChannelMode *cm);
321 
326  static ChannelMode *FindChannelModeByChar(char mode);
327 
332  static UserMode *FindUserModeByChar(char mode);
333 
338  static ChannelMode *FindChannelModeByName(const Anope::string &name);
339 
344  static UserMode *FindUserModeByName(const Anope::string &name);
345 
350  static char GetStatusChar(char symbol);
351 
352  static const std::vector<ChannelMode *> &GetChannelModes();
353  static const std::vector<UserMode *> &GetUserModes();
354  static const std::vector<ChannelModeStatus *> &GetStatusChannelModesByRank();
355  static void RebuildStatusModes();
356 
364  static void StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool set, const Anope::string &param = "");
365 
373  static void StackerAdd(BotInfo *bi, User *u, UserMode *um, bool set, const Anope::string &param = "");
374 
377  static void ProcessModes();
378 
381  static void StackerDel(User *u);
382  static void StackerDel(Channel *c);
383  static void StackerDel(Mode *m);
384 };
385 
389 {
392  public:
393  unsigned short cidr_len;
394  Anope::string nick, user, host, real;
395 
400  Entry(const Anope::string &mode, const Anope::string &host);
401 
405  const Anope::string GetMask() const;
406 
407  const Anope::string GetNUHMask() const;
408 
414  bool Matches(User *u, bool full = false) const;
415 };
416 
417 #endif // MODES_H
Definition: modes.h:39
Definition: bots.h:24
Definition: base.h:17
virtual bool Matches(User *u, const Entry *e)
Definition: modes.h:146
bool minus_no_arg
Definition: modes.h:174
unsigned short cidr_len
Definition: modes.h:393
ChannelModeOperOnly(const Anope::string &mname, char mc)
Definition: modes.h:270
static unsigned GenericChannelModes
Definition: modes.h:297
UserModeOperOnly(const Anope::string &mname, char um)
Definition: modes.h:242
virtual bool IsValid(Anope::string &value) const
Definition: modes.h:91
Definition: users.h:34
Anope::string modes
Definition: modes.h:226
ModeClass
Definition: modes.h:31
ChannelMode * basech
Definition: modes.h:211
UserModeNoone(const Anope::string &mname, char um)
Definition: modes.h:250
std::vector< ChannelMode * > listeners
Definition: modes.h:100
ModeClass mclass
Definition: modes.h:45
Anope::string name
Definition: modes.h:390
ModeType type
Definition: modes.h:49
Anope::string user
Definition: modes.h:394
Definition: modes.h:68
char mchar
Definition: modes.h:47
virtual bool IsValid(Anope::string &value) const
Definition: modes.h:180
#define anope_override
Definition: services.h:56
virtual void OnDel(Channel *chan, const Anope::string &mask)
Definition: modes.h:158
ChannelModeKey(char mc)
Definition: modes.h:260
bool CanSet(User *u) const anope_override
Definition: modes.cpp:144
Anope::string base
Definition: modes.h:210
static unsigned GenericUserModes
Definition: modes.h:298
ChannelModeNoone(const Anope::string &mname, char mc)
Definition: modes.h:281
#define CoreExport
Definition: services.h:62
static void StackerDel(std::map< T *, StackerInfo * > &map, T *obj)
Definition: modes.cpp:667
virtual bool CanSet(User *u) const
Definition: modes.cpp:126
Anope::string name
Definition: access.cpp:22
Definition: modes.h:34
Definition: modes.h:388
Anope::string name
Definition: modes.h:43
virtual void OnAdd(Channel *chan, const Anope::string &mask)
Definition: modes.h:152
ModeType
Definition: modes.h:17
Anope::string mask
Definition: modes.h:391