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 /** 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 /** Custom modes for the channel.
110 * Plugins may use this field in any way they see fit.
112 char custom_modes[64]; /* modes handled by modules */
115 * There are four user lists, one for
116 * all the users, one for the ops, one for
117 * the halfops and another for the voices.
119 CUList internal_userlist;
120 CUList internal_op_userlist;
121 CUList internal_halfop_userlist;
122 CUList internal_voice_userlist;
124 /** Parameters for custom modes
126 CustomModeList custom_mode_params;
129 * If this is an empty string, no channel topic is set.
131 char topic[MAXTOPIC];
135 /** Time topic was set.
136 * If no topic was ever set, this will be equal to chanrec::created
139 /** The last user to set the topic.
140 * If this member is an empty string, no topic was ever set.
144 /** Contains the channel user limit.
145 * If this value is zero, there is no limit in place.
149 /** Contains the channel key.
150 * If this value is an empty string, there is no channel key in place.
154 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
158 /** The list of all bans set on the channel.
162 /** Sets or unsets a custom mode in the channels info
163 * @param mode The mode character to set or unset
164 * @param mode_on True if you want to set the mode or false if you want to remove it
166 void SetCustomMode(char mode,bool mode_on);
168 /** Sets or unsets the parameters for a custom mode in a channels info
169 * @param mode The mode character to set or unset
170 * @param parameter The parameter string to associate with this mode character
171 * @param mode_on True if you want to set the mode or false if you want to remove it
173 void SetCustomModeParam(char mode,char* parameter,bool mode_on);
175 /** Returns true if a custom mode is set on a channel
176 * @param mode The mode character you wish to query
177 * @return True if the custom mode is set, false if otherwise
179 bool IsCustomModeSet(char mode);
181 /** Returns the parameter for a custom mode on a channel.
182 * @param mode The mode character you wish to query
184 * For example if "+L #foo" is set, and you pass this method
185 * 'L', it will return '#foo'. If the mode is not set on the
186 * channel, or the mode has no parameters associated with it,
187 * it will return an empty string.
189 * @return The parameter for this mode is returned, or an empty string
191 std::string GetModeParameter(char mode);
193 /** Obtain the channel "user counter"
194 * This returns the channel reference counter, which is initialized
195 * to 0 when the channel is created and incremented/decremented
196 * upon joins, parts quits and kicks.
198 * @return The number of users on this channel
200 long GetUserCounter();
202 /** Add a user pointer to the internal reference list
203 * @param user The user to add
205 * The data inserted into 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 AddUser(userrec* user);
210 void AddOppedUser(userrec* user);
211 void AddHalfoppedUser(userrec* user);
212 void AddVoicedUser(userrec* user);
214 /** Delete a user pointer to the internal reference list
215 * @param user The user to delete
216 * @return number of users left on the channel
218 unsigned long DelUser(userrec* user);
219 void DelOppedUser(userrec* user);
220 void DelHalfoppedUser(userrec* user);
221 void DelVoicedUser(userrec* user);
223 /** Obrain the internal reference list
224 * The internal reference list contains a list of userrec*.
225 * These are used for rapid comparison to determine
226 * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
227 * The resulting pointer to the vector should be considered
228 * readonly and only modified via AddUser and DelUser.
230 * @return This function returns pointer to a map of userrec pointers (CUList*).
233 CUList* GetOppedUsers();
234 CUList* GetHalfoppedUsers();
235 CUList* GetVoicedUsers();
237 bool HasUser(userrec* user);
239 /** Creates a channel record and initialises it with default values
243 virtual ~chanrec() { /* stub */ }
246 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
247 * needs to come AFTER struct chanrec */
248 enum UserChannelModes {
254 /** Holds a user's modes on a channel
255 * This class associates a users privilages with a channel by creating a pointer link between
256 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
257 * has on the channel, such as op, voice, etc.
259 class ucrec : public classbase
262 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
263 * If this value is zero, the user has no privilages upon the channel.
267 /** Points to the channel record where the given modes apply.
268 * If the record is not in use, this value will be NULL.
272 ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
273 virtual ~ucrec() { /* stub */ }
276 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
277 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
278 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
279 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);