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