]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/mode.h
d09d62439fc342a4121c6757dad3732d93ea6ad6
[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 ModeHandler
49 {
50         char mode;
51         int n_params_on;
52         int n_params_off;
53         bool list;
54         ModeType m_type;
55         bool oper;
56
57  public:
58         ModeHandler(char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly);
59         virtual ~ModeHandler();
60
61         bool IsListMode();
62         ModeType GetModeType();
63         bool NeedsOper();
64         int GetNumParams(bool adding);
65         char GetModeChar();
66
67         virtual ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding); /* Can change the mode parameter as its a ref */
68         virtual void DisplayList(userrec* user, chanrec* channel);
69         virtual bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel);
70 };
71
72 class ModeWatcher
73 {
74         char mode;
75         ModeType m_type;
76
77  public:
78         ModeWatcher(char modeletter, ModeType type);
79         virtual ~ModeWatcher();
80
81         char GetModeChar();
82         ModeType GetModeType();
83
84         virtual bool BeforeMode(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding, ModeType type); /* Can change the mode parameter */
85         virtual void AfterMode(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter, bool adding, ModeType type);
86 };
87
88 typedef std::vector<ModeWatcher*>::iterator ModeWatchIter;
89
90 class ModeParser
91 {
92  private:
93         /**
94          * Mode handlers for each mode, to access a handler subtract
95          * 65 from the ascii value of the mode letter.
96          */
97         ModeHandler* modehandlers[64];
98         /**
99          * Mode watcher classes
100          */
101         std::vector<ModeWatcher*> modewatchers[64];
102         
103         char* GiveOps(userrec *user,char *dest,chanrec *chan,int status);
104         char* GiveHops(userrec *user,char *dest,chanrec *chan,int status);
105         char* GiveVoice(userrec *user,char *dest,chanrec *chan,int status);
106         char* TakeOps(userrec *user,char *dest,chanrec *chan,int status);
107         char* TakeHops(userrec *user,char *dest,chanrec *chan,int status);
108         char* TakeVoice(userrec *user,char *dest,chanrec *chan,int status);
109         char* AddBan(userrec *user,char *dest,chanrec *chan,int status);
110         char* TakeBan(userrec *user,char *dest,chanrec *chan,int status);
111         userrec* SanityChecks(userrec *user,char *dest,chanrec *chan,int status);
112         char* Grant(userrec *d,chanrec *chan,int MASK);
113         char* Revoke(userrec *d,chanrec *chan,int MASK);
114  public:
115         void Process(char **parameters, int pcnt, userrec *user, bool servermode);
116
117         std::string CompressModes(std::string modes,bool channelmodes);
118         void ProcessModes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local);
119         bool AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride);
120         bool ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding);
121         void ServerMode(char **parameters, int pcnt, userrec *user);
122 };
123
124 class cmd_mode : public command_t
125 {
126  public:
127         cmd_mode () : command_t("MODE",0,1) { }
128         void Handle(char **parameters, int pcnt, userrec *user);
129 };
130
131 #endif