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