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