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 #define CM_TOPICLOCK 1
28 #define CM_NOEXTERNAL 2
29 #define CM_INVITEONLY 4
30 #define CM_MODERATED 8
36 /** Holds an entry for a ban list, exemption list, or invite list.
37 * This class contains a single element in a channel list, such as a banlist.
39 class HostItem : public classbase
46 HostItem() { /* stub */ }
47 virtual ~HostItem() { /* stub */ }
50 // banlist is inherited from HostList mainly for readability
53 /** A subclass of HostItem designed to hold channel bans (+b)
55 class BanItem : public HostItem
61 /** A subclass of HostItem designed to hold channel exempts (+e)
63 class ExemptItem : public HostItem
69 /** A subclass of HostItem designed to hold channel invites (+I)
71 class InviteItem : public HostItem
76 /** Holds a custom parameter to a module-defined channel mode
77 * e.g. for +L this would hold the channel name.
80 class ModeParameter : public classbase
84 char parameter[MAXBUF];
85 char channel[CHANMAX];
88 /** Holds a complete ban list
90 typedef std::vector<BanItem> BanList;
92 /** Holds a complete exempt list
94 typedef std::vector<ExemptItem> ExemptList;
96 /** Holds a complete invite list
98 typedef std::vector<InviteItem> InviteList;
100 /** Holds all relevent information for a channel.
101 * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
102 * etc, and an instance of the BanList type.
104 class chanrec : public Extensible
107 /** The channels name.
109 char name[CHANMAX]; /* channel name */
110 /** Custom modes for the channel.
111 * Plugins may use this field in any way they see fit.
113 char custom_modes[MAXMODES]; /* modes handled by modules */
115 /** User list (casted to char*'s to stop forward declaration stuff)
116 * (chicken and egg scenario!)
118 std::map<char*,char*> internal_userlist;
119 std::map<char*,char*> internal_op_userlist;
120 std::map<char*,char*> internal_halfop_userlist;
121 std::map<char*,char*> internal_voice_userlist;
123 /** Parameters for custom modes
125 std::vector<ModeParameter> custom_mode_params;
128 * If this is an empty string, no channel topic is set.
134 /** Time topic was set.
135 * If no topic was ever set, this will be equal to chanrec::created
138 /** The last user to set the topic.
139 * If this member is an empty string, no topic was ever set.
143 /** Contains the channel user limit.
144 * If this value is zero, there is no limit in place.
148 /** Contains the channel key.
149 * If this value is an empty string, there is no channel key in place.
153 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
157 /** The list of all bans set on the channel.
161 /** Sets or unsets a custom mode in the channels info
162 * @param mode The mode character to set or unset
163 * @param mode_on True if you want to set the mode or false if you want to remove it
165 void SetCustomMode(char mode,bool mode_on);
167 /** Sets or unsets the parameters for a custom mode in a channels info
168 * @param mode The mode character to set or unset
169 * @param parameter The parameter string to associate with this mode character
170 * @param mode_on True if you want to set the mode or false if you want to remove it
172 void SetCustomModeParam(char mode,char* parameter,bool mode_on);
174 /** Returns true if a custom mode is set on a channel
175 * @param mode The mode character you wish to query
176 * @return True if the custom mode is set, false if otherwise
178 bool IsCustomModeSet(char mode);
180 /** Returns the parameter for a custom mode on a channel.
181 * @param mode The mode character you wish to query
183 * For example if "+L #foo" is set, and you pass this method
184 * 'L', it will return '#foo'. If the mode is not set on the
185 * channel, or the mode has no parameters associated with it,
186 * it will return an empty string.
188 * @return The parameter for this mode is returned, or an empty string
190 std::string GetModeParameter(char mode);
192 /** Obtain the channel "user counter"
193 * This returns the channel reference counter, which is initialized
194 * to 0 when the channel is created and incremented/decremented
195 * upon joins, parts quits and kicks.
197 * @return The number of users on this channel
199 long GetUserCounter();
201 /** Add a user pointer to the internal reference list
202 * @param castuser This should be a pointer to a userrec, casted to char*
204 * The data inserted into the reference list is a table as it is
205 * an arbitary pointer compared to other users by its memory address,
206 * as this is a very fast 32 or 64 bit integer comparison.
208 void AddUser(char* castuser);
209 void AddOppedUser(char* castuser);
210 void AddHalfoppedUser(char* castuser);
211 void AddVoicedUser(char* castuser);
213 /** Delete a user pointer to the internal reference list
214 * @param castuser This should be a pointer to a userrec, casted to char*
216 * The data removed from the reference list is a table as it is
217 * an arbitary pointer compared to other users by its memory address,
218 * as this is a very fast 32 or 64 bit integer comparison.
220 void DelUser(char* castuser);
221 void DelOppedUser(char* castuser);
222 void DelHalfoppedUser(char* castuser);
223 void DelVoicedUser(char* castuser);
225 /** Obrain the internal reference list
226 * The internal reference list contains a list of userrec*
227 * cast to char*. 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 a vector of userrec pointers, each of which has been casted to char* to prevent circular references
234 std::map<char*,char*> *GetUsers();
235 std::map<char*,char*> *GetOppedUsers();
236 std::map<char*,char*> *GetHalfoppedUsers();
237 std::map<char*,char*> *GetVoicedUsers();
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 */
250 #define UCMODE_VOICE 2
252 #define UCMODE_PROTECT 8
253 #define UCMODE_FOUNDER 16
255 /** Holds a user's modes on a channel
256 * This class associates a users privilages with a channel by creating a pointer link between
257 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
258 * has on the channel, such as op, voice, etc.
260 class ucrec : public classbase
263 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
264 * If this value is zero, the user has no privilages upon the channel.
268 /** Points to the channel record where the given modes apply.
269 * If the record is not in use, this value will be NULL.
273 ucrec() { /* stub */ }
274 virtual ~ucrec() { /* stub */ }
277 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
278 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
279 void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
280 void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);