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 */
74 #define CHFL_OVERLAP (CHFL_CHANOP | CHFL_VOICE)
75 #define CHFL_BANVALIDMASK (CHFL_BANVALID | CHFL_BANNED)
76 #define CHFL_VOICED_OR_OPPED (CHFL_CHANOP | CHFL_VOICE)
78 /* Channel Visibility macros */
80 #define MODE_CHANOP CHFL_CHANOP
81 #define MODE_VOICE CHFL_VOICE
82 #define MODE_PRIVATE 0x0004
83 #define MODE_SECRET 0x0008
84 #define MODE_MODERATED 0x0010
85 #define MODE_TOPICLIMIT 0x0020
86 #define MODE_INVITEONLY 0x0040
87 #define MODE_NOPRIVMSGS 0x0080
88 #define MODE_KEY 0x0100
89 #define MODE_BAN 0x0200
90 #define MODE_LIMIT 0x0400
91 #define MODE_REGONLY 0x0800 /* Only +r users may join */
92 #define MODE_LISTED 0x10000
93 #define MODE_SAVE 0x20000 /* save this mode-with-arg 'til later */
94 #define MODE_FREE 0x40000 /* string needs to be passed to MyFree() */
95 #define MODE_BURSTADDED 0x80000 /* channel was created by a BURST */
96 #define MODE_UPASS 0x100000
97 #define MODE_APASS 0x200000
99 * mode flags which take another parameter (With PARAmeterS)
101 #define MODE_WPARAS (MODE_CHANOP|MODE_VOICE|MODE_BAN|MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS)
103 #define HoldChannel(x) (!(x))
105 #define SecretChannel(x) ((x) && ((x)->mode.mode & MODE_SECRET))
106 /* channel not shown but names are */
107 #define HiddenChannel(x) ((x) && ((x)->mode.mode & MODE_PRIVATE))
108 /* channel visible */
109 #define ShowChannel(v,c) (PubChannel(c) || find_channel_member((v),(c)) || \
110 (IsAnOper(v)) && HasPriv(v, PRIV_LIST_CHAN))
111 #define PubChannel(x) ((!x) || ((x)->mode.mode & \
112 (MODE_PRIVATE | MODE_SECRET)) == 0)
113 #define is_listed(x) ((x)->mode.mode & MODE_LISTED)
115 #define IsLocalChannel(name) (*(name) == '&')
116 #define IsModelessChannel(name) (*(name) == '+')
117 #define IsChannelName(name) (*(name) == '#' || \
118 IsModelessChannel(name) || IsLocalChannel(name))
120 typedef enum ChannelGetType {
125 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
128 #define MODE_ADD 0x40000000
129 #define MODE_DEL 0x20000000
132 * Maximum acceptable lag time in seconds: A channel younger than
133 * this is not protected against hacking admins.
134 * Mainly here to check if the TS clocks really sync (otherwise this
135 * will start causing HACK notices.
136 * This value must be the same on all servers.
138 * This value has been increased to 1 day in order to distinguish this
139 * "normal" type of HACK wallops / desyncs, from possiblity still
142 #define TS_LAG_TIME 86400
145 * A Magic TS that is used for channels that are created by JOIN,
146 * a channel with this TS accepts all TS without complaining that
147 * it might receive later via MODE or CREATE.
149 #define MAGIC_REMOTE_JOIN_TS 1270080000
152 * used in can_join to determine if an oper forced a join on a channel
154 #define MAGIC_OPER_OVERRIDE 1000
157 extern const char* const PartFmt1;
158 extern const char* const PartFmt2;
159 extern const char* const PartFmt1serv;
160 extern const char* const PartFmt2serv;
169 struct Channel* channel;
170 struct Membership* next_member;
171 struct Membership* prev_member;
172 struct Membership* next_channel;
173 struct Membership* prev_channel;
175 unsigned short oplevel;
178 #define MAXOPLEVELDIGITS 3
179 #define MAXOPLEVEL 999
181 #define IsZombie(x) ((x)->status & CHFL_ZOMBIE)
182 #define IsDeopped(x) ((x)->status & CHFL_DEOPPED)
183 #define IsBanned(x) ((x)->status & CHFL_BANNED)
184 #define IsBanValid(x) ((x)->status & CHFL_BANVALID)
185 #define IsChanOp(x) ((x)->status & CHFL_CHANOP)
186 #define OpLevel(x) ((x)->oplevel)
187 #define HasVoice(x) ((x)->status & CHFL_VOICE)
188 #define IsServOpOk(x) ((x)->status & CHFL_SERVOPOK)
189 #define IsBurstJoined(x) ((x)->status & CHFL_BURST_JOINED)
190 #define IsVoicedOrOpped(x) ((x)->status & CHFL_VOICED_OR_OPPED)
191 #define IsChannelManager(x) ((x)->status & CHFL_CHANNEL_MANAGER)
193 #define SetBanned(x) ((x)->status |= CHFL_BANNED)
194 #define SetBanValid(x) ((x)->status |= CHFL_BANVALID)
195 #define SetDeopped(x) ((x)->status |= CHFL_DEOPPED)
196 #define SetServOpOk(x) ((x)->status |= CHFL_SERVOPOK)
197 #define SetBurstJoined(x) ((x)->status |= CHFL_BURST_JOINED)
198 #define SetZombie(x) ((x)->status |= CHFL_ZOMBIE)
199 #define SetChannelManager(x) ((x)->status |= CHFL_CHANNEL_MANAGER)
200 #define SetOpLevel(x, v) (void)((x)->oplevel = (v))
202 #define ClearBanned(x) ((x)->status &= ~CHFL_BANNED)
203 #define ClearBanValid(x) ((x)->status &= ~CHFL_BANVALID)
204 #define ClearDeopped(x) ((x)->status &= ~CHFL_DEOPPED)
205 #define ClearServOpOk(x) ((x)->status &= ~CHFL_SERVOPOK)
206 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
212 char key[KEYLEN + 1];
213 char upass[PASSLEN + 1];
214 char apass[PASSLEN + 1];
218 struct Channel* next;
219 struct Channel* prev;
220 struct Channel* hnext;
221 struct DestructEvent* destruct_event;
225 struct Membership* members;
226 struct SLink* invites;
227 struct SLink* banlist;
229 char topic[TOPICLEN + 1];
230 char topic_nick[NICKLEN + 1];
237 unsigned int max_users;
238 unsigned int min_users;
239 unsigned int topic_limits;
240 time_t max_topic_time;
241 time_t min_topic_time;
242 struct Channel *chptr;
246 unsigned int mb_add; /* Modes to add */
247 unsigned int mb_rem; /* Modes to remove */
248 struct Client *mb_source; /* Source of MODE changes */
249 struct Client *mb_connect; /* Connection of MODE changes */
250 struct Channel *mb_channel; /* Channel they affect */
251 unsigned int mb_dest; /* Destination of MODE changes */
252 unsigned int mb_count; /* Number of modes w/args */
254 unsigned int mbm_type; /* Type of argument */
256 unsigned int mbma_uint; /* A limit */
257 char *mbma_string; /* A string */
258 struct Client *mbma_client; /* A client */
259 } mbm_arg; /* The mode argument */
260 } mb_modeargs[MAXMODEPARAMS];
264 #define MODEBUF_DEST_CHANNEL 0x0001 /* Mode is flushed to channel */
265 #define MODEBUF_DEST_SERVER 0x0002 /* Mode is flushed to server */
267 #define MODEBUF_DEST_OPMODE 0x0100 /* Send server mode as OPMODE */
268 #define MODEBUF_DEST_DEOP 0x0200 /* Deop the offender */
269 #define MODEBUF_DEST_BOUNCE 0x0400 /* Bounce the modes */
270 #define MODEBUF_DEST_LOG 0x0800 /* Log the mode changes to OPATH */
272 #define MODEBUF_DEST_HACK2 0x2000 /* Send a HACK(2) notice, reverse */
273 #define MODEBUF_DEST_HACK3 0x4000 /* Send a HACK(3) notice, TS == 0 */
274 #define MODEBUF_DEST_HACK4 0x8000 /* Send a HACK(4) notice, TS == 0 */
276 #define MB_TYPE(mb, i) ((mb)->mb_modeargs[(i)].mbm_type)
277 #define MB_UINT(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
278 #define MB_STRING(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
279 #define MB_CLIENT(mb, i) ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
282 struct Client *jb_source; /* Source of joins (ie, joiner) */
283 struct Client *jb_connect; /* Connection of joiner */
284 unsigned int jb_type; /* Type of join (JOIN or CREATE) */
285 char *jb_comment; /* part comment */
286 time_t jb_create; /* Creation timestamp */
287 unsigned int jb_count; /* Number of channels */
288 unsigned int jb_strlen; /* length so far */
289 struct Channel *jb_channels[MAXJOINARGS];
290 /* channels joined or whatever */
293 #define JOINBUF_TYPE_JOIN 0 /* send JOINs */
294 #define JOINBUF_TYPE_CREATE 1 /* send CREATEs */
295 #define JOINBUF_TYPE_PART 2 /* send PARTs */
296 #define JOINBUF_TYPE_PARTALL 3 /* send local PARTs, but not remote */
298 extern struct Channel* GlobalChannelList;
299 extern int LocalChanOperMode;
304 extern void clean_channelname(char* name);
305 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
306 int buflen, struct Channel *chptr,
307 struct Membership *member);
308 extern int set_mode(struct Client* cptr, struct Client* sptr,
309 struct Channel* chptr, int parc, char* parv[],
310 char* mbuf, char* pbuf, char* npbuf, int* badop);
311 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
312 int parc, char *parv[], int badop, int mtype);
313 extern struct Channel *get_channel(struct Client *cptr,
314 char *chname, ChannelGetType flag);
315 extern struct Membership* find_member_link(struct Channel * chptr,
316 const struct Client* cptr);
317 extern int sub1_from_channel(struct Channel* chptr);
318 extern int destruct_channel(struct Channel* chptr);
319 extern int can_join(struct Client *sptr, struct Channel *chptr, char *key);
320 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
321 unsigned int flags, int oplevel);
322 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
323 const char *param, int *count);
324 extern void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
325 int *send_itp, char is_a_ban, int mode);
326 extern int add_banid(struct Client *cptr, struct Channel *chptr, char *banid,
327 int change, int firsttime);
328 extern struct SLink *next_removed_overlapped_ban(void);
329 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
330 const char *param, int *count);
331 extern void make_zombie(struct Membership* member, struct Client* who,
332 struct Client* cptr, struct Client* sptr,
333 struct Channel* chptr);
334 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
335 void add_invite(struct Client *cptr, struct Channel *chptr);
336 int number_of_zombies(struct Channel *chptr);
338 extern const char* find_no_nickchange_channel(struct Client* cptr);
339 extern struct Membership* IsMember(struct Client *cptr, struct Channel *chptr);
340 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
341 extern int member_can_send_to_channel(struct Membership* member);
342 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr);
344 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
345 extern void remove_user_from_all_channels(struct Client* cptr);
347 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
348 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
349 extern int has_voice(struct Client *cptr, struct Channel *chptr);
350 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
351 extern char *pretty_mask(char *mask);
352 extern void del_invite(struct Client *cptr, struct Channel *chptr);
353 extern void list_next_channels(struct Client *cptr, int nr);
354 extern void list_set_default(void); /* this belongs elsewhere! */
356 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
357 struct Client *connect, struct Channel *chan,
359 extern void modebuf_mode(struct ModeBuf *mbuf, unsigned int mode);
360 extern void modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode,
362 extern void modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode,
363 char *string, int free);
364 extern void modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
365 struct Client *client);
366 extern int modebuf_flush(struct ModeBuf *mbuf);
367 extern void modebuf_extract(struct ModeBuf *mbuf, char *buf);
369 extern void mode_ban_invalidate(struct Channel *chan);
370 extern void mode_invite_clear(struct Channel *chan);
372 extern int mode_parse(struct ModeBuf *mbuf, struct Client *cptr,
373 struct Client *sptr, struct Channel *chptr,
374 int parc, char *parv[], unsigned int flags,
375 struct Membership* member);
377 #define MODE_PARSE_SET 0x01 /* actually set channel modes */
378 #define MODE_PARSE_STRICT 0x02 /* +m +n +t style not supported */
379 #define MODE_PARSE_FORCE 0x04 /* force the mode to be applied */
380 #define MODE_PARSE_BOUNCE 0x08 /* we will be bouncing the modes */
381 #define MODE_PARSE_NOTOPER 0x10 /* send "not chanop" to user */
382 #define MODE_PARSE_NOTMEMBER 0x20 /* send "not member" to user */
383 #define MODE_PARSE_WIPEOUT 0x40 /* wipe out +k and +l during burst */
384 #define MODE_PARSE_BURST 0x80 /* be even more strict w/extra args */
386 extern void joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
387 struct Client *connect, unsigned int type,
388 char *comment, time_t create);
389 extern void joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan,
391 extern int joinbuf_flush(struct JoinBuf *jbuf);
393 #endif /* INCLUDED_channel_h */