2 * IRC - Internet Relay Chat, ircd/channel.h
3 * Copyright (C) 1990 Jarkko Oikarinen
4 * Copyright (C) 1996 - 1997 Carlo Wood
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * @brief Channel management and maintenance.
22 * @version $Id: channel.h 1860 2007-12-28 15:52:43Z klmitch $
24 #ifndef INCLUDED_channel_h
25 #define INCLUDED_channel_h
26 #ifndef INCLUDED_ircd_defs_h
27 #include "ircd_defs.h" /* NICKLEN */
29 #ifndef INCLUDED_sys_types_h
30 #include <sys/types.h>
31 #define INCLUDED_sys_types_h
33 #ifndef INCLUDED_res_h
40 #if defined(_MSC_VER) || defined(__BORLANDC__)
41 typedef unsigned __int64 ulong64;
42 typedef signed __int64 long64;
44 typedef unsigned long long ulong64;
45 typedef signed long long long64;
52 #define MAXMODEPARAMS 6 /**< Maximum number of mode parameters */
53 #define MODEBUFLEN 200 /**< Maximum length of a mode */
55 #define KEYLEN 23 /**< Maximum length of a key */
56 #define CHANNELLEN 200 /**< Maximum length of a channel */
58 #define MAXJOINARGS 15 /**< number of slots for join buffer */
59 #define STARTJOINLEN 10 /**< fuzzy numbers */
60 #define STARTCREATELEN 20
66 #define ChannelExists(n) (0 != FindChannel(n))
68 #define CHFL_CHANOP 0x0001 /**< Channel operator */
69 #define CHFL_VOICE 0x0002 /**< the power to speak */
70 #define CHFL_DEOPPED 0x0004 /**< Is de-opped by a server */
71 #define CHFL_SERVOPOK 0x0008 /**< Server op allowed */
72 #define CHFL_ZOMBIE 0x0010 /**< Kicked from channel */
73 #define CHFL_BURST_JOINED 0x0100 /**< Just joined by net.junction */
74 #define CHFL_BANVALID 0x0800 /**< CHFL_BANNED bit is valid */
75 #define CHFL_BANNED 0x1000 /**< Channel member is banned */
76 #define CHFL_SILENCE_IPMASK 0x2000 /**< silence mask is a CIDR */
77 #define CHFL_BURST_ALREADY_OPPED 0x04000
78 /**< In oob BURST, but was already
81 #define CHFL_BURST_ALREADY_VOICED 0x08000
82 /**, In oob BURST, but was already
85 #define CHFL_CHANNEL_MANAGER 0x10000 /**< Set when creating channel or using
88 #define CHFL_USER_PARTING 0x20000 /**< User is already parting that
91 #define CHFL_DELAYED 0x40000 /**< User's join message is delayed */
92 #define CHFL_INVISIBLE 0x80000 /**< User's join message is delayed */
94 #define CHFL_OVERLAP (CHFL_CHANOP | CHFL_VOICE)
95 #define CHFL_BANVALIDMASK (CHFL_BANVALID | CHFL_BANNED)
96 #define CHFL_VOICED_OR_OPPED (CHFL_CHANOP | CHFL_VOICE)
98 /* Channel Visibility macros */
101 #define MODE_CHANOP CHFL_CHANOP /**< +o Chanop */
102 #define MODE_VOICE CHFL_VOICE /**< +v Voice */
103 #define MODE_PRIVATE 0x00004 /**< +p Private */
104 #define MODE_SECRET 0x00008 /**< +s Secret */
105 #define MODE_MODERATED 0x00010 /**< +m Moderated */
106 #define MODE_TOPICLIMIT 0x00020 /**< +t Topic Limited */
107 #define MODE_INVITEONLY 0x00040 /**< +i Invite only */
108 #define MODE_NOPRIVMSGS 0x00080 /**< +n No Private Messages */
109 #define MODE_KEY 0x00100 /**< +k Keyed */
110 #define MODE_BAN 0x00200 /**< +b Ban */
111 #define MODE_LIMIT 0x00400 /**< +l Limit */
112 #define MODE_REGONLY 0x00800 /**< Only +r users may join */
113 #define MODE_DELJOINS 0x01000 /**< New join messages are delayed */
114 #define MODE_REGISTERED 0x02000 /**< Channel marked as registered (for future semantic expansion) */
115 #define MODE_PERSIST 0x04000 /**< +z persistant channel */
116 #define MODE_NOCOLOUR 0x08000 /**< no ANSI color codes */
117 #define MODE_NOCTCP 0x10000 /**< no channel CTCPs */
118 #define MODE_SAVE 0x20000 /**< save this mode-with-arg 'til later */
119 #define MODE_FREE 0x40000 /**< string needs to be passed to MyFree() */
120 #define MODE_BURSTADDED 0x80000 /**< channel was created by a BURST */
121 #define MODE_UPASS 0x100000
122 #define MODE_APASS 0x200000
123 #define MODE_WASDELJOINS 0x400000 /**< Not DELJOINS, but some joins pending */
124 #define MODE_EXCEPTION 0x800000 /**< ban exceptions */
125 #define MODE_NOAMSGS 0x1000000 /**< No multi target messages */
126 #define MODE_NONOTICE 0x2000000 /**< No channel notices */
127 #define MODE_QUARANTINE 0x4000000 /**< No channel notices */
128 #define MODE_ALTCHAN 0x8000000 /**< Alternative channel */
129 #define MODE_DEL 0x20000000
130 #define MODE_ADD 0x40000000
131 #define MODE_ACCESS 0x100000000LLU /**< ChanServ access */
132 #define MODE_AUDITORIUM 0x200000000LLU /**< +u Auditorium */
133 /** mode flags which take another parameter (With PARAmeterS)
135 #define MODE_WPARAS (MODE_CHANOP|MODE_VOICE|MODE_BAN|MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS|MODE_EXCEPTION|MODE_ALTCHAN|MODE_ACCESS)
137 /** Available Channel modes */
138 #define infochanmodes feature_bool(FEAT_OPLEVELS) ? "AcCbiklmMnNopstuUvrDRzQu" : "cCbiklmMnNopstuvrDRzQu"
139 /** Available Channel modes that take parameters */
140 #define infochanmodeswithparams feature_bool(FEAT_OPLEVELS) ? "AbkloUvFa" : "bklovFa"
142 #define HoldChannel(x) (!(x))
143 /** name invisible */
144 #define SecretChannel(x) ((x) && ((x)->mode.mode & MODE_SECRET))
145 /** channel not shown but names are */
146 #define HiddenChannel(x) ((x) && ((x)->mode.mode & MODE_PRIVATE))
147 /** channel visible */
148 #define ShowChannel(v,c) (PubChannel(c) || find_channel_member((v),(c)))
149 #define PubChannel(x) ((!x) || ((x)->mode.mode & \
150 (MODE_PRIVATE | MODE_SECRET)) == 0)
152 #define IsGlobalChannel(name) (*(name) == '#')
153 #define IsLocalChannel(name) (*(name) == '&')
154 #define IsChannelName(name) (IsGlobalChannel(name) || IsLocalChannel(name))
156 typedef enum ChannelGetType {
161 /* used in ListingArgs.flags */
163 #define LISTARG_TOPICLIMITS 0x0001
164 #define LISTARG_SHOWSECRET 0x0002
165 #define LISTARG_NEGATEWILDCARD 0x0004
166 #define LISTARG_SHOWMODES 0x0008
169 * Maximum acceptable lag time in seconds: A channel younger than
170 * this is not protected against hacking admins.
171 * Mainly here to check if the TS clocks really sync (otherwise this
172 * will start causing HACK notices.
173 * This value must be the same on all servers.
175 * This value has been increased to 1 day in order to distinguish this
176 * "normal" type of HACK wallops / desyncs, from possiblity still
179 #define TS_LAG_TIME 86400
183 extern const char* const PartFmt1;
184 extern const char* const PartFmt2;
185 extern const char* const PartFmt1serv;
186 extern const char* const PartFmt2serv;
193 /** Information about a client on one channel
195 * This structure forms a sparse matrix with users down the side, and
196 * channels across the top. This matrix holds all the information about
197 * which users are on what channels, and what modes that user has on that
198 * channel (if they are op'd, voice'd and cached information if they are
202 struct Client* user; /**< The user */
203 struct Channel* channel; /**< The channel */
204 struct Membership* next_member; /**< The next user on this channel */
205 struct Membership* prev_member; /**< The previous user on this channel*/
206 struct Membership* next_channel; /**< Next channel this user is on */
207 struct Membership* prev_channel; /**< Previous channel this user is on*/
208 unsigned int status; /**< Flags for op'd, voice'd, etc */
209 unsigned short oplevel; /**< Op level */
212 #define MAXOPLEVELDIGITS 3
213 #define MAXOPLEVEL 999
215 #define IsZombie(x) ((x)->status & CHFL_ZOMBIE) /**< see \ref zombie */
216 #define IsDeopped(x) ((x)->status & CHFL_DEOPPED)
217 #define IsBanned(x) ((x)->status & CHFL_BANNED)
218 #define IsBanValid(x) ((x)->status & CHFL_BANVALID)
219 #define IsChanOp(x) ((x)->status & CHFL_CHANOP)
220 #define OpLevel(x) ((x)->oplevel)
221 #define HasVoice(x) ((x)->status & CHFL_VOICE)
222 #define IsServOpOk(x) ((x)->status & CHFL_SERVOPOK)
223 #define IsBurstJoined(x) ((x)->status & CHFL_BURST_JOINED)
224 #define IsVoicedOrOpped(x) ((x)->status & CHFL_VOICED_OR_OPPED)
225 #define IsChannelManager(x) ((x)->status & CHFL_CHANNEL_MANAGER)
226 #define IsUserParting(x) ((x)->status & CHFL_USER_PARTING)
227 #define IsDelayedJoin(x) ((x)->status & CHFL_DELAYED)
228 #define IsInvisibleJoin(x) ((x)->status & CHFL_INVISIBLE)
230 #define SetBanned(x) ((x)->status |= CHFL_BANNED)
231 #define SetBanValid(x) ((x)->status |= CHFL_BANVALID)
232 #define SetDeopped(x) ((x)->status |= CHFL_DEOPPED)
233 #define SetServOpOk(x) ((x)->status |= CHFL_SERVOPOK)
234 #define SetBurstJoined(x) ((x)->status |= CHFL_BURST_JOINED)
235 #define SetZombie(x) ((x)->status |= CHFL_ZOMBIE)
236 #define SetChannelManager(x) ((x)->status |= CHFL_CHANNEL_MANAGER)
237 #define SetOpLevel(x, v) (void)((x)->oplevel = (v))
238 #define SetUserParting(x) ((x)->status |= CHFL_USER_PARTING)
239 #define SetDelayedJoin(x) ((x)->status |= CHFL_DELAYED)
241 #define ClearBanned(x) ((x)->status &= ~CHFL_BANNED)
242 #define ClearBanValid(x) ((x)->status &= ~CHFL_BANVALID)
243 #define ClearDeopped(x) ((x)->status &= ~CHFL_DEOPPED)
244 #define ClearServOpOk(x) ((x)->status &= ~CHFL_SERVOPOK)
245 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
246 #define ClearDelayedJoin(x) ((x)->status &= ~CHFL_DELAYED)
247 #define ClearInvisibleJoin(x) ((x)->status &= ~CHFL_DELAYED)
249 /** Mode information for a channel */
254 char key[KEYLEN + 1];
255 char upass[KEYLEN + 1];
256 char apass[KEYLEN + 1];
257 char altchan[CHANNELLEN + 1];
260 #define BAN_IPMASK 0x0001 /**< ban mask is an IP-number mask */
261 #define BAN_OVERLAPPED 0x0002 /**< ban overlapped, need bounce */
262 #define BAN_BURSTED 0x0004 /**< Ban part of last BURST */
263 #define BAN_BURST_WIPEOUT 0x0008 /**< Ban will be wiped at EOB */
264 #define BAN_EXCEPTION 0x0010 /**< Ban is an exception */
265 #define BAN_DEL 0x4000 /**< Ban is being removed */
266 #define BAN_ADD 0x8000 /**< Ban is being added */
268 /** A single ban for a channel. */
270 struct Ban* next; /**< next ban in the channel */
271 struct irc_in_addr address; /**< address for BAN_IPMASK bans */
272 time_t when; /**< timestamp when ban was added */
273 unsigned short flags; /**< modifier flags for the ban */
274 unsigned char nu_len; /**< length of nick!user part of banstr */
275 unsigned char addrbits; /**< netmask length for BAN_IPMASK bans */
276 char who[NICKLEN+1]; /**< name of client that set the ban */
277 char banstr[NICKLEN+USERLEN+HOSTLEN+3]; /**< hostmask that the ban matches */
280 /** Information about a channel */
282 struct Channel* next; /**< next channel in the global channel list */
283 struct Channel* prev; /**< previous channel */
284 struct Channel* hnext; /**< Next channel in the hash table */
285 struct DestructEvent* destruct_event;
286 time_t creationtime; /**< Creation time of this channel */
287 time_t topic_time; /**< Modification time of the topic */
288 unsigned int users; /**< Number of clients on this channel */
289 struct Membership* members; /**< Pointer to the clients on this channel*/
290 struct SLink* invites; /**< List of invites on this channel */
291 struct Ban* banlist; /**< List of bans on this channel */
292 struct Mode mode; /**< This channels mode */
293 char topic[TOPICLEN + 1]; /**< Channels topic */
294 char topic_nick[NICKLEN + 1]; /**< Nick of the person who set
297 char chanowner[NICKLEN + 1]; //channel owner (auth)
298 char chname[1]; /**< Dynamically allocated string of the
303 /** Information about a /list in progress */
307 unsigned int max_users;
308 unsigned int min_users;
310 time_t max_topic_time;
311 time_t min_topic_time;
313 char wildcard[CHANNELLEN];
317 ulong64 mb_add; /**< Modes to add */
318 ulong64 mb_rem; /**< Modes to remove */
319 struct Client *mb_source; /**< Source of MODE changes */
320 struct Client *mb_connect; /**< Connection of MODE changes */
321 struct Channel *mb_channel; /**< Channel they affect */
322 unsigned int mb_dest; /**< Destination of MODE changes */
323 unsigned int mb_count; /**< Number of modes w/args */
325 ulong64 mbm_type; /**< Type of argument */
327 unsigned int mbma_uint; /**< A limit */
328 char *mbma_string; /**< A string */
329 struct Client *mbma_client; /**< A client */
330 } mbm_arg; /**< The mode argument */
331 unsigned short mbm_oplevel; /**< Oplevel for a bounce */
332 } mb_modeargs[MAXMODEPARAMS];
333 /**< A mode w/args */
336 #define MODEBUF_DEST_CHANNEL 0x00001 /**< Mode is flushed to channel */
337 #define MODEBUF_DEST_SERVER 0x00002 /**< Mode is flushed to server */
339 #define MODEBUF_DEST_OPMODE 0x00100 /**< Send server mode as OPMODE */
340 #define MODEBUF_DEST_DEOP 0x00200 /**< Deop the offender */
341 #define MODEBUF_DEST_BOUNCE 0x00400 /**< Bounce the modes */
342 #define MODEBUF_DEST_LOG 0x00800 /**< Log the mode changes to OPATH */
344 #define MODEBUF_DEST_HACK2 0x02000 /**< Send a HACK(2) notice, reverse */
345 #define MODEBUF_DEST_HACK3 0x04000 /**< Send a HACK(3) notice, TS == 0 */
346 #define MODEBUF_DEST_HACK4 0x08000 /**< Send a HACK(4) notice, TS == 0 */
348 #define MODEBUF_DEST_NOKEY 0x10000 /**< Don't send the real key */
350 #define MB_TYPE(mb, i) ((mb)->mb_modeargs[(i)].mbm_type)
351 #define MB_UINT(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
352 #define MB_STRING(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
353 #define MB_CLIENT(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
354 #define MB_OPLEVEL(mb, i) ((mb)->mb_modeargs[(i)].mbm_oplevel)
356 /** A buffer represeting a list of joins to send */
358 struct Client *jb_source; /**< Source of joins (ie, joiner) */
359 struct Client *jb_connect; /**< Connection of joiner */
360 unsigned int jb_type; /**< Type of join (JOIN or CREATE) */
361 char *jb_comment; /**< part comment */
362 time_t jb_create; /**< Creation timestamp */
363 unsigned int jb_count; /**< Number of channels */
364 unsigned int jb_strlen; /**< length so far */
365 struct Channel *jb_channels[MAXJOINARGS];
366 /**< channels joined or whatever */
369 #define JOINBUF_TYPE_JOIN 0 /**< send JOINs */
370 #define JOINBUF_TYPE_CREATE 1 /**< send CREATEs */
371 #define JOINBUF_TYPE_PART 2 /**< send PARTs */
372 #define JOINBUF_TYPE_PARTALL 3 /**< send local PARTs, but not remote */
374 extern struct Channel* GlobalChannelList;
375 extern int LocalChanOperMode;
380 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
381 int buflen, struct Channel *chptr,
382 struct Membership *member);
383 extern int set_mode(struct Client* cptr, struct Client* sptr,
384 struct Channel* chptr, int parc, char* parv[],
385 char* mbuf, char* pbuf, char* npbuf, int* badop);
386 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
387 int parc, char *parv[], int badop, int mtype);
388 extern struct Channel *get_channel(struct Client *cptr,
389 char *chname, ChannelGetType flag);
390 extern struct Membership* find_member_link(struct Channel * chptr,
391 const struct Client* cptr);
392 extern int sub1_from_channel(struct Channel* chptr);
393 extern int destruct_channel(struct Channel* chptr);
394 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
395 unsigned int flags, int oplevel);
396 extern void make_zombie(struct Membership* member, struct Client* who,
397 struct Client* cptr, struct Client* sptr,
398 struct Channel* chptr);
399 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
400 void add_invite(struct Client *cptr, struct Channel *chptr);
401 int number_of_zombies(struct Channel *chptr);
403 extern const char* find_no_nickchange_channel(struct Client* cptr);
404 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
405 extern int member_can_send_to_channel(struct Membership* member, int reveal);
406 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal);
408 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
409 extern void remove_user_from_all_channels(struct Client* cptr);
411 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
412 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
413 extern int has_voice(struct Client *cptr, struct Channel *chptr);
415 NOTE: pointer is compared, and not dereferenced, called by
416 add_target with a void*, since targets could be anything,
417 this function can't make any assumptions that it has a channel
419 extern int IsInvited(struct Client* cptr, const void* chptr);
420 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
421 extern char *pretty_mask(char *mask);
422 extern void del_invite(struct Client *cptr, struct Channel *chptr);
423 extern void list_set_default(void); /* this belongs elsewhere! */
425 extern void RevealDelayedJoinIfNeeded(struct Client *sptr, struct Channel *chptr);
426 extern void RevealDelayedJoin(struct Membership *member);
427 extern void CheckDelayedJoins(struct Channel *chan);
428 extern void CheckEnableDelayedJoins(struct Channel *chan);
430 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
431 struct Client *connect, struct Channel *chan,
433 extern void modebuf_mode(struct ModeBuf *mbuf, ulong64 mode);
434 extern void modebuf_mode_uint(struct ModeBuf *mbuf, ulong64 mode,
436 extern void modebuf_mode_string(struct ModeBuf *mbuf, ulong64 mode,
437 char *string, int free);
438 extern void modebuf_mode_client(struct ModeBuf *mbuf, ulong64 mode,
439 struct Client *client, int oplevel);
440 extern int modebuf_flush(struct ModeBuf *mbuf);
441 extern void modebuf_extract(struct ModeBuf *mbuf, char *buf);
443 extern void mode_ban_invalidate(struct Channel *chan);
444 extern void mode_invite_clear(struct Channel *chan);
446 extern int mode_parse(struct ModeBuf *mbuf, struct Client *cptr,
447 struct Client *sptr, struct Channel *chptr,
448 int parc, char *parv[], unsigned int flags,
449 struct Membership* member);
451 #define MODE_PARSE_SET 0x01 /**< actually set channel modes */
452 #define MODE_PARSE_STRICT 0x02 /**< +m +n +t style not supported */
453 #define MODE_PARSE_FORCE 0x04 /**< force the mode to be applied */
454 #define MODE_PARSE_BOUNCE 0x08 /**< we will be bouncing the modes */
455 #define MODE_PARSE_NOTOPER 0x10 /**< send "not chanop" to user */
456 #define MODE_PARSE_NOTMEMBER 0x20 /**< send "not member" to user */
457 #define MODE_PARSE_WIPEOUT 0x40 /**< wipe out +k and +l during burst */
458 #define MODE_PARSE_BURST 0x80 /**< be even more strict w/extra args */
460 extern void joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
461 struct Client *connect, unsigned int type,
462 char *comment, time_t create);
463 extern void joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan,
465 extern int joinbuf_flush(struct JoinBuf *jbuf);
466 extern struct Ban *make_ban(const char *banstr);
467 extern struct Ban *find_ban(struct Client *cptr, struct Ban *banlist);
468 extern int apply_ban(struct Ban **banlist, struct Ban *newban, int free);
469 extern void free_ban(struct Ban *ban);
470 extern signed int destruct_nonpers_channel(struct Channel *chptr);
471 extern int ext_amsg_block(struct Client *cptr, struct Channel *chptr, const char *msg);
473 #endif /* INCLUDED_channel_h */