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