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