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
49 /** Time the item was added
52 /** Who added the item
55 /** The actual item data
59 HostItem() { /* stub */ }
60 virtual ~HostItem() { /* stub */ }
63 /** A subclass of HostItem designed to hold channel bans (+b)
65 class BanItem : public HostItem
69 /** A subclass of HostItem designed to hold channel exempts (+e)
71 class ExemptItem : public HostItem
75 /** A subclass of HostItem designed to hold channel invites (+I)
77 class InviteItem : public HostItem
81 /** Holds a complete ban list
83 typedef std::vector<BanItem> BanList;
85 /** Holds a complete exempt list
87 typedef std::vector<ExemptItem> ExemptList;
89 /** Holds a complete invite list
91 typedef std::vector<InviteItem> InviteList;
93 /** A list of users on a channel
95 typedef std::map<userrec*,userrec*> CUList;
97 /** Shorthand for CUList::iterator
99 typedef CUList::iterator CUListIter;
101 /** Shorthand for CUList::const_iterator
103 typedef CUList::const_iterator CUListConstIter;
105 /** A list of custom modes parameters on a channel
107 typedef std::map<char,char*> CustomModeList;
110 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
112 enum UserChannelModes {
118 /** Holds a user's modes on a channel
119 * This class associates a users privilages with a channel by creating a pointer link between
120 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
121 * has on the channel, such as op, voice, etc.
123 class ucrec : public classbase
126 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
127 * If this value is zero, the user has no privilages upon the channel.
131 /** Points to the channel record where the given modes apply.
132 * If the record is not in use, this value will be NULL.
136 /** Constructor for ucrec
138 ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
140 /** Destructor for ucrec
142 virtual ~ucrec() { /* stub */ }
146 /** Holds all relevent information for a channel.
147 * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
148 * etc, and an instance of the BanList type.
150 class chanrec : public Extensible
154 /** Connect a chanrec to a userrec
156 static chanrec* ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created);
159 /** The channels name.
163 /** Modes for the channel.
164 * This is not a null terminated string! It is a hash where
165 * each item in it represents if a mode is set. For example
166 * for mode +A, index 0. Use modechar-65 to calculate which
172 * There are four user lists, one for
173 * all the users, one for the ops, one for
174 * the halfops and another for the voices.
176 CUList internal_userlist;
180 CUList internal_op_userlist;
184 CUList internal_halfop_userlist;
188 CUList internal_voice_userlist;
190 /** Parameters for custom modes
192 CustomModeList custom_mode_params;
195 * If this is an empty string, no channel topic is set.
197 char topic[MAXTOPIC];
201 /** Time topic was set.
202 * If no topic was ever set, this will be equal to chanrec::created
205 /** The last user to set the topic.
206 * If this member is an empty string, no topic was ever set.
210 /** Contains the channel user limit.
211 * If this value is zero, there is no limit in place.
215 /** Contains the channel key.
216 * If this value is an empty string, there is no channel key in place.
220 /** The list of all bans set on the channel.
224 /** Sets or unsets a custom mode in the channels info
225 * @param mode The mode character to set or unset
226 * @param mode_on True if you want to set the mode or false if you want to remove it
228 void SetMode(char mode,bool mode_on);
230 /** Sets or unsets the parameters for a custom mode in a channels info
231 * @param mode The mode character to set or unset
232 * @param parameter The parameter string to associate with this mode character
233 * @param mode_on True if you want to set the mode or false if you want to remove it
235 void SetModeParam(char mode,const char* parameter,bool mode_on);
237 /** Returns true if a mode is set on a channel
238 * @param mode The mode character you wish to query
239 * @return True if the custom mode is set, false if otherwise
241 bool IsModeSet(char mode);
243 /** Returns the parameter for a custom mode on a channel.
244 * @param mode The mode character you wish to query
246 * For example if "+L #foo" is set, and you pass this method
247 * 'L', it will return '#foo'. If the mode is not set on the
248 * channel, or the mode has no parameters associated with it,
249 * it will return an empty string.
251 * @return The parameter for this mode is returned, or an empty string
253 std::string GetModeParameter(char mode);
255 /** Obtain the channel "user counter"
256 * This returns the channel reference counter, which is initialized
257 * to 0 when the channel is created and incremented/decremented
258 * upon joins, parts quits and kicks.
260 * @return The number of users on this channel
262 long GetUserCounter();
264 /** Add a user pointer to the internal reference list
265 * @param user The user to add
267 * The data inserted into the reference list is a table as it is
268 * an arbitary pointer compared to other users by its memory address,
269 * as this is a very fast 32 or 64 bit integer comparison.
271 void AddUser(userrec* user);
273 /** Add a user pointer to the internal reference list of opped users
274 * @param user The user to add
276 void AddOppedUser(userrec* user);
278 /** Add a user pointer to the internal reference list of halfopped users
279 * @param user The user to add
281 void AddHalfoppedUser(userrec* user);
283 /** Add a user pointer to the internal reference list of voiced users
284 * @param user The user to add
286 void AddVoicedUser(userrec* user);
288 /** Delete a user pointer to the internal reference list
289 * @param user The user to delete
290 * @return number of users left on the channel after deletion of the user
292 unsigned long DelUser(userrec* user);
294 /** Delete a user pointer to the internal reference list of opped users
295 * @param user The user to delete
297 void DelOppedUser(userrec* user);
299 /** Delete a user pointer to the internal reference list of halfopped users
300 * @param user The user to delete
302 void DelHalfoppedUser(userrec* user);
304 /** Delete a user pointer to the internal reference list of voiced users
305 * @param user The user to delete
307 void DelVoicedUser(userrec* user);
309 /** Obtain the internal reference list
310 * The internal reference list contains a list of userrec*.
311 * These are used for rapid comparison to determine
312 * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
313 * The resulting pointer to the vector should be considered
314 * readonly and only modified via AddUser and DelUser.
316 * @return This function returns pointer to a map of userrec pointers (CUList*).
320 /** Obtain the internal reference list of opped users
321 * @return This function returns pointer to a map of userrec pointers (CUList*).
323 CUList* GetOppedUsers();
325 /** Obtain the internal reference list of halfopped users
326 * @return This function returns pointer to a map of userrec pointers (CUList*).
328 CUList* GetHalfoppedUsers();
330 /** Obtain the internal reference list of voiced users
331 * @return This function returns pointer to a map of userrec pointers (CUList*).
333 CUList* GetVoicedUsers();
335 /** Returns true if the user given is on the given channel.
336 * @param The user to look for
337 * @return True if the user is on this channel
339 bool HasUser(userrec* user);
341 /** Creates a channel record and initialises it with default values
342 * @throw Nothing at present.
346 /** Make src kick user from this channel with the given reason.
347 * @param src The source of the kick
348 * @param user The user being kicked (must be on this channel)
349 * @param reason The reason for the kick
350 * @return The number of users left on the channel. If this is zero
351 * when the method returns, you MUST delete the chanrec immediately!
353 long KickUser(userrec *src, userrec *user, const char* reason);
355 /** Make the server kick user from this channel with the given reason.
356 * @param user The user being kicked (must be on this channel)
357 * @param reason The reason for the kick
358 * @param triggerevents True if you wish this kick to trigger module events
359 * @return The number of users left on the channel. If this is zero
360 * when the method returns, you MUST delete the chanrec immediately!
362 long ServerKickUser(userrec* user, const char* reason, bool triggerevents);
364 /** Part a user from this channel with the given reason.
365 * If the reason field is NULL, no reason will be sent.
366 * @param user The user who is parting (must be on this channel)
367 * @param reason The (optional) part reason
368 * @return The number of users left on the channel. If this is zero
369 * when the method returns, you MUST delete the chanrec immediately!
371 long PartUser(userrec *user, const char* reason = NULL);
373 /* Join a user to a channel. May be a channel that doesnt exist yet.
374 * @param user The user to join to the channel.
375 * @param cn The channel name to join to. Does not have to exist.
376 * @param key The key of the channel, if given
377 * @param override If true, override all join restrictions such as +bkil
378 * @return A pointer to the chanrec the user was joined to. A new chanrec may have
379 * been created if the channel did not exist before the user was joined to it.
380 * If the user could not be joined to a channel, the return value may be NULL.
382 static chanrec* JoinUser(userrec *user, const char* cn, bool override, const char* key = "");
384 /** Write to a channel, from a user, using va_args for text
385 * @param user User whos details to prefix the line with
386 * @param text A printf-style format string which builds the output line without prefix
387 * @param ... Zero or more POD types
389 void WriteChannel(userrec* user, char* text, ...);
391 /** Write to a channel, from a user, using std::string for text
392 * @param user User whos details to prefix the line with
393 * @param text A std::string containing the output line without prefix
395 void WriteChannel(userrec* user, const std::string &text);
397 /** Write to a channel, from a server, using va_args for text
398 * @param ServName Server name to prefix the line with
399 * @param text A printf-style format string which builds the output line without prefi
400 * @param ... Zero or more POD type
402 void WriteChannelWithServ(const char* ServName, const char* text, ...);
404 /** Write to a channel, from a server, using std::string for text
405 * @param ServName Server name to prefix the line with
406 * @param text A std::string containing the output line without prefix
408 void WriteChannelWithServ(const char* ServName, const std::string &text);
410 /** Write to all users on a channel except a specific user, using va_args for text
411 * @param user User whos details to prefix the line with, and to omit from receipt of the message
412 * @param status The status of the users to write to, e.g. '@' or '%'. Use a value of 0 to write to everyone
413 * @param text A printf-style format string which builds the output line without prefi
414 * @param ... Zero or more POD type
416 void WriteAllExceptSender(userrec* user, char status, char* text, ...);
418 /** Write to all users on a channel except a specific user, using std::string for text
419 * @param user User whos details to prefix the line with, and to omit from receipt of the message
420 * @param status The status of the users to write to, e.g. '@' or '%'. Use a value of 0 to write to everyone
421 * @param text A std::string containing the output line without prefix
423 void WriteAllExceptSender(userrec* user, char status, const std::string& text);
425 /** Destructor for chanrec
427 virtual ~chanrec() { /* stub */ }