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;
89 /** Holds all relevent information for a channel.
90 * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
91 * etc, and an instance of the BanList type.
93 class chanrec : public Extensible
96 /** The channels name.
98 char name[CHANMAX]; /* channel name */
99 /** Custom modes for the channel.
100 * Plugins may use this field in any way they see fit.
102 char custom_modes[64]; /* modes handled by modules */
104 /** User list (casted to char*'s to stop forward declaration stuff)
105 * (chicken and egg scenario!)
107 std::map<char*,char*> internal_userlist;
108 std::map<char*,char*> internal_op_userlist;
109 std::map<char*,char*> internal_halfop_userlist;
110 std::map<char*,char*> internal_voice_userlist;
112 /** Parameters for custom modes
114 std::map<char,char*> custom_mode_params;
117 * If this is an empty string, no channel topic is set.
123 /** Time topic was set.
124 * If no topic was ever set, this will be equal to chanrec::created
127 /** The last user to set the topic.
128 * If this member is an empty string, no topic was ever set.
132 /** Contains the channel user limit.
133 * If this value is zero, there is no limit in place.
137 /** Contains the channel key.
138 * If this value is an empty string, there is no channel key in place.
142 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
146 /** The list of all bans set on the channel.
150 /** Sets or unsets a custom mode in the channels info
151 * @param mode The mode character to set or unset
152 * @param mode_on True if you want to set the mode or false if you want to remove it
154 void SetCustomMode(char mode,bool mode_on);
156 /** Sets or unsets the parameters for a custom mode in a channels info
157 * @param mode The mode character to set or unset
158 * @param parameter The parameter string to associate with this mode character
159 * @param mode_on True if you want to set the mode or false if you want to remove it
161 void SetCustomModeParam(char mode,char* parameter,bool mode_on);
163 /** Returns true if a custom mode is set on a channel
164 * @param mode The mode character you wish to query
165 * @return True if the custom mode is set, false if otherwise
167 bool IsCustomModeSet(char mode);
169 /** Returns the parameter for a custom mode on a channel.
170 * @param mode The mode character you wish to query
172 * For example if "+L #foo" is set, and you pass this method
173 * 'L', it will return '#foo'. If the mode is not set on the
174 * channel, or the mode has no parameters associated with it,
175 * it will return an empty string.
177 * @return The parameter for this mode is returned, or an empty string
179 std::string GetModeParameter(char mode);
181 /** Obtain the channel "user counter"
182 * This returns the channel reference counter, which is initialized
183 * to 0 when the channel is created and incremented/decremented
184 * upon joins, parts quits and kicks.
186 * @return The number of users on this channel
188 long GetUserCounter();
190 /** Add a user pointer to the internal reference list
191 * @param castuser This should be a pointer to a userrec, casted to char*
193 * The data inserted into the reference list is a table as it is
194 * an arbitary pointer compared to other users by its memory address,
195 * as this is a very fast 32 or 64 bit integer comparison.
197 void AddUser(char* castuser);
198 void AddOppedUser(char* castuser);
199 void AddHalfoppedUser(char* castuser);
200 void AddVoicedUser(char* castuser);
202 /** Delete a user pointer to the internal reference list
203 * @param castuser This should be a pointer to a userrec, casted to char*
205 * The data removed from the reference list is a table as it is
206 * an arbitary pointer compared to other users by its memory address,
207 * as this is a very fast 32 or 64 bit integer comparison.
209 void DelUser(char* castuser);
210 void DelOppedUser(char* castuser);
211 void DelHalfoppedUser(char* castuser);
212 void DelVoicedUser(char* castuser);
214 /** Obrain the internal reference list
215 * The internal reference list contains a list of userrec*
216 * cast to char*. These are used for rapid comparison to determine
217 * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
218 * The resulting pointer to the vector should be considered
219 * readonly and only modified via AddUser and DelUser.
221 * @return This function returns a vector of userrec pointers, each of which has been casted to char* to prevent circular references
223 std::map<char*,char*> *GetUsers();
224 std::map<char*,char*> *GetOppedUsers();
225 std::map<char*,char*> *GetHalfoppedUsers();
226 std::map<char*,char*> *GetVoicedUsers();
228 /** Creates a channel record and initialises it with default values
232 virtual ~chanrec() { /* stub */ }
235 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
236 * needs to come AFTER struct chanrec */
237 enum UserChannelModes {
243 /** Holds a user's modes on a channel
244 * This class associates a users privilages with a channel by creating a pointer link between
245 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
246 * has on the channel, such as op, voice, etc.
248 class ucrec : public classbase
251 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
252 * If this value is zero, the user has no privilages upon the channel.
256 /** Points to the channel record where the given modes apply.
257 * If the record is not in use, this value will be NULL.
261 ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
262 virtual ~ucrec() { /* stub */ }
265 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
266 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
267 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
268 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);