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