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"
28 CM_TOPICLOCK = 't'-65,
29 CM_NOEXTERNAL = 'n'-65,
30 CM_INVITEONLY = 'i'-65,
31 CM_MODERATED = 'm'-65,
40 /** Holds an entry for a ban list, exemption list, or invite list.
41 * This class contains a single element in a channel list, such as a banlist.
43 class HostItem : public classbase
50 HostItem() { /* stub */ }
51 virtual ~HostItem() { /* stub */ }
54 // banlist is inherited from HostList mainly for readability
57 /** A subclass of HostItem designed to hold channel bans (+b)
59 class BanItem : public HostItem
65 /** A subclass of HostItem designed to hold channel exempts (+e)
67 class ExemptItem : public HostItem
73 /** A subclass of HostItem designed to hold channel invites (+I)
75 class InviteItem : public HostItem
79 /** Holds a complete ban list
81 typedef std::vector<BanItem> BanList;
83 /** Holds a complete exempt list
85 typedef std::vector<ExemptItem> ExemptList;
87 /** Holds a complete invite list
89 typedef std::vector<InviteItem> InviteList;
93 /** A list of users on a channel
95 typedef std::map<userrec*,userrec*> CUList;
97 /** A list of custom modes parameters on a channel
99 typedef std::map<char,char*> CustomModeList;
101 /** Holds all relevent information for a channel.
102 * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
103 * etc, and an instance of the BanList type.
105 class chanrec : public Extensible
108 /** The channels name.
110 char name[CHANMAX]; /* channel name */
111 /** Custom modes for the channel.
112 * Plugins may use this field in any way they see fit.
114 char modes[64]; /* modes handled by modules */
117 * There are four user lists, one for
118 * all the users, one for the ops, one for
119 * the halfops and another for the voices.
121 CUList internal_userlist;
122 CUList internal_op_userlist;
123 CUList internal_halfop_userlist;
124 CUList internal_voice_userlist;
126 /** Parameters for custom modes
128 CustomModeList custom_mode_params;
131 * If this is an empty string, no channel topic is set.
133 char topic[MAXTOPIC];
137 /** Time topic was set.
138 * If no topic was ever set, this will be equal to chanrec::created
141 /** The last user to set the topic.
142 * If this member is an empty string, no topic was ever set.
146 /** Contains the channel user limit.
147 * If this value is zero, there is no limit in place.
151 /** Contains the channel key.
152 * If this value is an empty string, there is no channel key in place.
156 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
160 /** The list of all bans set on the channel.
164 /** Sets or unsets a custom mode in the channels info
165 * @param mode The mode character to set or unset
166 * @param mode_on True if you want to set the mode or false if you want to remove it
168 void SetCustomMode(char mode,bool mode_on);
170 /** Sets or unsets the parameters for a custom mode in a channels info
171 * @param mode The mode character to set or unset
172 * @param parameter The parameter string to associate with this mode character
173 * @param mode_on True if you want to set the mode or false if you want to remove it
175 void SetCustomModeParam(char mode,char* parameter,bool mode_on);
177 /** Returns true if a mode is set on a channel
178 * @param mode The mode character you wish to query
179 * @return True if the custom mode is set, false if otherwise
181 bool IsModeSet(char mode);
183 /** Returns the parameter for a custom mode on a channel.
184 * @param mode The mode character you wish to query
186 * For example if "+L #foo" is set, and you pass this method
187 * 'L', it will return '#foo'. If the mode is not set on the
188 * channel, or the mode has no parameters associated with it,
189 * it will return an empty string.
191 * @return The parameter for this mode is returned, or an empty string
193 std::string GetModeParameter(char mode);
195 /** Obtain the channel "user counter"
196 * This returns the channel reference counter, which is initialized
197 * to 0 when the channel is created and incremented/decremented
198 * upon joins, parts quits and kicks.
200 * @return The number of users on this channel
202 long GetUserCounter();
204 /** Add a user pointer to the internal reference list
205 * @param user The user to add
207 * The data inserted into the reference list is a table as it is
208 * an arbitary pointer compared to other users by its memory address,
209 * as this is a very fast 32 or 64 bit integer comparison.
211 void AddUser(userrec* user);
212 void AddOppedUser(userrec* user);
213 void AddHalfoppedUser(userrec* user);
214 void AddVoicedUser(userrec* user);
216 /** Delete a user pointer to the internal reference list
217 * @param user The user to delete
218 * @return number of users left on the channel
220 unsigned long DelUser(userrec* user);
221 void DelOppedUser(userrec* user);
222 void DelHalfoppedUser(userrec* user);
223 void DelVoicedUser(userrec* user);
225 /** Obrain the internal reference list
226 * The internal reference list contains a list of userrec*.
227 * These are used for rapid comparison to determine
228 * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
229 * The resulting pointer to the vector should be considered
230 * readonly and only modified via AddUser and DelUser.
232 * @return This function returns pointer to a map of userrec pointers (CUList*).
235 CUList* GetOppedUsers();
236 CUList* GetHalfoppedUsers();
237 CUList* GetVoicedUsers();
239 bool HasUser(userrec* user);
241 /** Creates a channel record and initialises it with default values
245 virtual ~chanrec() { /* stub */ }
248 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
249 * needs to come AFTER struct chanrec */
250 enum UserChannelModes {
256 /** Holds a user's modes on a channel
257 * This class associates a users privilages with a channel by creating a pointer link between
258 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
259 * has on the channel, such as op, voice, etc.
261 class ucrec : public classbase
264 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
265 * If this value is zero, the user has no privilages upon the channel.
269 /** Points to the channel record where the given modes apply.
270 * If the record is not in use, this value will be NULL.
274 ucrec() : uc_modes(0), channel(NULL) { /* stub */ }
275 virtual ~ucrec() { /* stub */ }
278 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
279 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
280 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
281 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);