]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/channels.h
e14c81f270143da501c1b1cdbff919a6a2962219
[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 /** 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         /** Custom modes for the channel.
110          * Plugins may use this field in any way they see fit.
111          */
112         char custom_modes[64];     /* modes handled by modules */
113
114         /** User lists
115          * There are four user lists, one for 
116          * all the users, one for the ops, one for
117          * the halfops and another for the voices.
118          */
119         CUList internal_userlist;
120         CUList internal_op_userlist;
121         CUList internal_halfop_userlist;
122         CUList internal_voice_userlist;
123
124         /** Parameters for custom modes
125          */
126         CustomModeList custom_mode_params;
127
128         /** Channel topic.
129          * If this is an empty string, no channel topic is set.
130          */
131         char topic[MAXTOPIC];
132         /** Creation time.
133          */
134         time_t created;
135         /** Time topic was set.
136          * If no topic was ever set, this will be equal to chanrec::created
137          */
138         time_t topicset;
139         /** The last user to set the topic.
140          * If this member is an empty string, no topic was ever set.
141          */
142         char setby[NICKMAX];
143
144         /** Contains the channel user limit.
145          * If this value is zero, there is no limit in place.
146          */
147         short int limit;
148         
149         /** Contains the channel key.
150          * If this value is an empty string, there is no channel key in place.
151          */
152         char key[32];
153         
154         /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
155          */
156         char binarymodes;
157         
158         /** The list of all bans set on the channel.
159          */
160         BanList bans;
161         
162         /** Sets or unsets a custom mode in the channels info
163          * @param mode The mode character to set or unset
164          * @param mode_on True if you want to set the mode or false if you want to remove it
165          */
166         void SetCustomMode(char mode,bool mode_on);
167
168         /** Sets or unsets the parameters for a custom mode in a channels info
169          * @param mode The mode character to set or unset
170          * @param parameter The parameter string to associate with this mode character
171          * @param mode_on True if you want to set the mode or false if you want to remove it
172          */
173         void SetCustomModeParam(char mode,char* parameter,bool mode_on);
174  
175         /** Returns true if a custom mode is set on a channel
176           * @param mode The mode character you wish to query
177           * @return True if the custom mode is set, false if otherwise
178           */
179         bool IsCustomModeSet(char mode);
180
181         /** Returns the parameter for a custom mode on a channel.
182           * @param mode The mode character you wish to query
183           *
184           * For example if "+L #foo" is set, and you pass this method
185           * 'L', it will return '#foo'. If the mode is not set on the
186           * channel, or the mode has no parameters associated with it,
187           * it will return an empty string.
188           *
189           * @return The parameter for this mode is returned, or an empty string
190           */
191         std::string GetModeParameter(char mode);
192
193         /** Obtain the channel "user counter"
194          * This returns the channel reference counter, which is initialized
195          * to 0 when the channel is created and incremented/decremented
196          * upon joins, parts quits and kicks.
197          *
198          * @return The number of users on this channel
199          */
200         long GetUserCounter();
201
202         /** Add a user pointer to the internal reference list
203          * @param user The user to add
204          *
205          * The data inserted into the reference list is a table as it is
206          * an arbitary pointer compared to other users by its memory address,
207          * as this is a very fast 32 or 64 bit integer comparison.
208          */
209         void AddUser(userrec* user);
210         void AddOppedUser(userrec* user);
211         void AddHalfoppedUser(userrec* user);
212         void AddVoicedUser(userrec* user);
213
214         /** Delete a user pointer to the internal reference list
215          * @param user The user to delete
216          * @return number of users left on the channel
217          */
218         unsigned long DelUser(userrec* user);
219         void DelOppedUser(userrec* user);
220         void DelHalfoppedUser(userrec* user);
221         void DelVoicedUser(userrec* user);
222
223         /** Obrain the internal reference list
224          * The internal reference list contains a list of userrec*.
225          * These are used for rapid comparison to determine
226          * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
227          * The resulting pointer to the vector should be considered
228          * readonly and only modified via AddUser and DelUser.
229          *
230          * @return This function returns pointer to a map of userrec pointers (CUList*).
231          */
232         CUList* GetUsers();
233         CUList* GetOppedUsers();
234         CUList* GetHalfoppedUsers();
235         CUList* GetVoicedUsers();
236
237         bool HasUser(userrec* user);
238
239         /** Creates a channel record and initialises it with default values
240          */
241         chanrec();
242
243         virtual ~chanrec() { /* stub */ }
244 };
245
246 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
247  * needs to come AFTER struct chanrec */
248 enum UserChannelModes {
249         UCMODE_OP      = 1,
250         UCMODE_VOICE   = 2,
251         UCMODE_HOP     = 4
252 };
253  
254 /** Holds a user's modes on a channel
255  * This class associates a users privilages with a channel by creating a pointer link between
256  * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
257  * has on the channel, such as op, voice, etc.
258  */
259 class ucrec : public classbase
260 {
261  public:
262         /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
263          * If this value is zero, the user has no privilages upon the channel.
264          */
265         char uc_modes;
266         
267         /** Points to the channel record where the given modes apply.
268          * If the record is not in use, this value will be NULL.
269          */
270         chanrec *channel;
271
272         ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
273         virtual ~ucrec() { /* stub */ }
274 };
275
276 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
277 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
278 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
279 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);
280
281 #endif
282