Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / include / client.h
1 /*
2  * IRC - Internet Relay Chat, include/client.h
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
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  *
21  * $Id$
22  */
23 #ifndef INCLUDED_client_h
24 #define INCLUDED_client_h
25 #ifndef INCLUDED_ircd_defs_h
26 #include "ircd_defs.h"
27 #endif
28 #ifndef INCLUDED_dbuf_h
29 #include "dbuf.h"
30 #endif
31 #ifndef INCLUDED_msgq_h
32 #include "msgq.h"
33 #endif
34 #ifndef INCLUDED_ircd_events_h
35 #include "ircd_events.h"
36 #endif
37 #ifndef INCLUDED_ircd_handler_h
38 #include "ircd_handler.h"
39 #endif
40 #ifndef INCLUDED_sys_types_h
41 #include <sys/types.h>          /* time_t, size_t */
42 #define INCLUDED_sys_types_h
43 #endif
44 #ifndef INCLUDED_netinet_in_h
45 #include <netinet/in.h>         /* in_addr */
46 #define INCLUDED_netinet_in_h
47 #endif
48
49 struct ConfItem;
50 struct Listener;
51 struct ListingArgs;
52 struct SLink;
53 struct Server;
54 struct User;
55 struct Whowas;
56 struct DNSReply;
57 struct hostent;
58 struct Privs;
59 struct AuthRequest;
60
61 /*
62  * Structures
63  *
64  * Only put structures here that are being used in a very large number of
65  * source files. Other structures go in the header file of there corresponding
66  * source file, or in the source file itself (when only used in that file).
67  */
68
69 #define PRIV_CHAN_LIMIT          1 /* no channel limit on oper */
70 #define PRIV_MODE_LCHAN          2 /* oper can mode local chans */
71 #define PRIV_WALK_LCHAN          3 /* oper can walk thru local modes */
72 #define PRIV_DEOP_LCHAN          4 /* no deop oper on local chans */
73 #define PRIV_SHOW_INVIS          5 /* show local invisible users */
74 #define PRIV_SHOW_ALL_INVIS      6 /* show all invisible users */
75 #define PRIV_UNLIMIT_QUERY       7 /* unlimit who queries */
76
77 #define PRIV_KILL                8 /* oper can KILL */
78 #define PRIV_LOCAL_KILL          9 /* oper can local KILL */
79 #define PRIV_REHASH             10 /* oper can REHASH */
80 #define PRIV_RESTART            11 /* oper can RESTART */
81 #define PRIV_DIE                12 /* oper can DIE */
82 #define PRIV_GLINE              13 /* oper can GLINE */
83 #define PRIV_LOCAL_GLINE        14 /* oper can local GLINE */
84 #define PRIV_JUPE               15 /* oper can JUPE */
85 #define PRIV_LOCAL_JUPE         16 /* oper can local JUPE */
86 #define PRIV_OPMODE             17 /* oper can OP/CLEARMODE */
87 #define PRIV_LOCAL_OPMODE       18 /* oper can local OP/CLEARMODE */
88 #define PRIV_SET                19 /* oper can SET */
89 #define PRIV_WHOX               20 /* oper can use /who x */
90 #define PRIV_BADCHAN            21 /* oper can BADCHAN */
91 #define PRIV_LOCAL_BADCHAN      22 /* oper can local BADCHAN */
92 #define PRIV_SEE_CHAN           23 /* oper can see in secret chans */
93
94 #define PRIV_PROPAGATE          24 /* propagate oper status */
95 #define PRIV_DISPLAY            25 /* "Is an oper" displayed */
96 #define PRIV_SEE_OPERS          26 /* display hidden opers */
97
98 #define PRIV_WIDE_GLINE         27 /* oper can set wider G-lines */
99
100 #define PRIV_LAST_PRIV          27 /* must be the same as the last priv */
101
102 #define _PRIV_NBITS             (8 * sizeof(unsigned long))
103
104 #define _PRIV_IDX(priv)         ((priv) / _PRIV_NBITS)
105 #define _PRIV_BIT(priv)         (1 << ((priv) % _PRIV_NBITS))
106
107 struct Privs {
108   unsigned long priv_mask[(PRIV_LAST_PRIV / _PRIV_NBITS) + 1];
109 };
110
111 struct Connection {
112   /*
113    *  The following fields are allocated only for local clients
114    *  (directly connected to *this* server with a socket.
115    *  The first of them *MUST* be the "count"--it is the field
116    *  to which the allocation is tied to! *Never* refer to
117    *  these fields, if (from != self).
118    */
119   unsigned long       con_magic; /* magic number */
120   struct Connection*  con_next;  /* Next connection with queued data */
121   struct Connection** con_prev_p; /* What points to us */
122   struct Client*      con_client; /* Client associated with connection */
123   unsigned int        con_count; /* Amount of data in buffer */
124   int                 con_fd;    /* >= 0, for local clients */
125   int                 con_freeflag; /* indicates if connection can be freed */
126   int                 con_error; /* last socket level error for client */
127   unsigned int        con_snomask; /* mask for server messages */
128   time_t              con_nextnick; /* Next time a nick change is allowed */
129   time_t              con_nexttarget;/* Next time a target change is allowed */
130   unsigned int        con_cookie; /* Random number the user must PONG */
131   struct MsgQ         con_sendQ; /* Outgoing message queue--if socket full */
132   struct DBuf         con_recvQ; /* Hold for data incoming yet to be parsed */
133   unsigned int        con_sendM; /* Statistics: protocol messages send */
134   unsigned int        con_sendK; /* Statistics: total k-bytes send */
135   unsigned int        con_receiveM;/* Statistics: protocol messages received */
136   unsigned int        con_receiveK; /* Statistics: total k-bytes received */
137   unsigned short      con_sendB; /* counters to count upto 1-k lots of bytes */
138   unsigned short      con_receiveB; /* sent and received. */
139   struct Listener*    con_listener; /* listening client which we accepted
140                                        from */
141   struct SLink*       con_confs; /* Configuration record associated */
142   HandlerType         con_handler; /* message index into command table
143                                       for parsing */
144   struct DNSReply*    con_dns_reply; /* DNS reply used during client
145                                         registration */
146   struct ListingArgs* con_listing;
147   unsigned int        con_max_sendq; /* cached max send queue for client */
148   unsigned int        con_ping_freq; /* cached ping freq from client conf
149                                         class */
150   unsigned short      con_lastsq; /* # 2k blocks when sendqueued called last */
151   unsigned short      con_port;  /* and the remote port# too :-) */
152   unsigned char       con_targets[MAXTARGETS]; /* Hash values of current
153                                                   targets */
154   char con_sock_ip[SOCKIPLEN + 1]; /* this is the ip address as a string */
155   char con_sockhost[HOSTLEN + 1]; /* This is the host name from the socket and
156                                     after which the connection was accepted. */
157   char con_passwd[PASSWDLEN + 1];
158   char con_buffer[BUFSIZE];     /* Incoming message buffer; or the error that
159                                    caused this clients socket to be `dead' */
160   struct Socket       con_socket; /* socket descriptor for client */
161   struct Timer        con_proc; /* process latent messages from client */
162   struct AuthRequest* con_auth; /* auth request for client */
163 };
164
165 #define CONNECTION_MAGIC 0x12f955f3
166
167 struct Client {
168   unsigned long  cli_magic;     /* magic number */
169   struct Client* cli_next;      /* link in GlobalClientList */
170   struct Client* cli_prev;      /* link in GlobalClientList */
171   struct Client* cli_hnext;     /* link in hash table bucket or this */
172   struct Connection* cli_connect; /* Connection structure associated with us */
173   struct User*   cli_user;      /* ...defined, if this is a User */
174   struct Server* cli_serv;      /* ...defined, if this is a server */
175   struct Whowas* cli_whowas;    /* Pointer to ww struct to be freed on quit */
176   char           cli_yxx[4];    /* Numeric Nick: YMM if this is a server,
177                                    XX0 if this is a user */
178   /*
179    * XXX - move these to local part for next release
180    * (lasttime, since)
181    */
182   time_t         cli_lasttime;  /* last time data read from socket */
183   time_t         cli_since;     /* last time we parsed something, flood control */
184                                 
185   time_t         cli_firsttime; /* time client was created */
186   time_t         cli_lastnick;  /* TimeStamp on nick */
187   int            cli_marker;    /* /who processing marker */
188   unsigned int   cli_flags;     /* client flags */
189   unsigned int   cli_hopcount;  /* number of servers to this 0 = local */
190   struct in_addr cli_ip;        /* Real ip# NOT defined for remote servers! */
191   short          cli_status;    /* Client type */
192   unsigned char  cli_local;     /* local or remote client */
193   struct Privs   cli_privs;     /* Oper privileges */
194   char cli_name[HOSTLEN + 1];   /* Unique name of the client, nick or host */
195   char cli_username[USERLEN + 1]; /* username here now for auth stuff */
196   char cli_info[REALLEN + 1];   /* Free form additional client information */
197 };
198
199 #define CLIENT_MAGIC 0x4ca08286
200
201 #define cli_verify(cli)         ((cli)->cli_magic == CLIENT_MAGIC)
202 #define cli_magic(cli)          ((cli)->cli_magic)
203 #define cli_next(cli)           ((cli)->cli_next)
204 #define cli_prev(cli)           ((cli)->cli_prev)
205 #define cli_hnext(cli)          ((cli)->cli_hnext)
206 #define cli_connect(cli)        ((cli)->cli_connect)
207 #define cli_from(cli)           ((cli)->cli_connect->con_client)
208 #define cli_user(cli)           ((cli)->cli_user)
209 #define cli_serv(cli)           ((cli)->cli_serv)
210 #define cli_whowas(cli)         ((cli)->cli_whowas)
211 #define cli_yxx(cli)            ((cli)->cli_yxx)
212 #define cli_lasttime(cli)       ((cli)->cli_lasttime)
213 #define cli_since(cli)          ((cli)->cli_since)
214 #define cli_firsttime(cli)      ((cli)->cli_firsttime)
215 #define cli_lastnick(cli)       ((cli)->cli_lastnick)
216 #define cli_marker(cli)         ((cli)->cli_marker)
217 #define cli_flags(cli)          ((cli)->cli_flags)
218 #define cli_hopcount(cli)       ((cli)->cli_hopcount)
219 #define cli_ip(cli)             ((cli)->cli_ip)
220 #define cli_status(cli)         ((cli)->cli_status)
221 #define cli_local(cli)          ((cli)->cli_local)
222 #define cli_privs(cli)          ((cli)->cli_privs)
223 #define cli_name(cli)           ((cli)->cli_name)
224 #define cli_username(cli)       ((cli)->cli_username)
225 #define cli_info(cli)           ((cli)->cli_info)
226
227 #define cli_count(cli)          ((cli)->cli_connect->con_count)
228 #define cli_fd(cli)             ((cli)->cli_connect->con_fd)
229 #define cli_freeflag(cli)       ((cli)->cli_connect->con_freeflag)
230 #define cli_error(cli)          ((cli)->cli_connect->con_error)
231 #define cli_snomask(cli)        ((cli)->cli_connect->con_snomask)
232 #define cli_nextnick(cli)       ((cli)->cli_connect->con_nextnick)
233 #define cli_nexttarget(cli)     ((cli)->cli_connect->con_nexttarget)
234 #define cli_cookie(cli)         ((cli)->cli_connect->con_cookie)
235 #define cli_sendQ(cli)          ((cli)->cli_connect->con_sendQ)
236 #define cli_recvQ(cli)          ((cli)->cli_connect->con_recvQ)
237 #define cli_sendM(cli)          ((cli)->cli_connect->con_sendM)
238 #define cli_sendK(cli)          ((cli)->cli_connect->con_sendK)
239 #define cli_receiveM(cli)       ((cli)->cli_connect->con_receiveM)
240 #define cli_receiveK(cli)       ((cli)->cli_connect->con_receiveK)
241 #define cli_sendB(cli)          ((cli)->cli_connect->con_sendB)
242 #define cli_receiveB(cli)       ((cli)->cli_connect->con_receiveB)
243 #define cli_listener(cli)       ((cli)->cli_connect->con_listener)
244 #define cli_confs(cli)          ((cli)->cli_connect->con_confs)
245 #define cli_handler(cli)        ((cli)->cli_connect->con_handler)
246 #define cli_dns_reply(cli)      ((cli)->cli_connect->con_dns_reply)
247 #define cli_listing(cli)        ((cli)->cli_connect->con_listing)
248 #define cli_max_sendq(cli)      ((cli)->cli_connect->con_max_sendq)
249 #define cli_ping_freq(cli)      ((cli)->cli_connect->con_ping_freq)
250 #define cli_lastsq(cli)         ((cli)->cli_connect->con_lastsq)
251 #define cli_port(cli)           ((cli)->cli_connect->con_port)
252 #define cli_targets(cli)        ((cli)->cli_connect->con_targets)
253 #define cli_sock_ip(cli)        ((cli)->cli_connect->con_sock_ip)
254 #define cli_sockhost(cli)       ((cli)->cli_connect->con_sockhost)
255 #define cli_passwd(cli)         ((cli)->cli_connect->con_passwd)
256 #define cli_buffer(cli)         ((cli)->cli_connect->con_buffer)
257 #define cli_socket(cli)         ((cli)->cli_connect->con_socket)
258 #define cli_proc(cli)           ((cli)->cli_connect->con_proc)
259 #define cli_auth(cli)           ((cli)->cli_connect->con_auth)
260
261 #define con_verify(con)         ((con)->con_magic == CONNECTION_MAGIC)
262 #define con_magic(con)          ((con)->con_magic)
263 #define con_next(con)           ((con)->con_next)
264 #define con_prev_p(con)         ((con)->con_prev_p)
265 #define con_client(con)         ((con)->con_client)
266 #define con_count(con)          ((con)->con_count)
267 #define con_fd(con)             ((con)->con_fd)
268 #define con_freeflag(con)       ((con)->con_freeflag)
269 #define con_error(con)          ((con)->con_error)
270 #define con_snomask(con)        ((con)->con_snomask)
271 #define con_nextnick(con)       ((con)->con_nextnick)
272 #define con_nexttarget(con)     ((con)->con_nexttarget)
273 #define con_cookie(con)         ((con)->con_cookie)
274 #define con_sendQ(con)          ((con)->con_sendQ)
275 #define con_recvQ(con)          ((con)->con_recvQ)
276 #define con_sendM(con)          ((con)->con_sendM)
277 #define con_sendK(con)          ((con)->con_sendK)
278 #define con_receiveM(con)       ((con)->con_receiveM)
279 #define con_receiveK(con)       ((con)->con_receiveK)
280 #define con_sendB(con)          ((con)->con_sendB)
281 #define con_receiveB(con)       ((con)->con_receiveB)
282 #define con_listener(con)       ((con)->con_listener)
283 #define con_confs(con)          ((con)->con_confs)
284 #define con_handler(con)        ((con)->con_handler)
285 #define con_dns_reply(con)      ((con)->con_dns_reply)
286 #define con_listing(con)        ((con)->con_listing)
287 #define con_max_sendq(con)      ((con)->con_max_sendq)
288 #define con_ping_freq(con)      ((con)->con_ping_freq)
289 #define con_lastsq(con)         ((con)->con_lastsq)
290 #define con_port(con)           ((con)->con_port)
291 #define con_targets(con)        ((con)->con_targets)
292 #define con_sock_ip(con)        ((con)->con_sock_ip)
293 #define con_sockhost(con)       ((con)->con_sockhost)
294 #define con_passwd(con)         ((con)->con_passwd)
295 #define con_buffer(con)         ((con)->con_buffer)
296 #define con_socket(con)         ((con)->con_socket)
297 #define con_proc(con)           ((con)->con_proc)
298 #define con_auth(con)           ((con)->con_auth)
299
300 #define STAT_CONNECTING         0x001 /* connecting to another server */
301 #define STAT_HANDSHAKE          0x002 /* pass - server sent */
302 #define STAT_ME                 0x004 /* this server */
303 #define STAT_UNKNOWN            0x008 /* unidentified connection */
304 #define STAT_UNKNOWN_USER       0x010 /* Connect to client port */
305 #define STAT_UNKNOWN_SERVER     0x020 /* Connect to server port */
306 #define STAT_SERVER             0x040
307 #define STAT_USER               0x080
308
309 /*
310  * status macros.
311  */
312 #define IsRegistered(x)         (cli_status(x) & (STAT_SERVER | STAT_USER))
313 #define IsConnecting(x)         (cli_status(x) == STAT_CONNECTING)
314 #define IsHandshake(x)          (cli_status(x) == STAT_HANDSHAKE)
315 #define IsMe(x)                 (cli_status(x) == STAT_ME)
316 #define IsUnknown(x)            (cli_status(x) & \
317         (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
318
319 #define IsServerPort(x)         (cli_status(x) == STAT_UNKNOWN_SERVER )
320 #define IsUserPort(x)           (cli_status(x) == STAT_UNKNOWN_USER )
321 #define IsClient(x)             (cli_status(x) & \
322         (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
323          STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
324
325 #define IsTrusted(x)            (cli_status(x) & \
326         (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
327
328 #define IsServer(x)             (cli_status(x) == STAT_SERVER)
329 #define IsUser(x)               (cli_status(x) == STAT_USER)
330
331
332 #define SetConnecting(x)        (cli_status(x) = STAT_CONNECTING)
333 #define SetHandshake(x)         (cli_status(x) = STAT_HANDSHAKE)
334 #define SetServer(x)            (cli_status(x) = STAT_SERVER)
335 #define SetMe(x)                (cli_status(x) = STAT_ME)
336 #define SetUser(x)              (cli_status(x) = STAT_USER)
337
338 #define MyConnect(x)    (cli_from(x) == (x))
339 #define MyUser(x)       (MyConnect(x) && IsUser(x))
340 #define MyOper(x)       (MyConnect(x) && IsOper(x))
341 #define Protocol(x)     ((cli_serv(x))->prot)
342
343 #define PARSE_AS_SERVER(x) (cli_status(x) & \
344             (STAT_SERVER | STAT_CONNECTING | STAT_HANDSHAKE))
345
346 /*
347  * FLAGS macros
348  */
349 #define FLAGS_PINGSENT   0x0001 /* Unreplied ping sent */
350 #define FLAGS_DEADSOCKET 0x0002 /* Local socket is dead--Exiting soon */
351 #define FLAGS_KILLED     0x0004 /* Prevents "QUIT" from being sent for this */
352 #define FLAGS_OPER       0x0008 /* Operator */
353 #define FLAGS_LOCOP      0x0010 /* Local operator -- SRB */
354 #define FLAGS_INVISIBLE  0x0020 /* makes user invisible */
355 #define FLAGS_WALLOP     0x0040 /* send wallops to them */
356 #define FLAGS_SERVNOTICE 0x0080 /* server notices such as kill */
357 #define FLAGS_BLOCKED    0x0100 /* socket is in a blocked condition */
358 #define FLAGS_CLOSING    0x0400 /* set when closing to suppress errors */
359 #define FLAGS_UPING      0x0800 /* has active UDP ping request */
360 #define FLAGS_CHKACCESS  0x1000 /* ok to check clients access if set */
361 #define FLAGS_HUB        0x2000 /* server is a hub */
362 #define FLAGS_SERVICE    0x4000 /* server is a service */
363 #define FLAGS_LOCAL     0x00010000      /* set for local clients */
364 #define FLAGS_GOTID     0x00020000      /* successful ident lookup achieved */
365 #define FLAGS_DOID      0x00040000      /* I-lines say must use ident return */
366 #define FLAGS_NONL      0x00080000      /* No \n in buffer */
367 #define FLAGS_TS8       0x00100000      /* Why do you want to know? */
368 #define FLAGS_MAP       0x00800000      /* Show server on the map */
369 #define FLAGS_JUNCTION  0x01000000      /* Junction causing the net.burst */
370 #define FLAGS_DEAF      0x02000000      /* Makes user deaf */
371 #define FLAGS_CHSERV    0x04000000      /* Disallow KICK or MODE -o on the user;
372                                            don't display channels in /whois */
373 #define FLAGS_BURST     0x08000000      /* Server is receiving a net.burst */
374 #define FLAGS_BURST_ACK 0x10000000      /* Server is waiting for eob ack */
375 #define FLAGS_DEBUG     0x20000000      /* send global debug/anti-hack info */
376 #define FLAGS_IPCHECK   0x40000000      /* Added or updated IPregistry data */
377
378 #define SEND_UMODES \
379     (FLAGS_INVISIBLE|FLAGS_OPER|FLAGS_WALLOP|FLAGS_DEAF|FLAGS_CHSERV|FLAGS_DEBUG)
380 #define ALL_UMODES (SEND_UMODES|FLAGS_SERVNOTICE|FLAGS_LOCOP)
381 #define FLAGS_ID (FLAGS_DOID|FLAGS_GOTID)
382
383 /*
384  * flags macros.
385  */
386 #define DoAccess(x)             (cli_flags(x) & FLAGS_CHKACCESS)
387 #define IsAnOper(x)             (cli_flags(x) & (FLAGS_OPER|FLAGS_LOCOP))
388 #define IsBlocked(x)            (cli_flags(x) & FLAGS_BLOCKED)
389 #define IsBurst(x)              (cli_flags(x) & FLAGS_BURST)
390 #define IsBurstAck(x)           (cli_flags(x) & FLAGS_BURST_ACK)
391 #define IsBurstOrBurstAck(x)    (cli_flags(x) & (FLAGS_BURST|FLAGS_BURST_ACK))
392 #define IsChannelService(x)     (cli_flags(x) & FLAGS_CHSERV)
393 #define IsDead(x)               (cli_flags(x) & FLAGS_DEADSOCKET)
394 #define IsDeaf(x)               (cli_flags(x) & FLAGS_DEAF)
395 #define IsIPChecked(x)          (cli_flags(x) & FLAGS_IPCHECK)
396 #define IsIdented(x)            (cli_flags(x) & FLAGS_GOTID)
397 #define IsInvisible(x)          (cli_flags(x) & FLAGS_INVISIBLE)
398 #define IsJunction(x)           (cli_flags(x) & FLAGS_JUNCTION)
399 #define IsLocOp(x)              (cli_flags(x) & FLAGS_LOCOP)
400 #define IsLocal(x)              (cli_flags(x) & FLAGS_LOCAL)
401 #define IsOper(x)               (cli_flags(x) & FLAGS_OPER)
402 #define IsUPing(x)              (cli_flags(x) & FLAGS_UPING)
403 #define NoNewLine(x)            (cli_flags(x) & FLAGS_NONL)
404 #define SendDebug(x)            (cli_flags(x) & FLAGS_DEBUG)
405 #define SendServNotice(x)       (cli_flags(x) & FLAGS_SERVNOTICE)
406 #define SendWallops(x)          (cli_flags(x) & FLAGS_WALLOP)
407 #define IsHub(x)                (cli_flags(x) & FLAGS_HUB)
408 #define IsService(x)            (cli_flags(x) & FLAGS_SERVICE)
409
410 #define IsPrivileged(x)         (IsAnOper(x) || IsServer(x))
411
412 #define SetAccess(x)            (cli_flags(x) |= FLAGS_CHKACCESS)
413 #define SetBurst(x)             (cli_flags(x) |= FLAGS_BURST)
414 #define SetBurstAck(x)          (cli_flags(x) |= FLAGS_BURST_ACK)
415 #define SetChannelService(x)    (cli_flags(x) |= FLAGS_CHSERV)
416 #define SetDeaf(x)              (cli_flags(x) |= FLAGS_DEAF)
417 #define SetDebug(x)             (cli_flags(x) |= FLAGS_DEBUG)
418 #define SetGotId(x)             (cli_flags(x) |= FLAGS_GOTID)
419 #define SetIPChecked(x)         (cli_flags(x) |= FLAGS_IPCHECK)
420 #define SetInvisible(x)         (cli_flags(x) |= FLAGS_INVISIBLE)
421 #define SetJunction(x)          (cli_flags(x) |= FLAGS_JUNCTION)
422 #define SetLocOp(x)             (cli_flags(x) |= FLAGS_LOCOP)
423 #define SetOper(x)              (cli_flags(x) |= FLAGS_OPER)
424 #define SetUPing(x)             (cli_flags(x) |= FLAGS_UPING)
425 #define SetWallops(x)           (cli_flags(x) |= FLAGS_WALLOP)
426 #define SetServNotice(x)        (cli_flags(x) |= FLAGS_SERVNOTICE)
427 #define SetHub(x)               (cli_flags(x) |= FLAGS_HUB)
428 #define SetService(x)           (cli_flags(x) |= FLAGS_SERVICE)
429
430 #define ClearAccess(x)          (cli_flags(x) &= ~FLAGS_CHKACCESS)
431 #define ClearBurst(x)           (cli_flags(x) &= ~FLAGS_BURST)
432 #define ClearBurstAck(x)        (cli_flags(x) &= ~FLAGS_BURST_ACK)
433 #define ClearChannelService(x)  (cli_flags(x) &= ~FLAGS_CHSERV)
434 #define ClearDeaf(x)            (cli_flags(x) &= ~FLAGS_DEAF)
435 #define ClearDebug(x)           (cli_flags(x) &= ~FLAGS_DEBUG)
436 #define ClearIPChecked(x)       (cli_flags(x) &= ~FLAGS_IPCHECK)
437 #define ClearInvisible(x)       (cli_flags(x) &= ~FLAGS_INVISIBLE)
438 #define ClearLocOp(x)           (cli_flags(x) &= ~FLAGS_LOCOP)
439 #define ClearOper(x)            (cli_flags(x) &= ~FLAGS_OPER)
440 #define ClearUPing(x)           (cli_flags(x) &= ~FLAGS_UPING)
441 #define ClearWallops(x)         (cli_flags(x) &= ~FLAGS_WALLOP)
442 #define ClearServNotice(x)      (cli_flags(x) &= ~FLAGS_SERVNOTICE)
443
444 /* free flags */
445 #define FREEFLAG_SOCKET 0x0001  /* socket needs to be freed */
446 #define FREEFLAG_TIMER  0x0002  /* timer needs to be freed */
447
448 /* server notice stuff */
449
450 #define SNO_ADD         1
451 #define SNO_DEL         2
452 #define SNO_SET         3
453                                 /* DON'T CHANGE THESE VALUES ! */
454                                 /* THE CLIENTS DEPEND ON IT  ! */
455 #define SNO_OLDSNO      0x1     /* unsorted old messages */
456 #define SNO_SERVKILL    0x2     /* server kills (nick collisions) */
457 #define SNO_OPERKILL    0x4     /* oper kills */
458 #define SNO_HACK2       0x8     /* desyncs */
459 #define SNO_HACK3       0x10    /* temporary desyncs */
460 #define SNO_UNAUTH      0x20    /* unauthorized connections */
461 #define SNO_TCPCOMMON   0x40    /* common TCP or socket errors */
462 #define SNO_TOOMANY     0x80    /* too many connections */
463 #define SNO_HACK4       0x100   /* Uworld actions on channels */
464 #define SNO_GLINE       0x200   /* glines */
465 #define SNO_NETWORK     0x400   /* net join/break, etc */
466 #define SNO_IPMISMATCH  0x800   /* IP mismatches */
467 #define SNO_THROTTLE    0x1000  /* host throttle add/remove notices */
468 #define SNO_OLDREALOP   0x2000  /* old oper-only messages */
469 #define SNO_CONNEXIT    0x4000  /* client connect/exit (ugh) */
470 #define SNO_DEBUG       0x8000  /* debugging messages (DEBUGMODE only) */
471
472 #ifdef DEBUGMODE
473 # define SNO_ALL        0xffff  /* Don't make it larger then significant,
474                                  * that looks nicer */
475 #else
476 # define SNO_ALL        0x7fff
477 #endif
478
479 #define SNO_USER        (SNO_ALL & ~SNO_OPER)
480
481 #define SNO_DEFAULT (SNO_NETWORK|SNO_OPERKILL|SNO_GLINE)
482 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO)
483 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP)
484 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
485
486 #define PrivSet(pset, priv)     ((pset)->priv_mask[_PRIV_IDX(priv)] |= \
487                                  _PRIV_BIT(priv))
488 #define PrivClr(pset, priv)     ((pset)->priv_mask[_PRIV_IDX(priv)] &= \
489                                  ~(_PRIV_BIT(priv)))
490 #define PrivHas(pset, priv)     ((pset)->priv_mask[_PRIV_IDX(priv)] & \
491                                  _PRIV_BIT(priv))
492
493 #define GrantPriv(cli, priv)    (PrivSet(&(cli_privs(cli)), priv))
494 #define RevokePriv(cli, priv)   (PrivClr(&(cli_privs(cli)), priv))
495 #define HasPriv(cli, priv)      (PrivHas(&(cli_privs(cli)), priv))
496
497 typedef enum ShowIPType {
498   HIDE_IP,
499   SHOW_IP,
500   MASK_IP
501 } ShowIPType;
502
503 extern const char* get_client_name(const struct Client* sptr, int showip);
504 extern int client_get_ping(const struct Client* local_client);
505 extern void client_drop_sendq(struct Connection* con);
506 extern void client_add_sendq(struct Connection* con,
507                              struct Connection** con_p);
508 extern void client_set_privs(struct Client* client);
509 extern int client_report_privs(struct Client* to, struct Client* client);
510
511 #endif /* INCLUDED_client_h */
512