1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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 #include "inspircd_config.h"
23 #ifndef __CHANNELS_H__
24 #define __CHANNELS_H__
26 #define CM_TOPICLOCK 1
27 #define CM_NOEXTERNAL 2
28 #define CM_INVITEONLY 4
29 #define CM_MODERATED 8
33 /** Holds an entry for a ban list, exemption list, or invite list.
34 * This class contains a single element in a channel list, such as a banlist.
36 class HostItem : public classbase
43 HostItem() { /* stub */ }
44 virtual ~HostItem() { /* stub */ }
47 // banlist is inherited from HostList mainly for readability
50 /** A subclass of HostItem designed to hold channel bans (+b)
52 class BanItem : public HostItem
58 /** A subclass of HostItem designed to hold channel exempts (+e)
60 class ExemptItem : public HostItem
66 /** A subclass of HostItem designed to hold channel invites (+I)
68 class InviteItem : public HostItem
73 /** Holds a custom parameter to a module-defined channel mode
74 * e.g. for +L this would hold the channel name.
77 class ModeParameter : public classbase
81 char parameter[MAXBUF];
82 char channel[CHANMAX];
85 /** Holds a complete ban list
87 typedef std::vector<BanItem> BanList;
89 /** Holds a complete exempt list
91 typedef std::vector<ExemptItem> ExemptList;
93 /** Holds a complete invite list
95 typedef std::vector<InviteItem> InviteList;
97 /** Holds all relevent information for a channel.
98 * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
99 * etc, and an instance of the BanList type.
101 class chanrec : public Extensible
104 /** The channels name.
106 char name[CHANMAX]; /* channel name */
107 /** Custom modes for the channel.
108 * Plugins may use this field in any way they see fit.
110 char custom_modes[MAXMODES]; /* modes handled by modules */
112 /** User list (casted to char*'s to stop forward declaration stuff)
113 * (chicken and egg scenario!)
115 std::vector<char*> internal_userlist;
118 * If this is an empty string, no channel topic is set.
124 /** Time topic was set.
125 * If no topic was ever set, this will be equal to chanrec::created
128 /** The last user to set the topic.
129 * If this member is an empty string, no topic was ever set.
133 /** Contains the channel user limit.
134 * If this value is zero, there is no limit in place.
138 /** Contains the channel key.
139 * If this value is an empty string, there is no channel key in place.
143 /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
147 /** The list of all bans set on the channel.
151 /** Sets or unsets a custom mode in the channels info
152 * @param mode The mode character to set or unset
153 * @param mode_on True if you want to set the mode or false if you want to remove it
155 void SetCustomMode(char mode,bool mode_on);
157 /** Sets or unsets the parameters for a custom mode in a channels info
158 * @param mode The mode character to set or unset
159 * @param parameter The parameter string to associate with this mode character
160 * @param mode_on True if you want to set the mode or false if you want to remove it
162 void SetCustomModeParam(char mode,char* parameter,bool mode_on);
164 /** Returns true if a custom mode is set on a channel
165 * @param mode The mode character you wish to query
166 * @return True if the custom mode is set, false if otherwise
168 bool IsCustomModeSet(char mode);
170 /** Returns the parameter for a custom mode on a channel.
171 * @param mode The mode character you wish to query
173 * For example if "+L #foo" is set, and you pass this method
174 * 'L', it will return '#foo'. If the mode is not set on the
175 * channel, or the mode has no parameters associated with it,
176 * it will return an empty string.
178 * @return The parameter for this mode is returned, or an empty string
180 std::string GetModeParameter(char mode);
182 /** Obtain the channel "user counter"
183 * This returns the channel reference counter, which is initialized
184 * to 0 when the channel is created and incremented/decremented
185 * upon joins, parts quits and kicks.
187 * @return The number of users on this channel
189 long GetUserCounter();
191 /** Add a user pointer to the internal reference list
192 * @param castuser This should be a pointer to a userrec, casted to char*
194 * The data inserted into the reference list is a table as it is
195 * an arbitary pointer compared to other users by its memory address,
196 * as this is a very fast 32 or 64 bit integer comparison.
198 void AddUser(char* castuser);
200 /** Delete a user pointer to the internal reference list
201 * @param castuser This should be a pointer to a userrec, casted to char*
203 * The data removed from the reference list is a table as it is
204 * an arbitary pointer compared to other users by its memory address,
205 * as this is a very fast 32 or 64 bit integer comparison.
207 void DelUser(char* castuser);
209 /** Obrain the internal reference list
210 * The internal reference list contains a list of userrec*
211 * cast to char*. These are used for rapid comparison to determine
212 * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
213 * The resulting pointer to the vector should be considered
214 * readonly and only modified via AddUser and DelUser.
216 * @return This function returns a vector of userrec pointers, each of which has been casted to char* to prevent circular references
218 std::vector<char*> *GetUsers();
220 /** Creates a channel record and initialises it with default values
224 virtual ~chanrec() { /* stub */ }
227 /* used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
228 * needs to come AFTER struct chanrec */
231 #define UCMODE_VOICE 2
233 #define UCMODE_PROTECT 8
234 #define UCMODE_FOUNDER 16
236 /** Holds a user's modes on a channel
237 * This class associates a users privilages with a channel by creating a pointer link between
238 * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user
239 * has on the channel, such as op, voice, etc.
241 class ucrec : public classbase
244 /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
245 * If this value is zero, the user has no privilages upon the channel.
249 /** Points to the channel record where the given modes apply.
250 * If the record is not in use, this value will be NULL.
254 ucrec() { /* stub */ }
255 virtual ~ucrec() { /* stub */ }