2 * IRC - Internet Relay Chat, include/client.h
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
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)
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.
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.
23 #ifndef INCLUDED_client_h
24 #define INCLUDED_client_h
25 #ifndef INCLUDED_ircd_defs_h
26 #include "ircd_defs.h"
28 #ifndef INCLUDED_config_h
31 #ifndef INCLUDED_dbuf_h
34 #ifndef INCLUDED_ircd_handler_h
35 #include "ircd_handler.h"
37 #ifndef INCLUDED_sys_types_h
38 #include <sys/types.h> /* time_t, size_t */
39 #define INCLUDED_sys_types_h
41 #ifndef INCLUDED_netinet_in_h
42 #include <netinet/in.h> /* in_addr */
43 #define INCLUDED_netinet_in_h
56 /*-----------------------------------------------------------------------------
59 #define CLIENT_LOCAL_SIZE sizeof(struct Client)
60 #define CLIENT_REMOTE_SIZE offsetof(struct Client, count)
65 * Only put structures here that are being used in a very large number of
66 * source files. Other structures go in the header file of there corresponding
67 * source file, or in the source file itself (when only used in that file).
71 struct Client* next; /* link in GlobalClientList */
72 struct Client* prev; /* link in GlobalClientList */
73 struct Client* hnext; /* link in hash table bucket or this */
74 struct Client* from; /* == self, if Local Client, *NEVER* NULL! */
75 struct User* user; /* ...defined, if this is a User */
76 struct Server* serv; /* ...defined, if this is a server */
77 struct Whowas* whowas; /* Pointer to ww struct to be freed on quit */
78 char yxx[4]; /* Numeric Nick: YMM if this is a server,
79 XX0 if this is a user */
81 * XXX - move these to local part for next release
84 time_t lasttime; /* last time data read from socket */
85 time_t since; /* last time we parsed something, flood control */
87 time_t firsttime; /* time client was created */
88 time_t lastnick; /* TimeStamp on nick */
89 int marker; /* /who processing marker */
90 unsigned int flags; /* client flags */
91 unsigned int hopcount; /* number of servers to this 0 = local */
92 struct in_addr ip; /* Real ip# NOT defined for remote servers! */
93 short status; /* Client type */
94 unsigned char local; /* local or remote client */
95 char name[HOSTLEN + 1]; /* Unique name of the client, nick or host */
96 char username[USERLEN + 1]; /* username here now for auth stuff */
97 char info[REALLEN + 1]; /* Free form additional client information */
99 * The following fields are allocated only for local clients
100 * (directly connected to *this* server with a socket.
101 * The first of them *MUST* be the "count"--it is the field
102 * to which the allocation is tied to! *Never* refer to
103 * these fields, if (from != self).
105 unsigned int count; /* Amount of data in buffer, DON'T PUT
106 variables ABOVE this one! */
107 int fd; /* >= 0, for local clients */
108 int error; /* last socket level error for client */
109 unsigned int snomask; /* mask for server messages */
110 time_t nextnick; /* Next time a nick change is allowed */
111 time_t nexttarget; /* Next time a target change is allowed */
112 unsigned int cookie; /* Random number the user must PONG */
113 struct DBuf sendQ; /* Outgoing message queue--if socket full */
114 struct DBuf recvQ; /* Hold for data incoming yet to be parsed */
115 unsigned int sendM; /* Statistics: protocol messages send */
116 unsigned int sendK; /* Statistics: total k-bytes send */
117 unsigned int receiveM; /* Statistics: protocol messages received */
118 unsigned int receiveK; /* Statistics: total k-bytes received */
119 unsigned short sendB; /* counters to count upto 1-k lots of bytes */
120 unsigned short receiveB; /* sent and received. */
121 struct Listener* listener; /* listening client which we accepted from */
122 struct SLink* confs; /* Configuration record associated */
123 HandlerType handler; /* message index into command table for parsing */
124 struct DNSReply* dns_reply; /* DNS reply used during client registration */
125 struct ListingArgs* listing;
126 unsigned int max_sendq; /* cached max send queue for client */
127 unsigned int ping_freq; /* cached ping freq from client conf class */
128 unsigned short lastsq; /* # 2k blocks when sendqueued called last */
129 unsigned short port; /* and the remote port# too :-) */
130 unsigned char targets[MAXTARGETS]; /* Hash values of current targets */
131 char sock_ip[SOCKIPLEN + 1]; /* this is the ip address as a string */
132 char sockhost[HOSTLEN + 1]; /* This is the host name from the socket and
133 after which the connection was accepted. */
134 char passwd[PASSWDLEN + 1];
135 char buffer[BUFSIZE]; /* Incoming message buffer; or the error that
136 caused this clients socket to be `dead' */
140 #define STAT_CONNECTING 0x001 /* connecting to another server */
141 #define STAT_HANDSHAKE 0x002 /* pass - server sent */
142 #define STAT_ME 0x004 /* this server */
143 #define STAT_UNKNOWN 0x008 /* unidentified connection */
144 #define STAT_UNKNOWN_USER 0x010 /* Connect to client port */
145 #define STAT_UNKNOWN_SERVER 0x020 /* Connect to server port */
146 #define STAT_SERVER 0x040
147 #define STAT_USER 0x080
152 #define IsRegistered(x) ((x)->status & (STAT_SERVER | STAT_USER))
153 #define IsConnecting(x) ((x)->status == STAT_CONNECTING)
154 #define IsHandshake(x) ((x)->status == STAT_HANDSHAKE)
155 #define IsMe(x) ((x)->status == STAT_ME)
156 #define IsUnknown(x) ((x)->status & \
157 (STAT_UNKNOWN | STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER))
159 #define IsServerPort(x) ((x)->status == STAT_UNKNOWN_SERVER )
160 #define IsUserPort(x) ((x)->status == STAT_UNKNOWN_USER )
161 #define IsClient(x) ((x)->status & \
162 (STAT_HANDSHAKE | STAT_ME | STAT_UNKNOWN |\
163 STAT_UNKNOWN_USER | STAT_UNKNOWN_SERVER | STAT_SERVER | STAT_USER))
165 #define IsTrusted(x) ((x)->status & \
166 (STAT_CONNECTING | STAT_HANDSHAKE | STAT_ME | STAT_SERVER))
168 #define IsServer(x) ((x)->status == STAT_SERVER)
169 #define IsUser(x) ((x)->status == STAT_USER)
172 #define SetConnecting(x) ((x)->status = STAT_CONNECTING)
173 #define SetHandshake(x) ((x)->status = STAT_HANDSHAKE)
174 #define SetServer(x) ((x)->status = STAT_SERVER)
175 #define SetMe(x) ((x)->status = STAT_ME)
176 #define SetUser(x) ((x)->status = STAT_USER)
178 #define MyConnect(x) ((x)->from == (x))
179 #define MyUser(x) (MyConnect(x) && IsUser(x))
180 #define MyOper(x) (MyConnect(x) && IsOper(x))
181 #define Protocol(x) ((x)->serv->prot)
183 #define PARSE_AS_SERVER(x) ((x)->status & \
184 (STAT_SERVER | STAT_CONNECTING | STAT_HANDSHAKE))
189 #define FLAGS_PINGSENT 0x0001 /* Unreplied ping sent */
190 #define FLAGS_DEADSOCKET 0x0002 /* Local socket is dead--Exiting soon */
191 #define FLAGS_KILLED 0x0004 /* Prevents "QUIT" from being sent for this */
192 #define FLAGS_OPER 0x0008 /* Operator */
193 #define FLAGS_LOCOP 0x0010 /* Local operator -- SRB */
194 #define FLAGS_INVISIBLE 0x0020 /* makes user invisible */
195 #define FLAGS_WALLOP 0x0040 /* send wallops to them */
196 #define FLAGS_SERVNOTICE 0x0080 /* server notices such as kill */
197 #define FLAGS_BLOCKED 0x0100 /* socket is in a blocked condition */
198 #define FLAGS_CLOSING 0x0400 /* set when closing to suppress errors */
199 #define FLAGS_UPING 0x0800 /* has active UDP ping request */
200 #define FLAGS_CHKACCESS 0x1000 /* ok to check clients access if set */
201 #define FLAGS_LOCAL 0x00010000 /* set for local clients */
202 #define FLAGS_GOTID 0x00020000 /* successful ident lookup achieved */
203 #define FLAGS_DOID 0x00040000 /* I-lines say must use ident return */
204 #define FLAGS_NONL 0x00080000 /* No \n in buffer */
205 #define FLAGS_TS8 0x00100000 /* Why do you want to know? */
206 #define FLAGS_MAP 0x00800000 /* Show server on the map */
207 #define FLAGS_JUNCTION 0x01000000 /* Junction causing the net.burst */
208 #define FLAGS_DEAF 0x02000000 /* Makes user deaf */
209 #define FLAGS_CHSERV 0x04000000 /* Disallow KICK or MODE -o on the user;
210 don't display channels in /whois */
211 #define FLAGS_BURST 0x08000000 /* Server is receiving a net.burst */
212 #define FLAGS_BURST_ACK 0x10000000 /* Server is waiting for eob ack */
213 #define FLAGS_DEBUG 0x20000000 /* send global debug/anti-hack info */
214 #define FLAGS_IPCHECK 0x40000000 /* Added or updated IPregistry data */
216 #define SEND_UMODES \
217 (FLAGS_INVISIBLE|FLAGS_OPER|FLAGS_WALLOP|FLAGS_DEAF|FLAGS_CHSERV|FLAGS_DEBUG)
218 #define ALL_UMODES (SEND_UMODES|FLAGS_SERVNOTICE|FLAGS_LOCOP)
219 #define FLAGS_ID (FLAGS_DOID|FLAGS_GOTID)
224 #define DoAccess(x) ((x)->flags & FLAGS_CHKACCESS)
225 #define IsAnOper(x) ((x)->flags & (FLAGS_OPER|FLAGS_LOCOP))
226 #define IsBlocked(x) ((x)->flags & FLAGS_BLOCKED)
227 #define IsBurst(x) ((x)->flags & FLAGS_BURST)
228 #define IsBurstAck(x) ((x)->flags & FLAGS_BURST_ACK)
229 #define IsBurstOrBurstAck(x) ((x)->flags & (FLAGS_BURST|FLAGS_BURST_ACK))
230 #define IsChannelService(x) ((x)->flags & FLAGS_CHSERV)
231 #define IsDead(x) ((x)->flags & FLAGS_DEADSOCKET)
232 #define IsDeaf(x) ((x)->flags & FLAGS_DEAF)
233 #define IsIPChecked(x) ((x)->flags & FLAGS_IPCHECK)
234 #define IsIdented(x) ((x)->flags & FLAGS_GOTID)
235 #define IsInvisible(x) ((x)->flags & FLAGS_INVISIBLE)
236 #define IsJunction(x) ((x)->flags & FLAGS_JUNCTION)
237 #define IsLocOp(x) ((x)->flags & FLAGS_LOCOP)
238 #define IsLocal(x) ((x)->flags & FLAGS_LOCAL)
239 #define IsOper(x) ((x)->flags & FLAGS_OPER)
240 #define IsUPing(x) ((x)->flags & FLAGS_UPING)
241 #define NoNewLine(x) ((x)->flags & FLAGS_NONL)
242 #define SendDebug(x) ((x)->flags & FLAGS_DEBUG)
243 #define SendServNotice(x) ((x)->flags & FLAGS_SERVNOTICE)
244 #define SendWallops(x) ((x)->flags & FLAGS_WALLOP)
246 #define IsPrivileged(x) (IsAnOper(x) || IsServer(x))
248 #define SetAccess(x) ((x)->flags |= FLAGS_CHKACCESS)
249 #define SetBurst(x) ((x)->flags |= FLAGS_BURST)
250 #define SetBurstAck(x) ((x)->flags |= FLAGS_BURST_ACK)
251 #define SetChannelService(x) ((x)->flags |= FLAGS_CHSERV)
252 #define SetDeaf(x) ((x)->flags |= FLAGS_DEAF)
253 #define SetDebug(x) ((x)->flags |= FLAGS_DEBUG)
254 #define SetGotId(x) ((x)->flags |= FLAGS_GOTID)
255 #define SetIPChecked(x) ((x)->flags |= FLAGS_IPCHECK)
256 #define SetInvisible(x) ((x)->flags |= FLAGS_INVISIBLE)
257 #define SetJunction(x) ((x)->flags |= FLAGS_JUNCTION)
258 #define SetLocOp(x) ((x)->flags |= FLAGS_LOCOP)
259 #define SetOper(x) ((x)->flags |= FLAGS_OPER)
260 #define SetUPing(x) ((x)->flags |= FLAGS_UPING)
261 #define SetWallops(x) ((x)->flags |= FLAGS_WALLOP)
263 #define ClearAccess(x) ((x)->flags &= ~FLAGS_CHKACCESS)
264 #define ClearBurst(x) ((x)->flags &= ~FLAGS_BURST)
265 #define ClearBurstAck(x) ((x)->flags &= ~FLAGS_BURST_ACK)
266 #define ClearChannelService(x) ((x)->flags &= ~FLAGS_CHSERV)
267 #define ClearDeaf(x) ((x)->flags &= ~FLAGS_DEAF)
268 #define ClearDebug(x) ((x)->flags &= ~FLAGS_DEBUG)
269 #define ClearIPChecked(x) ((x)->flags &= ~FLAGS_IPCHECK)
270 #define ClearInvisible(x) ((x)->flags &= ~FLAGS_INVISIBLE)
271 #define ClearLocOp(x) ((x)->flags &= ~FLAGS_LOCOP)
272 #define ClearOper(x) ((x)->flags &= ~FLAGS_OPER)
273 #define ClearUPing(x) ((x)->flags &= ~FLAGS_UPING)
274 #define ClearWallops(x) ((x)->flags &= ~FLAGS_WALLOP)
276 /* server notice stuff */
281 /* DON'T CHANGE THESE VALUES ! */
282 /* THE CLIENTS DEPEND ON IT ! */
283 #define SNO_OLDSNO 0x1 /* unsorted old messages */
284 #define SNO_SERVKILL 0x2 /* server kills (nick collisions) */
285 #define SNO_OPERKILL 0x4 /* oper kills */
286 #define SNO_HACK2 0x8 /* desyncs */
287 #define SNO_HACK3 0x10 /* temporary desyncs */
288 #define SNO_UNAUTH 0x20 /* unauthorized connections */
289 #define SNO_TCPCOMMON 0x40 /* common TCP or socket errors */
290 #define SNO_TOOMANY 0x80 /* too many connections */
291 #define SNO_HACK4 0x100 /* Uworld actions on channels */
292 #define SNO_GLINE 0x200 /* glines */
293 #define SNO_NETWORK 0x400 /* net join/break, etc */
294 #define SNO_IPMISMATCH 0x800 /* IP mismatches */
295 #define SNO_THROTTLE 0x1000 /* host throttle add/remove notices */
296 #define SNO_OLDREALOP 0x2000 /* old oper-only messages */
297 #define SNO_CONNEXIT 0x4000 /* client connect/exit (ugh) */
298 #define SNO_DEBUG 0x8000 /* debugging messages (DEBUGMODE only) */
301 # define SNO_ALL 0xffff /* Don't make it larger then significant,
302 * that looks nicer */
304 # define SNO_ALL 0x7fff
307 #define SNO_USER (SNO_ALL & ~SNO_OPER)
309 #define SNO_DEFAULT ((SNO_NETWORK|SNO_OPERKILL|SNO_GLINE|SNO_DEBUG)&SNO_ALL)
310 #define SNO_OPERDEFAULT (SNO_DEFAULT|SNO_HACK2|SNO_HACK4|SNO_THROTTLE|SNO_OLDSNO)
311 #define SNO_OPER (SNO_CONNEXIT|SNO_OLDREALOP)
312 #define SNO_NOISY (SNO_SERVKILL|SNO_UNAUTH)
314 typedef enum ShowIPType {
320 extern const char* get_client_name(const struct Client* sptr, int showip);
321 extern int client_get_ping(const struct Client* local_client);
324 #endif /* INCLUDED_client_h */