]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/mode.h
Start of mode parser refactoring
[user/henk/code/inspircd.git] / include / mode.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __MODE_H
18 #define __MODE_H
19
20 // include the common header files
21
22 #include <typeinfo>
23 #include <iostream>
24 #include <string>
25 #include <deque>
26 #include <sstream>
27 #include <vector>
28 #include "users.h"
29 #include "channels.h"
30 #include "ctables.h"
31
32 enum UserModeBits {
33         UM_INVISIBLE = 1,
34         UM_SERVERNOTICE = 2,
35         UM_WALLOPS = 4
36 };
37
38 enum ModeType {
39         MODETYPE_USER = 0,
40         MODETYPE_CHANNEL = 1
41 };
42
43 enum ModeAction {
44         MODEACTION_DENY = 0, /* Drop the mode change, AND a parameter if its a parameterized mode */
45         MODEACTION_ALLOW = 1 /* Allow the mode */
46 };
47
48 class ModeOutput
49 {
50  private:
51         std::string par;
52         ModeAction act;
53  public:
54         ModeOutput(std::string parameter, ModeAction action);
55         ModeAction GetAction();
56         std::string& GetParameter();
57 };
58
59 class ModeHandler
60 {
61         char mode;
62         int n_params;
63         bool list;
64         ModeType m_type;
65         bool oper;
66
67  public:
68         ModeHandler(char modeletter, int parameters, bool listmode, ModeType type, bool operonly);
69         virtual ~ModeHandler();
70
71         bool IsListMode();
72         ModeType GetModeType();
73         bool NeedsOper();
74         int GetNumParams();
75         char GetModeChar();
76
77         virtual ModeOutput OnModeChange(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter, bool adding);
78         virtual void DisplayList(userrec* user, chanrec* channel);
79         virtual bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel);
80 };
81
82 class ModeWatcher
83 {
84         char mode;
85         ModeType m_type;
86
87  public:
88         ModeWatcher(char modeletter, ModeType type);
89         virtual ~ModeWatcher();
90
91         char GetModeChar();
92         ModeType GetModeType();
93
94         virtual bool BeforeMode(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter, bool adding);
95         virtual void AfterMode(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter, bool adding);
96 };
97
98 class ModeParser
99 {
100  private:
101         char* GiveOps(userrec *user,char *dest,chanrec *chan,int status);
102         char* GiveHops(userrec *user,char *dest,chanrec *chan,int status);
103         char* GiveVoice(userrec *user,char *dest,chanrec *chan,int status);
104         char* TakeOps(userrec *user,char *dest,chanrec *chan,int status);
105         char* TakeHops(userrec *user,char *dest,chanrec *chan,int status);
106         char* TakeVoice(userrec *user,char *dest,chanrec *chan,int status);
107         char* AddBan(userrec *user,char *dest,chanrec *chan,int status);
108         char* TakeBan(userrec *user,char *dest,chanrec *chan,int status);
109         userrec* SanityChecks(userrec *user,char *dest,chanrec *chan,int status);
110         char* Grant(userrec *d,chanrec *chan,int MASK);
111         char* Revoke(userrec *d,chanrec *chan,int MASK);
112  public:
113         std::string CompressModes(std::string modes,bool channelmodes);
114         void ProcessModes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local);
115         bool AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride);
116         bool ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding);
117         void ServerMode(char **parameters, int pcnt, userrec *user);
118 };
119
120 class cmd_mode : public command_t
121 {
122  public:
123         cmd_mode () : command_t("MODE",0,1) { }
124         void Handle(char **parameters, int pcnt, userrec *user);
125 };
126
127 #endif