Author: Gavin Grieve <hektik@dimebox.net> (by way of 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_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
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_REGONLY    0x0800  /* Only +r users may join */
93 #define MODE_LISTED     0x10000
94 #define MODE_SAVE       0x20000 /* save this mode-with-arg 'til later */
95 #define MODE_FREE       0x40000 /* string needs to be passed to MyFree() */
96 #define MODE_BURSTADDED 0x80000 /* channel was created by a BURST */
97 #define MODE_UPASS      0x100000
98 #define MODE_APASS      0x200000
99 /*
100  * mode flags which take another parameter (With PARAmeterS)
101  */
102 #define MODE_WPARAS     (MODE_CHANOP|MODE_VOICE|MODE_BAN|MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS)
103
104 #define infochanmodes feature_bool(FEAT_OPLEVELS) ? "Abiklmnopstuvr" : "biklmnopstvr"
105 #define infochanmodeswithparams feature_bool(FEAT_OPLEVELS) ? "Abklouv" : "bklov"
106
107 #define HoldChannel(x)          (!(x))
108 /* name invisible */
109 #define SecretChannel(x)        ((x) && ((x)->mode.mode & MODE_SECRET))
110 /* channel not shown but names are */
111 #define HiddenChannel(x)        ((x) && ((x)->mode.mode & MODE_PRIVATE))
112 /* channel visible */
113 #define ShowChannel(v,c)        (PubChannel(c) || find_channel_member((v),(c)) || \
114                                  (IsAnOper(v) && HasPriv(v, PRIV_LIST_CHAN)))
115 #define PubChannel(x)           ((!x) || ((x)->mode.mode & \
116                                     (MODE_PRIVATE | MODE_SECRET)) == 0)
117 #define is_listed(x)            ((x)->mode.mode & MODE_LISTED)
118
119 #define IsLocalChannel(name)    (*(name) == '&')
120 #define IsChannelName(name)     (*(name) == '#' || \
121                                 IsLocalChannel(name))
122
123 typedef enum ChannelGetType {
124   CGT_NO_CREATE,
125   CGT_CREATE
126 } ChannelGetType;
127
128 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
129
130 #define MODE_NULL      0
131 #define MODE_ADD       0x40000000
132 #define MODE_DEL       0x20000000
133
134 /*
135  * Maximum acceptable lag time in seconds: A channel younger than
136  * this is not protected against hacking admins.
137  * Mainly here to check if the TS clocks really sync (otherwise this
138  * will start causing HACK notices.
139  * This value must be the same on all servers.
140  *
141  * This value has been increased to 1 day in order to distinguish this
142  * "normal" type of HACK wallops / desyncs, from possiblity still
143  * existing bugs.
144  */
145 #define TS_LAG_TIME 86400
146
147 /*
148  * A Magic TS that is used for channels that are created by JOIN,
149  * a channel with this TS accepts all TS without complaining that
150  * it might receive later via MODE or CREATE.
151  */
152 #define MAGIC_REMOTE_JOIN_TS 1270080000
153
154 /*
155  * used in can_join to determine if an oper forced a join on a channel
156  */
157 #define MAGIC_OPER_OVERRIDE 1000
158
159
160 extern const char* const PartFmt1;
161 extern const char* const PartFmt2;
162 extern const char* const PartFmt1serv;
163 extern const char* const PartFmt2serv;
164
165
166 /*
167  * Structures
168  */
169
170 struct Membership {
171   struct Client*     user;
172   struct Channel*    channel;
173   struct Membership* next_member;
174   struct Membership* prev_member;
175   struct Membership* next_channel;
176   struct Membership* prev_channel;
177   unsigned int       status;
178   unsigned short     oplevel;
179 };
180
181 #define MAXOPLEVELDIGITS    3
182 #define MAXOPLEVEL          999
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 OpLevel(x)          ((x)->oplevel)
190 #define HasVoice(x)         ((x)->status & CHFL_VOICE)
191 #define IsServOpOk(x)       ((x)->status & CHFL_SERVOPOK)
192 #define IsBurstJoined(x)    ((x)->status & CHFL_BURST_JOINED)
193 #define IsVoicedOrOpped(x)  ((x)->status & CHFL_VOICED_OR_OPPED)
194 #define IsChannelManager(x) ((x)->status & CHFL_CHANNEL_MANAGER)
195 #define IsUserParting(x)    ((x)->status & CHFL_USER_PARTING)
196
197 #define SetBanned(x)        ((x)->status |= CHFL_BANNED)
198 #define SetBanValid(x)      ((x)->status |= CHFL_BANVALID)
199 #define SetDeopped(x)       ((x)->status |= CHFL_DEOPPED)
200 #define SetServOpOk(x)      ((x)->status |= CHFL_SERVOPOK)
201 #define SetBurstJoined(x)   ((x)->status |= CHFL_BURST_JOINED)
202 #define SetZombie(x)        ((x)->status |= CHFL_ZOMBIE)
203 #define SetChannelManager(x) ((x)->status |= CHFL_CHANNEL_MANAGER)
204 #define SetOpLevel(x, v)    (void)((x)->oplevel = (v))
205 #define SetUserParting(x)   ((x)->status |= CHFL_USER_PARTING)
206
207 #define ClearBanned(x)      ((x)->status &= ~CHFL_BANNED)
208 #define ClearBanValid(x)    ((x)->status &= ~CHFL_BANVALID)
209 #define ClearDeopped(x)     ((x)->status &= ~CHFL_DEOPPED)
210 #define ClearServOpOk(x)    ((x)->status &= ~CHFL_SERVOPOK)
211 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
212
213
214 struct Mode {
215   unsigned int mode;
216   unsigned int limit;
217   char key[KEYLEN + 1];
218   char upass[PASSLEN + 1];
219   char apass[PASSLEN + 1];
220 };
221
222 struct Channel {
223   struct Channel*    next;
224   struct Channel*    prev;
225   struct Channel*    hnext;
226   struct DestructEvent* destruct_event;
227   time_t             creationtime;
228   time_t             topic_time;
229   unsigned int       users;
230   struct Membership* members;
231   struct SLink*      invites;
232   struct SLink*      banlist;
233   struct Mode        mode;
234   char               topic[TOPICLEN + 1];
235   char               topic_nick[NICKLEN + 1];
236   char               chname[1];
237 };
238
239 struct ListingArgs {
240   time_t max_time;
241   time_t min_time;
242   unsigned int max_users;
243   unsigned int min_users;
244   unsigned int topic_limits;
245   time_t max_topic_time;
246   time_t min_topic_time;
247   struct Channel *chptr;
248 };
249
250 struct ModeBuf {
251   unsigned int          mb_add;         /* Modes to add */
252   unsigned int          mb_rem;         /* Modes to remove */
253   struct Client        *mb_source;      /* Source of MODE changes */
254   struct Client        *mb_connect;     /* Connection of MODE changes */
255   struct Channel       *mb_channel;     /* Channel they affect */
256   unsigned int          mb_dest;        /* Destination of MODE changes */
257   unsigned int          mb_count;       /* Number of modes w/args */
258   struct {
259     unsigned int        mbm_type;       /* Type of argument */
260     union {
261       unsigned int      mbma_uint;      /* A limit */
262       char             *mbma_string;    /* A string */
263       struct Client    *mbma_client;    /* A client */
264     }                   mbm_arg;        /* The mode argument */
265   }                     mb_modeargs[MAXMODEPARAMS];
266                                         /* A mode w/args */
267 };
268
269 #define MODEBUF_DEST_CHANNEL    0x00001 /* Mode is flushed to channel */
270 #define MODEBUF_DEST_SERVER     0x00002 /* Mode is flushed to server */
271
272 #define MODEBUF_DEST_OPMODE     0x00100 /* Send server mode as OPMODE */
273 #define MODEBUF_DEST_DEOP       0x00200 /* Deop the offender */
274 #define MODEBUF_DEST_BOUNCE     0x00400 /* Bounce the modes */
275 #define MODEBUF_DEST_LOG        0x00800 /* Log the mode changes to OPATH */
276
277 #define MODEBUF_DEST_HACK2      0x02000 /* Send a HACK(2) notice, reverse */
278 #define MODEBUF_DEST_HACK3      0x04000 /* Send a HACK(3) notice, TS == 0 */
279 #define MODEBUF_DEST_HACK4      0x08000 /* Send a HACK(4) notice, TS == 0 */
280
281 #define MODEBUF_DEST_NOKEY      0x10000 /* Don't send the real key */
282
283 #define MB_TYPE(mb, i)          ((mb)->mb_modeargs[(i)].mbm_type)
284 #define MB_UINT(mb, i)          ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
285 #define MB_STRING(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
286 #define MB_CLIENT(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
287
288 struct JoinBuf {
289   struct Client        *jb_source;      /* Source of joins (ie, joiner) */
290   struct Client        *jb_connect;     /* Connection of joiner */
291   unsigned int          jb_type;        /* Type of join (JOIN or CREATE) */
292   char                 *jb_comment;     /* part comment */
293   time_t                jb_create;      /* Creation timestamp */
294   unsigned int          jb_count;       /* Number of channels */
295   unsigned int          jb_strlen;      /* length so far */
296   struct Channel       *jb_channels[MAXJOINARGS];
297                                         /* channels joined or whatever */
298 };
299
300 #define JOINBUF_TYPE_JOIN       0       /* send JOINs */
301 #define JOINBUF_TYPE_CREATE     1       /* send CREATEs */
302 #define JOINBUF_TYPE_PART       2       /* send PARTs */
303 #define JOINBUF_TYPE_PARTALL    3       /* send local PARTs, but not remote */
304
305 extern struct Channel* GlobalChannelList;
306 extern int             LocalChanOperMode;
307
308 /*
309  * Proto types
310  */
311 extern void clean_channelname(char* name);
312 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
313                           int buflen, struct Channel *chptr,
314                           struct Membership *member);
315 extern int set_mode(struct Client* cptr, struct Client* sptr,
316                     struct Channel* chptr, int parc, char* parv[],
317                     char* mbuf, char* pbuf, char* npbuf, int* badop);
318 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
319                              int parc, char *parv[], int badop, int mtype);
320 extern struct Channel *get_channel(struct Client *cptr,
321                                    char *chname, ChannelGetType flag);
322 extern struct Membership* find_member_link(struct Channel * chptr,
323                                            const struct Client* cptr);
324 extern int sub1_from_channel(struct Channel* chptr);
325 extern int destruct_channel(struct Channel* chptr);
326 extern int can_join(struct Client *sptr, struct Channel *chptr, char *key);
327 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
328                                 unsigned int flags, int oplevel);
329 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
330                         const char *param, int *count);
331 extern void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
332                                  int *send_itp, char is_a_ban, int mode);
333 extern int add_banid(struct Client *cptr, struct Channel *chptr, char *banid,
334                      int change, int firsttime);
335 extern struct SLink *next_removed_overlapped_ban(void);
336 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
337                         const char *param, int *count);
338 extern void make_zombie(struct Membership* member, struct Client* who,
339                         struct Client* cptr, struct Client* sptr,
340                         struct Channel* chptr);
341 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
342 void add_invite(struct Client *cptr, struct Channel *chptr);
343 int number_of_zombies(struct Channel *chptr);
344
345 extern const char* find_no_nickchange_channel(struct Client* cptr);
346 extern struct Membership* IsMember(struct Client *cptr, struct Channel *chptr);
347 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
348 extern int member_can_send_to_channel(struct Membership* member);
349 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr);
350
351 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
352 extern void remove_user_from_all_channels(struct Client* cptr);
353
354 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
355 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
356 extern int has_voice(struct Client *cptr, struct Channel *chptr);
357 /*
358    NOTE: pointer is compared, and not dereferenced, called by
359    add_target with a void*, since targets could be anything,
360    this function can't make any assumptions that it has a channel
361 */
362 extern int IsInvited(struct Client* cptr, const void* chptr);
363 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
364 extern char *pretty_mask(char *mask);
365 extern void del_invite(struct Client *cptr, struct Channel *chptr);
366 extern void list_next_channels(struct Client *cptr, int nr);
367 extern void list_set_default(void); /* this belongs elsewhere! */
368
369 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
370                          struct Client *connect, struct Channel *chan,
371                          unsigned int dest);
372 extern void modebuf_mode(struct ModeBuf *mbuf, unsigned int mode);
373 extern void modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode,
374                               unsigned int uint);
375 extern void modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode,
376                                 char *string, int free);
377 extern void modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
378                                 struct Client *client);
379 extern int modebuf_flush(struct ModeBuf *mbuf);
380 extern void modebuf_extract(struct ModeBuf *mbuf, char *buf);
381
382 extern void mode_ban_invalidate(struct Channel *chan);
383 extern void mode_invite_clear(struct Channel *chan);
384
385 extern int mode_parse(struct ModeBuf *mbuf, struct Client *cptr,
386                       struct Client *sptr, struct Channel *chptr,
387                       int parc, char *parv[], unsigned int flags,
388                       struct Membership* member);
389
390 #define MODE_PARSE_SET          0x01    /* actually set channel modes */
391 #define MODE_PARSE_STRICT       0x02    /* +m +n +t style not supported */
392 #define MODE_PARSE_FORCE        0x04    /* force the mode to be applied */
393 #define MODE_PARSE_BOUNCE       0x08    /* we will be bouncing the modes */
394 #define MODE_PARSE_NOTOPER      0x10    /* send "not chanop" to user */
395 #define MODE_PARSE_NOTMEMBER    0x20    /* send "not member" to user */
396 #define MODE_PARSE_WIPEOUT      0x40    /* wipe out +k and +l during burst */
397 #define MODE_PARSE_BURST        0x80    /* be even more strict w/extra args */
398
399 extern void joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
400                          struct Client *connect, unsigned int type,
401                          char *comment, time_t create);
402 extern void joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan,
403                          unsigned int flags);
404 extern int joinbuf_flush(struct JoinBuf *jbuf);
405
406 #endif /* INCLUDED_channel_h */