]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/channels.h
Alter SetModeParam to take const char* to save on casts, notice a load of modules...
[user/henk/code/inspircd.git] / include / channels.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 __CHANNELS_H__
18 #define __CHANNELS_H__
19
20 #include "inspircd_config.h"
21 #include "base.h"
22 #include <time.h>
23 #include <vector>
24 #include <string>
25 #include <map>
26
27 /** RFC1459 channel modes
28  */
29 enum ChannelModes {
30         CM_TOPICLOCK = 't'-65,
31         CM_NOEXTERNAL = 'n'-65,
32         CM_INVITEONLY = 'i'-65,
33         CM_MODERATED = 'm'-65,
34         CM_SECRET = 's'-65,
35         CM_PRIVATE = 'p'-65,
36         CM_KEY = 'k'-65,
37         CM_LIMIT = 'l'-65
38 };
39
40 class userrec;
41
42 /** Holds an entry for a ban list, exemption list, or invite list.
43  * This class contains a single element in a channel list, such as a banlist.
44  */
45 class HostItem : public classbase
46 {
47  public:
48         time_t set_time;
49         char set_by[NICKMAX];
50         char data[MAXBUF];
51
52         HostItem() { /* stub */ }
53         virtual ~HostItem() { /* stub */ }
54 };
55
56 /** A subclass of HostItem designed to hold channel bans (+b)
57  */
58 class BanItem : public HostItem
59 {
60 };
61
62 /** A subclass of HostItem designed to hold channel exempts (+e)
63  */
64 class ExemptItem : public HostItem
65 {
66 };
67
68 /** A subclass of HostItem designed to hold channel invites (+I)
69  */
70 class InviteItem : public HostItem
71 {
72 };
73
74 /** Holds a complete ban list
75  */
76 typedef std::vector<BanItem>    BanList;
77
78 /** Holds a complete exempt list
79  */
80 typedef std::vector<ExemptItem> ExemptList;
81
82 /** Holds a complete invite list
83  */
84 typedef std::vector<InviteItem> InviteList;
85
86 /** A list of users on a channel
87  */
88 typedef std::map<userrec*,userrec*> CUList;
89
90 /** Shorthand for CUList::iterator
91  */
92 typedef CUList::iterator CUListIter;
93 typedef CUList::const_iterator CUListConstIter;
94
95 /** A list of custom modes parameters on a channel
96  */
97 typedef std::map<char,char*> CustomModeList;
98
99 /** Holds all relevent information for a channel.
100  * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
101  * etc, and an instance of the BanList type.
102  */
103 class chanrec : public Extensible
104 {
105  public:
106         /** The channels name.
107          */
108         char name[CHANMAX]; /* channel name */
109         /** Modes for the channel.
110          * This is not a null terminated string! It is a hash where
111          * each item in it represents if a mode is set. For example
112          * for mode +A, index 0. Use modechar-65 to calculate which
113          * field to check.
114          */
115         char modes[64];
116
117         /** User lists
118          * There are four user lists, one for 
119          * all the users, one for the ops, one for
120          * the halfops and another for the voices.
121          */
122         CUList internal_userlist;
123         CUList internal_op_userlist;
124         CUList internal_halfop_userlist;
125         CUList internal_voice_userlist;
126
127         /** Parameters for custom modes
128          */
129         CustomModeList custom_mode_params;
130
131         /** Channel topic.
132          * If this is an empty string, no channel topic is set.
133          */
134         char topic[MAXTOPIC];
135         /** Creation time.
136          */
137         time_t created;
138         /** Time topic was set.
139          * If no topic was ever set, this will be equal to chanrec::created
140          */
141         time_t topicset;
142         /** The last user to set the topic.
143          * If this member is an empty string, no topic was ever set.
144          */
145         char setby[NICKMAX];
146
147         /** Contains the channel user limit.
148          * If this value is zero, there is no limit in place.
149          */
150         short int limit;
151         
152         /** Contains the channel key.
153          * If this value is an empty string, there is no channel key in place.
154          */
155         char key[32];
156         
157         /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
158          */
159         //char binarymodes;
160         
161         /** The list of all bans set on the channel.
162          */
163         BanList bans;
164         
165         /** Sets or unsets a custom mode in the channels info
166          * @param mode The mode character to set or unset
167          * @param mode_on True if you want to set the mode or false if you want to remove it
168          */
169         void SetMode(char mode,bool mode_on);
170
171         /** Sets or unsets the parameters for a custom mode in a channels info
172          * @param mode The mode character to set or unset
173          * @param parameter The parameter string to associate with this mode character
174          * @param mode_on True if you want to set the mode or false if you want to remove it
175          */
176         void SetModeParam(char mode,const char* parameter,bool mode_on);
177  
178         /** Returns true if a mode is set on a channel
179           * @param mode The mode character you wish to query
180           * @return True if the custom mode is set, false if otherwise
181           */
182         bool IsModeSet(char mode);
183
184         /** Returns the parameter for a custom mode on a channel.
185           * @param mode The mode character you wish to query
186           *
187           * For example if "+L #foo" is set, and you pass this method
188           * 'L', it will return '#foo'. If the mode is not set on the
189           * channel, or the mode has no parameters associated with it,
190           * it will return an empty string.
191           *
192           * @return The parameter for this mode is returned, or an empty string
193           */
194         std::string GetModeParameter(char mode);
195
196         /** Obtain the channel "user counter"
197          * This returns the channel reference counter, which is initialized
198          * to 0 when the channel is created and incremented/decremented
199          * upon joins, parts quits and kicks.
200          *
201          * @return The number of users on this channel
202          */
203         long GetUserCounter();
204
205         /** Add a user pointer to the internal reference list
206          * @param user The user to add
207          *
208          * The data inserted into the reference list is a table as it is
209          * an arbitary pointer compared to other users by its memory address,
210          * as this is a very fast 32 or 64 bit integer comparison.
211          */
212         void AddUser(userrec* user);
213         void AddOppedUser(userrec* user);
214         void AddHalfoppedUser(userrec* user);
215         void AddVoicedUser(userrec* user);
216
217         /** Delete a user pointer to the internal reference list
218          * @param user The user to delete
219          * @return number of users left on the channel
220          */
221         unsigned long DelUser(userrec* user);
222         void DelOppedUser(userrec* user);
223         void DelHalfoppedUser(userrec* user);
224         void DelVoicedUser(userrec* user);
225
226         /** Obtain the internal reference list
227          * The internal reference list contains a list of userrec*.
228          * These are used for rapid comparison to determine
229          * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
230          * The resulting pointer to the vector should be considered
231          * readonly and only modified via AddUser and DelUser.
232          *
233          * @return This function returns pointer to a map of userrec pointers (CUList*).
234          */
235         CUList* GetUsers();
236         CUList* GetOppedUsers();
237         CUList* GetHalfoppedUsers();
238         CUList* GetVoicedUsers();
239
240         /** Returns true if the user given is on the given channel.
241          */
242         bool HasUser(userrec* user);
243
244         /** Creates a channel record and initialises it with default values
245          */
246         chanrec();
247
248         /** Destructor for chanrec
249          */
250         virtual ~chanrec() { /* stub */ }
251 };
252
253 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
254  * needs to come AFTER struct chanrec */
255 enum UserChannelModes {
256         UCMODE_OP      = 1,
257         UCMODE_VOICE   = 2,
258         UCMODE_HOP     = 4
259 };
260  
261 /** Holds a user's modes on a channel
262  * This class associates a users privilages with a channel by creating a pointer link between
263  * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
264  * has on the channel, such as op, voice, etc.
265  */
266 class ucrec : public classbase
267 {
268  public:
269         /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
270          * If this value is zero, the user has no privilages upon the channel.
271          */
272         char uc_modes;
273         
274         /** Points to the channel record where the given modes apply.
275          * If the record is not in use, this value will be NULL.
276          */
277         chanrec *channel;
278
279         /** Constructor for ucrec
280          */
281         ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
282
283         /** Destructor for ucrec
284          */
285         virtual ~ucrec() { /* stub */ }
286 };
287
288 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
289 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
290 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
291 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);
292
293 #endif