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