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