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