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