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,
43 /** Holds an entry for a ban list, exemption list, or invite list.
44 * This class contains a single element in a channel list, such as a banlist.
46 class HostItem : public classbase
53 HostItem() { /* stub */ }
54 virtual ~HostItem() { /* stub */ }
57 /** A subclass of HostItem designed to hold channel bans (+b)
59 class BanItem : public HostItem
63 /** A subclass of HostItem designed to hold channel exempts (+e)
65 class ExemptItem : public HostItem
69 /** A subclass of HostItem designed to hold channel invites (+I)
71 class InviteItem : public HostItem
75 /** Holds a complete ban list
77 typedef std::vector<BanItem> BanList;
79 /** Holds a complete exempt list
81 typedef std::vector<ExemptItem> ExemptList;
83 /** Holds a complete invite list
85 typedef std::vector<InviteItem> InviteList;
87 /** A list of users on a channel
89 typedef std::map<userrec*,userrec*> CUList;
91 /** Shorthand for CUList::iterator
93 typedef CUList::iterator CUListIter;
94 typedef CUList::const_iterator CUListConstIter;
96 /** A list of custom modes parameters on a channel
98 typedef std::map<char,char*> CustomModeList;
101 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
102 * needs to come AFTER struct chanrec */
103 enum UserChannelModes {
109 /** Holds a user's modes on a channel
110 * This class associates a users privilages with a channel by creating a pointer link between
111 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
112 * has on the channel, such as op, voice, etc.
114 class ucrec : public classbase
117 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
118 * If this value is zero, the user has no privilages upon the channel.
122 /** Points to the channel record where the given modes apply.
123 * If the record is not in use, this value will be NULL.
127 /** Constructor for ucrec
129 ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
131 /** Destructor for ucrec
133 virtual ~ucrec() { /* stub */ }
137 /** Holds all relevent information for a channel.
138 * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
139 * etc, and an instance of the BanList type.
141 class chanrec : public Extensible
145 /** Connect a chanrec to a userrec
147 static chanrec* ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created);
150 /** The channels name.
152 char name[CHANMAX]; /* channel name */
153 /** Modes for the channel.
154 * This is not a null terminated string! It is a hash where
155 * each item in it represents if a mode is set. For example
156 * for mode +A, index 0. Use modechar-65 to calculate which
162 * There are four user lists, one for
163 * all the users, one for the ops, one for
164 * the halfops and another for the voices.
166 CUList internal_userlist;
167 CUList internal_op_userlist;
168 CUList internal_halfop_userlist;
169 CUList internal_voice_userlist;
171 /** Parameters for custom modes
173 CustomModeList custom_mode_params;
176 * If this is an empty string, no channel topic is set.
178 char topic[MAXTOPIC];
182 /** Time topic was set.
183 * If no topic was ever set, this will be equal to chanrec::created
186 /** The last user to set the topic.
187 * If this member is an empty string, no topic was ever set.
191 /** Contains the channel user limit.
192 * If this value is zero, there is no limit in place.
196 /** Contains the channel key.
197 * If this value is an empty string, there is no channel key in place.
201 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
205 /** The list of all bans set on the channel.
209 /** Sets or unsets a custom mode in the channels info
210 * @param mode The mode character to set or unset
211 * @param mode_on True if you want to set the mode or false if you want to remove it
213 void SetMode(char mode,bool mode_on);
215 /** Sets or unsets the parameters for a custom mode in a channels info
216 * @param mode The mode character to set or unset
217 * @param parameter The parameter string to associate with this mode character
218 * @param mode_on True if you want to set the mode or false if you want to remove it
220 void SetModeParam(char mode,const char* parameter,bool mode_on);
222 /** Returns true if a mode is set on a channel
223 * @param mode The mode character you wish to query
224 * @return True if the custom mode is set, false if otherwise
226 bool IsModeSet(char mode);
228 /** Returns the parameter for a custom mode on a channel.
229 * @param mode The mode character you wish to query
231 * For example if "+L #foo" is set, and you pass this method
232 * 'L', it will return '#foo'. If the mode is not set on the
233 * channel, or the mode has no parameters associated with it,
234 * it will return an empty string.
236 * @return The parameter for this mode is returned, or an empty string
238 std::string GetModeParameter(char mode);
240 /** Obtain the channel "user counter"
241 * This returns the channel reference counter, which is initialized
242 * to 0 when the channel is created and incremented/decremented
243 * upon joins, parts quits and kicks.
245 * @return The number of users on this channel
247 long GetUserCounter();
249 /** Add a user pointer to the internal reference list
250 * @param user The user to add
252 * The data inserted into the reference list is a table as it is
253 * an arbitary pointer compared to other users by its memory address,
254 * as this is a very fast 32 or 64 bit integer comparison.
256 void AddUser(userrec* user);
257 void AddOppedUser(userrec* user);
258 void AddHalfoppedUser(userrec* user);
259 void AddVoicedUser(userrec* user);
261 /** Delete a user pointer to the internal reference list
262 * @param user The user to delete
263 * @return number of users left on the channel
265 unsigned long DelUser(userrec* user);
266 void DelOppedUser(userrec* user);
267 void DelHalfoppedUser(userrec* user);
268 void DelVoicedUser(userrec* user);
270 /** Obtain the internal reference list
271 * The internal reference list contains a list of userrec*.
272 * These are used for rapid comparison to determine
273 * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
274 * The resulting pointer to the vector should be considered
275 * readonly and only modified via AddUser and DelUser.
277 * @return This function returns pointer to a map of userrec pointers (CUList*).
280 CUList* GetOppedUsers();
281 CUList* GetHalfoppedUsers();
282 CUList* GetVoicedUsers();
284 /** Returns true if the user given is on the given channel.
286 bool HasUser(userrec* user);
288 /** Creates a channel record and initialises it with default values
292 /** Make src kick user from this channel with the given reason.
293 * @param src The source of the kick
294 * @param user The user being kicked (must be on this channel)
295 * @param reason The reason for the kick
296 * @return The number of users left on the channel. If this is zero
297 * when the method returns, you MUST delete the chanrec immediately!
299 long KickUser(userrec *src, userrec *user, const char* reason);
301 /** Make the server kick user from this channel with the given reason.
302 * @param user The user being kicked (must be on this channel)
303 * @param reason The reason for the kick
304 * @param triggerevents True if you wish this kick to trigger module events
305 * @return The number of users left on the channel. If this is zero
306 * when the method returns, you MUST delete the chanrec immediately!
308 long ServerKickUser(userrec* user, const char* reason, bool triggerevents);
310 /** Part a user from this channel with the given reason.
311 * If the reason field is NULL, no reason will be sent.
312 * @param user The user who is parting (must be on this channel)
313 * @param reason The (optional) part reason
314 * @return The number of users left on the channel. If this is zero
315 * when the method returns, you MUST delete the chanrec immediately!
317 long PartUser(userrec *user, const char* reason = NULL);
319 /* Join a user to a channel. May be a channel that doesnt exist yet.
320 * @param user The user to join to the channel.
321 * @param cn The channel name to join to. Does not have to exist.
322 * @param key The key of the channel, if given
323 * @param override If true, override all join restrictions such as +bkil
324 * @return A pointer to the chanrec the user was joined to. A new chanrec may have
325 * been created if the channel did not exist before the user was joined to it.
326 * If the user could not be joined to a channel, the return value may be NULL.
328 static chanrec* JoinUser(userrec *user, const char* cn, bool override, const char* key = "");
330 void WriteChannel(userrec* user, char* text, ...);
331 void WriteChannel(userrec* user, const std::string &text);
332 void WriteChannelWithServ(const char* ServName, const char* text, ...);
333 void WriteChannelWithServ(const char* ServName, const std::string &text);
334 void WriteAllExceptSender(userrec* user, char status, char* text, ...);
335 void WriteAllExceptSender(userrec* user, char status, const std::string& text);
337 /** Destructor for chanrec
339 virtual ~chanrec() { /* stub */ }