1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
17 #ifndef __CHANNELS_H__
18 #define __CHANNELS_H__
20 #include "inspircd_config.h"
27 /** RFC1459 channel modes
30 CM_TOPICLOCK = 't'-65,
31 CM_NOEXTERNAL = 'n'-65,
32 CM_INVITEONLY = 'i'-65,
33 CM_MODERATED = 'm'-65,
42 /** Holds an entry for a ban list, exemption list, or invite list.
43 * This class contains a single element in a channel list, such as a banlist.
45 class HostItem : public classbase
52 HostItem() { /* stub */ }
53 virtual ~HostItem() { /* stub */ }
56 /** A subclass of HostItem designed to hold channel bans (+b)
58 class BanItem : public HostItem
62 /** A subclass of HostItem designed to hold channel exempts (+e)
64 class ExemptItem : public HostItem
68 /** A subclass of HostItem designed to hold channel invites (+I)
70 class InviteItem : public HostItem
74 /** Holds a complete ban list
76 typedef std::vector<BanItem> BanList;
78 /** Holds a complete exempt list
80 typedef std::vector<ExemptItem> ExemptList;
82 /** Holds a complete invite list
84 typedef std::vector<InviteItem> InviteList;
86 /** A list of users on a channel
88 typedef std::map<userrec*,userrec*> CUList;
90 /** A list of custom modes parameters on a channel
92 typedef std::map<char,char*> CustomModeList;
94 /** Holds all relevent information for a channel.
95 * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
96 * etc, and an instance of the BanList type.
98 class chanrec : public Extensible
101 /** The channels name.
103 char name[CHANMAX]; /* channel name */
104 /** Modes for the channel.
105 * This is not a null terminated string! It is a hash where
106 * each item in it represents if a mode is set. For example
107 * for mode +A, index 0. Use modechar-65 to calculate which
113 * There are four user lists, one for
114 * all the users, one for the ops, one for
115 * the halfops and another for the voices.
117 CUList internal_userlist;
118 CUList internal_op_userlist;
119 CUList internal_halfop_userlist;
120 CUList internal_voice_userlist;
122 /** Parameters for custom modes
124 CustomModeList custom_mode_params;
127 * If this is an empty string, no channel topic is set.
129 char topic[MAXTOPIC];
133 /** Time topic was set.
134 * If no topic was ever set, this will be equal to chanrec::created
137 /** The last user to set the topic.
138 * If this member is an empty string, no topic was ever set.
142 /** Contains the channel user limit.
143 * If this value is zero, there is no limit in place.
147 /** Contains the channel key.
148 * If this value is an empty string, there is no channel key in place.
152 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
156 /** The list of all bans set on the channel.
160 /** Sets or unsets a custom mode in the channels info
161 * @param mode The mode character to set or unset
162 * @param mode_on True if you want to set the mode or false if you want to remove it
164 void SetCustomMode(char mode,bool mode_on);
166 /** Sets or unsets the parameters for a custom mode in a channels info
167 * @param mode The mode character to set or unset
168 * @param parameter The parameter string to associate with this mode character
169 * @param mode_on True if you want to set the mode or false if you want to remove it
171 void SetCustomModeParam(char mode,char* parameter,bool mode_on);
173 /** Returns true if a mode is set on a channel
174 * @param mode The mode character you wish to query
175 * @return True if the custom mode is set, false if otherwise
177 bool IsModeSet(char mode);
179 /** Returns the parameter for a custom mode on a channel.
180 * @param mode The mode character you wish to query
182 * For example if "+L #foo" is set, and you pass this method
183 * 'L', it will return '#foo'. If the mode is not set on the
184 * channel, or the mode has no parameters associated with it,
185 * it will return an empty string.
187 * @return The parameter for this mode is returned, or an empty string
189 std::string GetModeParameter(char mode);
191 /** Obtain the channel "user counter"
192 * This returns the channel reference counter, which is initialized
193 * to 0 when the channel is created and incremented/decremented
194 * upon joins, parts quits and kicks.
196 * @return The number of users on this channel
198 long GetUserCounter();
200 /** Add a user pointer to the internal reference list
201 * @param user The user to add
203 * The data inserted into the reference list is a table as it is
204 * an arbitary pointer compared to other users by its memory address,
205 * as this is a very fast 32 or 64 bit integer comparison.
207 void AddUser(userrec* user);
208 void AddOppedUser(userrec* user);
209 void AddHalfoppedUser(userrec* user);
210 void AddVoicedUser(userrec* user);
212 /** Delete a user pointer to the internal reference list
213 * @param user The user to delete
214 * @return number of users left on the channel
216 unsigned long DelUser(userrec* user);
217 void DelOppedUser(userrec* user);
218 void DelHalfoppedUser(userrec* user);
219 void DelVoicedUser(userrec* user);
221 /** Obtain the internal reference list
222 * The internal reference list contains a list of userrec*.
223 * 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.
228 * @return This function returns pointer to a map of userrec pointers (CUList*).
231 CUList* GetOppedUsers();
232 CUList* GetHalfoppedUsers();
233 CUList* GetVoicedUsers();
235 /** Returns true if the user given is on the given channel.
237 bool HasUser(userrec* user);
239 /** Creates a channel record and initialises it with default values
243 /** Destructor for chanrec
245 virtual ~chanrec() { /* stub */ }
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 {
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.
261 class ucrec : public classbase
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.
269 /** Points to the channel record where the given modes apply.
270 * If the record is not in use, this value will be NULL.
274 /** Constructor for ucrec
276 ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
278 /** Destructor for ucrec
280 virtual ~ucrec() { /* stub */ }
283 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
284 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
285 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
286 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);