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 /** Shorthand for CUList::iterator
92 typedef CUList::iterator CUListIter;
93 typedef CUList::const_iterator CUListConstIter;
95 /** A list of custom modes parameters on a channel
97 typedef std::map<char,char*> CustomModeList;
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.
103 class chanrec : public Extensible
106 /** The channels name.
108 char name[CHANMAX]; /* channel name */
109 /** Modes for the channel.
110 * This is not a null terminated string! It is a hash where
111 * each item in it represents if a mode is set. For example
112 * for mode +A, index 0. Use modechar-65 to calculate which
118 * There are four user lists, one for
119 * all the users, one for the ops, one for
120 * the halfops and another for the voices.
122 CUList internal_userlist;
123 CUList internal_op_userlist;
124 CUList internal_halfop_userlist;
125 CUList internal_voice_userlist;
127 /** Parameters for custom modes
129 CustomModeList custom_mode_params;
132 * If this is an empty string, no channel topic is set.
134 char topic[MAXTOPIC];
138 /** Time topic was set.
139 * If no topic was ever set, this will be equal to chanrec::created
142 /** The last user to set the topic.
143 * If this member is an empty string, no topic was ever set.
147 /** Contains the channel user limit.
148 * If this value is zero, there is no limit in place.
152 /** Contains the channel key.
153 * If this value is an empty string, there is no channel key in place.
157 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
161 /** The list of all bans set on the channel.
165 /** Sets or unsets a custom mode in the channels info
166 * @param mode The mode character to set or unset
167 * @param mode_on True if you want to set the mode or false if you want to remove it
169 void SetCustomMode(char mode,bool mode_on);
171 /** Sets or unsets the parameters for a custom mode in a channels info
172 * @param mode The mode character to set or unset
173 * @param parameter The parameter string to associate with this mode character
174 * @param mode_on True if you want to set the mode or false if you want to remove it
176 void SetCustomModeParam(char mode,char* parameter,bool mode_on);
178 /** Returns true if a mode is set on a channel
179 * @param mode The mode character you wish to query
180 * @return True if the custom mode is set, false if otherwise
182 bool IsModeSet(char mode);
184 /** Returns the parameter for a custom mode on a channel.
185 * @param mode The mode character you wish to query
187 * For example if "+L #foo" is set, and you pass this method
188 * 'L', it will return '#foo'. If the mode is not set on the
189 * channel, or the mode has no parameters associated with it,
190 * it will return an empty string.
192 * @return The parameter for this mode is returned, or an empty string
194 std::string GetModeParameter(char mode);
196 /** Obtain the channel "user counter"
197 * This returns the channel reference counter, which is initialized
198 * to 0 when the channel is created and incremented/decremented
199 * upon joins, parts quits and kicks.
201 * @return The number of users on this channel
203 long GetUserCounter();
205 /** Add a user pointer to the internal reference list
206 * @param user The user to add
208 * The data inserted into the reference list is a table as it is
209 * an arbitary pointer compared to other users by its memory address,
210 * as this is a very fast 32 or 64 bit integer comparison.
212 void AddUser(userrec* user);
213 void AddOppedUser(userrec* user);
214 void AddHalfoppedUser(userrec* user);
215 void AddVoicedUser(userrec* user);
217 /** Delete a user pointer to the internal reference list
218 * @param user The user to delete
219 * @return number of users left on the channel
221 unsigned long DelUser(userrec* user);
222 void DelOppedUser(userrec* user);
223 void DelHalfoppedUser(userrec* user);
224 void DelVoicedUser(userrec* user);
226 /** Obtain the internal reference list
227 * The internal reference list contains a list of userrec*.
228 * These are used for rapid comparison to determine
229 * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
230 * The resulting pointer to the vector should be considered
231 * readonly and only modified via AddUser and DelUser.
233 * @return This function returns pointer to a map of userrec pointers (CUList*).
236 CUList* GetOppedUsers();
237 CUList* GetHalfoppedUsers();
238 CUList* GetVoicedUsers();
240 /** Returns true if the user given is on the given channel.
242 bool HasUser(userrec* user);
244 /** Creates a channel record and initialises it with default values
248 /** Destructor for chanrec
250 virtual ~chanrec() { /* stub */ }
253 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
254 * needs to come AFTER struct chanrec */
255 enum UserChannelModes {
261 /** Holds a user's modes on a channel
262 * This class associates a users privilages with a channel by creating a pointer link between
263 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
264 * has on the channel, such as op, voice, etc.
266 class ucrec : public classbase
269 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
270 * If this value is zero, the user has no privilages upon the channel.
274 /** Points to the channel record where the given modes apply.
275 * If the record is not in use, this value will be NULL.
279 /** Constructor for ucrec
281 ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
283 /** Destructor for ucrec
285 virtual ~ucrec() { /* stub */ }
288 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
289 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
290 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
291 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);