InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
mode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  * Copyright (C) 2004-2006, 2008 Craig Edwards <craigedwards@brainbox.cc>
6  * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8  *
9  * This file is part of InspIRCd. InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #ifndef MODE_H
24 #define MODE_H
25 
26 #include "ctables.h"
27 
32 enum ModeType
33 {
35  MODETYPE_USER = 0,
37  MODETYPE_CHANNEL = 1
38 };
39 
43 enum ModeAction
44 {
45  MODEACTION_DENY = 0, /* Drop the mode change, AND a parameter if its a parameterized mode */
46  MODEACTION_ALLOW = 1 /* Allow the mode */
47 };
48 
54 enum ModeMasks
55 {
56  MASK_USER = 128, /* A user mode */
57  MASK_CHANNEL = 0 /* A channel mode */
58 };
59 
68 enum PrefixModeValue
69 {
70  /* +v */
71  VOICE_VALUE = 10000,
72  /* +h */
73  HALFOP_VALUE = 20000,
74  /* +o */
75  OP_VALUE = 30000
76 };
77 
78 enum ParamSpec
79 {
81  PARAM_NONE,
83  PARAM_SETONLY,
85  PARAM_ALWAYS
86 };
87 
102 class CoreExport ModeHandler : public ServiceProvider
103 {
104  protected:
108  TranslateType m_paramtype;
109 
112  ParamSpec parameters_taken;
113 
117  char mode;
118 
121  char prefix;
122 
127  bool oper;
128 
139  bool list;
140 
145  ModeType m_type;
146 
151 
152  public:
163  ModeHandler(Module* me, const std::string& name, char modeletter, ParamSpec params, ModeType type);
164  virtual CullResult cull();
165  virtual ~ModeHandler();
169  bool IsListMode();
175  inline char GetPrefix() const { return prefix; }
183  virtual unsigned int GetPrefixRank();
187  inline ModeType GetModeType() const { return m_type; }
191  inline TranslateType GetTranslateType() const { return m_paramtype; }
195  inline bool NeedsOper() const { return oper; }
202  int GetNumParams(bool adding);
207  inline char GetModeChar() { return mode; }
208 
211  virtual std::string GetUserParameter(User* useor);
212 
221  virtual ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding);
222 
235  virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding); /* Can change the mode parameter as its a ref */
242  virtual void DisplayList(User* user, Channel* channel);
243 
250  virtual void OnParameterMissing(User* user, User* dest, Channel* channel);
251 
257  virtual void DisplayEmptyList(User* user, Channel* channel);
258 
269  virtual bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel* channel);
270 
280  virtual void RemoveMode(User* user, irc::modestacker* stack = NULL);
281 
291  virtual void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
292 
293  inline unsigned int GetLevelRequired() const { return levelrequired; }
294 };
295 
301 class CoreExport SimpleUserModeHandler : public ModeHandler
302 {
303  public:
304  SimpleUserModeHandler(Module* Creator, const std::string& Name, char modeletter)
305  : ModeHandler(Creator, Name, modeletter, PARAM_NONE, MODETYPE_USER) {}
306  virtual ~SimpleUserModeHandler() {}
307  virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
308 };
309 
315 class CoreExport SimpleChannelModeHandler : public ModeHandler
316 {
317  public:
318  SimpleChannelModeHandler(Module* Creator, const std::string& Name, char modeletter)
319  : ModeHandler(Creator, Name, modeletter, PARAM_NONE, MODETYPE_CHANNEL) {}
320  virtual ~SimpleChannelModeHandler() {}
321  virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
322 };
323 
324 class CoreExport ParamChannelModeHandler : public ModeHandler
325 {
326  public:
327  ParamChannelModeHandler(Module* Creator, const std::string& Name, char modeletter)
328  : ModeHandler(Creator, Name, modeletter, PARAM_SETONLY, MODETYPE_CHANNEL) {}
329  virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
331  virtual bool ParamValidate(std::string& parameter);
332 };
333 
340 class CoreExport ModeWatcher : public classbase
341 {
342  protected:
346  char mode;
350  ModeType m_type;
351 
352  public:
353  ModuleRef creator;
357  ModeWatcher(Module* creator, char modeletter, ModeType type);
361  virtual ~ModeWatcher();
362 
367  char GetModeChar();
372  ModeType GetModeType();
373 
387  virtual bool BeforeMode(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, ModeType type);
398  virtual void AfterMode(User* source, User* dest, Channel* channel, const std::string &parameter, bool adding, ModeType type);
399 };
400 
401 typedef std::vector<ModeWatcher*>::iterator ModeWatchIter;
402 
408 class CoreExport ModeParser
409 {
410  private:
416  ModeHandler* modehandlers[256];
421  std::vector<ModeWatcher*> modewatchers[256];
425  void DisplayCurrentModes(User *user, User* targetuser, Channel* targetchannel, const char* text);
429  void DisplayListModes(User* user, Channel* chan, std::string &mode_sequence);
430 
434  ModeAction TryMode(User* user, User* targu, Channel* targc, bool adding, unsigned char mode, std::string &param, bool SkipACL);
435 
439  std::string LastParse;
440  std::vector<std::string> LastParseParams;
441  std::vector<TranslateType> LastParseTranslate;
442 
443  unsigned int sent[256];
444 
445  unsigned int seq;
446 
447  public:
448 
451  ModeParser();
452  ~ModeParser();
453 
457  User* SanityChecks(User *user,const char *dest,Channel *chan,int status);
471  static void CleanMask(std::string &mask);
477  const std::string& GetLastParse();
478  const std::vector<std::string>& GetLastParseParams() { return LastParseParams; }
479  const std::vector<TranslateType>& GetLastParseTranslate() { return LastParseTranslate; }
483  bool AddMode(ModeHandler* mh);
492  bool DelMode(ModeHandler* mh);
493 
501  bool AddModeWatcher(ModeWatcher* mw);
509  bool DelModeWatcher(ModeWatcher* mw);
518  void Process(const std::vector<std::string>& parameters, User *user, bool merge = false);
519 
525  ModeHandler* FindMode(unsigned const char modeletter, ModeType mt);
526 
532  ModeHandler* FindPrefix(unsigned const char pfxletter);
533 
537  std::string UserModeList();
538 
542  std::string ChannelModeList();
543 
547  std::string ParaModeList();
548 
555  std::string GiveModeList(ModeMasks m);
556 
557  static bool PrefixComparison(ModeHandler* one, ModeHandler* two);
558 
562  std::string BuildPrefixes(bool lettersAndModes = true);
563 };
564 
565 #endif
Definition: mode.h:102
ModeType GetModeType() const
Definition: mode.h:187
virtual CullResult cull()
Definition: base.cpp:34
Definition: mode.h:324
bool list
Definition: mode.h:139
Definition: mode.h:340
Definition: hashcomp.h:219
Definition: mode.h:301
bool NeedsOper() const
Definition: mode.h:195
char mode
Definition: mode.h:346
ModeType m_type
Definition: mode.h:145
Definition: mode.h:315
Definition: users.h:230
TranslateType GetTranslateType() const
Definition: mode.h:191
Definition: base.h:42
ParamSpec parameters_taken
Definition: mode.h:112
char prefix
Definition: mode.h:121
Definition: mode.h:408
virtual ModeAction OnModeChange(User *source, User *dest, Channel *channel, std::string &parameter, bool adding)
Definition: mode.cpp:104
TranslateType m_paramtype
Definition: mode.h:108
Definition: modules.h:350
Definition: modules.h:75
ModeType m_type
Definition: mode.h:350
char mode
Definition: mode.h:117
int levelrequired
Definition: mode.h:150
Definition: base.h:244
ModeHandler(Module *me, const std::string &name, char modeletter, ParamSpec params, ModeType type)
Definition: mode.cpp:52
char GetModeChar()
Definition: mode.h:207
Definition: base.h:32
bool oper
Definition: mode.h:127
char GetPrefix() const
Definition: mode.h:175
Definition: channels.h:59