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.
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
44 #define MAXMODEPARAMS 6 /**< Maximum number of mode parameters */
45 #define MODEBUFLEN 200 /**< Maximum length of a mode */
47 #define KEYLEN 23 /**< Maximum length of a key */
48 #define PASSLEN 23 /**< Maximum length of a password */
49 #define CHANNELLEN 200 /**< Maximum length of a channel */
51 #define MAXJOINARGS 15 /**< number of slots for join buffer */
52 #define STARTJOINLEN 10 /**< fuzzy numbers */
53 #define STARTCREATELEN 20
59 #define ChannelExists(n) (0 != FindChannel(n))
61 #define CHFL_CHANOP 0x0001 /**< Channel operator */
62 #define CHFL_VOICE 0x0002 /**< the power to speak */
63 #define CHFL_DEOPPED 0x0004 /**< Is de-opped by a server */
64 #define CHFL_SERVOPOK 0x0008 /**< Server op allowed */
65 #define CHFL_ZOMBIE 0x0010 /**< Kicked from channel */
66 #define CHFL_BURST_JOINED 0x0100 /**< Just joined by net.junction */
67 #define CHFL_BANVALID 0x0800 /**< CHFL_BANNED bit is valid */
68 #define CHFL_BANNED 0x1000 /**< Channel member is banned */
69 #define CHFL_SILENCE_IPMASK 0x2000 /**< silence mask is a CIDR */
70 #define CHFL_BURST_ALREADY_OPPED 0x04000
71 /**< In oob BURST, but was already
74 #define CHFL_BURST_ALREADY_VOICED 0x08000
75 /**, In oob BURST, but was already
78 #define CHFL_CHANNEL_MANAGER 0x10000 /**< Set when creating channel or using
81 #define CHFL_USER_PARTING 0x20000 /**< User is already parting that
84 #define CHFL_DELAYED 0x40000 /**< User's join message is delayed */
86 #define CHFL_OVERLAP (CHFL_CHANOP | CHFL_VOICE)
87 #define CHFL_BANVALIDMASK (CHFL_BANVALID | CHFL_BANNED)
88 #define CHFL_VOICED_OR_OPPED (CHFL_CHANOP | CHFL_VOICE)
90 /* Channel Visibility macros */
92 #define MODE_CHANOP CHFL_CHANOP /**< +o Chanop */
93 #define MODE_VOICE CHFL_VOICE /**< +v Voice */
94 #define MODE_PRIVATE 0x0004 /**< +p Private */
95 #define MODE_SECRET 0x0008 /**< +s Secret */
96 #define MODE_MODERATED 0x0010 /**< +m Moderated */
97 #define MODE_TOPICLIMIT 0x0020 /**< +t Topic Limited */
98 #define MODE_INVITEONLY 0x0040 /**< +i Invite only */
99 #define MODE_NOPRIVMSGS 0x0080 /**< +n No Private Messages */
100 #define MODE_KEY 0x0100 /**< +k Keyed */
101 #define MODE_BAN 0x0200 /**< +b Ban */
102 #define MODE_LIMIT 0x0400 /**< +l Limit */
103 #define MODE_REGONLY 0x0800 /**< Only +r users may join */
104 #define MODE_DELJOINS 0x1000 /**< New join messages are delayed */
105 #define MODE_SAVE 0x20000 /**< save this mode-with-arg 'til
107 #define MODE_FREE 0x40000 /**< string needs to be passed to
109 #define MODE_BURSTADDED 0x80000 /**< channel was created by a BURST */
110 #define MODE_UPASS 0x100000
111 #define MODE_APASS 0x200000
112 #define MODE_WASDELJOINS 0x400000 /**< Not DELJOINS, but some joins
114 /** mode flags which take another parameter (With PARAmeterS)
116 #define MODE_WPARAS (MODE_CHANOP|MODE_VOICE|MODE_BAN|MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS)
118 /** Available Channel modes */
119 #define infochanmodes feature_bool(FEAT_OPLEVELS) ? "AbiklmnopstUvrD" : "biklmnopstvrD"
120 /** Available Channel modes that take parameters */
121 #define infochanmodeswithparams feature_bool(FEAT_OPLEVELS) ? "AbkloUv" : "bklov"
123 #define HoldChannel(x) (!(x))
124 /** name invisible */
125 #define SecretChannel(x) ((x) && ((x)->mode.mode & MODE_SECRET))
126 /** channel not shown but names are */
127 #define HiddenChannel(x) ((x) && ((x)->mode.mode & MODE_PRIVATE))
128 /** channel visible */
129 #define ShowChannel(v,c) (PubChannel(c) || find_channel_member((v),(c)))
130 #define PubChannel(x) ((!x) || ((x)->mode.mode & \
131 (MODE_PRIVATE | MODE_SECRET)) == 0)
133 #define IsGlobalChannel(name) (*(name) == '#')
134 #define IsLocalChannel(name) (*(name) == '&')
135 #define IsChannelName(name) (IsGlobalChannel(name) || IsLocalChannel(name))
137 typedef enum ChannelGetType {
142 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
145 #define MODE_ADD 0x40000000
146 #define MODE_DEL 0x20000000
148 /* used in ListingArgs.flags */
150 #define LISTARG_TOPICLIMITS 0x0001
151 #define LISTARG_SHOWSECRET 0x0002
154 * Maximum acceptable lag time in seconds: A channel younger than
155 * this is not protected against hacking admins.
156 * Mainly here to check if the TS clocks really sync (otherwise this
157 * will start causing HACK notices.
158 * This value must be the same on all servers.
160 * This value has been increased to 1 day in order to distinguish this
161 * "normal" type of HACK wallops / desyncs, from possiblity still
164 #define TS_LAG_TIME 86400
167 * A Magic TS that is used for channels that are created by JOIN,
168 * a channel with this TS accepts all TS without complaining that
169 * it might receive later via MODE or CREATE.
171 * Part of the P9 compatibility, shouldn't occur on a P10 network.
173 #define MAGIC_REMOTE_JOIN_TS 1270080000
176 * used in can_join to determine if an oper forced a join on a channel
178 #define MAGIC_OPER_OVERRIDE 1000
181 extern const char* const PartFmt1;
182 extern const char* const PartFmt2;
183 extern const char* const PartFmt1serv;
184 extern const char* const PartFmt2serv;
191 /** Information about a client on one channel
193 * This structure forms a sparse matrix with users down the side, and
194 * channels across the top. This matrix holds all the information about
195 * which users are on what channels, and what modes that user has on that
196 * channel (if they are op'd, voice'd and cached information if they are
200 struct Client* user; /**< The user */
201 struct Channel* channel; /**< The channel */
202 struct Membership* next_member; /**< The next user on this channel */
203 struct Membership* prev_member; /**< The previous user on this channel*/
204 struct Membership* next_channel; /**< Next channel this user is on */
205 struct Membership* prev_channel; /**< Previous channel this user is on*/
206 unsigned int status; /**< Flags for op'd, voice'd, etc */
207 unsigned short oplevel; /**< Op level */
210 #define MAXOPLEVELDIGITS 3
211 #define MAXOPLEVEL 999
213 #define IsZombie(x) ((x)->status & CHFL_ZOMBIE) /**< see \ref zombie */
214 #define IsDeopped(x) ((x)->status & CHFL_DEOPPED)
215 #define IsBanned(x) ((x)->status & CHFL_BANNED)
216 #define IsBanValid(x) ((x)->status & CHFL_BANVALID)
217 #define IsChanOp(x) ((x)->status & CHFL_CHANOP)
218 #define OpLevel(x) ((x)->oplevel)
219 #define HasVoice(x) ((x)->status & CHFL_VOICE)
220 #define IsServOpOk(x) ((x)->status & CHFL_SERVOPOK)
221 #define IsBurstJoined(x) ((x)->status & CHFL_BURST_JOINED)
222 #define IsVoicedOrOpped(x) ((x)->status & CHFL_VOICED_OR_OPPED)
223 #define IsChannelManager(x) ((x)->status & CHFL_CHANNEL_MANAGER)
224 #define IsUserParting(x) ((x)->status & CHFL_USER_PARTING)
225 #define IsDelayedJoin(x) ((x)->status & CHFL_DELAYED)
227 #define SetBanned(x) ((x)->status |= CHFL_BANNED)
228 #define SetBanValid(x) ((x)->status |= CHFL_BANVALID)
229 #define SetDeopped(x) ((x)->status |= CHFL_DEOPPED)
230 #define SetServOpOk(x) ((x)->status |= CHFL_SERVOPOK)
231 #define SetBurstJoined(x) ((x)->status |= CHFL_BURST_JOINED)
232 #define SetZombie(x) ((x)->status |= CHFL_ZOMBIE)
233 #define SetChannelManager(x) ((x)->status |= CHFL_CHANNEL_MANAGER)
234 #define SetOpLevel(x, v) (void)((x)->oplevel = (v))
235 #define SetUserParting(x) ((x)->status |= CHFL_USER_PARTING)
236 #define SetDelayedJoin(x) ((x)->status |= CHFL_DELAYED)
238 #define ClearBanned(x) ((x)->status &= ~CHFL_BANNED)
239 #define ClearBanValid(x) ((x)->status &= ~CHFL_BANVALID)
240 #define ClearDeopped(x) ((x)->status &= ~CHFL_DEOPPED)
241 #define ClearServOpOk(x) ((x)->status &= ~CHFL_SERVOPOK)
242 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
243 #define ClearDelayedJoin(x) ((x)->status &= ~CHFL_DELAYED)
245 /** Mode information for a channel */
249 char key[KEYLEN + 1];
250 char upass[PASSLEN + 1];
251 char apass[PASSLEN + 1];
254 #define BAN_IPMASK 0x0001 /**< ban mask is an IP-number mask */
255 #define BAN_OVERLAPPED 0x0002 /**< ban overlapped, need bounce */
256 #define BAN_BURSTED 0x0004 /**< Ban part of last BURST */
257 #define BAN_BURST_WIPEOUT 0x0008 /**< Ban will be wiped at EOB */
258 #define BAN_EXCEPTION 0x0010 /**< Ban is an exception */
259 #define BAN_DEL 0x4000 /**< Ban is being removed */
260 #define BAN_ADD 0x8000 /**< Ban is being added */
262 /** A single ban for a channel. */
264 struct Ban* next; /**< next ban in the channel */
265 struct irc_in_addr address; /**< addres for BAN_IPMASK bans */
266 time_t when; /**< timestamp when ban was added */
267 unsigned short flags; /**< modifier flags for the ban */
268 unsigned char nu_len; /**< length of nick!user part of banstr */
269 unsigned char addrbits; /**< netmask length for BAN_IPMASK bans */
270 char *who; /**< name of client that set the ban */
271 char *banstr; /**< hostmask that the ban matches */
274 /** Information about a channel */
276 struct Channel* next; /**< next channel in the global channel list */
277 struct Channel* prev; /**< previous channel */
278 struct Channel* hnext; /**< Next channel in the hash table */
279 struct DestructEvent* destruct_event;
280 time_t creationtime; /**< Creation time of this channel */
281 time_t topic_time; /**< Modification time of the topic */
282 unsigned int users; /**< Number of clients on this channel */
283 struct Membership* members; /**< Pointer to the clients on this channel*/
284 struct SLink* invites; /**< List of invites on this channel */
285 struct Ban* banlist; /**< List of bans on this channel */
286 struct Mode mode; /**< This channels mode */
287 char topic[TOPICLEN + 1]; /**< Channels topic */
288 char topic_nick[NICKLEN + 1]; /**< Nick of the person who set
291 char chname[1]; /**< Dynamically allocated string of the
296 /** Information about a /list in progress */
300 unsigned int max_users;
301 unsigned int min_users;
303 time_t max_topic_time;
304 time_t min_topic_time;
309 unsigned int mb_add; /**< Modes to add */
310 unsigned int mb_rem; /**< Modes to remove */
311 struct Client *mb_source; /**< Source of MODE changes */
312 struct Client *mb_connect; /**< Connection of MODE changes */
313 struct Channel *mb_channel; /**< Channel they affect */
314 unsigned int mb_dest; /**< Destination of MODE changes */
315 unsigned int mb_count; /**< Number of modes w/args */
317 unsigned int mbm_type; /**< Type of argument */
319 unsigned int mbma_uint; /**< A limit */
320 char *mbma_string; /**< A string */
321 struct Client *mbma_client; /**< A client */
322 } mbm_arg; /**< The mode argument */
323 } mb_modeargs[MAXMODEPARAMS];
324 /**< A mode w/args */
327 #define MODEBUF_DEST_CHANNEL 0x00001 /**< Mode is flushed to channel */
328 #define MODEBUF_DEST_SERVER 0x00002 /**< Mode is flushed to server */
330 #define MODEBUF_DEST_OPMODE 0x00100 /**< Send server mode as OPMODE */
331 #define MODEBUF_DEST_DEOP 0x00200 /**< Deop the offender */
332 #define MODEBUF_DEST_BOUNCE 0x00400 /**< Bounce the modes */
333 #define MODEBUF_DEST_LOG 0x00800 /**< Log the mode changes to OPATH */
335 #define MODEBUF_DEST_HACK2 0x02000 /**< Send a HACK(2) notice, reverse */
336 #define MODEBUF_DEST_HACK3 0x04000 /**< Send a HACK(3) notice, TS == 0 */
337 #define MODEBUF_DEST_HACK4 0x08000 /**< Send a HACK(4) notice, TS == 0 */
339 #define MODEBUF_DEST_NOKEY 0x10000 /**< Don't send the real key */
341 #define MB_TYPE(mb, i) ((mb)->mb_modeargs[(i)].mbm_type)
342 #define MB_UINT(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
343 #define MB_STRING(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
344 #define MB_CLIENT(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
346 /** A buffer represeting a list of joins to send */
348 struct Client *jb_source; /**< Source of joins (ie, joiner) */
349 struct Client *jb_connect; /**< Connection of joiner */
350 unsigned int jb_type; /**< Type of join (JOIN or CREATE) */
351 char *jb_comment; /**< part comment */
352 time_t jb_create; /**< Creation timestamp */
353 unsigned int jb_count; /**< Number of channels */
354 unsigned int jb_strlen; /**< length so far */
355 struct Channel *jb_channels[MAXJOINARGS];
356 /**< channels joined or whatever */
359 #define JOINBUF_TYPE_JOIN 0 /**< send JOINs */
360 #define JOINBUF_TYPE_CREATE 1 /**< send CREATEs */
361 #define JOINBUF_TYPE_PART 2 /**< send PARTs */
362 #define JOINBUF_TYPE_PARTALL 3 /**< send local PARTs, but not remote */
364 extern struct Channel* GlobalChannelList;
365 extern int LocalChanOperMode;
370 extern void clean_channelname(char* name);
371 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
372 int buflen, struct Channel *chptr,
373 struct Membership *member);
374 extern int set_mode(struct Client* cptr, struct Client* sptr,
375 struct Channel* chptr, int parc, char* parv[],
376 char* mbuf, char* pbuf, char* npbuf, int* badop);
377 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
378 int parc, char *parv[], int badop, int mtype);
379 extern struct Channel *get_channel(struct Client *cptr,
380 char *chname, ChannelGetType flag);
381 extern struct Membership* find_member_link(struct Channel * chptr,
382 const struct Client* cptr);
383 extern int sub1_from_channel(struct Channel* chptr);
384 extern int destruct_channel(struct Channel* chptr);
385 extern int can_join(struct Client *sptr, struct Channel *chptr, char *key);
386 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
387 unsigned int flags, int oplevel);
388 extern void make_zombie(struct Membership* member, struct Client* who,
389 struct Client* cptr, struct Client* sptr,
390 struct Channel* chptr);
391 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
392 void add_invite(struct Client *cptr, struct Channel *chptr);
393 int number_of_zombies(struct Channel *chptr);
395 extern const char* find_no_nickchange_channel(struct Client* cptr);
396 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
397 extern int member_can_send_to_channel(struct Membership* member, int reveal);
398 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal);
400 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
401 extern void remove_user_from_all_channels(struct Client* cptr);
403 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
404 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
405 extern int has_voice(struct Client *cptr, struct Channel *chptr);
407 NOTE: pointer is compared, and not dereferenced, called by
408 add_target with a void*, since targets could be anything,
409 this function can't make any assumptions that it has a channel
411 extern int IsInvited(struct Client* cptr, const void* chptr);
412 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
413 extern char *pretty_mask(char *mask);
414 extern void del_invite(struct Client *cptr, struct Channel *chptr);
415 extern void list_set_default(void); /* this belongs elsewhere! */
417 extern void RevealDelayedJoin(struct Membership *member);
418 extern void CheckDelayedJoins(struct Channel *chan);
420 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
421 struct Client *connect, struct Channel *chan,
423 extern void modebuf_mode(struct ModeBuf *mbuf, unsigned int mode);
424 extern void modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode,
426 extern void modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode,
427 char *string, int free);
428 extern void modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
429 struct Client *client);
430 extern int modebuf_flush(struct ModeBuf *mbuf);
431 extern void modebuf_extract(struct ModeBuf *mbuf, char *buf);
433 extern void mode_ban_invalidate(struct Channel *chan);
434 extern void mode_invite_clear(struct Channel *chan);
436 extern int mode_parse(struct ModeBuf *mbuf, struct Client *cptr,
437 struct Client *sptr, struct Channel *chptr,
438 int parc, char *parv[], unsigned int flags,
439 struct Membership* member);
441 #define MODE_PARSE_SET 0x01 /**< actually set channel modes */
442 #define MODE_PARSE_STRICT 0x02 /**< +m +n +t style not supported */
443 #define MODE_PARSE_FORCE 0x04 /**< force the mode to be applied */
444 #define MODE_PARSE_BOUNCE 0x08 /**< we will be bouncing the modes */
445 #define MODE_PARSE_NOTOPER 0x10 /**< send "not chanop" to user */
446 #define MODE_PARSE_NOTMEMBER 0x20 /**< send "not member" to user */
447 #define MODE_PARSE_WIPEOUT 0x40 /**< wipe out +k and +l during burst */
448 #define MODE_PARSE_BURST 0x80 /**< be even more strict w/extra args */
450 extern void joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
451 struct Client *connect, unsigned int type,
452 char *comment, time_t create);
453 extern void joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan,
455 extern int joinbuf_flush(struct JoinBuf *jbuf);
456 extern struct Ban *make_ban(const char *banstr);
457 extern struct Ban *find_ban(struct Client *cptr, struct Ban *banlist);
458 extern int apply_ban(struct Ban **banlist, struct Ban *newban, int free);
459 extern void free_ban(struct Ban *ban);
461 #endif /* INCLUDED_channel_h */