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"
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.
41 class HostItem : public classbase
48 HostItem() { /* stub */ }
49 virtual ~HostItem() { /* stub */ }
52 // banlist is inherited from HostList mainly for readability
55 /** A subclass of HostItem designed to hold channel bans (+b)
57 class BanItem : public HostItem
63 /** A subclass of HostItem designed to hold channel exempts (+e)
65 class ExemptItem : public HostItem
71 /** A subclass of HostItem designed to hold channel invites (+I)
73 class InviteItem : public HostItem
77 /** Holds a complete ban list
79 typedef std::vector<BanItem> BanList;
81 /** Holds a complete exempt list
83 typedef std::vector<ExemptItem> ExemptList;
85 /** Holds a complete invite list
87 typedef std::vector<InviteItem> InviteList;
91 /** A list of users on a channel
93 typedef std::map<userrec*,userrec*> CUList;
95 /** Holds all relevent information for a channel.
96 * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
97 * etc, and an instance of the BanList type.
99 class chanrec : public Extensible
102 /** The channels name.
104 char name[CHANMAX]; /* channel name */
105 /** Custom modes for the channel.
106 * Plugins may use this field in any way they see fit.
108 char custom_modes[64]; /* modes handled by modules */
110 /** User list (casted to char*'s to stop forward declaration stuff)
111 * (chicken and egg scenario!)
113 CUList internal_userlist;
114 CUList internal_op_userlist;
115 CUList internal_halfop_userlist;
116 CUList internal_voice_userlist;
118 /** Parameters for custom modes
120 std::map<char,char*> custom_mode_params;
123 * If this is an empty string, no channel topic is set.
129 /** Time topic was set.
130 * If no topic was ever set, this will be equal to chanrec::created
133 /** The last user to set the topic.
134 * If this member is an empty string, no topic was ever set.
138 /** Contains the channel user limit.
139 * If this value is zero, there is no limit in place.
143 /** Contains the channel key.
144 * If this value is an empty string, there is no channel key in place.
148 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
152 /** The list of all bans set on the channel.
156 /** Sets or unsets a custom mode in the channels info
157 * @param mode The mode character to set or unset
158 * @param mode_on True if you want to set the mode or false if you want to remove it
160 void SetCustomMode(char mode,bool mode_on);
162 /** Sets or unsets the parameters for a custom mode in a channels info
163 * @param mode The mode character to set or unset
164 * @param parameter The parameter string to associate with this mode character
165 * @param mode_on True if you want to set the mode or false if you want to remove it
167 void SetCustomModeParam(char mode,char* parameter,bool mode_on);
169 /** Returns true if a custom mode is set on a channel
170 * @param mode The mode character you wish to query
171 * @return True if the custom mode is set, false if otherwise
173 bool IsCustomModeSet(char mode);
175 /** Returns the parameter for a custom mode on a channel.
176 * @param mode The mode character you wish to query
178 * For example if "+L #foo" is set, and you pass this method
179 * 'L', it will return '#foo'. If the mode is not set on the
180 * channel, or the mode has no parameters associated with it,
181 * it will return an empty string.
183 * @return The parameter for this mode is returned, or an empty string
185 std::string GetModeParameter(char mode);
187 /** Obtain the channel "user counter"
188 * This returns the channel reference counter, which is initialized
189 * to 0 when the channel is created and incremented/decremented
190 * upon joins, parts quits and kicks.
192 * @return The number of users on this channel
194 long GetUserCounter();
196 /** Add a user pointer to the internal reference list
197 * @param castuser This should be a pointer to a userrec, casted to char*
199 * The data inserted into the reference list is a table as it is
200 * an arbitary pointer compared to other users by its memory address,
201 * as this is a very fast 32 or 64 bit integer comparison.
203 void AddUser(userrec* castuser);
204 void AddOppedUser(userrec* castuser);
205 void AddHalfoppedUser(userrec* castuser);
206 void AddVoicedUser(userrec* castuser);
208 /** Delete a user pointer to the internal reference list
209 * @param castuser This should be a pointer to a userrec, casted to char*
211 * The data removed from the reference list is a table as it is
212 * an arbitary pointer compared to other users by its memory address,
213 * as this is a very fast 32 or 64 bit integer comparison.
215 void DelUser(userrec* castuser);
216 void DelOppedUser(userrec* castuser);
217 void DelHalfoppedUser(userrec* castuser);
218 void DelVoicedUser(userrec* castuser);
220 /** Obrain the internal reference list
221 * The internal reference list contains a list of userrec*
222 * cast to char*. These are used for rapid comparison to determine
223 * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
224 * The resulting pointer to the vector should be considered
225 * readonly and only modified via AddUser and DelUser.
227 * @return This function returns a vector of userrec pointers, each of which has been casted to char* to prevent circular references
230 CUList *GetOppedUsers();
231 CUList *GetHalfoppedUsers();
232 CUList *GetVoicedUsers();
234 /** Creates a channel record and initialises it with default values
238 virtual ~chanrec() { /* stub */ }
241 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
242 * needs to come AFTER struct chanrec */
243 enum UserChannelModes {
249 /** Holds a user's modes on a channel
250 * This class associates a users privilages with a channel by creating a pointer link between
251 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
252 * has on the channel, such as op, voice, etc.
254 class ucrec : public classbase
257 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
258 * If this value is zero, the user has no privilages upon the channel.
262 /** Points to the channel record where the given modes apply.
263 * If the record is not in use, this value will be NULL.
267 ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
268 virtual ~ucrec() { /* stub */ }
271 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
272 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
273 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
274 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);