Blame


1 38b9cb88 2001-12-14 alex /*
2 38b9cb88 2001-12-14 alex * ngIRCd -- The Next Generation IRC Daemon
3 7f0d1011 2005-05-16 alex * Copyright (c)2001-2005 by Alexander Barton (alex@barton.de)
4 38b9cb88 2001-12-14 alex *
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
10 38b9cb88 2001-12-14 alex *
11 490f28ff 2002-12-12 alex * Client management.
12 38b9cb88 2001-12-14 alex */
13 38b9cb88 2001-12-14 alex
14 38b9cb88 2001-12-14 alex
15 f7551900 2002-01-04 alex #define __client_c__
16 f7551900 2002-01-04 alex
17 f7551900 2002-01-04 alex
18 ca33cbda 2002-03-12 alex #include "portab.h"
19 38b9cb88 2001-12-14 alex
20 5c20474f 2005-06-12 alex static char UNUSED id[] = "$Id: client.c,v 1.84 2005/06/12 16:39:42 alex Exp $";
21 490f28ff 2002-12-12 alex
22 ca33cbda 2002-03-12 alex #include "imp.h"
23 38b9cb88 2001-12-14 alex #include <assert.h>
24 d0ac1e9c 2001-12-23 alex #include <unistd.h>
25 118adda8 2001-12-27 alex #include <stdio.h>
26 b20fa7c6 2002-01-01 alex #include <stdlib.h>
27 d0ac1e9c 2001-12-23 alex #include <string.h>
28 57c7e236 2004-01-17 alex #include <strings.h>
29 c57a4645 2001-12-27 alex #include <netdb.h>
30 38b9cb88 2001-12-14 alex
31 a02f25a8 2005-04-27 alex #include "defines.h"
32 c2f60abe 2002-05-27 alex #include "conn.h"
33 c2f60abe 2002-05-27 alex
34 ca33cbda 2002-03-12 alex #include "exp.h"
35 08cf5607 2001-12-26 alex #include "client.h"
36 08cf5607 2001-12-26 alex
37 08cf5607 2001-12-26 alex #include <imp.h>
38 79809118 2002-01-06 alex #include "ngircd.h"
39 38b9cb88 2001-12-14 alex #include "channel.h"
40 c2f60abe 2002-05-27 alex #include "resolve.h"
41 9856253d 2001-12-30 alex #include "conf.h"
42 b5c16c22 2002-03-25 alex #include "hash.h"
43 ff54198f 2002-02-27 alex #include "irc-write.h"
44 38b9cb88 2001-12-14 alex #include "log.h"
45 08cf5607 2001-12-26 alex #include "messages.h"
46 38b9cb88 2001-12-14 alex
47 38b9cb88 2001-12-14 alex #include <exp.h>
48 38b9cb88 2001-12-14 alex
49 38b9cb88 2001-12-14 alex
50 467e76aa 2002-10-04 alex #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
51 467e76aa 2002-10-04 alex
52 467e76aa 2002-10-04 alex
53 f7551900 2002-01-04 alex LOCAL CLIENT *This_Server, *My_Clients;
54 8adff592 2005-03-19 fw LOCAL char GetID_Buffer[GETID_LEN];
55 08cf5607 2001-12-26 alex
56 7f0d1011 2005-05-16 alex LOCAL WHOWAS My_Whowas[MAX_WHOWAS];
57 7f0d1011 2005-05-16 alex LOCAL int Last_Whowas = -1;
58 08cf5607 2001-12-26 alex
59 7f0d1011 2005-05-16 alex
60 8adff592 2005-03-19 fw LOCAL long Count PARAMS(( CLIENT_TYPE Type ));
61 8adff592 2005-03-19 fw LOCAL long MyCount PARAMS(( CLIENT_TYPE Type ));
62 b9d701db 2002-01-16 alex
63 8adff592 2005-03-19 fw LOCAL CLIENT *New_Client_Struct PARAMS(( void ));
64 8adff592 2005-03-19 fw LOCAL void Generate_MyToken PARAMS(( CLIENT *Client ));
65 8adff592 2005-03-19 fw LOCAL void Adjust_Counters PARAMS(( CLIENT *Client ));
66 939767d5 2003-01-15 alex
67 939767d5 2003-01-15 alex #ifndef Client_DestroyNow
68 8adff592 2005-03-19 fw GLOBAL void Client_DestroyNow PARAMS((CLIENT *Client ));
69 939767d5 2003-01-15 alex #endif
70 38b9cb88 2001-12-14 alex
71 38b9cb88 2001-12-14 alex
72 8adff592 2005-03-19 fw long Max_Users = 0, My_Max_Users = 0;
73 d0304b19 2002-12-22 alex
74 d0304b19 2002-12-22 alex
75 8adff592 2005-03-19 fw GLOBAL void
76 8adff592 2005-03-19 fw Client_Init( void )
77 38b9cb88 2001-12-14 alex {
78 c57a4645 2001-12-27 alex struct hostent *h;
79 c57a4645 2001-12-27 alex
80 38b9cb88 2001-12-14 alex This_Server = New_Client_Struct( );
81 38b9cb88 2001-12-14 alex if( ! This_Server )
82 38b9cb88 2001-12-14 alex {
83 38b9cb88 2001-12-14 alex Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
84 62796722 2003-03-31 alex Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
85 38b9cb88 2001-12-14 alex exit( 1 );
86 38b9cb88 2001-12-14 alex }
87 38b9cb88 2001-12-14 alex
88 38b9cb88 2001-12-14 alex /* Client-Struktur dieses Servers */
89 38b9cb88 2001-12-14 alex This_Server->next = NULL;
90 38b9cb88 2001-12-14 alex This_Server->type = CLIENT_SERVER;
91 38b9cb88 2001-12-14 alex This_Server->conn_id = NONE;
92 38b9cb88 2001-12-14 alex This_Server->introducer = This_Server;
93 8f7e7d66 2002-01-09 alex This_Server->mytoken = 1;
94 4fe7e9d6 2002-01-11 alex This_Server->hops = 0;
95 c57a4645 2001-12-27 alex
96 d0ac1e9c 2001-12-23 alex gethostname( This_Server->host, CLIENT_HOST_LEN );
97 c57a4645 2001-12-27 alex h = gethostbyname( This_Server->host );
98 695631b2 2002-12-26 alex if( h ) strlcpy( This_Server->host, h->h_name, sizeof( This_Server->host ));
99 c57a4645 2001-12-27 alex
100 b5c16c22 2002-03-25 alex Client_SetID( This_Server, Conf_ServerName );
101 b5c16c22 2002-03-25 alex Client_SetInfo( This_Server, Conf_ServerInfo );
102 d0ac1e9c 2001-12-23 alex
103 38b9cb88 2001-12-14 alex My_Clients = This_Server;
104 7f0d1011 2005-05-16 alex
105 7f0d1011 2005-05-16 alex memset( &My_Whowas, 0, sizeof( My_Whowas ));
106 38b9cb88 2001-12-14 alex } /* Client_Init */
107 38b9cb88 2001-12-14 alex
108 38b9cb88 2001-12-14 alex
109 8adff592 2005-03-19 fw GLOBAL void
110 8adff592 2005-03-19 fw Client_Exit( void )
111 38b9cb88 2001-12-14 alex {
112 d0ac1e9c 2001-12-23 alex CLIENT *c, *next;
113 8adff592 2005-03-19 fw int cnt;
114 d0ac1e9c 2001-12-23 alex
115 8adff592 2005-03-19 fw if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, false );
116 8adff592 2005-03-19 fw else Client_Destroy( This_Server, "Server going down.", NULL, false );
117 d0ac1e9c 2001-12-23 alex
118 d0ac1e9c 2001-12-23 alex cnt = 0;
119 d0ac1e9c 2001-12-23 alex c = My_Clients;
120 d0ac1e9c 2001-12-23 alex while( c )
121 d0ac1e9c 2001-12-23 alex {
122 d0ac1e9c 2001-12-23 alex cnt++;
123 95a4b1b1 2002-03-25 alex next = (CLIENT *)c->next;
124 d0ac1e9c 2001-12-23 alex free( c );
125 d0ac1e9c 2001-12-23 alex c = next;
126 d0ac1e9c 2001-12-23 alex }
127 d4a60bd4 2001-12-25 alex if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
128 79809118 2002-01-06 alex } /* Client_Exit */
129 38b9cb88 2001-12-14 alex
130 38b9cb88 2001-12-14 alex
131 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
132 8adff592 2005-03-19 fw Client_ThisServer( void )
133 d0ac1e9c 2001-12-23 alex {
134 f7551900 2002-01-04 alex return This_Server;
135 f7551900 2002-01-04 alex } /* Client_ThisServer */
136 f7551900 2002-01-04 alex
137 f7551900 2002-01-04 alex
138 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
139 8adff592 2005-03-19 fw Client_NewLocal( CONN_ID Idx, char *Hostname, int Type, bool Idented )
140 f7551900 2002-01-04 alex {
141 f7551900 2002-01-04 alex /* Neuen lokalen Client erzeugen: Wrapper-Funktion fuer Client_New(). */
142 1ab92bb9 2002-01-29 alex return Client_New( Idx, This_Server, NULL, Type, NULL, NULL, Hostname, NULL, 0, 0, NULL, Idented );
143 f7551900 2002-01-04 alex } /* Client_NewLocal */
144 f7551900 2002-01-04 alex
145 f7551900 2002-01-04 alex
146 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
147 8adff592 2005-03-19 fw Client_NewRemoteServer( CLIENT *Introducer, char *Hostname, CLIENT *TopServer, int Hops, int Token, char *Info, bool Idented )
148 f7551900 2002-01-04 alex {
149 f7551900 2002-01-04 alex /* Neuen Remote-Client erzeugen: Wrapper-Funktion fuer Client_New (). */
150 1ab92bb9 2002-01-29 alex return Client_New( NONE, Introducer, TopServer, CLIENT_SERVER, Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented );
151 f7551900 2002-01-04 alex } /* Client_NewRemoteServer */
152 f7551900 2002-01-04 alex
153 f7551900 2002-01-04 alex
154 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
155 8adff592 2005-03-19 fw Client_NewRemoteUser( CLIENT *Introducer, char *Nick, int Hops, char *User, char *Hostname, int Token, char *Modes, char *Info, bool Idented )
156 f7551900 2002-01-04 alex {
157 f7551900 2002-01-04 alex /* Neuen Remote-Client erzeugen: Wrapper-Funktion fuer Client_New (). */
158 1ab92bb9 2002-01-29 alex return Client_New( NONE, Introducer, NULL, CLIENT_USER, Nick, User, Hostname, Info, Hops, Token, Modes, Idented );
159 f7551900 2002-01-04 alex } /* Client_NewRemoteUser */
160 f7551900 2002-01-04 alex
161 f7551900 2002-01-04 alex
162 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
163 8adff592 2005-03-19 fw Client_New( CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, int Type, char *ID, char *User, char *Hostname, char *Info, int Hops, int Token, char *Modes, bool Idented )
164 f7551900 2002-01-04 alex {
165 d0ac1e9c 2001-12-23 alex CLIENT *client;
166 d0ac1e9c 2001-12-23 alex
167 f7551900 2002-01-04 alex assert( Idx >= NONE );
168 f7551900 2002-01-04 alex assert( Introducer != NULL );
169 b7a18e9f 2001-12-24 alex assert( Hostname != NULL );
170 f7551900 2002-01-04 alex
171 d0ac1e9c 2001-12-23 alex client = New_Client_Struct( );
172 d0ac1e9c 2001-12-23 alex if( ! client ) return NULL;
173 d0ac1e9c 2001-12-23 alex
174 2c5da58d 2001-12-29 alex /* Initialisieren */
175 a4660f40 2005-06-12 alex client->starttime = time(NULL);
176 d0ac1e9c 2001-12-23 alex client->conn_id = Idx;
177 f7551900 2002-01-04 alex client->introducer = Introducer;
178 1ab92bb9 2002-01-29 alex client->topserver = TopServer;
179 f7551900 2002-01-04 alex client->type = Type;
180 f7551900 2002-01-04 alex if( ID ) Client_SetID( client, ID );
181 904d5e5b 2002-01-05 alex if( User ) Client_SetUser( client, User, Idented );
182 f7551900 2002-01-04 alex if( Hostname ) Client_SetHostname( client, Hostname );
183 f7551900 2002-01-04 alex if( Info ) Client_SetInfo( client, Info );
184 f7551900 2002-01-04 alex client->hops = Hops;
185 f7551900 2002-01-04 alex client->token = Token;
186 f7551900 2002-01-04 alex if( Modes ) Client_SetModes( client, Modes );
187 a53857b4 2002-01-07 alex if( Type == CLIENT_SERVER ) Generate_MyToken( client );
188 d0ac1e9c 2001-12-23 alex
189 a1a3e67d 2002-03-04 alex /* ist der User away? */
190 695631b2 2002-12-26 alex if( strchr( client->modes, 'a' )) strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away ));
191 a1a3e67d 2002-03-04 alex
192 d0ac1e9c 2001-12-23 alex /* Verketten */
193 95a4b1b1 2002-03-25 alex client->next = (POINTER *)My_Clients;
194 d0ac1e9c 2001-12-23 alex My_Clients = client;
195 f7551900 2002-01-04 alex
196 d0304b19 2002-12-22 alex /* Adjust counters */
197 d0304b19 2002-12-22 alex Adjust_Counters( client );
198 d0304b19 2002-12-22 alex
199 d0ac1e9c 2001-12-23 alex return client;
200 f7551900 2002-01-04 alex } /* Client_New */
201 d0ac1e9c 2001-12-23 alex
202 d0ac1e9c 2001-12-23 alex
203 8adff592 2005-03-19 fw GLOBAL void
204 8adff592 2005-03-19 fw Client_Destroy( CLIENT *Client, char *LogMsg, char *FwdMsg, bool SendQuit )
205 d0ac1e9c 2001-12-23 alex {
206 d0ac1e9c 2001-12-23 alex /* Client entfernen. */
207 d0ac1e9c 2001-12-23 alex
208 d0ac1e9c 2001-12-23 alex CLIENT *last, *c;
209 8adff592 2005-03-19 fw char msg[LINE_LEN], *txt;
210 d0ac1e9c 2001-12-23 alex
211 b7a18e9f 2001-12-24 alex assert( Client != NULL );
212 c4854470 2002-01-04 alex
213 79809118 2002-01-06 alex if( LogMsg ) txt = LogMsg;
214 79809118 2002-01-06 alex else txt = FwdMsg;
215 79809118 2002-01-06 alex if( ! txt ) txt = "Reason unknown.";
216 dce77559 2002-03-10 alex
217 03c3f3c9 2002-03-12 alex /* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */
218 cac9f279 2005-06-04 fw if( Client->type == CLIENT_SERVER ) {
219 cac9f279 2005-06-04 fw strlcpy(msg, This_Server->id, sizeof (msg));
220 cac9f279 2005-06-04 fw strlcat(msg, " ", sizeof (msg));
221 cac9f279 2005-06-04 fw strlcat(msg, Client->id, sizeof (msg));
222 cac9f279 2005-06-04 fw }
223 79809118 2002-01-06 alex
224 d0ac1e9c 2001-12-23 alex last = NULL;
225 d0ac1e9c 2001-12-23 alex c = My_Clients;
226 d0ac1e9c 2001-12-23 alex while( c )
227 d0ac1e9c 2001-12-23 alex {
228 c4854470 2002-01-04 alex if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
229 c4854470 2002-01-04 alex {
230 dce77559 2002-03-10 alex /* der Client, der geloescht wird ist ein Server. Der Client, den wir gerade
231 dce77559 2002-03-10 alex * pruefen, ist ein Child von diesem und muss daher auch entfernt werden */
232 8adff592 2005-03-19 fw Client_Destroy( c, NULL, msg, false );
233 c4854470 2002-01-04 alex last = NULL;
234 c4854470 2002-01-04 alex c = My_Clients;
235 c4854470 2002-01-04 alex continue;
236 c4854470 2002-01-04 alex }
237 d0ac1e9c 2001-12-23 alex if( c == Client )
238 d0ac1e9c 2001-12-23 alex {
239 dce77559 2002-03-10 alex /* Wir haben den Client gefunden: entfernen */
240 d0ac1e9c 2001-12-23 alex if( last ) last->next = c->next;
241 95a4b1b1 2002-03-25 alex else My_Clients = (CLIENT *)c->next;
242 15764f98 2001-12-27 alex
243 c4854470 2002-01-04 alex if( c->type == CLIENT_USER )
244 c4854470 2002-01-04 alex {
245 db58d347 2002-01-05 alex if( c->conn_id != NONE )
246 db58d347 2002-01-05 alex {
247 50ec7a56 2002-03-11 alex /* Ein lokaler User */
248 b89c3108 2002-01-07 alex Log( LOG_NOTICE, "User \"%s\" unregistered (connection %d): %s", Client_Mask( c ), c->conn_id, txt );
249 79809118 2002-01-06 alex
250 50ec7a56 2002-03-11 alex if( SendQuit )
251 50ec7a56 2002-03-11 alex {
252 50ec7a56 2002-03-11 alex /* Alle andere Server informieren! */
253 50ec7a56 2002-03-11 alex if( FwdMsg ) IRC_WriteStrServersPrefix( NULL, c, "QUIT :%s", FwdMsg );
254 50ec7a56 2002-03-11 alex else IRC_WriteStrServersPrefix( NULL, c, "QUIT :" );
255 50ec7a56 2002-03-11 alex }
256 db58d347 2002-01-05 alex }
257 79809118 2002-01-06 alex else
258 79809118 2002-01-06 alex {
259 50ec7a56 2002-03-11 alex /* Remote User */
260 b89c3108 2002-01-07 alex Log( LOG_DEBUG, "User \"%s\" unregistered: %s", Client_Mask( c ), txt );
261 50ec7a56 2002-03-11 alex
262 50ec7a56 2002-03-11 alex if( SendQuit )
263 50ec7a56 2002-03-11 alex {
264 50ec7a56 2002-03-11 alex /* Andere Server informieren, ausser denen, die "in
265 50ec7a56 2002-03-11 alex * Richtung dem liegen", auf dem der User registriert
266 50ec7a56 2002-03-11 alex * ist. Von denen haben wir das QUIT ja wohl bekommen. */
267 50ec7a56 2002-03-11 alex if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "QUIT :%s", FwdMsg );
268 50ec7a56 2002-03-11 alex else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "QUIT :" );
269 50ec7a56 2002-03-11 alex }
270 79809118 2002-01-06 alex }
271 7f0d1011 2005-05-16 alex
272 7f0d1011 2005-05-16 alex /* Unregister client from channels */
273 dadebb21 2002-06-01 alex Channel_Quit( c, FwdMsg ? FwdMsg : c->id );
274 7f0d1011 2005-05-16 alex
275 7f0d1011 2005-05-16 alex /* Register client in My_Whowas structure */
276 1aeaf64c 2005-05-17 alex Client_RegisterWhowas( c );
277 c4854470 2002-01-04 alex }
278 79809118 2002-01-06 alex else if( c->type == CLIENT_SERVER )
279 79809118 2002-01-06 alex {
280 28d58986 2002-02-27 alex if( c != This_Server )
281 28d58986 2002-02-27 alex {
282 6b58ab84 2002-03-27 alex if( c->conn_id != NONE ) Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
283 6b58ab84 2002-03-27 alex else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
284 28d58986 2002-02-27 alex }
285 8f7e7d66 2002-01-09 alex
286 8f7e7d66 2002-01-09 alex /* andere Server informieren */
287 77c4c015 2002-12-19 alex if( ! NGIRCd_SignalQuit )
288 8f7e7d66 2002-01-09 alex {
289 8f7e7d66 2002-01-09 alex if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
290 8f7e7d66 2002-01-09 alex else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
291 8f7e7d66 2002-01-09 alex }
292 79809118 2002-01-06 alex }
293 28d58986 2002-02-27 alex else
294 28d58986 2002-02-27 alex {
295 28d58986 2002-02-27 alex if( c->conn_id != NONE )
296 28d58986 2002-02-27 alex {
297 28d58986 2002-02-27 alex if( c->id[0] ) Log( LOG_NOTICE, "Client \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
298 28d58986 2002-02-27 alex else Log( LOG_NOTICE, "Client unregistered (connection %d): %s", c->conn_id, txt );
299 28d58986 2002-02-27 alex }
300 28d58986 2002-02-27 alex else
301 28d58986 2002-02-27 alex {
302 28d58986 2002-02-27 alex if( c->id[0] ) Log( LOG_WARNING, "Unregistered unknown client \"%s\": %s", c->id, txt );
303 28d58986 2002-02-27 alex else Log( LOG_WARNING, "Unregistered unknown client: %s", c->id, txt );
304 28d58986 2002-02-27 alex }
305 28d58986 2002-02-27 alex }
306 15764f98 2001-12-27 alex
307 d0ac1e9c 2001-12-23 alex free( c );
308 d0ac1e9c 2001-12-23 alex break;
309 d0ac1e9c 2001-12-23 alex }
310 d0ac1e9c 2001-12-23 alex last = c;
311 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
312 d0ac1e9c 2001-12-23 alex }
313 d0ac1e9c 2001-12-23 alex } /* Client_Destroy */
314 d0ac1e9c 2001-12-23 alex
315 d0ac1e9c 2001-12-23 alex
316 8adff592 2005-03-19 fw GLOBAL void
317 939767d5 2003-01-15 alex Client_DestroyNow( CLIENT *Client )
318 939767d5 2003-01-15 alex {
319 939767d5 2003-01-15 alex /* Destroy client structure immediately. This function is only
320 939767d5 2003-01-15 alex * intended for the connection layer to remove client structures
321 939767d5 2003-01-15 alex * of connections that can't be established! */
322 939767d5 2003-01-15 alex
323 939767d5 2003-01-15 alex CLIENT *last, *c;
324 939767d5 2003-01-15 alex
325 939767d5 2003-01-15 alex assert( Client != NULL );
326 939767d5 2003-01-15 alex
327 939767d5 2003-01-15 alex last = NULL;
328 939767d5 2003-01-15 alex c = My_Clients;
329 939767d5 2003-01-15 alex while( c )
330 939767d5 2003-01-15 alex {
331 939767d5 2003-01-15 alex if( c == Client )
332 939767d5 2003-01-15 alex {
333 939767d5 2003-01-15 alex /* Wir haben den Client gefunden: entfernen */
334 939767d5 2003-01-15 alex if( last ) last->next = c->next;
335 939767d5 2003-01-15 alex else My_Clients = (CLIENT *)c->next;
336 939767d5 2003-01-15 alex free( c );
337 939767d5 2003-01-15 alex break;
338 939767d5 2003-01-15 alex }
339 939767d5 2003-01-15 alex last = c;
340 939767d5 2003-01-15 alex c = (CLIENT *)c->next;
341 939767d5 2003-01-15 alex }
342 939767d5 2003-01-15 alex } /* Client_DestroyNow */
343 939767d5 2003-01-15 alex
344 939767d5 2003-01-15 alex
345 8adff592 2005-03-19 fw GLOBAL void
346 8adff592 2005-03-19 fw Client_SetHostname( CLIENT *Client, char *Hostname )
347 2c5da58d 2001-12-29 alex {
348 2c5da58d 2001-12-29 alex /* Hostname eines Clients setzen */
349 2c5da58d 2001-12-29 alex
350 2c5da58d 2001-12-29 alex assert( Client != NULL );
351 c68c092c 2002-03-06 alex assert( Hostname != NULL );
352 c68c092c 2002-03-06 alex
353 0ced4181 2002-12-26 alex strlcpy( Client->host, Hostname, sizeof( Client->host ));
354 2c5da58d 2001-12-29 alex } /* Client_SetHostname */
355 f7551900 2002-01-04 alex
356 f7551900 2002-01-04 alex
357 8adff592 2005-03-19 fw GLOBAL void
358 8adff592 2005-03-19 fw Client_SetID( CLIENT *Client, char *ID )
359 f7551900 2002-01-04 alex {
360 b5c16c22 2002-03-25 alex /* Hostname eines Clients setzen, Hash-Wert berechnen */
361 f7551900 2002-01-04 alex
362 f7551900 2002-01-04 alex assert( Client != NULL );
363 c68c092c 2002-03-06 alex assert( ID != NULL );
364 c68c092c 2002-03-06 alex
365 0ced4181 2002-12-26 alex strlcpy( Client->id, ID, sizeof( Client->id ));
366 b5c16c22 2002-03-25 alex
367 b5c16c22 2002-03-25 alex /* Hash */
368 b5c16c22 2002-03-25 alex Client->hash = Hash( Client->id );
369 f7551900 2002-01-04 alex } /* Client_SetID */
370 f7551900 2002-01-04 alex
371 f7551900 2002-01-04 alex
372 8adff592 2005-03-19 fw GLOBAL void
373 8adff592 2005-03-19 fw Client_SetUser( CLIENT *Client, char *User, bool Idented )
374 f7551900 2002-01-04 alex {
375 f7551900 2002-01-04 alex /* Username eines Clients setzen */
376 f7551900 2002-01-04 alex
377 f7551900 2002-01-04 alex assert( Client != NULL );
378 c68c092c 2002-03-06 alex assert( User != NULL );
379 c68c092c 2002-03-06 alex
380 0ced4181 2002-12-26 alex if( Idented ) strlcpy( Client->user, User, sizeof( Client->user ));
381 904d5e5b 2002-01-05 alex else
382 904d5e5b 2002-01-05 alex {
383 904d5e5b 2002-01-05 alex Client->user[0] = '~';
384 0ced4181 2002-12-26 alex strlcpy( Client->user + 1, User, sizeof( Client->user ) - 1 );
385 904d5e5b 2002-01-05 alex }
386 f7551900 2002-01-04 alex } /* Client_SetUser */
387 f7551900 2002-01-04 alex
388 f7551900 2002-01-04 alex
389 8adff592 2005-03-19 fw GLOBAL void
390 8adff592 2005-03-19 fw Client_SetInfo( CLIENT *Client, char *Info )
391 f7551900 2002-01-04 alex {
392 f7551900 2002-01-04 alex /* Hostname eines Clients setzen */
393 f7551900 2002-01-04 alex
394 f7551900 2002-01-04 alex assert( Client != NULL );
395 c68c092c 2002-03-06 alex assert( Info != NULL );
396 c68c092c 2002-03-06 alex
397 0ced4181 2002-12-26 alex strlcpy( Client->info, Info, sizeof( Client->info ));
398 f7551900 2002-01-04 alex } /* Client_SetInfo */
399 f7551900 2002-01-04 alex
400 f7551900 2002-01-04 alex
401 8adff592 2005-03-19 fw GLOBAL void
402 8adff592 2005-03-19 fw Client_SetModes( CLIENT *Client, char *Modes )
403 f7551900 2002-01-04 alex {
404 e62ad979 2002-09-03 alex /* Modes eines Clients setzen */
405 f7551900 2002-01-04 alex
406 f7551900 2002-01-04 alex assert( Client != NULL );
407 c68c092c 2002-03-06 alex assert( Modes != NULL );
408 c68c092c 2002-03-06 alex
409 0ced4181 2002-12-26 alex strlcpy( Client->modes, Modes, sizeof( Client->modes ));
410 f7551900 2002-01-04 alex } /* Client_SetModes */
411 e62ad979 2002-09-03 alex
412 e62ad979 2002-09-03 alex
413 8adff592 2005-03-19 fw GLOBAL void
414 8adff592 2005-03-19 fw Client_SetFlags( CLIENT *Client, char *Flags )
415 e62ad979 2002-09-03 alex {
416 e62ad979 2002-09-03 alex /* Flags eines Clients setzen */
417 e62ad979 2002-09-03 alex
418 e62ad979 2002-09-03 alex assert( Client != NULL );
419 e62ad979 2002-09-03 alex assert( Flags != NULL );
420 e62ad979 2002-09-03 alex
421 0ced4181 2002-12-26 alex strlcpy( Client->flags, Flags, sizeof( Client->flags ));
422 e62ad979 2002-09-03 alex } /* Client_SetFlags */
423 f7551900 2002-01-04 alex
424 f7551900 2002-01-04 alex
425 8adff592 2005-03-19 fw GLOBAL void
426 8adff592 2005-03-19 fw Client_SetPassword( CLIENT *Client, char *Pwd )
427 f7551900 2002-01-04 alex {
428 f7551900 2002-01-04 alex /* Von einem Client geliefertes Passwort */
429 f7551900 2002-01-04 alex
430 f7551900 2002-01-04 alex assert( Client != NULL );
431 c68c092c 2002-03-06 alex assert( Pwd != NULL );
432 c68c092c 2002-03-06 alex
433 0ced4181 2002-12-26 alex strlcpy( Client->pwd, Pwd, sizeof( Client->pwd ));
434 f7551900 2002-01-04 alex } /* Client_SetPassword */
435 c4850124 2002-02-27 alex
436 c4850124 2002-02-27 alex
437 8adff592 2005-03-19 fw GLOBAL void
438 8adff592 2005-03-19 fw Client_SetAway( CLIENT *Client, char *Txt )
439 c4850124 2002-02-27 alex {
440 51e1a2e0 2003-01-08 alex /* Set AWAY reason of client */
441 c4850124 2002-02-27 alex
442 c4850124 2002-02-27 alex assert( Client != NULL );
443 51e1a2e0 2003-01-08 alex assert( Txt != NULL );
444 c4850124 2002-02-27 alex
445 51e1a2e0 2003-01-08 alex strlcpy( Client->away, Txt, sizeof( Client->away ));
446 51e1a2e0 2003-01-08 alex Log( LOG_DEBUG, "User \"%s\" is away: %s", Client_Mask( Client ), Txt );
447 c4850124 2002-02-27 alex } /* Client_SetAway */
448 f7551900 2002-01-04 alex
449 f7551900 2002-01-04 alex
450 8adff592 2005-03-19 fw GLOBAL void
451 8adff592 2005-03-19 fw Client_SetType( CLIENT *Client, int Type )
452 f7551900 2002-01-04 alex {
453 f7551900 2002-01-04 alex assert( Client != NULL );
454 f7551900 2002-01-04 alex Client->type = Type;
455 a53857b4 2002-01-07 alex if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
456 d0304b19 2002-12-22 alex Adjust_Counters( Client );
457 f7551900 2002-01-04 alex } /* Client_SetType */
458 f7551900 2002-01-04 alex
459 f7551900 2002-01-04 alex
460 8adff592 2005-03-19 fw GLOBAL void
461 8adff592 2005-03-19 fw Client_SetHops( CLIENT *Client, int Hops )
462 f7551900 2002-01-04 alex {
463 f7551900 2002-01-04 alex assert( Client != NULL );
464 f7551900 2002-01-04 alex Client->hops = Hops;
465 f7551900 2002-01-04 alex } /* Client_SetHops */
466 f7551900 2002-01-04 alex
467 f7551900 2002-01-04 alex
468 8adff592 2005-03-19 fw GLOBAL void
469 8adff592 2005-03-19 fw Client_SetToken( CLIENT *Client, int Token )
470 f7551900 2002-01-04 alex {
471 f7551900 2002-01-04 alex assert( Client != NULL );
472 f7551900 2002-01-04 alex Client->token = Token;
473 f7551900 2002-01-04 alex } /* Client_SetToken */
474 f7551900 2002-01-04 alex
475 f7551900 2002-01-04 alex
476 8adff592 2005-03-19 fw GLOBAL void
477 c2f60abe 2002-05-27 alex Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
478 f7551900 2002-01-04 alex {
479 f7551900 2002-01-04 alex assert( Client != NULL );
480 c68c092c 2002-03-06 alex assert( Introducer != NULL );
481 f7551900 2002-01-04 alex Client->introducer = Introducer;
482 f7551900 2002-01-04 alex } /* Client_SetIntroducer */
483 f7551900 2002-01-04 alex
484 f7551900 2002-01-04 alex
485 8adff592 2005-03-19 fw GLOBAL void
486 8adff592 2005-03-19 fw Client_SetOperByMe( CLIENT *Client, bool OperByMe )
487 f7551900 2002-01-04 alex {
488 f7551900 2002-01-04 alex assert( Client != NULL );
489 f7551900 2002-01-04 alex Client->oper_by_me = OperByMe;
490 f7551900 2002-01-04 alex } /* Client_SetOperByMe */
491 f7551900 2002-01-04 alex
492 f7551900 2002-01-04 alex
493 8adff592 2005-03-19 fw GLOBAL bool
494 8adff592 2005-03-19 fw Client_ModeAdd( CLIENT *Client, char Mode )
495 f7551900 2002-01-04 alex {
496 8adff592 2005-03-19 fw /* Set Mode.
497 8adff592 2005-03-19 fw * If Client already alread had Mode, return false.
498 8adff592 2005-03-19 fw * If the Mode was newly set, return true.
499 8adff592 2005-03-19 fw */
500 f7551900 2002-01-04 alex
501 8adff592 2005-03-19 fw char x[2];
502 f7551900 2002-01-04 alex
503 f7551900 2002-01-04 alex assert( Client != NULL );
504 f7551900 2002-01-04 alex
505 f7551900 2002-01-04 alex x[0] = Mode; x[1] = '\0';
506 f7551900 2002-01-04 alex if( ! strchr( Client->modes, x[0] ))
507 f7551900 2002-01-04 alex {
508 f7551900 2002-01-04 alex /* Client hat den Mode noch nicht -> setzen */
509 6626395c 2002-12-26 alex strlcat( Client->modes, x, sizeof( Client->modes ));
510 8adff592 2005-03-19 fw return true;
511 f7551900 2002-01-04 alex }
512 8adff592 2005-03-19 fw else return false;
513 f7551900 2002-01-04 alex } /* Client_ModeAdd */
514 f7551900 2002-01-04 alex
515 f7551900 2002-01-04 alex
516 8adff592 2005-03-19 fw GLOBAL bool
517 8adff592 2005-03-19 fw Client_ModeDel( CLIENT *Client, char Mode )
518 f7551900 2002-01-04 alex {
519 8adff592 2005-03-19 fw /* Delete Mode.
520 8adff592 2005-03-19 fw * If Mode was removed, return true.
521 8adff592 2005-03-19 fw * If Client did not have Mode, return false.
522 8adff592 2005-03-19 fw */
523 f7551900 2002-01-04 alex
524 8adff592 2005-03-19 fw char x[2], *p;
525 f7551900 2002-01-04 alex
526 f7551900 2002-01-04 alex assert( Client != NULL );
527 f7551900 2002-01-04 alex
528 f7551900 2002-01-04 alex x[0] = Mode; x[1] = '\0';
529 2c5da58d 2001-12-29 alex
530 f7551900 2002-01-04 alex p = strchr( Client->modes, x[0] );
531 8adff592 2005-03-19 fw if( ! p ) return false;
532 2c5da58d 2001-12-29 alex
533 8adff592 2005-03-19 fw /* Client has Mode -> delete */
534 f7551900 2002-01-04 alex while( *p )
535 f7551900 2002-01-04 alex {
536 f7551900 2002-01-04 alex *p = *(p + 1);
537 f7551900 2002-01-04 alex p++;
538 f7551900 2002-01-04 alex }
539 8adff592 2005-03-19 fw return true;
540 f7551900 2002-01-04 alex } /* Client_ModeDel */
541 f7551900 2002-01-04 alex
542 f7551900 2002-01-04 alex
543 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
544 c2f60abe 2002-05-27 alex Client_GetFromConn( CONN_ID Idx )
545 d0ac1e9c 2001-12-23 alex {
546 8adff592 2005-03-19 fw /* return Client-Structure that belongs to the local Connection Idx gehoert.
547 8adff592 2005-03-19 fw * If none is found, return NULL.
548 8adff592 2005-03-19 fw */
549 d0ac1e9c 2001-12-23 alex
550 d0ac1e9c 2001-12-23 alex CLIENT *c;
551 d0ac1e9c 2001-12-23 alex
552 b7a18e9f 2001-12-24 alex assert( Idx >= 0 );
553 b7a18e9f 2001-12-24 alex
554 d0ac1e9c 2001-12-23 alex c = My_Clients;
555 d0ac1e9c 2001-12-23 alex while( c )
556 d0ac1e9c 2001-12-23 alex {
557 d0ac1e9c 2001-12-23 alex if( c->conn_id == Idx ) return c;
558 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
559 d0ac1e9c 2001-12-23 alex }
560 d0ac1e9c 2001-12-23 alex return NULL;
561 d0ac1e9c 2001-12-23 alex } /* Client_GetFromConn */
562 d0ac1e9c 2001-12-23 alex
563 d0ac1e9c 2001-12-23 alex
564 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
565 8adff592 2005-03-19 fw Client_Search( char *Nick )
566 90676129 2001-12-26 alex {
567 8adff592 2005-03-19 fw /* return Client-Structure that has the corresponding Nick.
568 8adff592 2005-03-19 fw * If none is found, return NULL.
569 8adff592 2005-03-19 fw */
570 804b1ec4 2001-12-31 alex
571 8adff592 2005-03-19 fw char search_id[CLIENT_ID_LEN], *ptr;
572 40c9fd26 2002-01-27 alex CLIENT *c = NULL;
573 b5c16c22 2002-03-25 alex UINT32 search_hash;
574 804b1ec4 2001-12-31 alex
575 804b1ec4 2001-12-31 alex assert( Nick != NULL );
576 d17748e9 2002-01-27 alex
577 8adff592 2005-03-19 fw /* copy Nick and truncate hostmask if necessary */
578 0ced4181 2002-12-26 alex strlcpy( search_id, Nick, sizeof( search_id ));
579 b5c16c22 2002-03-25 alex ptr = strchr( search_id, '!' );
580 d17748e9 2002-01-27 alex if( ptr ) *ptr = '\0';
581 804b1ec4 2001-12-31 alex
582 b5c16c22 2002-03-25 alex search_hash = Hash( search_id );
583 b5c16c22 2002-03-25 alex
584 804b1ec4 2001-12-31 alex c = My_Clients;
585 804b1ec4 2001-12-31 alex while( c )
586 804b1ec4 2001-12-31 alex {
587 b5c16c22 2002-03-25 alex if( c->hash == search_hash )
588 b5c16c22 2002-03-25 alex {
589 b5c16c22 2002-03-25 alex /* lt. Hash-Wert: Treffer! */
590 b5c16c22 2002-03-25 alex if( strcasecmp( c->id, search_id ) == 0 ) return c;
591 b5c16c22 2002-03-25 alex }
592 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
593 804b1ec4 2001-12-31 alex }
594 804b1ec4 2001-12-31 alex return NULL;
595 b5c16c22 2002-03-25 alex } /* Client_Search */
596 804b1ec4 2001-12-31 alex
597 804b1ec4 2001-12-31 alex
598 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
599 8adff592 2005-03-19 fw Client_GetFromToken( CLIENT *Client, int Token )
600 804b1ec4 2001-12-31 alex {
601 f7551900 2002-01-04 alex /* Client-Struktur, die den entsprechenden Introducer (=Client)
602 f7551900 2002-01-04 alex * und das gegebene Token hat, liefern. Wird keine gefunden,
603 f7551900 2002-01-04 alex * so wird NULL geliefert. */
604 f7551900 2002-01-04 alex
605 f7551900 2002-01-04 alex CLIENT *c;
606 f7551900 2002-01-04 alex
607 90676129 2001-12-26 alex assert( Client != NULL );
608 f7551900 2002-01-04 alex assert( Token > 0 );
609 90676129 2001-12-26 alex
610 f7551900 2002-01-04 alex c = My_Clients;
611 f7551900 2002-01-04 alex while( c )
612 f7551900 2002-01-04 alex {
613 f7551900 2002-01-04 alex if(( c->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c->token == Token )) return c;
614 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
615 f7551900 2002-01-04 alex }
616 f7551900 2002-01-04 alex return NULL;
617 f7551900 2002-01-04 alex } /* Client_GetFromToken */
618 f7551900 2002-01-04 alex
619 f7551900 2002-01-04 alex
620 8adff592 2005-03-19 fw GLOBAL int
621 c2f60abe 2002-05-27 alex Client_Type( CLIENT *Client )
622 f7551900 2002-01-04 alex {
623 f7551900 2002-01-04 alex assert( Client != NULL );
624 f7551900 2002-01-04 alex return Client->type;
625 f7551900 2002-01-04 alex } /* Client_Type */
626 f7551900 2002-01-04 alex
627 f7551900 2002-01-04 alex
628 c2f60abe 2002-05-27 alex GLOBAL CONN_ID
629 c2f60abe 2002-05-27 alex Client_Conn( CLIENT *Client )
630 f7551900 2002-01-04 alex {
631 f7551900 2002-01-04 alex assert( Client != NULL );
632 f7551900 2002-01-04 alex return Client->conn_id;
633 f7551900 2002-01-04 alex } /* Client_Conn */
634 f7551900 2002-01-04 alex
635 f7551900 2002-01-04 alex
636 8adff592 2005-03-19 fw GLOBAL char *
637 c2f60abe 2002-05-27 alex Client_ID( CLIENT *Client )
638 f7551900 2002-01-04 alex {
639 f7551900 2002-01-04 alex assert( Client != NULL );
640 f7551900 2002-01-04 alex
641 c68c092c 2002-03-06 alex #ifdef DEBUG
642 c68c092c 2002-03-06 alex if( Client->type == CLIENT_USER ) assert( strlen( Client->id ) < CLIENT_NICK_LEN );
643 c68c092c 2002-03-06 alex #endif
644 c68c092c 2002-03-06 alex
645 f7551900 2002-01-04 alex if( Client->id[0] ) return Client->id;
646 90676129 2001-12-26 alex else return "*";
647 f7551900 2002-01-04 alex } /* Client_ID */
648 90676129 2001-12-26 alex
649 90676129 2001-12-26 alex
650 8adff592 2005-03-19 fw GLOBAL char *
651 c2f60abe 2002-05-27 alex Client_Info( CLIENT *Client )
652 f7551900 2002-01-04 alex {
653 f7551900 2002-01-04 alex assert( Client != NULL );
654 f7551900 2002-01-04 alex return Client->info;
655 f7551900 2002-01-04 alex } /* Client_Info */
656 f7551900 2002-01-04 alex
657 f7551900 2002-01-04 alex
658 8adff592 2005-03-19 fw GLOBAL char *
659 c2f60abe 2002-05-27 alex Client_User( CLIENT *Client )
660 f7551900 2002-01-04 alex {
661 f7551900 2002-01-04 alex assert( Client != NULL );
662 95a4b1b1 2002-03-25 alex if( Client->user[0] ) return Client->user;
663 f7551900 2002-01-04 alex else return "~";
664 f7551900 2002-01-04 alex } /* Client_User */
665 f7551900 2002-01-04 alex
666 f7551900 2002-01-04 alex
667 8adff592 2005-03-19 fw GLOBAL char *
668 c2f60abe 2002-05-27 alex Client_Hostname( CLIENT *Client )
669 f7551900 2002-01-04 alex {
670 f7551900 2002-01-04 alex assert( Client != NULL );
671 f7551900 2002-01-04 alex return Client->host;
672 f7551900 2002-01-04 alex } /* Client_Hostname */
673 f7551900 2002-01-04 alex
674 f7551900 2002-01-04 alex
675 8adff592 2005-03-19 fw GLOBAL char *
676 c2f60abe 2002-05-27 alex Client_Password( CLIENT *Client )
677 f7551900 2002-01-04 alex {
678 f7551900 2002-01-04 alex assert( Client != NULL );
679 f7551900 2002-01-04 alex return Client->pwd;
680 f7551900 2002-01-04 alex } /* Client_Password */
681 f7551900 2002-01-04 alex
682 f7551900 2002-01-04 alex
683 8adff592 2005-03-19 fw GLOBAL char *
684 c2f60abe 2002-05-27 alex Client_Modes( CLIENT *Client )
685 f7551900 2002-01-04 alex {
686 f7551900 2002-01-04 alex assert( Client != NULL );
687 f7551900 2002-01-04 alex return Client->modes;
688 f7551900 2002-01-04 alex } /* Client_Modes */
689 e62ad979 2002-09-03 alex
690 e62ad979 2002-09-03 alex
691 8adff592 2005-03-19 fw GLOBAL char *
692 e62ad979 2002-09-03 alex Client_Flags( CLIENT *Client )
693 e62ad979 2002-09-03 alex {
694 e62ad979 2002-09-03 alex assert( Client != NULL );
695 e62ad979 2002-09-03 alex return Client->flags;
696 e62ad979 2002-09-03 alex } /* Client_Flags */
697 f7551900 2002-01-04 alex
698 f7551900 2002-01-04 alex
699 8adff592 2005-03-19 fw GLOBAL bool
700 c2f60abe 2002-05-27 alex Client_OperByMe( CLIENT *Client )
701 f7551900 2002-01-04 alex {
702 f7551900 2002-01-04 alex assert( Client != NULL );
703 f7551900 2002-01-04 alex return Client->oper_by_me;
704 f7551900 2002-01-04 alex } /* Client_OperByMe */
705 f7551900 2002-01-04 alex
706 f7551900 2002-01-04 alex
707 8adff592 2005-03-19 fw GLOBAL int
708 c2f60abe 2002-05-27 alex Client_Hops( CLIENT *Client )
709 f7551900 2002-01-04 alex {
710 f7551900 2002-01-04 alex assert( Client != NULL );
711 f7551900 2002-01-04 alex return Client->hops;
712 f7551900 2002-01-04 alex } /* Client_Hops */
713 f7551900 2002-01-04 alex
714 f7551900 2002-01-04 alex
715 8adff592 2005-03-19 fw GLOBAL int
716 c2f60abe 2002-05-27 alex Client_Token( CLIENT *Client )
717 f7551900 2002-01-04 alex {
718 f7551900 2002-01-04 alex assert( Client != NULL );
719 f7551900 2002-01-04 alex return Client->token;
720 f7551900 2002-01-04 alex } /* Client_Token */
721 a53857b4 2002-01-07 alex
722 a53857b4 2002-01-07 alex
723 8adff592 2005-03-19 fw GLOBAL int
724 c2f60abe 2002-05-27 alex Client_MyToken( CLIENT *Client )
725 a53857b4 2002-01-07 alex {
726 a53857b4 2002-01-07 alex assert( Client != NULL );
727 a53857b4 2002-01-07 alex return Client->mytoken;
728 a53857b4 2002-01-07 alex } /* Client_MyToken */
729 f7551900 2002-01-04 alex
730 f7551900 2002-01-04 alex
731 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
732 c2f60abe 2002-05-27 alex Client_NextHop( CLIENT *Client )
733 e7be3a01 2002-01-05 alex {
734 e7be3a01 2002-01-05 alex CLIENT *c;
735 e7be3a01 2002-01-05 alex
736 e7be3a01 2002-01-05 alex assert( Client != NULL );
737 e7be3a01 2002-01-05 alex
738 e7be3a01 2002-01-05 alex c = Client;
739 e7be3a01 2002-01-05 alex while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server )) c = c->introducer;
740 e7be3a01 2002-01-05 alex return c;
741 e7be3a01 2002-01-05 alex } /* Client_NextHop */
742 e7be3a01 2002-01-05 alex
743 e7be3a01 2002-01-05 alex
744 8adff592 2005-03-19 fw GLOBAL char *
745 c2f60abe 2002-05-27 alex Client_Mask( CLIENT *Client )
746 f7551900 2002-01-04 alex {
747 f7551900 2002-01-04 alex /* Client-"ID" liefern, wie sie z.B. fuer
748 f7551900 2002-01-04 alex * Prefixe benoetigt wird. */
749 f7551900 2002-01-04 alex
750 f7551900 2002-01-04 alex assert( Client != NULL );
751 f7551900 2002-01-04 alex
752 f7551900 2002-01-04 alex if( Client->type == CLIENT_SERVER ) return Client->id;
753 f7551900 2002-01-04 alex
754 467e76aa 2002-10-04 alex snprintf( GetID_Buffer, GETID_LEN, "%s!%s@%s", Client->id, Client->user, Client->host );
755 f7551900 2002-01-04 alex return GetID_Buffer;
756 f7551900 2002-01-04 alex } /* Client_Mask */
757 f7551900 2002-01-04 alex
758 f7551900 2002-01-04 alex
759 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
760 c2f60abe 2002-05-27 alex Client_Introducer( CLIENT *Client )
761 f7551900 2002-01-04 alex {
762 f7551900 2002-01-04 alex assert( Client != NULL );
763 f7551900 2002-01-04 alex return Client->introducer;
764 f7551900 2002-01-04 alex } /* Client_Introducer */
765 f7551900 2002-01-04 alex
766 f7551900 2002-01-04 alex
767 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
768 c2f60abe 2002-05-27 alex Client_TopServer( CLIENT *Client )
769 1ab92bb9 2002-01-29 alex {
770 1ab92bb9 2002-01-29 alex assert( Client != NULL );
771 1ab92bb9 2002-01-29 alex return Client->topserver;
772 1ab92bb9 2002-01-29 alex } /* Client_TopServer */
773 1ab92bb9 2002-01-29 alex
774 1ab92bb9 2002-01-29 alex
775 8adff592 2005-03-19 fw GLOBAL bool
776 8adff592 2005-03-19 fw Client_HasMode( CLIENT *Client, char Mode )
777 f7551900 2002-01-04 alex {
778 f7551900 2002-01-04 alex assert( Client != NULL );
779 f7551900 2002-01-04 alex return strchr( Client->modes, Mode ) != NULL;
780 f7551900 2002-01-04 alex } /* Client_HasMode */
781 c4850124 2002-02-27 alex
782 c4850124 2002-02-27 alex
783 8adff592 2005-03-19 fw GLOBAL char *
784 c2f60abe 2002-05-27 alex Client_Away( CLIENT *Client )
785 c4850124 2002-02-27 alex {
786 c4850124 2002-02-27 alex /* AWAY-Text liefern */
787 c4850124 2002-02-27 alex
788 c4850124 2002-02-27 alex assert( Client != NULL );
789 c4850124 2002-02-27 alex return Client->away;
790 c4850124 2002-02-27 alex } /* Client_Away */
791 f7551900 2002-01-04 alex
792 f7551900 2002-01-04 alex
793 8adff592 2005-03-19 fw GLOBAL bool
794 8adff592 2005-03-19 fw Client_CheckNick( CLIENT *Client, char *Nick )
795 08cf5607 2001-12-26 alex {
796 08cf5607 2001-12-26 alex /* Nick ueberpruefen */
797 08cf5607 2001-12-26 alex
798 08cf5607 2001-12-26 alex assert( Client != NULL );
799 08cf5607 2001-12-26 alex assert( Nick != NULL );
800 08cf5607 2001-12-26 alex
801 33944e8c 2002-02-06 alex /* Nick ungueltig? */
802 9f3a9df2 2002-02-17 alex if( ! Client_IsValidNick( Nick ))
803 9f3a9df2 2002-02-17 alex {
804 9f3a9df2 2002-02-17 alex IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
805 8adff592 2005-03-19 fw return false;
806 9f3a9df2 2002-02-17 alex }
807 08cf5607 2001-12-26 alex
808 08cf5607 2001-12-26 alex /* Nick bereits vergeben? */
809 b5c16c22 2002-03-25 alex if( Client_Search( Nick ))
810 08cf5607 2001-12-26 alex {
811 b5c16c22 2002-03-25 alex /* den Nick gibt es bereits */
812 b5c16c22 2002-03-25 alex IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
813 8adff592 2005-03-19 fw return false;
814 08cf5607 2001-12-26 alex }
815 08cf5607 2001-12-26 alex
816 8adff592 2005-03-19 fw return true;
817 08cf5607 2001-12-26 alex } /* Client_CheckNick */
818 07903baa 2002-01-03 alex
819 07903baa 2002-01-03 alex
820 8adff592 2005-03-19 fw GLOBAL bool
821 8adff592 2005-03-19 fw Client_CheckID( CLIENT *Client, char *ID )
822 07903baa 2002-01-03 alex {
823 07903baa 2002-01-03 alex /* Nick ueberpruefen */
824 07903baa 2002-01-03 alex
825 8adff592 2005-03-19 fw char str[COMMAND_LEN];
826 07903baa 2002-01-03 alex CLIENT *c;
827 07903baa 2002-01-03 alex
828 07903baa 2002-01-03 alex assert( Client != NULL );
829 07903baa 2002-01-03 alex assert( Client->conn_id > NONE );
830 07903baa 2002-01-03 alex assert( ID != NULL );
831 07903baa 2002-01-03 alex
832 07903baa 2002-01-03 alex /* Nick zu lang? */
833 9f3a9df2 2002-02-17 alex if( strlen( ID ) > CLIENT_ID_LEN )
834 9f3a9df2 2002-02-17 alex {
835 9f3a9df2 2002-02-17 alex IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), ID );
836 8adff592 2005-03-19 fw return false;
837 9f3a9df2 2002-02-17 alex }
838 08cf5607 2001-12-26 alex
839 07903baa 2002-01-03 alex /* ID bereits vergeben? */
840 07903baa 2002-01-03 alex c = My_Clients;
841 07903baa 2002-01-03 alex while( c )
842 07903baa 2002-01-03 alex {
843 f7551900 2002-01-04 alex if( strcasecmp( c->id, ID ) == 0 )
844 07903baa 2002-01-03 alex {
845 07903baa 2002-01-03 alex /* die Server-ID gibt es bereits */
846 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), "ID \"%s\" already registered", ID );
847 9f122037 2002-12-03 alex if( Client->conn_id != c->conn_id ) Log( LOG_ERR, "%s (on connection %d)!", str, c->conn_id );
848 9f122037 2002-12-03 alex else Log( LOG_ERR, "%s (via network)!", str );
849 8adff592 2005-03-19 fw Conn_Close( Client->conn_id, str, str, true);
850 8adff592 2005-03-19 fw return false;
851 07903baa 2002-01-03 alex }
852 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
853 07903baa 2002-01-03 alex }
854 08cf5607 2001-12-26 alex
855 8adff592 2005-03-19 fw return true;
856 07903baa 2002-01-03 alex } /* Client_CheckID */
857 07903baa 2002-01-03 alex
858 07903baa 2002-01-03 alex
859 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
860 8adff592 2005-03-19 fw Client_First( void )
861 fb9d6ce1 2001-12-31 alex {
862 fb9d6ce1 2001-12-31 alex /* Ersten Client liefern. */
863 fb9d6ce1 2001-12-31 alex
864 fb9d6ce1 2001-12-31 alex return My_Clients;
865 fb9d6ce1 2001-12-31 alex } /* Client_First */
866 15764f98 2001-12-27 alex
867 15764f98 2001-12-27 alex
868 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
869 c2f60abe 2002-05-27 alex Client_Next( CLIENT *c )
870 fb9d6ce1 2001-12-31 alex {
871 fb9d6ce1 2001-12-31 alex /* Naechsten Client liefern. Existiert keiner,
872 fb9d6ce1 2001-12-31 alex * so wird NULL geliefert. */
873 fb9d6ce1 2001-12-31 alex
874 fb9d6ce1 2001-12-31 alex assert( c != NULL );
875 95a4b1b1 2002-03-25 alex return (CLIENT *)c->next;
876 fb9d6ce1 2001-12-31 alex } /* Client_Next */
877 b9d701db 2002-01-16 alex
878 b9d701db 2002-01-16 alex
879 8adff592 2005-03-19 fw GLOBAL long
880 8adff592 2005-03-19 fw Client_UserCount( void )
881 b9d701db 2002-01-16 alex {
882 b9d701db 2002-01-16 alex return Count( CLIENT_USER );
883 b9d701db 2002-01-16 alex } /* Client_UserCount */
884 b9d701db 2002-01-16 alex
885 b9d701db 2002-01-16 alex
886 8adff592 2005-03-19 fw GLOBAL long
887 8adff592 2005-03-19 fw Client_ServiceCount( void )
888 b9d701db 2002-01-16 alex {
889 b9d701db 2002-01-16 alex return Count( CLIENT_SERVICE );;
890 b9d701db 2002-01-16 alex } /* Client_ServiceCount */
891 b9d701db 2002-01-16 alex
892 b9d701db 2002-01-16 alex
893 8adff592 2005-03-19 fw GLOBAL long
894 8adff592 2005-03-19 fw Client_ServerCount( void )
895 b9d701db 2002-01-16 alex {
896 b9d701db 2002-01-16 alex return Count( CLIENT_SERVER );
897 b9d701db 2002-01-16 alex } /* Client_ServerCount */
898 b9d701db 2002-01-16 alex
899 b9d701db 2002-01-16 alex
900 8adff592 2005-03-19 fw GLOBAL long
901 8adff592 2005-03-19 fw Client_MyUserCount( void )
902 b9d701db 2002-01-16 alex {
903 b9d701db 2002-01-16 alex return MyCount( CLIENT_USER );
904 b9d701db 2002-01-16 alex } /* Client_MyUserCount */
905 b9d701db 2002-01-16 alex
906 b9d701db 2002-01-16 alex
907 8adff592 2005-03-19 fw GLOBAL long
908 8adff592 2005-03-19 fw Client_MyServiceCount( void )
909 b9d701db 2002-01-16 alex {
910 b9d701db 2002-01-16 alex return MyCount( CLIENT_SERVICE );
911 b9d701db 2002-01-16 alex } /* Client_MyServiceCount */
912 b9d701db 2002-01-16 alex
913 b9d701db 2002-01-16 alex
914 8adff592 2005-03-19 fw GLOBAL long
915 8adff592 2005-03-19 fw Client_MyServerCount( void )
916 b9d701db 2002-01-16 alex {
917 3be7b9ef 2002-04-14 alex CLIENT *c;
918 8adff592 2005-03-19 fw long cnt;
919 3be7b9ef 2002-04-14 alex
920 3be7b9ef 2002-04-14 alex cnt = 0;
921 3be7b9ef 2002-04-14 alex c = My_Clients;
922 3be7b9ef 2002-04-14 alex while( c )
923 3be7b9ef 2002-04-14 alex {
924 3be7b9ef 2002-04-14 alex if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
925 3be7b9ef 2002-04-14 alex c = (CLIENT *)c->next;
926 3be7b9ef 2002-04-14 alex }
927 3be7b9ef 2002-04-14 alex return cnt;
928 b9d701db 2002-01-16 alex } /* Client_MyServerCount */
929 b9d701db 2002-01-16 alex
930 b9d701db 2002-01-16 alex
931 8adff592 2005-03-19 fw GLOBAL long
932 8adff592 2005-03-19 fw Client_OperCount( void )
933 b9d701db 2002-01-16 alex {
934 b9d701db 2002-01-16 alex CLIENT *c;
935 8adff592 2005-03-19 fw long cnt;
936 b9d701db 2002-01-16 alex
937 b9d701db 2002-01-16 alex cnt = 0;
938 b9d701db 2002-01-16 alex c = My_Clients;
939 b9d701db 2002-01-16 alex while( c )
940 b9d701db 2002-01-16 alex {
941 b9d701db 2002-01-16 alex if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
942 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
943 b9d701db 2002-01-16 alex }
944 b9d701db 2002-01-16 alex return cnt;
945 b9d701db 2002-01-16 alex } /* Client_OperCount */
946 fb9d6ce1 2001-12-31 alex
947 fb9d6ce1 2001-12-31 alex
948 8adff592 2005-03-19 fw GLOBAL long
949 8adff592 2005-03-19 fw Client_UnknownCount( void )
950 b9d701db 2002-01-16 alex {
951 b9d701db 2002-01-16 alex CLIENT *c;
952 8adff592 2005-03-19 fw long cnt;
953 b9d701db 2002-01-16 alex
954 b9d701db 2002-01-16 alex cnt = 0;
955 b9d701db 2002-01-16 alex c = My_Clients;
956 b9d701db 2002-01-16 alex while( c )
957 b9d701db 2002-01-16 alex {
958 b9d701db 2002-01-16 alex if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
959 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
960 b9d701db 2002-01-16 alex }
961 b9d701db 2002-01-16 alex return cnt;
962 b9d701db 2002-01-16 alex } /* Client_UnknownCount */
963 d0304b19 2002-12-22 alex
964 d0304b19 2002-12-22 alex
965 8adff592 2005-03-19 fw GLOBAL long
966 8adff592 2005-03-19 fw Client_MaxUserCount( void )
967 d0304b19 2002-12-22 alex {
968 d0304b19 2002-12-22 alex return Max_Users;
969 d0304b19 2002-12-22 alex } /* Client_MaxUserCount */
970 d0304b19 2002-12-22 alex
971 d0304b19 2002-12-22 alex
972 8adff592 2005-03-19 fw GLOBAL long
973 8adff592 2005-03-19 fw Client_MyMaxUserCount( void )
974 d0304b19 2002-12-22 alex {
975 d0304b19 2002-12-22 alex return My_Max_Users;
976 d0304b19 2002-12-22 alex } /* Client_MyMaxUserCount */
977 b9d701db 2002-01-16 alex
978 b9d701db 2002-01-16 alex
979 8adff592 2005-03-19 fw GLOBAL bool
980 8adff592 2005-03-19 fw Client_IsValidNick( char *Nick )
981 33944e8c 2002-02-06 alex {
982 33944e8c 2002-02-06 alex /* Ist der Nick gueltig? */
983 7157d936 2002-03-02 alex
984 8adff592 2005-03-19 fw char *ptr, goodchars[20];
985 33944e8c 2002-02-06 alex
986 33944e8c 2002-02-06 alex assert( Nick != NULL );
987 33944e8c 2002-02-06 alex
988 f7327524 2002-05-30 alex strcpy( goodchars, ";0123456789-" );
989 f7327524 2002-05-30 alex
990 8adff592 2005-03-19 fw if( Nick[0] == '#' ) return false;
991 8adff592 2005-03-19 fw if( strchr( goodchars, Nick[0] )) return false;
992 8adff592 2005-03-19 fw if( strlen( Nick ) >= CLIENT_NICK_LEN ) return false;
993 7157d936 2002-03-02 alex
994 7157d936 2002-03-02 alex ptr = Nick;
995 7157d936 2002-03-02 alex while( *ptr )
996 7157d936 2002-03-02 alex {
997 8adff592 2005-03-19 fw if(( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return false;
998 8adff592 2005-03-19 fw if(( *ptr > '}' ) && ( ! strchr( goodchars, *ptr ))) return false;
999 7157d936 2002-03-02 alex ptr++;
1000 7157d936 2002-03-02 alex }
1001 7157d936 2002-03-02 alex
1002 8adff592 2005-03-19 fw return true;
1003 33944e8c 2002-02-06 alex } /* Client_IsValidNick */
1004 7f0d1011 2005-05-16 alex
1005 7f0d1011 2005-05-16 alex
1006 7f0d1011 2005-05-16 alex /**
1007 7f0d1011 2005-05-16 alex * Return pointer to "My_Whowas" structure.
1008 7f0d1011 2005-05-16 alex */
1009 7f0d1011 2005-05-16 alex GLOBAL WHOWAS *
1010 7f0d1011 2005-05-16 alex Client_GetWhowas( void )
1011 7f0d1011 2005-05-16 alex {
1012 7f0d1011 2005-05-16 alex return My_Whowas;
1013 7f0d1011 2005-05-16 alex } /* Client_GetWhowas */
1014 33944e8c 2002-02-06 alex
1015 7f0d1011 2005-05-16 alex /**
1016 7f0d1011 2005-05-16 alex * Return the index of the last used WHOWAS entry.
1017 7f0d1011 2005-05-16 alex */
1018 7f0d1011 2005-05-16 alex GLOBAL int
1019 7f0d1011 2005-05-16 alex Client_GetLastWhowasIndex( void )
1020 7f0d1011 2005-05-16 alex {
1021 7f0d1011 2005-05-16 alex return Last_Whowas;
1022 7f0d1011 2005-05-16 alex } /* Client_GetLastWhowasIndex */
1023 a4660f40 2005-06-12 alex
1024 a4660f40 2005-06-12 alex
1025 a4660f40 2005-06-12 alex /**
1026 a4660f40 2005-06-12 alex * Get the start time of this client.
1027 a4660f40 2005-06-12 alex * The result is the start time in seconds since 1970-01-01, as reported
1028 a4660f40 2005-06-12 alex * by the C function time(NULL).
1029 a4660f40 2005-06-12 alex */
1030 a4660f40 2005-06-12 alex GLOBAL time_t
1031 a4660f40 2005-06-12 alex Client_StartTime(CLIENT *Client)
1032 a4660f40 2005-06-12 alex {
1033 a4660f40 2005-06-12 alex assert( Client != NULL );
1034 a4660f40 2005-06-12 alex return Client->starttime;
1035 a4660f40 2005-06-12 alex } /* Client_Uptime */
1036 33944e8c 2002-02-06 alex
1037 7f0d1011 2005-05-16 alex
1038 8adff592 2005-03-19 fw LOCAL long
1039 c2f60abe 2002-05-27 alex Count( CLIENT_TYPE Type )
1040 b9d701db 2002-01-16 alex {
1041 b9d701db 2002-01-16 alex CLIENT *c;
1042 8adff592 2005-03-19 fw long cnt;
1043 b9d701db 2002-01-16 alex
1044 b9d701db 2002-01-16 alex cnt = 0;
1045 b9d701db 2002-01-16 alex c = My_Clients;
1046 b9d701db 2002-01-16 alex while( c )
1047 b9d701db 2002-01-16 alex {
1048 3be7b9ef 2002-04-14 alex if( c->type == Type ) cnt++;
1049 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
1050 b9d701db 2002-01-16 alex }
1051 b9d701db 2002-01-16 alex return cnt;
1052 b9d701db 2002-01-16 alex } /* Count */
1053 b9d701db 2002-01-16 alex
1054 b9d701db 2002-01-16 alex
1055 8adff592 2005-03-19 fw LOCAL long
1056 c2f60abe 2002-05-27 alex MyCount( CLIENT_TYPE Type )
1057 b9d701db 2002-01-16 alex {
1058 b9d701db 2002-01-16 alex CLIENT *c;
1059 8adff592 2005-03-19 fw long cnt;
1060 b9d701db 2002-01-16 alex
1061 b9d701db 2002-01-16 alex cnt = 0;
1062 b9d701db 2002-01-16 alex c = My_Clients;
1063 b9d701db 2002-01-16 alex while( c )
1064 b9d701db 2002-01-16 alex {
1065 3be7b9ef 2002-04-14 alex if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
1066 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
1067 b9d701db 2002-01-16 alex }
1068 b9d701db 2002-01-16 alex return cnt;
1069 b9d701db 2002-01-16 alex } /* MyCount */
1070 b9d701db 2002-01-16 alex
1071 b9d701db 2002-01-16 alex
1072 c2f60abe 2002-05-27 alex LOCAL CLIENT *
1073 8adff592 2005-03-19 fw New_Client_Struct( void )
1074 38b9cb88 2001-12-14 alex {
1075 d0ac1e9c 2001-12-23 alex /* Neue CLIENT-Struktur pre-initialisieren */
1076 d0ac1e9c 2001-12-23 alex
1077 38b9cb88 2001-12-14 alex CLIENT *c;
1078 38b9cb88 2001-12-14 alex
1079 cb76d96e 2004-03-11 alex c = (CLIENT *)malloc( sizeof( CLIENT ));
1080 38b9cb88 2001-12-14 alex if( ! c )
1081 38b9cb88 2001-12-14 alex {
1082 e6d1bcdf 2002-06-10 alex Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
1083 38b9cb88 2001-12-14 alex return NULL;
1084 38b9cb88 2001-12-14 alex }
1085 38b9cb88 2001-12-14 alex
1086 d16ce5a7 2005-01-20 alex memset( c, 0, sizeof ( CLIENT ));
1087 d16ce5a7 2005-01-20 alex
1088 38b9cb88 2001-12-14 alex c->type = CLIENT_UNKNOWN;
1089 38b9cb88 2001-12-14 alex c->conn_id = NONE;
1090 8adff592 2005-03-19 fw c->oper_by_me = false;
1091 f7551900 2002-01-04 alex c->hops = -1;
1092 f7551900 2002-01-04 alex c->token = -1;
1093 a53857b4 2002-01-07 alex c->mytoken = -1;
1094 d0ac1e9c 2001-12-23 alex
1095 38b9cb88 2001-12-14 alex return c;
1096 38b9cb88 2001-12-14 alex } /* New_Client */
1097 38b9cb88 2001-12-14 alex
1098 38b9cb88 2001-12-14 alex
1099 8adff592 2005-03-19 fw LOCAL void
1100 c2f60abe 2002-05-27 alex Generate_MyToken( CLIENT *Client )
1101 a53857b4 2002-01-07 alex {
1102 a53857b4 2002-01-07 alex CLIENT *c;
1103 8adff592 2005-03-19 fw int token;
1104 a53857b4 2002-01-07 alex
1105 a53857b4 2002-01-07 alex c = My_Clients;
1106 a53857b4 2002-01-07 alex token = 2;
1107 a53857b4 2002-01-07 alex while( c )
1108 a53857b4 2002-01-07 alex {
1109 a53857b4 2002-01-07 alex if( c->mytoken == token )
1110 a53857b4 2002-01-07 alex {
1111 a53857b4 2002-01-07 alex /* Das Token wurde bereits vergeben */
1112 a53857b4 2002-01-07 alex token++;
1113 a53857b4 2002-01-07 alex c = My_Clients;
1114 a53857b4 2002-01-07 alex continue;
1115 a53857b4 2002-01-07 alex }
1116 95a4b1b1 2002-03-25 alex else c = (CLIENT *)c->next;
1117 a53857b4 2002-01-07 alex }
1118 a53857b4 2002-01-07 alex Client->mytoken = token;
1119 a53857b4 2002-01-07 alex Log( LOG_DEBUG, "Assigned token %d to server \"%s\".", token, Client->id );
1120 a53857b4 2002-01-07 alex } /* Generate_MyToken */
1121 a53857b4 2002-01-07 alex
1122 a53857b4 2002-01-07 alex
1123 8adff592 2005-03-19 fw LOCAL void
1124 d0304b19 2002-12-22 alex Adjust_Counters( CLIENT *Client )
1125 d0304b19 2002-12-22 alex {
1126 8adff592 2005-03-19 fw long count;
1127 d0304b19 2002-12-22 alex
1128 d0304b19 2002-12-22 alex assert( Client != NULL );
1129 d0304b19 2002-12-22 alex
1130 d0304b19 2002-12-22 alex if( Client->type != CLIENT_USER ) return;
1131 d0304b19 2002-12-22 alex
1132 d0304b19 2002-12-22 alex if( Client->conn_id != NONE )
1133 d0304b19 2002-12-22 alex {
1134 d0304b19 2002-12-22 alex /* Local connection */
1135 d0304b19 2002-12-22 alex count = Client_MyUserCount( );
1136 d0304b19 2002-12-22 alex if( count > My_Max_Users ) My_Max_Users = count;
1137 d0304b19 2002-12-22 alex }
1138 d0304b19 2002-12-22 alex count = Client_UserCount( );
1139 d0304b19 2002-12-22 alex if( count > Max_Users ) Max_Users = count;
1140 d0304b19 2002-12-22 alex } /* Adjust_Counters */
1141 d0304b19 2002-12-22 alex
1142 d0304b19 2002-12-22 alex
1143 7f0d1011 2005-05-16 alex /**
1144 7f0d1011 2005-05-16 alex * Register client in My_Whowas structure for further recall by WHOWAS.
1145 5c20474f 2005-06-12 alex * Note: Only clients that have been connected at least 30 seconds will be
1146 5c20474f 2005-06-12 alex * registered to prevent automated IRC bots to "destroy" a nice server
1147 5c20474f 2005-06-12 alex * history database.
1148 7f0d1011 2005-05-16 alex */
1149 1aeaf64c 2005-05-17 alex GLOBAL void
1150 1aeaf64c 2005-05-17 alex Client_RegisterWhowas( CLIENT *Client )
1151 7f0d1011 2005-05-16 alex {
1152 7f0d1011 2005-05-16 alex int slot;
1153 7f0d1011 2005-05-16 alex
1154 7f0d1011 2005-05-16 alex assert( Client != NULL );
1155 7f0d1011 2005-05-16 alex
1156 5c20474f 2005-06-12 alex /* Don't register clients that were connected less than 30 seconds. */
1157 5c20474f 2005-06-12 alex if( time(NULL) - Client->starttime < 30 )
1158 5c20474f 2005-06-12 alex return;
1159 5c20474f 2005-06-12 alex
1160 7f0d1011 2005-05-16 alex slot = Last_Whowas + 1;
1161 7f0d1011 2005-05-16 alex if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;
1162 7f0d1011 2005-05-16 alex
1163 7f0d1011 2005-05-16 alex #ifdef DEBUG
1164 7f0d1011 2005-05-16 alex Log( LOG_DEBUG, "Saving WHOWAS information to slot %d ...", slot );
1165 7f0d1011 2005-05-16 alex #endif
1166 7f0d1011 2005-05-16 alex
1167 7f0d1011 2005-05-16 alex My_Whowas[slot].time = time( NULL );
1168 7f0d1011 2005-05-16 alex strlcpy( My_Whowas[slot].id, Client_ID( Client ),
1169 7f0d1011 2005-05-16 alex sizeof( My_Whowas[slot].id ));
1170 7f0d1011 2005-05-16 alex strlcpy( My_Whowas[slot].user, Client_User( Client ),
1171 7f0d1011 2005-05-16 alex sizeof( My_Whowas[slot].user ));
1172 7f0d1011 2005-05-16 alex strlcpy( My_Whowas[slot].host, Client_Hostname( Client ),
1173 7f0d1011 2005-05-16 alex sizeof( My_Whowas[slot].host ));
1174 7f0d1011 2005-05-16 alex strlcpy( My_Whowas[slot].info, Client_Info( Client ),
1175 7f0d1011 2005-05-16 alex sizeof( My_Whowas[slot].info ));
1176 7f0d1011 2005-05-16 alex strlcpy( My_Whowas[slot].server, Client_ID( Client_Introducer( Client )),
1177 7f0d1011 2005-05-16 alex sizeof( My_Whowas[slot].server ));
1178 7f0d1011 2005-05-16 alex
1179 7f0d1011 2005-05-16 alex Last_Whowas = slot;
1180 1aeaf64c 2005-05-17 alex } /* Client_RegisterWhowas */
1181 7f0d1011 2005-05-16 alex
1182 7f0d1011 2005-05-16 alex
1183 38b9cb88 2001-12-14 alex /* -eof- */