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.
22 #ifndef INCLUDED_channel_h
23 #define INCLUDED_channel_h
24 #ifndef INCLUDED_ircd_defs_h
25 #include "ircd_defs.h" /* NICKLEN */
27 #ifndef INCLUDED_sys_types_h
28 #include <sys/types.h>
29 #define INCLUDED_sys_types_h
39 #define MAXMODEPARAMS 6
40 #define MODEBUFLEN 200
44 #define CHANNELLEN 200
46 #define MAXJOINARGS 15 /* number of slots for join buffer */
47 #define STARTJOINLEN 10 /* fuzzy numbers */
48 #define STARTCREATELEN 20
54 #define ChannelExists(n) (0 != FindChannel(n))
56 #define CHFL_CHANOP 0x0001 /* Channel operator */
57 #define CHFL_VOICE 0x0002 /* the power to speak */
58 #define CHFL_DEOPPED 0x0004 /* Is de-opped by a server */
59 #define CHFL_SERVOPOK 0x0008 /* Server op allowed */
60 #define CHFL_ZOMBIE 0x0010 /* Kicked from channel */
61 #define CHFL_BAN 0x0020 /* ban channel flag */
62 #define CHFL_BAN_IPMASK 0x0040 /* ban mask is an IP-number mask */
63 #define CHFL_BAN_OVERLAPPED 0x0080 /* ban overlapped, need bounce */
64 #define CHFL_BURST_JOINED 0x0100 /* Just joined by net.junction */
65 #define CHFL_BURST_BAN 0x0200 /* Ban part of last BURST */
66 #define CHFL_BURST_BAN_WIPEOUT 0x0400 /* Ban will be wiped at end of BURST */
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 an IP-number mask */
70 #define CHFL_BURST_ALREADY_OPPED 0x04000 /* In oob BURST, but was already joined and opped */
71 #define CHFL_BURST_ALREADY_VOICED 0x08000 /* In oob BURST, but was already joined and voiced */
72 #define CHFL_CHANNEL_MANAGER 0x10000 /* Set when creating channel or using Apass */
73 #define CHFL_USER_PARTING 0x20000 /* User is already parting that channel */
74 #define CHFL_DELAYED 0x40000 /* User's join message is delayed */
76 #define CHFL_OVERLAP (CHFL_CHANOP | CHFL_VOICE)
77 #define CHFL_BANVALIDMASK (CHFL_BANVALID | CHFL_BANNED)
78 #define CHFL_VOICED_OR_OPPED (CHFL_CHANOP | CHFL_VOICE)
80 /* Channel Visibility macros */
82 #define MODE_CHANOP CHFL_CHANOP
83 #define MODE_VOICE CHFL_VOICE
84 #define MODE_PRIVATE 0x0004
85 #define MODE_SECRET 0x0008
86 #define MODE_MODERATED 0x0010
87 #define MODE_TOPICLIMIT 0x0020
88 #define MODE_INVITEONLY 0x0040
89 #define MODE_NOPRIVMSGS 0x0080
90 #define MODE_KEY 0x0100
91 #define MODE_BAN 0x0200
92 #define MODE_LIMIT 0x0400
93 #define MODE_REGONLY 0x0800 /* Only +r users may join */
94 #define MODE_DELJOINS 0x1000 /* New join messages are delayed */
95 #define MODE_LISTED 0x10000
96 #define MODE_SAVE 0x20000 /* save this mode-with-arg 'til later */
97 #define MODE_FREE 0x40000 /* string needs to be passed to MyFree() */
98 #define MODE_BURSTADDED 0x80000 /* channel was created by a BURST */
99 #define MODE_UPASS 0x100000
100 #define MODE_APASS 0x200000
101 #define MODE_WASDELJOINS 0x400000 /* Not DELJOINS, but some joins pending */
103 * mode flags which take another parameter (With PARAmeterS)
105 #define MODE_WPARAS (MODE_CHANOP|MODE_VOICE|MODE_BAN|MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS)
107 #define infochanmodes feature_bool(FEAT_OPLEVELS) ? "AbiklmnopstuvrD" : "biklmnopstvrD"
108 #define infochanmodeswithparams feature_bool(FEAT_OPLEVELS) ? "Abklouv" : "bklov"
110 #define HoldChannel(x) (!(x))
112 #define SecretChannel(x) ((x) && ((x)->mode.mode & MODE_SECRET))
113 /* channel not shown but names are */
114 #define HiddenChannel(x) ((x) && ((x)->mode.mode & MODE_PRIVATE))
115 /* channel visible */
116 #define ShowChannel(v,c) (PubChannel(c) || find_channel_member((v),(c)) || \
117 (IsAnOper(v) && HasPriv(v, PRIV_LIST_CHAN)))
118 #define PubChannel(x) ((!x) || ((x)->mode.mode & \
119 (MODE_PRIVATE | MODE_SECRET)) == 0)
120 #define is_listed(x) ((x)->mode.mode & MODE_LISTED)
122 #define IsLocalChannel(name) (*(name) == '&')
123 #define IsChannelName(name) (*(name) == '#' || \
124 IsLocalChannel(name))
126 typedef enum ChannelGetType {
131 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
134 #define MODE_ADD 0x40000000
135 #define MODE_DEL 0x20000000
138 * Maximum acceptable lag time in seconds: A channel younger than
139 * this is not protected against hacking admins.
140 * Mainly here to check if the TS clocks really sync (otherwise this
141 * will start causing HACK notices.
142 * This value must be the same on all servers.
144 * This value has been increased to 1 day in order to distinguish this
145 * "normal" type of HACK wallops / desyncs, from possiblity still
148 #define TS_LAG_TIME 86400
151 * A Magic TS that is used for channels that are created by JOIN,
152 * a channel with this TS accepts all TS without complaining that
153 * it might receive later via MODE or CREATE.
155 #define MAGIC_REMOTE_JOIN_TS 1270080000
158 * used in can_join to determine if an oper forced a join on a channel
160 #define MAGIC_OPER_OVERRIDE 1000
163 extern const char* const PartFmt1;
164 extern const char* const PartFmt2;
165 extern const char* const PartFmt1serv;
166 extern const char* const PartFmt2serv;
175 struct Channel* channel;
176 struct Membership* next_member;
177 struct Membership* prev_member;
178 struct Membership* next_channel;
179 struct Membership* prev_channel;
181 unsigned short oplevel;
184 #define MAXOPLEVELDIGITS 3
185 #define MAXOPLEVEL 999
187 #define IsZombie(x) ((x)->status & CHFL_ZOMBIE)
188 #define IsDeopped(x) ((x)->status & CHFL_DEOPPED)
189 #define IsBanned(x) ((x)->status & CHFL_BANNED)
190 #define IsBanValid(x) ((x)->status & CHFL_BANVALID)
191 #define IsChanOp(x) ((x)->status & CHFL_CHANOP)
192 #define OpLevel(x) ((x)->oplevel)
193 #define HasVoice(x) ((x)->status & CHFL_VOICE)
194 #define IsServOpOk(x) ((x)->status & CHFL_SERVOPOK)
195 #define IsBurstJoined(x) ((x)->status & CHFL_BURST_JOINED)
196 #define IsVoicedOrOpped(x) ((x)->status & CHFL_VOICED_OR_OPPED)
197 #define IsChannelManager(x) ((x)->status & CHFL_CHANNEL_MANAGER)
198 #define IsUserParting(x) ((x)->status & CHFL_USER_PARTING)
199 #define IsDelayedJoin(x) ((x)->status & CHFL_DELAYED)
201 #define SetBanned(x) ((x)->status |= CHFL_BANNED)
202 #define SetBanValid(x) ((x)->status |= CHFL_BANVALID)
203 #define SetDeopped(x) ((x)->status |= CHFL_DEOPPED)
204 #define SetServOpOk(x) ((x)->status |= CHFL_SERVOPOK)
205 #define SetBurstJoined(x) ((x)->status |= CHFL_BURST_JOINED)
206 #define SetZombie(x) ((x)->status |= CHFL_ZOMBIE)
207 #define SetChannelManager(x) ((x)->status |= CHFL_CHANNEL_MANAGER)
208 #define SetOpLevel(x, v) (void)((x)->oplevel = (v))
209 #define SetUserParting(x) ((x)->status |= CHFL_USER_PARTING)
210 #define SetDelayedJoin(x) ((x)->status |= CHFL_DELAYED)
212 #define ClearBanned(x) ((x)->status &= ~CHFL_BANNED)
213 #define ClearBanValid(x) ((x)->status &= ~CHFL_BANVALID)
214 #define ClearDeopped(x) ((x)->status &= ~CHFL_DEOPPED)
215 #define ClearServOpOk(x) ((x)->status &= ~CHFL_SERVOPOK)
216 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
217 #define ClearDelayedJoin(x) ((x)->status &= ~CHFL_DELAYED)
223 char key[KEYLEN + 1];
224 char upass[PASSLEN + 1];
225 char apass[PASSLEN + 1];
229 struct Channel* next;
230 struct Channel* prev;
231 struct Channel* hnext;
232 struct DestructEvent* destruct_event;
236 struct Membership* members;
237 struct SLink* invites;
238 struct SLink* banlist;
240 char topic[TOPICLEN + 1];
241 char topic_nick[NICKLEN + 1];
248 unsigned int max_users;
249 unsigned int min_users;
250 unsigned int topic_limits;
251 time_t max_topic_time;
252 time_t min_topic_time;
253 struct Channel *chptr;
257 unsigned int mb_add; /* Modes to add */
258 unsigned int mb_rem; /* Modes to remove */
259 struct Client *mb_source; /* Source of MODE changes */
260 struct Client *mb_connect; /* Connection of MODE changes */
261 struct Channel *mb_channel; /* Channel they affect */
262 unsigned int mb_dest; /* Destination of MODE changes */
263 unsigned int mb_count; /* Number of modes w/args */
265 unsigned int mbm_type; /* Type of argument */
267 unsigned int mbma_uint; /* A limit */
268 char *mbma_string; /* A string */
269 struct Client *mbma_client; /* A client */
270 } mbm_arg; /* The mode argument */
271 } mb_modeargs[MAXMODEPARAMS];
275 #define MODEBUF_DEST_CHANNEL 0x00001 /* Mode is flushed to channel */
276 #define MODEBUF_DEST_SERVER 0x00002 /* Mode is flushed to server */
278 #define MODEBUF_DEST_OPMODE 0x00100 /* Send server mode as OPMODE */
279 #define MODEBUF_DEST_DEOP 0x00200 /* Deop the offender */
280 #define MODEBUF_DEST_BOUNCE 0x00400 /* Bounce the modes */
281 #define MODEBUF_DEST_LOG 0x00800 /* Log the mode changes to OPATH */
283 #define MODEBUF_DEST_HACK2 0x02000 /* Send a HACK(2) notice, reverse */
284 #define MODEBUF_DEST_HACK3 0x04000 /* Send a HACK(3) notice, TS == 0 */
285 #define MODEBUF_DEST_HACK4 0x08000 /* Send a HACK(4) notice, TS == 0 */
287 #define MODEBUF_DEST_NOKEY 0x10000 /* Don't send the real key */
289 #define MB_TYPE(mb, i) ((mb)->mb_modeargs[(i)].mbm_type)
290 #define MB_UINT(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
291 #define MB_STRING(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
292 #define MB_CLIENT(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
295 struct Client *jb_source; /* Source of joins (ie, joiner) */
296 struct Client *jb_connect; /* Connection of joiner */
297 unsigned int jb_type; /* Type of join (JOIN or CREATE) */
298 char *jb_comment; /* part comment */
299 time_t jb_create; /* Creation timestamp */
300 unsigned int jb_count; /* Number of channels */
301 unsigned int jb_strlen; /* length so far */
302 struct Channel *jb_channels[MAXJOINARGS];
303 /* channels joined or whatever */
306 #define JOINBUF_TYPE_JOIN 0 /* send JOINs */
307 #define JOINBUF_TYPE_CREATE 1 /* send CREATEs */
308 #define JOINBUF_TYPE_PART 2 /* send PARTs */
309 #define JOINBUF_TYPE_PARTALL 3 /* send local PARTs, but not remote */
311 extern struct Channel* GlobalChannelList;
312 extern int LocalChanOperMode;
317 extern void clean_channelname(char* name);
318 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
319 int buflen, struct Channel *chptr,
320 struct Membership *member);
321 extern int set_mode(struct Client* cptr, struct Client* sptr,
322 struct Channel* chptr, int parc, char* parv[],
323 char* mbuf, char* pbuf, char* npbuf, int* badop);
324 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
325 int parc, char *parv[], int badop, int mtype);
326 extern struct Channel *get_channel(struct Client *cptr,
327 char *chname, ChannelGetType flag);
328 extern struct Membership* find_member_link(struct Channel * chptr,
329 const struct Client* cptr);
330 extern int sub1_from_channel(struct Channel* chptr);
331 extern int destruct_channel(struct Channel* chptr);
332 extern int can_join(struct Client *sptr, struct Channel *chptr, char *key);
333 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
334 unsigned int flags, int oplevel);
335 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
336 const char *param, int *count);
337 extern void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
338 int *send_itp, char is_a_ban, int mode);
339 extern int add_banid(struct Client *cptr, struct Channel *chptr, char *banid,
340 int change, int firsttime);
341 extern struct SLink *next_removed_overlapped_ban(void);
342 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
343 const char *param, int *count);
344 extern void make_zombie(struct Membership* member, struct Client* who,
345 struct Client* cptr, struct Client* sptr,
346 struct Channel* chptr);
347 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
348 void add_invite(struct Client *cptr, struct Channel *chptr);
349 int number_of_zombies(struct Channel *chptr);
351 extern const char* find_no_nickchange_channel(struct Client* cptr);
352 extern struct Membership* IsMember(struct Client *cptr, struct Channel *chptr);
353 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
354 extern int member_can_send_to_channel(struct Membership* member, int reveal);
355 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal);
357 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
358 extern void remove_user_from_all_channels(struct Client* cptr);
360 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
361 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
362 extern int has_voice(struct Client *cptr, struct Channel *chptr);
364 NOTE: pointer is compared, and not dereferenced, called by
365 add_target with a void*, since targets could be anything,
366 this function can't make any assumptions that it has a channel
368 extern int IsInvited(struct Client* cptr, const void* chptr);
369 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
370 extern char *pretty_mask(char *mask);
371 extern void del_invite(struct Client *cptr, struct Channel *chptr);
372 extern void list_next_channels(struct Client *cptr, int nr);
373 extern void list_set_default(void); /* this belongs elsewhere! */
375 extern void RevealDelayedJoin(struct Membership *member);
376 extern void CheckDelayedJoins(struct Channel *chan);
378 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
379 struct Client *connect, struct Channel *chan,
381 extern void modebuf_mode(struct ModeBuf *mbuf, unsigned int mode);
382 extern void modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode,
384 extern void modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode,
385 char *string, int free);
386 extern void modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
387 struct Client *client);
388 extern int modebuf_flush(struct ModeBuf *mbuf);
389 extern void modebuf_extract(struct ModeBuf *mbuf, char *buf);
391 extern void mode_ban_invalidate(struct Channel *chan);
392 extern void mode_invite_clear(struct Channel *chan);
394 extern int mode_parse(struct ModeBuf *mbuf, struct Client *cptr,
395 struct Client *sptr, struct Channel *chptr,
396 int parc, char *parv[], unsigned int flags,
397 struct Membership* member);
399 #define MODE_PARSE_SET 0x01 /* actually set channel modes */
400 #define MODE_PARSE_STRICT 0x02 /* +m +n +t style not supported */
401 #define MODE_PARSE_FORCE 0x04 /* force the mode to be applied */
402 #define MODE_PARSE_BOUNCE 0x08 /* we will be bouncing the modes */
403 #define MODE_PARSE_NOTOPER 0x10 /* send "not chanop" to user */
404 #define MODE_PARSE_NOTMEMBER 0x20 /* send "not member" to user */
405 #define MODE_PARSE_WIPEOUT 0x40 /* wipe out +k and +l during burst */
406 #define MODE_PARSE_BURST 0x80 /* be even more strict w/extra args */
408 extern void joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
409 struct Client *connect, unsigned int type,
410 char *comment, time_t create);
411 extern void joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan,
413 extern int joinbuf_flush(struct JoinBuf *jbuf);
415 #endif /* INCLUDED_channel_h */