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