c76ab208bd6d4b9a78936ca08acb84fad6a9d5f5
[ircu2.10.12-pk.git] / include / channel.h
1 /*
2  * IRC - Internet Relay Chat, ircd/channel.h
3  * Copyright (C) 1990 Jarkko Oikarinen
4  * Copyright (C) 1996 - 1997 Carlo Wood
5  *
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)
9  * any later version.
10  *
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.
15  *
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.
19  *
20  * $Id$
21  */
22 #ifndef INCLUDED_channel_h
23 #define INCLUDED_channel_h
24 #ifndef INCLUDED_ircd_defs_h
25 #include "ircd_defs.h"        /* NICKLEN */
26 #endif
27 #ifndef INCLUDED_sys_types_h
28 #include <sys/types.h>
29 #define INCLUDED_sys_types_h
30 #endif
31
32 struct SLink;
33 struct Client;
34
35 /*
36  * General defines
37  */
38
39 #define MAXMODEPARAMS   6
40 #define MODEBUFLEN      200
41
42 #define KEYLEN          23
43 #define PASSLEN         23
44 #define CHANNELLEN      200
45
46 #define MAXJOINARGS     15 /* number of slots for join buffer */
47 #define STARTJOINLEN    10 /* fuzzy numbers */
48 #define STARTCREATELEN  20
49
50 /*
51  * Macro's
52  */
53
54 #define ChannelExists(n)        (0 != FindChannel(n))
55
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 */
75
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)
79
80 /* Channel Visibility macros */
81
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 */
102 /*
103  * mode flags which take another parameter (With PARAmeterS)
104  */
105 #define MODE_WPARAS     (MODE_CHANOP|MODE_VOICE|MODE_BAN|MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS)
106
107 #define infochanmodes feature_bool(FEAT_OPLEVELS) ? "AbiklmnopstUvrD" : "biklmnopstvrD"
108 #define infochanmodeswithparams feature_bool(FEAT_OPLEVELS) ? "AbkloUv" : "bklov"
109
110 #define HoldChannel(x)          (!(x))
111 /* name invisible */
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)
121
122 #define IsGlobalChannel(name)   (*(name) == '#')
123 #define IsLocalChannel(name)    (*(name) == '&')
124 #define IsChannelName(name)     (IsGlobalChannel(name) || IsLocalChannel(name))
125
126 typedef enum ChannelGetType {
127   CGT_NO_CREATE,
128   CGT_CREATE
129 } ChannelGetType;
130
131 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
132
133 #define MODE_NULL      0
134 #define MODE_ADD       0x40000000
135 #define MODE_DEL       0x20000000
136
137 /* used in ListingArgs.flags */
138
139 #define LISTARG_TOPICLIMITS     0x0001
140 #define LISTARG_SHOWSECRET      0x0002
141
142 /*
143  * Maximum acceptable lag time in seconds: A channel younger than
144  * this is not protected against hacking admins.
145  * Mainly here to check if the TS clocks really sync (otherwise this
146  * will start causing HACK notices.
147  * This value must be the same on all servers.
148  *
149  * This value has been increased to 1 day in order to distinguish this
150  * "normal" type of HACK wallops / desyncs, from possiblity still
151  * existing bugs.
152  */
153 #define TS_LAG_TIME 86400
154
155 /*
156  * A Magic TS that is used for channels that are created by JOIN,
157  * a channel with this TS accepts all TS without complaining that
158  * it might receive later via MODE or CREATE.
159  */
160 #define MAGIC_REMOTE_JOIN_TS 1270080000
161
162 /*
163  * used in can_join to determine if an oper forced a join on a channel
164  */
165 #define MAGIC_OPER_OVERRIDE 1000
166
167
168 extern const char* const PartFmt1;
169 extern const char* const PartFmt2;
170 extern const char* const PartFmt1serv;
171 extern const char* const PartFmt2serv;
172
173
174 /*
175  * Structures
176  */
177
178 struct Membership {
179   struct Client*     user;
180   struct Channel*    channel;
181   struct Membership* next_member;
182   struct Membership* prev_member;
183   struct Membership* next_channel;
184   struct Membership* prev_channel;
185   unsigned int       status;
186   unsigned short     oplevel;
187 };
188
189 #define MAXOPLEVELDIGITS    3
190 #define MAXOPLEVEL          999
191
192 #define IsZombie(x)         ((x)->status & CHFL_ZOMBIE)
193 #define IsDeopped(x)        ((x)->status & CHFL_DEOPPED)
194 #define IsBanned(x)         ((x)->status & CHFL_BANNED)
195 #define IsBanValid(x)       ((x)->status & CHFL_BANVALID)
196 #define IsChanOp(x)         ((x)->status & CHFL_CHANOP)
197 #define OpLevel(x)          ((x)->oplevel)
198 #define HasVoice(x)         ((x)->status & CHFL_VOICE)
199 #define IsServOpOk(x)       ((x)->status & CHFL_SERVOPOK)
200 #define IsBurstJoined(x)    ((x)->status & CHFL_BURST_JOINED)
201 #define IsVoicedOrOpped(x)  ((x)->status & CHFL_VOICED_OR_OPPED)
202 #define IsChannelManager(x) ((x)->status & CHFL_CHANNEL_MANAGER)
203 #define IsUserParting(x)    ((x)->status & CHFL_USER_PARTING)
204 #define IsDelayedJoin(x)    ((x)->status & CHFL_DELAYED)
205
206 #define SetBanned(x)        ((x)->status |= CHFL_BANNED)
207 #define SetBanValid(x)      ((x)->status |= CHFL_BANVALID)
208 #define SetDeopped(x)       ((x)->status |= CHFL_DEOPPED)
209 #define SetServOpOk(x)      ((x)->status |= CHFL_SERVOPOK)
210 #define SetBurstJoined(x)   ((x)->status |= CHFL_BURST_JOINED)
211 #define SetZombie(x)        ((x)->status |= CHFL_ZOMBIE)
212 #define SetChannelManager(x) ((x)->status |= CHFL_CHANNEL_MANAGER)
213 #define SetOpLevel(x, v)    (void)((x)->oplevel = (v))
214 #define SetUserParting(x)   ((x)->status |= CHFL_USER_PARTING)
215 #define SetDelayedJoin(x)   ((x)->status |= CHFL_DELAYED)
216
217 #define ClearBanned(x)      ((x)->status &= ~CHFL_BANNED)
218 #define ClearBanValid(x)    ((x)->status &= ~CHFL_BANVALID)
219 #define ClearDeopped(x)     ((x)->status &= ~CHFL_DEOPPED)
220 #define ClearServOpOk(x)    ((x)->status &= ~CHFL_SERVOPOK)
221 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
222 #define ClearDelayedJoin(x) ((x)->status &= ~CHFL_DELAYED)
223
224
225 struct Mode {
226   unsigned int mode;
227   unsigned int limit;
228   char key[KEYLEN + 1];
229   char upass[PASSLEN + 1];
230   char apass[PASSLEN + 1];
231 };
232
233 struct Channel {
234   struct Channel*    next;
235   struct Channel*    prev;
236   struct Channel*    hnext;
237   struct DestructEvent* destruct_event;
238   time_t             creationtime;
239   time_t             topic_time;
240   unsigned int       users;
241   struct Membership* members;
242   struct SLink*      invites;
243   struct SLink*      banlist;
244   struct Mode        mode;
245   char               topic[TOPICLEN + 1];
246   char               topic_nick[NICKLEN + 1];
247   char               chname[1];
248 };
249
250 struct ListingArgs {
251   time_t max_time;
252   time_t min_time;
253   unsigned int max_users;
254   unsigned int min_users;
255   unsigned int flags;
256   time_t max_topic_time;
257   time_t min_topic_time;
258   struct Channel *chptr;
259 };
260
261 struct ModeBuf {
262   unsigned int          mb_add;         /* Modes to add */
263   unsigned int          mb_rem;         /* Modes to remove */
264   struct Client        *mb_source;      /* Source of MODE changes */
265   struct Client        *mb_connect;     /* Connection of MODE changes */
266   struct Channel       *mb_channel;     /* Channel they affect */
267   unsigned int          mb_dest;        /* Destination of MODE changes */
268   unsigned int          mb_count;       /* Number of modes w/args */
269   struct {
270     unsigned int        mbm_type;       /* Type of argument */
271     union {
272       unsigned int      mbma_uint;      /* A limit */
273       char             *mbma_string;    /* A string */
274       struct Client    *mbma_client;    /* A client */
275     }                   mbm_arg;        /* The mode argument */
276   }                     mb_modeargs[MAXMODEPARAMS];
277                                         /* A mode w/args */
278 };
279
280 #define MODEBUF_DEST_CHANNEL    0x00001 /* Mode is flushed to channel */
281 #define MODEBUF_DEST_SERVER     0x00002 /* Mode is flushed to server */
282
283 #define MODEBUF_DEST_OPMODE     0x00100 /* Send server mode as OPMODE */
284 #define MODEBUF_DEST_DEOP       0x00200 /* Deop the offender */
285 #define MODEBUF_DEST_BOUNCE     0x00400 /* Bounce the modes */
286 #define MODEBUF_DEST_LOG        0x00800 /* Log the mode changes to OPATH */
287
288 #define MODEBUF_DEST_HACK2      0x02000 /* Send a HACK(2) notice, reverse */
289 #define MODEBUF_DEST_HACK3      0x04000 /* Send a HACK(3) notice, TS == 0 */
290 #define MODEBUF_DEST_HACK4      0x08000 /* Send a HACK(4) notice, TS == 0 */
291
292 #define MODEBUF_DEST_NOKEY      0x10000 /* Don't send the real key */
293
294 #define MB_TYPE(mb, i)          ((mb)->mb_modeargs[(i)].mbm_type)
295 #define MB_UINT(mb, i)          ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
296 #define MB_STRING(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
297 #define MB_CLIENT(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
298
299 struct JoinBuf {
300   struct Client        *jb_source;      /* Source of joins (ie, joiner) */
301   struct Client        *jb_connect;     /* Connection of joiner */
302   unsigned int          jb_type;        /* Type of join (JOIN or CREATE) */
303   char                 *jb_comment;     /* part comment */
304   time_t                jb_create;      /* Creation timestamp */
305   unsigned int          jb_count;       /* Number of channels */
306   unsigned int          jb_strlen;      /* length so far */
307   struct Channel       *jb_channels[MAXJOINARGS];
308                                         /* channels joined or whatever */
309 };
310
311 #define JOINBUF_TYPE_JOIN       0       /* send JOINs */
312 #define JOINBUF_TYPE_CREATE     1       /* send CREATEs */
313 #define JOINBUF_TYPE_PART       2       /* send PARTs */
314 #define JOINBUF_TYPE_PARTALL    3       /* send local PARTs, but not remote */
315
316 extern struct Channel* GlobalChannelList;
317 extern int             LocalChanOperMode;
318
319 /*
320  * Proto types
321  */
322 extern void clean_channelname(char* name);
323 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
324                           int buflen, struct Channel *chptr,
325                           struct Membership *member);
326 extern int set_mode(struct Client* cptr, struct Client* sptr,
327                     struct Channel* chptr, int parc, char* parv[],
328                     char* mbuf, char* pbuf, char* npbuf, int* badop);
329 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
330                              int parc, char *parv[], int badop, int mtype);
331 extern struct Channel *get_channel(struct Client *cptr,
332                                    char *chname, ChannelGetType flag);
333 extern struct Membership* find_member_link(struct Channel * chptr,
334                                            const struct Client* cptr);
335 extern int sub1_from_channel(struct Channel* chptr);
336 extern int destruct_channel(struct Channel* chptr);
337 extern int can_join(struct Client *sptr, struct Channel *chptr, char *key);
338 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
339                                 unsigned int flags, int oplevel);
340 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
341                         const char *param, int *count);
342 extern void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
343                                  int *send_itp, char is_a_ban, int mode);
344 extern int add_banid(struct Client *cptr, struct Channel *chptr, char *banid,
345                      int change, int firsttime);
346 extern struct SLink *next_removed_overlapped_ban(void);
347 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
348                         const char *param, int *count);
349 extern void make_zombie(struct Membership* member, struct Client* who,
350                         struct Client* cptr, struct Client* sptr,
351                         struct Channel* chptr);
352 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
353 void add_invite(struct Client *cptr, struct Channel *chptr);
354 int number_of_zombies(struct Channel *chptr);
355
356 extern const char* find_no_nickchange_channel(struct Client* cptr);
357 extern struct Membership* IsMember(struct Client *cptr, struct Channel *chptr);
358 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
359 extern int member_can_send_to_channel(struct Membership* member, int reveal);
360 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal);
361
362 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
363 extern void remove_user_from_all_channels(struct Client* cptr);
364
365 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
366 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
367 extern int has_voice(struct Client *cptr, struct Channel *chptr);
368 /*
369    NOTE: pointer is compared, and not dereferenced, called by
370    add_target with a void*, since targets could be anything,
371    this function can't make any assumptions that it has a channel
372 */
373 extern int IsInvited(struct Client* cptr, const void* chptr);
374 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
375 extern char *pretty_mask(char *mask);
376 extern void del_invite(struct Client *cptr, struct Channel *chptr);
377 extern void list_next_channels(struct Client *cptr, int nr);
378 extern void list_set_default(void); /* this belongs elsewhere! */
379
380 extern void RevealDelayedJoin(struct Membership *member);
381 extern void CheckDelayedJoins(struct Channel *chan);
382
383 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
384                          struct Client *connect, struct Channel *chan,
385                          unsigned int dest);
386 extern void modebuf_mode(struct ModeBuf *mbuf, unsigned int mode);
387 extern void modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode,
388                               unsigned int uint);
389 extern void modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode,
390                                 char *string, int free);
391 extern void modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
392                                 struct Client *client);
393 extern int modebuf_flush(struct ModeBuf *mbuf);
394 extern void modebuf_extract(struct ModeBuf *mbuf, char *buf);
395
396 extern void mode_ban_invalidate(struct Channel *chan);
397 extern void mode_invite_clear(struct Channel *chan);
398
399 extern int mode_parse(struct ModeBuf *mbuf, struct Client *cptr,
400                       struct Client *sptr, struct Channel *chptr,
401                       int parc, char *parv[], unsigned int flags,
402                       struct Membership* member);
403
404 #define MODE_PARSE_SET          0x01    /* actually set channel modes */
405 #define MODE_PARSE_STRICT       0x02    /* +m +n +t style not supported */
406 #define MODE_PARSE_FORCE        0x04    /* force the mode to be applied */
407 #define MODE_PARSE_BOUNCE       0x08    /* we will be bouncing the modes */
408 #define MODE_PARSE_NOTOPER      0x10    /* send "not chanop" to user */
409 #define MODE_PARSE_NOTMEMBER    0x20    /* send "not member" to user */
410 #define MODE_PARSE_WIPEOUT      0x40    /* wipe out +k and +l during burst */
411 #define MODE_PARSE_BURST        0x80    /* be even more strict w/extra args */
412
413 extern void joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
414                          struct Client *connect, unsigned int type,
415                          char *comment, time_t create);
416 extern void joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan,
417                          unsigned int flags);
418 extern int joinbuf_flush(struct JoinBuf *jbuf);
419
420 #endif /* INCLUDED_channel_h */