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 /*
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_SENDTS     0x0800  /* TS was 0 during a local user /join; send
89                                  * temporary TS; can be removed when all 2.10 */
90 #define MODE_LISTED     0x10000
91 #define MODE_SAVE       0x20000 /* save this mode-with-arg 'til later */
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 /*
114  * Check if a sptr is an oper, and chptr is a local channel.
115  */
116 #define IsOperOnLocalChannel(sptr,chname) \
117                 ((IsAnOper(sptr)) && (IsLocalChannel(chname)))
118
119 typedef enum ChannelGetType {
120   CGT_NO_CREATE,
121   CGT_CREATE
122 } ChannelGetType;
123
124 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
125
126 #define MODE_NULL      0
127 #define MODE_ADD       0x40000000
128 #define MODE_DEL       0x20000000
129
130 /*
131  * Maximum acceptable lag time in seconds: A channel younger than
132  * this is not protected against hacking admins.
133  * Mainly here to check if the TS clocks really sync (otherwise this
134  * will start causing HACK notices.
135  * This value must be the same on all servers.
136  *
137  * This value has been increased to 1 day in order to distinguish this
138  * "normal" type of HACK wallops / desyncs, from possiblity still
139  * existing bugs.
140  */
141 #define TS_LAG_TIME 86400
142
143 /*
144  * A Magic TS that is used for channels that are created by JOIN,
145  * a channel with this TS accepts all TS without complaining that
146  * it might receive later via MODE or CREATE.
147  */
148 #define MAGIC_REMOTE_JOIN_TS 1270080000
149
150 #ifdef OPER_WALK_THROUGH_LMODES
151 /*
152  * used in can_join to determine if an oper forced a join on a channel
153  */
154 #define MAGIC_OPER_OVERRIDE 1000
155 #endif
156
157
158 extern const char* const PartFmt1;
159 extern const char* const PartFmt2;
160 extern const char* const PartFmt1serv;
161 extern const char* const PartFmt2serv;
162
163
164 /*
165  * Structures
166  */
167
168 struct Membership {
169   struct Client*     user;
170   struct Channel*    channel;
171   struct Membership* next_member;
172   struct Membership* prev_member;
173   struct Membership* next_channel;
174   struct Membership* prev_channel;
175   unsigned int       status;
176 };
177
178 #define IsZombie(x)         ((x)->status & CHFL_ZOMBIE)
179 #define IsDeopped(x)        ((x)->status & CHFL_DEOPPED)
180 #define IsBanned(x)         ((x)->status & CHFL_BANNED)
181 #define IsBanValid(x)       ((x)->status & CHFL_BANVALID)
182 #define IsChanOp(x)         ((x)->status & CHFL_CHANOP)
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
195 #define ClearBanned(x)      ((x)->status &= ~CHFL_BANNED)
196 #define ClearBanValid(x)    ((x)->status &= ~CHFL_BANVALID)
197 #define ClearDeopped(x)     ((x)->status &= ~CHFL_DEOPPED)
198 #define ClearServOpOk(x)    ((x)->status &= ~CHFL_SERVOPOK)
199 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
200
201
202 struct Mode {
203   unsigned int mode;
204   unsigned int limit;
205   char key[KEYLEN + 1];
206 };
207
208 struct Channel {
209   struct Channel*    next;
210   struct Channel*    prev;
211   struct Channel*    hnext;
212   time_t             creationtime;
213   time_t             topic_time;
214   unsigned int       users;
215   struct Membership* members;
216   struct SLink*      invites;
217   struct SLink*      banlist;
218   struct Mode        mode;
219   char               topic[TOPICLEN + 1];
220   char               topic_nick[NICKLEN + 1];
221   char               chname[1];
222 };
223
224 struct ListingArgs {
225   time_t max_time;
226   time_t min_time;
227   unsigned int max_users;
228   unsigned int min_users;
229   unsigned int topic_limits;
230   time_t max_topic_time;
231   time_t min_topic_time;
232   struct Channel *chptr;
233 };
234
235 struct ModeBuf {
236   unsigned int          mb_add;         /* Modes to add */
237   unsigned int          mb_rem;         /* Modes to remove */
238   struct Client        *mb_source;      /* Source of MODE changes */
239   struct Client        *mb_connect;     /* Connection of MODE changes */
240   struct Channel       *mb_channel;     /* Channel they affect */
241   unsigned int          mb_dest;        /* Destination of MODE changes */
242   unsigned int          mb_count;       /* Number of modes w/args */
243   struct {
244     unsigned int        mbm_type;       /* Type of argument */
245     union {
246       unsigned int      mbma_uint;      /* A limit */
247       char             *mbma_string;    /* A string */
248       struct Client    *mbma_client;    /* A client */
249     }                   mbm_arg;        /* The mode argument */
250   }                     mb_modeargs[MAXMODEPARAMS];
251                                         /* A mode w/args */
252 };
253
254 #define MODEBUF_DEST_CHANNEL    0x0001  /* Mode is flushed to channel */
255 #define MODEBUF_DEST_SERVER     0x0002  /* Mode is flushed to server */
256
257 #define MODEBUF_DEST_OPMODE     0x0100  /* Send server mode as OPMODE */
258 #define MODEBUF_DEST_DEOP       0x0200  /* Deop the offender */
259 #define MODEBUF_DEST_BOUNCE     0x0400  /* Bounce the modes */
260
261 #define MODEBUF_DEST_HACK2      0x2000  /* Send a HACK(2) notice, reverse */
262 #define MODEBUF_DEST_HACK3      0x4000  /* Send a HACK(3) notice, TS == 0 */
263 #define MODEBUF_DEST_HACK4      0x8000  /* Send a HACK(4) notice, TS == 0 */
264
265 #define MB_TYPE(mb, i)          ((mb)->mb_modeargs[(i)].mbm_type)
266 #define MB_UINT(mb, i)          ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
267 #define MB_STRING(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
268 #define MB_CLIENT(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
269
270 extern struct Channel* GlobalChannelList;
271 extern int             LocalChanOperMode;
272
273 /*
274  * Proto types
275  */
276 extern void clean_channelname(char* name);
277 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
278                           struct Channel *chptr);
279 extern int set_mode(struct Client* cptr, struct Client* sptr,
280                     struct Channel* chptr, int parc, char* parv[],
281                     char* mbuf, char* pbuf, char* npbuf, int* badop);
282 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
283                              int parc, char *parv[], int badop, int mtype);
284 extern struct Channel *get_channel(struct Client *cptr,
285                                    char *chname, ChannelGetType flag);
286 extern struct Membership* find_member_link(struct Channel * chptr,
287                                            const struct Client* cptr);
288 extern int sub1_from_channel(struct Channel* chptr);
289 extern int can_join(struct Client *sptr, struct Channel *chptr, char *key);
290 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
291                                 unsigned int flags);
292 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
293                         const char *param, int *count);
294 extern void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
295                                  int *send_itp, char is_a_ban, int mode);
296 extern int add_banid(struct Client *cptr, struct Channel *chptr, char *banid,
297                      int change, int firsttime);
298 extern struct SLink *next_removed_overlapped_ban(void);
299 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
300                         const char *param, int *count);
301 extern void make_zombie(struct Membership* member, struct Client* who,
302                         struct Client* cptr, struct Client* sptr,
303                         struct Channel* chptr);
304 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
305 void add_invite(struct Client *cptr, struct Channel *chptr);
306 int number_of_zombies(struct Channel *chptr);
307
308 extern const char* find_no_nickchange_channel(struct Client* cptr);
309 extern struct Membership* IsMember(struct Client *cptr, struct Channel *chptr);
310 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
311 extern int member_can_send_to_channel(struct Membership* member);
312 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr);
313
314 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
315 extern void remove_user_from_all_channels(struct Client* cptr);
316
317 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
318 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
319 extern int has_voice(struct Client *cptr, struct Channel *chptr);
320 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
321 extern char *pretty_mask(char *mask);
322 extern void del_invite(struct Client *cptr, struct Channel *chptr);
323 extern void list_next_channels(struct Client *cptr, int nr);
324 extern void send_user_joins(struct Client *cptr, struct Client *user);
325
326 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
327                          struct Client *connect, struct Channel *chan,
328                          unsigned int dest);
329 extern void modebuf_mode(struct ModeBuf *mbuf, unsigned int mode);
330 extern void modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode,
331                               unsigned int uint);
332 extern void modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode,
333                                 char *string);
334 extern void modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
335                                 struct Client *client);
336 extern int modebuf_flush(struct ModeBuf *mbuf);
337
338 #endif /* INCLUDED_channel_h */