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