Author: Kev <klmitch@mit.edu>
[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_config_h
25 #include "config.h"
26 #endif
27 #ifndef INCLUDED_ircd_defs_h
28 #include "ircd_defs.h"        /* NICKLEN */
29 #endif
30 #ifndef INCLUDED_sys_types_h
31 #include <sys/types.h>
32 #define INCLUDED_sys_types_h
33 #endif
34
35 struct SLink;
36 struct Client;
37
38 /*
39  * General defines
40  */
41
42 #define MAXMODEPARAMS   6
43 #define MODEBUFLEN      200
44
45 #define KEYLEN          23
46 #define CHANNELLEN      200
47 #define MAXBANS         30
48 #define MAXBANLENGTH    1024
49
50 #define MAXJOINARGS     15 /* number of slots for join buffer */
51 #define STARTJOINLEN    10 /* fuzzy numbers */
52 #define STARTCREATELEN  20
53
54 /*
55  * Macro's
56  */
57
58 #define ChannelExists(n)        (0 != FindChannel(n))
59
60 #define CHFL_CHANOP             0x0001  /* Channel operator */
61 #define CHFL_VOICE              0x0002  /* the power to speak */
62 #define CHFL_DEOPPED            0x0004  /* Is de-opped by a server */
63 #define CHFL_SERVOPOK           0x0008  /* Server op allowed */
64 #define CHFL_ZOMBIE             0x0010  /* Kicked from channel */
65 #define CHFL_BAN                0x0020  /* ban channel flag */
66 #define CHFL_BAN_IPMASK         0x0040  /* ban mask is an IP-number mask */
67 #define CHFL_BAN_OVERLAPPED     0x0080  /* ban overlapped, need bounce */
68 #define CHFL_BURST_JOINED       0x0100  /* Just joined by net.junction */
69 #define CHFL_BURST_BAN          0x0200  /* Ban part of last BURST */
70 #define CHFL_BURST_BAN_WIPEOUT  0x0400  /* Ban will be wiped at end of BURST */
71 #define CHFL_BANVALID           0x0800  /* CHFL_BANNED bit is valid */
72 #define CHFL_BANNED             0x1000  /* Channel member is banned */
73 #define CHFL_SILENCE_IPMASK     0x2000  /* silence mask is an IP-number mask */
74
75 #define CHFL_OVERLAP         (CHFL_CHANOP | CHFL_VOICE)
76 #define CHFL_BANVALIDMASK    (CHFL_BANVALID | CHFL_BANNED)
77 #define CHFL_VOICED_OR_OPPED (CHFL_CHANOP | CHFL_VOICE)
78
79 /* Channel Visibility macros */
80
81 #define MODE_CHANOP     CHFL_CHANOP
82 #define MODE_VOICE      CHFL_VOICE
83 #define MODE_PRIVATE    0x0004
84 #define MODE_SECRET     0x0008
85 #define MODE_MODERATED  0x0010
86 #define MODE_TOPICLIMIT 0x0020
87 #define MODE_INVITEONLY 0x0040
88 #define MODE_NOPRIVMSGS 0x0080
89 #define MODE_KEY        0x0100
90 #define MODE_BAN        0x0200
91 #define MODE_LIMIT      0x0400
92 #define MODE_SENDTS     0x0800  /* TS was 0 during a local user /join; send
93                                  * temporary TS; can be removed when all 2.10 */
94 #define MODE_LISTED     0x10000
95 #define MODE_SAVE       0x20000 /* save this mode-with-arg 'til later */
96 #define MODE_FREE       0x40000 /* string needs to be passed to MyFree() */
97 #define MODE_BURSTADDED 0x80000 /* channel was created by a BURST */
98 /*
99  * mode flags which take another parameter (With PARAmeterS)
100  */
101 #define MODE_WPARAS     (MODE_CHANOP|MODE_VOICE|MODE_BAN|MODE_KEY|MODE_LIMIT)
102
103 #define HoldChannel(x)          (!(x))
104 /* name invisible */
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 #define PubChannel(x)           ((!x) || ((x)->mode.mode & \
111                                     (MODE_PRIVATE | MODE_SECRET)) == 0)
112 #define is_listed(x)            ((x)->mode.mode & MODE_LISTED)
113
114 #define IsLocalChannel(name)    (*(name) == '&')
115 #define IsModelessChannel(name) (*(name) == '+')
116 #define IsChannelName(name)     (*(name) == '#' || \
117                                 IsModelessChannel(name) || IsLocalChannel(name))
118
119 /*
120  * Check if a sptr is an oper, and chptr is a local channel.
121  */
122 #define IsOperOnLocalChannel(sptr,chname) \
123                 ((IsAnOper(sptr)) && (IsLocalChannel(chname)))
124
125 typedef enum ChannelGetType {
126   CGT_NO_CREATE,
127   CGT_CREATE
128 } ChannelGetType;
129
130 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
131
132 #define MODE_NULL      0
133 #define MODE_ADD       0x40000000
134 #define MODE_DEL       0x20000000
135
136 /*
137  * Maximum acceptable lag time in seconds: A channel younger than
138  * this is not protected against hacking admins.
139  * Mainly here to check if the TS clocks really sync (otherwise this
140  * will start causing HACK notices.
141  * This value must be the same on all servers.
142  *
143  * This value has been increased to 1 day in order to distinguish this
144  * "normal" type of HACK wallops / desyncs, from possiblity still
145  * existing bugs.
146  */
147 #define TS_LAG_TIME 86400
148
149 /*
150  * A Magic TS that is used for channels that are created by JOIN,
151  * a channel with this TS accepts all TS without complaining that
152  * it might receive later via MODE or CREATE.
153  */
154 #define MAGIC_REMOTE_JOIN_TS 1270080000
155
156 #ifdef OPER_WALK_THROUGH_LMODES
157 /*
158  * used in can_join to determine if an oper forced a join on a channel
159  */
160 #define MAGIC_OPER_OVERRIDE 1000
161 #endif
162
163
164 extern const char* const PartFmt1;
165 extern const char* const PartFmt2;
166 extern const char* const PartFmt1serv;
167 extern const char* const PartFmt2serv;
168
169
170 /*
171  * Structures
172  */
173
174 struct Membership {
175   struct Client*     user;
176   struct Channel*    channel;
177   struct Membership* next_member;
178   struct Membership* prev_member;
179   struct Membership* next_channel;
180   struct Membership* prev_channel;
181   unsigned int       status;
182 };
183
184 #define IsZombie(x)         ((x)->status & CHFL_ZOMBIE)
185 #define IsDeopped(x)        ((x)->status & CHFL_DEOPPED)
186 #define IsBanned(x)         ((x)->status & CHFL_BANNED)
187 #define IsBanValid(x)       ((x)->status & CHFL_BANVALID)
188 #define IsChanOp(x)         ((x)->status & CHFL_CHANOP)
189 #define HasVoice(x)         ((x)->status & CHFL_VOICE)
190 #define IsServOpOk(x)       ((x)->status & CHFL_SERVOPOK)
191 #define IsBurstJoined(x)    ((x)->status & CHFL_BURST_JOINED)
192 #define IsVoicedOrOpped(x)  ((x)->status & CHFL_VOICED_OR_OPPED)
193
194 #define SetBanned(x)        ((x)->status |= CHFL_BANNED)
195 #define SetBanValid(x)      ((x)->status |= CHFL_BANVALID)
196 #define SetDeopped(x)       ((x)->status |= CHFL_DEOPPED)
197 #define SetServOpOk(x)      ((x)->status |= CHFL_SERVOPOK)
198 #define SetBurstJoined(x)   ((x)->status |= CHFL_BURST_JOINED)
199 #define SetZombie(x)        ((x)->status |= CHFL_ZOMBIE)
200
201 #define ClearBanned(x)      ((x)->status &= ~CHFL_BANNED)
202 #define ClearBanValid(x)    ((x)->status &= ~CHFL_BANVALID)
203 #define ClearDeopped(x)     ((x)->status &= ~CHFL_DEOPPED)
204 #define ClearServOpOk(x)    ((x)->status &= ~CHFL_SERVOPOK)
205 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
206
207
208 struct Mode {
209   unsigned int mode;
210   unsigned int limit;
211   char key[KEYLEN + 1];
212 };
213
214 struct Channel {
215   struct Channel*    next;
216   struct Channel*    prev;
217   struct Channel*    hnext;
218   time_t             creationtime;
219   time_t             topic_time;
220   unsigned int       users;
221   struct Membership* members;
222   struct SLink*      invites;
223   struct SLink*      banlist;
224   struct Mode        mode;
225   char               topic[TOPICLEN + 1];
226   char               topic_nick[NICKLEN + 1];
227   char               chname[1];
228 };
229
230 struct ListingArgs {
231   time_t max_time;
232   time_t min_time;
233   unsigned int max_users;
234   unsigned int min_users;
235   unsigned int topic_limits;
236   time_t max_topic_time;
237   time_t min_topic_time;
238   struct Channel *chptr;
239 };
240
241 struct ModeBuf {
242   unsigned int          mb_add;         /* Modes to add */
243   unsigned int          mb_rem;         /* Modes to remove */
244   struct Client        *mb_source;      /* Source of MODE changes */
245   struct Client        *mb_connect;     /* Connection of MODE changes */
246   struct Channel       *mb_channel;     /* Channel they affect */
247   unsigned int          mb_dest;        /* Destination of MODE changes */
248   unsigned int          mb_count;       /* Number of modes w/args */
249   struct {
250     unsigned int        mbm_type;       /* Type of argument */
251     union {
252       unsigned int      mbma_uint;      /* A limit */
253       char             *mbma_string;    /* A string */
254       struct Client    *mbma_client;    /* A client */
255     }                   mbm_arg;        /* The mode argument */
256   }                     mb_modeargs[MAXMODEPARAMS];
257                                         /* A mode w/args */
258 };
259
260 #define MODEBUF_DEST_CHANNEL    0x0001  /* Mode is flushed to channel */
261 #define MODEBUF_DEST_SERVER     0x0002  /* Mode is flushed to server */
262
263 #define MODEBUF_DEST_OPMODE     0x0100  /* Send server mode as OPMODE */
264 #define MODEBUF_DEST_DEOP       0x0200  /* Deop the offender */
265 #define MODEBUF_DEST_BOUNCE     0x0400  /* Bounce the modes */
266 #define MODEBUF_DEST_LOG        0x0800  /* Log the mode changes to OPATH */
267
268 #define MODEBUF_DEST_HACK2      0x2000  /* Send a HACK(2) notice, reverse */
269 #define MODEBUF_DEST_HACK3      0x4000  /* Send a HACK(3) notice, TS == 0 */
270 #define MODEBUF_DEST_HACK4      0x8000  /* Send a HACK(4) notice, TS == 0 */
271
272 #define MB_TYPE(mb, i)          ((mb)->mb_modeargs[(i)].mbm_type)
273 #define MB_UINT(mb, i)          ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
274 #define MB_STRING(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
275 #define MB_CLIENT(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
276
277 struct JoinBuf {
278   struct Client        *jb_source;      /* Source of joins (ie, joiner) */
279   struct Client        *jb_connect;     /* Connection of joiner */
280   unsigned int          jb_type;        /* Type of join (JOIN or CREATE) */
281   char                 *jb_comment;     /* part comment */
282   time_t                jb_create;      /* Creation timestamp */
283   unsigned int          jb_count;       /* Number of channels */
284   unsigned int          jb_strlen;      /* length so far */
285   struct Channel       *jb_channels[MAXJOINARGS];
286                                         /* channels joined or whatever */
287 };
288
289 #define JOINBUF_TYPE_JOIN       0       /* send JOINs */
290 #define JOINBUF_TYPE_CREATE     1       /* send CREATEs */
291 #define JOINBUF_TYPE_PART       2       /* send PARTs */
292 #define JOINBUF_TYPE_PARTALL    3       /* send local PARTs, but not remote */
293
294 extern struct Channel* GlobalChannelList;
295 extern int             LocalChanOperMode;
296
297 /*
298  * Proto types
299  */
300 extern void clean_channelname(char* name);
301 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
302                           struct Channel *chptr);
303 extern int set_mode(struct Client* cptr, struct Client* sptr,
304                     struct Channel* chptr, int parc, char* parv[],
305                     char* mbuf, char* pbuf, char* npbuf, int* badop);
306 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
307                              int parc, char *parv[], int badop, int mtype);
308 extern struct Channel *get_channel(struct Client *cptr,
309                                    char *chname, ChannelGetType flag);
310 extern struct Membership* find_member_link(struct Channel * chptr,
311                                            const struct Client* cptr);
312 extern int sub1_from_channel(struct Channel* chptr);
313 extern int can_join(struct Client *sptr, struct Channel *chptr, char *key);
314 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
315                                 unsigned int flags);
316 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
317                         const char *param, int *count);
318 extern void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
319                                  int *send_itp, char is_a_ban, int mode);
320 extern int add_banid(struct Client *cptr, struct Channel *chptr, char *banid,
321                      int change, int firsttime);
322 extern struct SLink *next_removed_overlapped_ban(void);
323 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
324                         const char *param, int *count);
325 extern void make_zombie(struct Membership* member, struct Client* who,
326                         struct Client* cptr, struct Client* sptr,
327                         struct Channel* chptr);
328 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
329 void add_invite(struct Client *cptr, struct Channel *chptr);
330 int number_of_zombies(struct Channel *chptr);
331
332 extern const char* find_no_nickchange_channel(struct Client* cptr);
333 extern struct Membership* IsMember(struct Client *cptr, struct Channel *chptr);
334 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
335 extern int member_can_send_to_channel(struct Membership* member);
336 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr);
337
338 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
339 extern void remove_user_from_all_channels(struct Client* cptr);
340
341 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
342 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
343 extern int has_voice(struct Client *cptr, struct Channel *chptr);
344 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
345 extern char *pretty_mask(char *mask);
346 extern void del_invite(struct Client *cptr, struct Channel *chptr);
347 extern void list_next_channels(struct Client *cptr, int nr);
348
349 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
350                          struct Client *connect, struct Channel *chan,
351                          unsigned int dest);
352 extern void modebuf_mode(struct ModeBuf *mbuf, unsigned int mode);
353 extern void modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode,
354                               unsigned int uint);
355 extern void modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode,
356                                 char *string, int free);
357 extern void modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
358                                 struct Client *client);
359 extern int modebuf_flush(struct ModeBuf *mbuf);
360 extern void modebuf_extract(struct ModeBuf *mbuf, char *buf);
361
362 extern void mode_ban_invalidate(struct Channel *chan);
363 extern void mode_invite_clear(struct Channel *chan);
364
365 extern int mode_parse(struct ModeBuf *mbuf, struct Client *cptr,
366                       struct Client *sptr, struct Channel *chptr,
367                       int parc, char *parv[], unsigned int flags);
368
369 #define MODE_PARSE_SET          0x01    /* actually set channel modes */
370 #define MODE_PARSE_STRICT       0x02    /* +m +n +t style not supported */
371 #define MODE_PARSE_FORCE        0x04    /* force the mode to be applied */
372 #define MODE_PARSE_BOUNCE       0x08    /* we will be bouncing the modes */
373 #define MODE_PARSE_NOTOPER      0x10    /* send "not chanop" to user */
374 #define MODE_PARSE_NOTMEMBER    0x20    /* send "not member" to user */
375 #define MODE_PARSE_WIPEOUT      0x40    /* wipe out +k and +l during burst */
376 #define MODE_PARSE_BURST        0x80    /* be even more strict w/extra args */
377
378 extern void joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
379                          struct Client *connect, unsigned int type,
380                          char *comment, time_t create);
381 extern void joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan,
382                          unsigned int flags);
383 extern int joinbuf_flush(struct JoinBuf *jbuf);
384
385 #endif /* INCLUDED_channel_h */