]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/channels.h
Add example modules.conf files that match Unreal and Charybdis feature sets [jdhore]
[user/henk/code/inspircd.git] / include / channels.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __CHANNELS_H__
15 #define __CHANNELS_H__
16
17 #include "membership.h"
18
19 /** RFC1459 channel modes
20  */
21 enum ChannelModes {
22         CM_TOPICLOCK = 't'-65,  /* +t: Only operators can change topic */
23         CM_NOEXTERNAL = 'n'-65, /* +n: Only users in the channel can message it */
24         CM_INVITEONLY = 'i'-65, /* +i: Invite only */
25         CM_MODERATED = 'm'-65,  /* +m: Only voices and above can talk */
26         CM_SECRET = 's'-65,     /* +s: Secret channel */
27         CM_PRIVATE = 'p'-65,    /* +p: Private channel */
28         CM_KEY = 'k'-65,        /* +k: Keyed channel */
29         CM_LIMIT = 'l'-65       /* +l: Maximum user limit */
30 };
31
32 /** Holds an entry for a ban list, exemption list, or invite list.
33  * This class contains a single element in a channel list, such as a banlist.
34  */
35 class HostItem
36 {
37  public:
38         /** Time the item was added
39          */
40         time_t set_time;
41         /** Who added the item
42          */
43         std::string set_by;
44         /** The actual item data
45          */
46         std::string data;
47
48         HostItem() { /* stub */ }
49         virtual ~HostItem() { /* stub */ }
50 };
51
52 /** A subclass of HostItem designed to hold channel bans (+b)
53  */
54 class BanItem : public HostItem
55 {
56 };
57
58 /** used to hold a channel and a users modes on that channel, e.g. +v, +h, +o
59  */
60 enum UserChannelModes {
61         UCMODE_OP       = 1,    /* Opped user */
62         UCMODE_VOICE    = 2,    /* Voiced user */
63         UCMODE_HOP      = 4     /* Halfopped user */
64 };
65
66 /** Holds all relevent information for a channel.
67  * This class represents a channel, and contains its name, modes, topic, topic set time,
68  * etc, and an instance of the BanList type.
69  */
70 class CoreExport Channel : public Extensible
71 {
72         /** Connect a Channel to a User
73          */
74         static Channel* ForceChan(Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created);
75
76         /** Set default modes for the channel on creation
77          */
78         void SetDefaultModes();
79
80         /** Maximum number of bans (cached)
81          */
82         int maxbans;
83
84  public:
85         /** Creates a channel record and initialises it with default values
86          * @throw Nothing at present.
87          */
88         Channel(const std::string &name, time_t ts);
89
90         /** The channel's name.
91          */
92         std::string name; /* CHANMAX */
93
94         /** Time that the object was instantiated (used for TS calculation etc)
95         */
96         time_t age;
97
98         /** Modes for the channel.
99          * This is not a null terminated string! It is a bitset where
100          * each item in it represents if a mode is set. For example
101          * for mode +A, index 0. Use modechar-65 to calculate which
102          * field to check.
103          */
104         std::bitset<64> modes;
105
106         /** User list.
107          */
108         UserMembList userlist;
109
110         /** Parameters for custom modes.
111          * One for each custom mode letter.
112          */
113         CustomModeList custom_mode_params;
114
115         /** Channel topic.
116          * If this is an empty string, no channel topic is set.
117          */
118         std::string topic; /* MAXTOPIC */
119
120         /** Time topic was set.
121          * If no topic was ever set, this will be equal to Channel::created
122          */
123         time_t topicset;
124
125         /** The last user to set the topic.
126          * If this member is an empty string, no topic was ever set.
127          */
128         std::string setby; /* 128 */
129
130         /** The list of all bans set on the channel.
131          */
132         BanList bans;
133
134         /** Sets or unsets a custom mode in the channels info
135          * @param mode The mode character to set or unset
136          * @param mode_on True if you want to set the mode or false if you want to remove it
137          */
138         void SetMode(char mode,bool mode_on);
139
140         /** Sets or unsets a custom mode in the channels info
141          * @param mode The mode character to set or unset
142          * @param parameter The parameter string to associate with this mode character.
143          * If it is empty, the mode is unset; if it is nonempty, the mode is set.
144          */
145         void SetModeParam(char mode, std::string parameter);
146
147         /** Returns true if a mode is set on a channel
148           * @param mode The mode character you wish to query
149           * @return True if the custom mode is set, false if otherwise
150           */
151         inline bool IsModeSet(char mode) { return modes[mode-'A']; }
152
153
154         /** Returns the parameter for a custom mode on a channel.
155           * @param mode The mode character you wish to query
156           *
157           * For example if "+L #foo" is set, and you pass this method
158           * 'L', it will return '#foo'. If the mode is not set on the
159           * channel, or the mode has no parameters associated with it,
160           * it will return an empty string.
161           *
162           * @return The parameter for this mode is returned, or an empty string
163           */
164         std::string GetModeParameter(char mode);
165
166         /** Sets the channel topic.
167          * @param u The user setting the topic
168          * @param t The topic to set it to. Non-const, as it may be modified by a hook.
169          * @param forceset If set to true then all access checks will be bypassed.
170          */
171         int SetTopic(User *u, std::string &t, bool forceset = false);
172
173         /** Obtain the channel "user counter"
174          * This returns the channel reference counter, which is initialized
175          * to 0 when the channel is created and incremented/decremented
176          * upon joins, parts quits and kicks.
177          *
178          * @return The number of users on this channel
179          */
180         long GetUserCounter();
181
182         /** Add a user pointer to the internal reference list
183          * @param user The user to add
184          *
185          * The data inserted into the reference list is a table as it is
186          * an arbitary pointer compared to other users by its memory address,
187          * as this is a very fast 32 or 64 bit integer comparison.
188          */
189         Membership* AddUser(User* user);
190
191         /** Delete a user pointer to the internal reference list
192          * @param user The user to delete
193          * @return number of users left on the channel after deletion of the user
194          */
195         void DelUser(User* user);
196
197         /** Obtain the internal reference list
198          * The internal reference list contains a list of User*.
199          * These are used for rapid comparison to determine
200          * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
201          * The resulting pointer to the vector should be considered
202          * readonly and only modified via AddUser and DelUser.
203          *
204          * @return This function returns pointer to a map of User pointers (CUList*).
205          */
206         const UserMembList* GetUsers();
207
208         /** Returns true if the user given is on the given channel.
209          * @param The user to look for
210          * @return True if the user is on this channel
211          */
212         bool HasUser(User* user);
213
214         Membership* GetUser(User* user);
215
216         /** Make src kick user from this channel with the given reason.
217          * @param src The source of the kick
218          * @param user The user being kicked (must be on this channel)
219          * @param reason The reason for the kick
220          */
221         void KickUser(User *src, User *user, const char* reason);
222
223         /** Part a user from this channel with the given reason.
224          * If the reason field is NULL, no reason will be sent.
225          * @param user The user who is parting (must be on this channel)
226          * @param reason The part reason
227          */
228         void PartUser(User *user, std::string &reason);
229
230         /* Join a user to a channel. May be a channel that doesnt exist yet.
231          * @param user The user to join to the channel.
232          * @param cn The channel name to join to. Does not have to exist.
233          * @param key The key of the channel, if given
234          * @param override If true, override all join restrictions such as +bkil
235          * @return A pointer to the Channel the user was joined to. A new Channel may have
236          * been created if the channel did not exist before the user was joined to it.
237          * If the user could not be joined to a channel, the return value may be NULL.
238          */
239         static Channel* JoinUser(User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS = 0);
240
241         /** Write to a channel, from a user, using va_args for text
242          * @param user User whos details to prefix the line with
243          * @param text A printf-style format string which builds the output line without prefix
244          * @param ... Zero or more POD types
245          */
246         void WriteChannel(User* user, const char* text, ...) CUSTOM_PRINTF(3, 4);
247
248         /** Write to a channel, from a user, using std::string for text
249          * @param user User whos details to prefix the line with
250          * @param text A std::string containing the output line without prefix
251          */
252         void WriteChannel(User* user, const std::string &text);
253
254         /** Write to a channel, from a server, using va_args for text
255          * @param ServName Server name to prefix the line with
256          * @param text A printf-style format string which builds the output line without prefix
257          * @param ... Zero or more POD type
258          */
259         void WriteChannelWithServ(const std::string& ServName, const char* text, ...) CUSTOM_PRINTF(3, 4);
260
261         /** Write to a channel, from a server, using std::string for text
262          * @param ServName Server name to prefix the line with
263          * @param text A std::string containing the output line without prefix
264          */
265         void WriteChannelWithServ(const std::string& ServName, const std::string &text);
266
267         /** Write to all users on a channel except a specific user, using va_args for text.
268          * Internally, this calls WriteAllExcept().
269          * @param user User whos details to prefix the line with, and to omit from receipt of the message
270          * @param serversource If this parameter is true, use the local server name as the source of the text, otherwise,
271          * use the nick!user@host of the user.
272          * @param status The status of the users to write to, e.g. '@' or '%'. Use a value of 0 to write to everyone
273          * @param text A printf-style format string which builds the output line without prefix
274          * @param ... Zero or more POD type
275          */
276         void WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...) CUSTOM_PRINTF(5, 6);
277
278         /** Write to all users on a channel except a list of users, using va_args for text
279          * @param user User whos details to prefix the line with, and to omit from receipt of the message
280          * @param serversource If this parameter is true, use the local server name as the source of the text, otherwise,
281          * use the nick!user@host of the user.
282          * @param status The status of the users to write to, e.g. '@' or '%'. Use a value of 0 to write to everyone
283          * @param except_list A list of users NOT to send the text to
284          * @param text A printf-style format string which builds the output line without prefix
285          * @param ... Zero or more POD type
286          */
287         void WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...) CUSTOM_PRINTF(6, 7);
288
289         /** Write to all users on a channel except a specific user, using std::string for text.
290          * Internally, this calls WriteAllExcept().
291          * @param user User whos details to prefix the line with, and to omit from receipt of the message
292          * @param serversource If this parameter is true, use the local server name as the source of the text, otherwise,
293          * use the nick!user@host of the user.
294          * @param status The status of the users to write to, e.g. '@' or '%'. Use a value of 0 to write to everyone
295          * @param text A std::string containing the output line without prefix
296          */
297         void WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text);
298
299         /** Write to all users on a channel except a list of users, using std::string for text
300          * @param user User whos details to prefix the line with, and to omit from receipt of the message
301          * @param serversource If this parameter is true, use the local server name as the source of the text, otherwise,
302          * use the nick!user@host of the user.
303          * @param status The status of the users to write to, e.g. '@' or '%'. Use a value of 0 to write to everyone
304          * @param except_list A list of users NOT to send the text to
305          * @param text A std::string containing the output line without prefix
306          */
307         void WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text);
308         /** Write a line of text that already includes the source */
309         void RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text);
310
311         /** Returns the maximum number of bans allowed to be set on this channel
312          * @return The maximum number of bans allowed
313          */
314         long GetMaxBans();
315
316         /** Return the channel's modes with parameters.
317          * @param showkey If this is set to true, the actual key is shown,
318          * otherwise it is replaced with '&lt;KEY&gt;'
319          * @return The channel mode string
320          */
321         char* ChanModes(bool showkey);
322
323         /** Spool the NAMES list for this channel to the given user
324          * @param user The user to spool the NAMES list to
325          */
326         void UserList(User *user);
327
328         /** Get the number of invisible users on this channel
329          * @return Number of invisible users
330          */
331         int CountInvisible();
332
333         /** Get a users prefix on this channel in a string.
334          * @param user The user to look up
335          * @return A character array containing the prefix string.
336          * Unlike GetStatus and GetStatusFlags which will only return the
337          * core specified modes @, % and + (op, halfop and voice), GetPrefixChar
338          * will also return module-defined prefixes. If the user has to prefix,
339          * an empty but non-null string is returned. If the user has multiple
340          * prefixes, the highest is returned. If you do not recognise the prefix
341          * character you can get, you can deal with it in a 'proprtional' manner
342          * compared to known prefixes, using GetPrefixValue().
343          */
344         const char* GetPrefixChar(User *user);
345
346         /** Return all of a users mode prefixes into a char* string.
347          * @param user The user to look up
348          * @return A list of all prefix characters. The prefixes will always
349          * be in rank order, greatest first, as certain IRC clients require
350          * this when multiple prefixes are used names lists.
351          */
352         const char* GetAllPrefixChars(User* user);
353
354         /** Get the value of a users prefix on this channel.
355          * @param user The user to look up
356          * @return The module or core-defined value of the users prefix.
357          * The values for op, halfop and voice status are constants in
358          * mode.h, and are OP_VALUE, HALFOP_VALUE, and VOICE_VALUE respectively.
359          * If the value you are given does not match one of these three, it is
360          * a module-defined mode, and it should be compared in proportion to
361          * these three constants. For example a value greater than OP_VALUE
362          * is a prefix of greater 'worth' than ops, and a value less than
363          * VOICE_VALUE is of lesser 'worth' than a voice.
364          */
365         unsigned int GetPrefixValue(User* user);
366
367         /** This method removes all prefix characters from a user.
368          * It will not inform the user or the channel of the removal of prefixes,
369          * and should be used when the user parts or quits.
370          * @param user The user to remove all prefixes from
371          */
372         void RemoveAllPrefixes(User* user);
373
374         /** Add a prefix character to a user.
375          * Only the core should call this method, usually  from
376          * within the mode parser or when the first user joins
377          * the channel (to grant ops to them)
378          * @param user The user to associate the privilage with
379          * @param prefix The prefix character to associate
380          * @param adding True if adding the prefix, false when removing
381          */
382         void SetPrefix(User* user, char prefix, bool adding);
383
384         /** Check if a user is banned on this channel
385          * @param user A user to check against the banlist
386          * @returns True if the user given is banned
387          */
388         bool IsBanned(User* user);
389
390         /** Check a single ban for match
391          */
392         bool CheckBan(User* user, const std::string& banmask);
393
394         /** Get the status of an "action" type extban
395          */
396         ModResult GetExtBanStatus(User *u, char type);
397
398         /** Clears the cached max bans value
399          */
400         void ResetMaxBans();
401
402         /** Destructor for Channel
403          */
404         virtual ~Channel() { /* stub */ }
405 };
406
407 #endif