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