2 38b9cb88 2001-12-14 alex * ngIRCd -- The Next Generation IRC Daemon
3 1547f76c 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
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.
11 490f28ff 2002-12-12 alex * Client management.
15 f7551900 2002-01-04 alex #define __client_c__
18 ca33cbda 2002-03-12 alex #include "portab.h"
20 d16ce5a7 2005-01-20 alex static char UNUSED id[] = "$Id: client.c,v 1.77 2005/01/20 00:11:49 alex Exp $";
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>
31 c2f60abe 2002-05-27 alex #include "conn.h"
33 ca33cbda 2002-03-12 alex #include "exp.h"
34 08cf5607 2001-12-26 alex #include "client.h"
36 08cf5607 2001-12-26 alex #include <imp.h>
37 79809118 2002-01-06 alex #include "ngircd.h"
38 38b9cb88 2001-12-14 alex #include "channel.h"
39 c2f60abe 2002-05-27 alex #include "resolve.h"
40 9856253d 2001-12-30 alex #include "conf.h"
41 b5c16c22 2002-03-25 alex #include "hash.h"
42 ff54198f 2002-02-27 alex #include "irc-write.h"
43 38b9cb88 2001-12-14 alex #include "log.h"
44 08cf5607 2001-12-26 alex #include "messages.h"
46 38b9cb88 2001-12-14 alex #include <exp.h>
49 467e76aa 2002-10-04 alex #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
52 f7551900 2002-01-04 alex LOCAL CLIENT *This_Server, *My_Clients;
53 467e76aa 2002-10-04 alex LOCAL CHAR GetID_Buffer[GETID_LEN];
56 c7b55aa6 2002-10-09 alex LOCAL LONG Count PARAMS(( CLIENT_TYPE Type ));
57 c7b55aa6 2002-10-09 alex LOCAL LONG MyCount PARAMS(( CLIENT_TYPE Type ));
59 c2f60abe 2002-05-27 alex LOCAL CLIENT *New_Client_Struct PARAMS(( VOID ));
60 c2f60abe 2002-05-27 alex LOCAL VOID Generate_MyToken PARAMS(( CLIENT *Client ));
61 d0304b19 2002-12-22 alex LOCAL VOID Adjust_Counters PARAMS(( CLIENT *Client ));
63 939767d5 2003-01-15 alex #ifndef Client_DestroyNow
64 939767d5 2003-01-15 alex GLOBAL VOID Client_DestroyNow PARAMS((CLIENT *Client ));
68 d0304b19 2002-12-22 alex LONG Max_Users = 0, My_Max_Users = 0;
72 c2f60abe 2002-05-27 alex Client_Init( VOID )
74 c57a4645 2001-12-27 alex struct hostent *h;
76 38b9cb88 2001-12-14 alex This_Server = New_Client_Struct( );
77 38b9cb88 2001-12-14 alex if( ! This_Server )
79 38b9cb88 2001-12-14 alex Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
80 62796722 2003-03-31 alex Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
84 38b9cb88 2001-12-14 alex /* Client-Struktur dieses Servers */
85 38b9cb88 2001-12-14 alex This_Server->next = NULL;
86 38b9cb88 2001-12-14 alex This_Server->type = CLIENT_SERVER;
87 38b9cb88 2001-12-14 alex This_Server->conn_id = NONE;
88 38b9cb88 2001-12-14 alex This_Server->introducer = This_Server;
89 8f7e7d66 2002-01-09 alex This_Server->mytoken = 1;
90 4fe7e9d6 2002-01-11 alex This_Server->hops = 0;
92 d0ac1e9c 2001-12-23 alex gethostname( This_Server->host, CLIENT_HOST_LEN );
93 c57a4645 2001-12-27 alex h = gethostbyname( This_Server->host );
94 695631b2 2002-12-26 alex if( h ) strlcpy( This_Server->host, h->h_name, sizeof( This_Server->host ));
96 b5c16c22 2002-03-25 alex Client_SetID( This_Server, Conf_ServerName );
97 b5c16c22 2002-03-25 alex Client_SetInfo( This_Server, Conf_ServerInfo );
99 38b9cb88 2001-12-14 alex My_Clients = This_Server;
100 38b9cb88 2001-12-14 alex } /* Client_Init */
103 c2f60abe 2002-05-27 alex GLOBAL VOID
104 c2f60abe 2002-05-27 alex Client_Exit( VOID )
106 d0ac1e9c 2001-12-23 alex CLIENT *c, *next;
109 77c4c015 2002-12-19 alex if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, FALSE );
110 9cb74e81 2002-06-02 alex else Client_Destroy( This_Server, "Server going down.", NULL, FALSE );
113 d0ac1e9c 2001-12-23 alex c = My_Clients;
117 95a4b1b1 2002-03-25 alex next = (CLIENT *)c->next;
121 d4a60bd4 2001-12-25 alex if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
122 79809118 2002-01-06 alex } /* Client_Exit */
125 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
126 c2f60abe 2002-05-27 alex Client_ThisServer( VOID )
128 f7551900 2002-01-04 alex return This_Server;
129 f7551900 2002-01-04 alex } /* Client_ThisServer */
132 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
133 c2f60abe 2002-05-27 alex Client_NewLocal( CONN_ID Idx, CHAR *Hostname, INT Type, BOOLEAN Idented )
135 f7551900 2002-01-04 alex /* Neuen lokalen Client erzeugen: Wrapper-Funktion fuer Client_New(). */
136 1ab92bb9 2002-01-29 alex return Client_New( Idx, This_Server, NULL, Type, NULL, NULL, Hostname, NULL, 0, 0, NULL, Idented );
137 f7551900 2002-01-04 alex } /* Client_NewLocal */
140 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
141 c2f60abe 2002-05-27 alex Client_NewRemoteServer( CLIENT *Introducer, CHAR *Hostname, CLIENT *TopServer, INT Hops, INT Token, CHAR *Info, BOOLEAN Idented )
143 f7551900 2002-01-04 alex /* Neuen Remote-Client erzeugen: Wrapper-Funktion fuer Client_New (). */
144 1ab92bb9 2002-01-29 alex return Client_New( NONE, Introducer, TopServer, CLIENT_SERVER, Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented );
145 f7551900 2002-01-04 alex } /* Client_NewRemoteServer */
148 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
149 c2f60abe 2002-05-27 alex Client_NewRemoteUser( CLIENT *Introducer, CHAR *Nick, INT Hops, CHAR *User, CHAR *Hostname, INT Token, CHAR *Modes, CHAR *Info, BOOLEAN Idented )
151 f7551900 2002-01-04 alex /* Neuen Remote-Client erzeugen: Wrapper-Funktion fuer Client_New (). */
152 1ab92bb9 2002-01-29 alex return Client_New( NONE, Introducer, NULL, CLIENT_USER, Nick, User, Hostname, Info, Hops, Token, Modes, Idented );
153 f7551900 2002-01-04 alex } /* Client_NewRemoteUser */
156 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
157 c2f60abe 2002-05-27 alex 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, BOOLEAN Idented )
159 d0ac1e9c 2001-12-23 alex CLIENT *client;
161 f7551900 2002-01-04 alex assert( Idx >= NONE );
162 f7551900 2002-01-04 alex assert( Introducer != NULL );
163 b7a18e9f 2001-12-24 alex assert( Hostname != NULL );
165 d0ac1e9c 2001-12-23 alex client = New_Client_Struct( );
166 d0ac1e9c 2001-12-23 alex if( ! client ) return NULL;
168 2c5da58d 2001-12-29 alex /* Initialisieren */
169 d0ac1e9c 2001-12-23 alex client->conn_id = Idx;
170 f7551900 2002-01-04 alex client->introducer = Introducer;
171 1ab92bb9 2002-01-29 alex client->topserver = TopServer;
172 f7551900 2002-01-04 alex client->type = Type;
173 f7551900 2002-01-04 alex if( ID ) Client_SetID( client, ID );
174 904d5e5b 2002-01-05 alex if( User ) Client_SetUser( client, User, Idented );
175 f7551900 2002-01-04 alex if( Hostname ) Client_SetHostname( client, Hostname );
176 f7551900 2002-01-04 alex if( Info ) Client_SetInfo( client, Info );
177 f7551900 2002-01-04 alex client->hops = Hops;
178 f7551900 2002-01-04 alex client->token = Token;
179 f7551900 2002-01-04 alex if( Modes ) Client_SetModes( client, Modes );
180 a53857b4 2002-01-07 alex if( Type == CLIENT_SERVER ) Generate_MyToken( client );
182 a1a3e67d 2002-03-04 alex /* ist der User away? */
183 695631b2 2002-12-26 alex if( strchr( client->modes, 'a' )) strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away ));
185 d0ac1e9c 2001-12-23 alex /* Verketten */
186 95a4b1b1 2002-03-25 alex client->next = (POINTER *)My_Clients;
187 d0ac1e9c 2001-12-23 alex My_Clients = client;
189 d0304b19 2002-12-22 alex /* Adjust counters */
190 d0304b19 2002-12-22 alex Adjust_Counters( client );
192 d0ac1e9c 2001-12-23 alex return client;
193 f7551900 2002-01-04 alex } /* Client_New */
196 c2f60abe 2002-05-27 alex GLOBAL VOID
197 c2f60abe 2002-05-27 alex Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN SendQuit )
199 d0ac1e9c 2001-12-23 alex /* Client entfernen. */
201 d0ac1e9c 2001-12-23 alex CLIENT *last, *c;
202 dce77559 2002-03-10 alex CHAR msg[LINE_LEN], *txt;
204 b7a18e9f 2001-12-24 alex assert( Client != NULL );
206 79809118 2002-01-06 alex if( LogMsg ) txt = LogMsg;
207 79809118 2002-01-06 alex else txt = FwdMsg;
208 79809118 2002-01-06 alex if( ! txt ) txt = "Reason unknown.";
210 03c3f3c9 2002-03-12 alex /* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */
211 b316c380 2002-12-26 alex if( Client->type == CLIENT_SERVER ) snprintf( msg, sizeof( msg ), "%s: lost server %s", This_Server->id, Client->id );
213 d0ac1e9c 2001-12-23 alex last = NULL;
214 d0ac1e9c 2001-12-23 alex c = My_Clients;
217 c4854470 2002-01-04 alex if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
219 dce77559 2002-03-10 alex /* der Client, der geloescht wird ist ein Server. Der Client, den wir gerade
220 dce77559 2002-03-10 alex * pruefen, ist ein Child von diesem und muss daher auch entfernt werden */
221 50ec7a56 2002-03-11 alex Client_Destroy( c, NULL, msg, FALSE );
222 c4854470 2002-01-04 alex last = NULL;
223 c4854470 2002-01-04 alex c = My_Clients;
226 d0ac1e9c 2001-12-23 alex if( c == Client )
228 dce77559 2002-03-10 alex /* Wir haben den Client gefunden: entfernen */
229 d0ac1e9c 2001-12-23 alex if( last ) last->next = c->next;
230 95a4b1b1 2002-03-25 alex else My_Clients = (CLIENT *)c->next;
232 c4854470 2002-01-04 alex if( c->type == CLIENT_USER )
234 db58d347 2002-01-05 alex if( c->conn_id != NONE )
236 50ec7a56 2002-03-11 alex /* Ein lokaler User */
237 b89c3108 2002-01-07 alex Log( LOG_NOTICE, "User \"%s\" unregistered (connection %d): %s", Client_Mask( c ), c->conn_id, txt );
239 50ec7a56 2002-03-11 alex if( SendQuit )
241 50ec7a56 2002-03-11 alex /* Alle andere Server informieren! */
242 50ec7a56 2002-03-11 alex if( FwdMsg ) IRC_WriteStrServersPrefix( NULL, c, "QUIT :%s", FwdMsg );
243 50ec7a56 2002-03-11 alex else IRC_WriteStrServersPrefix( NULL, c, "QUIT :" );
248 50ec7a56 2002-03-11 alex /* Remote User */
249 b89c3108 2002-01-07 alex Log( LOG_DEBUG, "User \"%s\" unregistered: %s", Client_Mask( c ), txt );
251 50ec7a56 2002-03-11 alex if( SendQuit )
253 50ec7a56 2002-03-11 alex /* Andere Server informieren, ausser denen, die "in
254 50ec7a56 2002-03-11 alex * Richtung dem liegen", auf dem der User registriert
255 50ec7a56 2002-03-11 alex * ist. Von denen haben wir das QUIT ja wohl bekommen. */
256 50ec7a56 2002-03-11 alex if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "QUIT :%s", FwdMsg );
257 50ec7a56 2002-03-11 alex else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "QUIT :" );
260 dadebb21 2002-06-01 alex Channel_Quit( c, FwdMsg ? FwdMsg : c->id );
262 79809118 2002-01-06 alex else if( c->type == CLIENT_SERVER )
264 28d58986 2002-02-27 alex if( c != This_Server )
266 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 );
267 6b58ab84 2002-03-27 alex else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
270 8f7e7d66 2002-01-09 alex /* andere Server informieren */
271 77c4c015 2002-12-19 alex if( ! NGIRCd_SignalQuit )
273 8f7e7d66 2002-01-09 alex if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
274 8f7e7d66 2002-01-09 alex else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
279 28d58986 2002-02-27 alex if( c->conn_id != NONE )
281 28d58986 2002-02-27 alex if( c->id[0] ) Log( LOG_NOTICE, "Client \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
282 28d58986 2002-02-27 alex else Log( LOG_NOTICE, "Client unregistered (connection %d): %s", c->conn_id, txt );
286 28d58986 2002-02-27 alex if( c->id[0] ) Log( LOG_WARNING, "Unregistered unknown client \"%s\": %s", c->id, txt );
287 28d58986 2002-02-27 alex else Log( LOG_WARNING, "Unregistered unknown client: %s", c->id, txt );
295 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
297 d0ac1e9c 2001-12-23 alex } /* Client_Destroy */
300 c2f60abe 2002-05-27 alex GLOBAL VOID
301 939767d5 2003-01-15 alex Client_DestroyNow( CLIENT *Client )
303 939767d5 2003-01-15 alex /* Destroy client structure immediately. This function is only
304 939767d5 2003-01-15 alex * intended for the connection layer to remove client structures
305 939767d5 2003-01-15 alex * of connections that can't be established! */
307 939767d5 2003-01-15 alex CLIENT *last, *c;
309 939767d5 2003-01-15 alex assert( Client != NULL );
311 939767d5 2003-01-15 alex last = NULL;
312 939767d5 2003-01-15 alex c = My_Clients;
315 939767d5 2003-01-15 alex if( c == Client )
317 939767d5 2003-01-15 alex /* Wir haben den Client gefunden: entfernen */
318 939767d5 2003-01-15 alex if( last ) last->next = c->next;
319 939767d5 2003-01-15 alex else My_Clients = (CLIENT *)c->next;
324 939767d5 2003-01-15 alex c = (CLIENT *)c->next;
326 939767d5 2003-01-15 alex } /* Client_DestroyNow */
329 939767d5 2003-01-15 alex GLOBAL VOID
330 c2f60abe 2002-05-27 alex Client_SetHostname( CLIENT *Client, CHAR *Hostname )
332 2c5da58d 2001-12-29 alex /* Hostname eines Clients setzen */
334 2c5da58d 2001-12-29 alex assert( Client != NULL );
335 c68c092c 2002-03-06 alex assert( Hostname != NULL );
337 0ced4181 2002-12-26 alex strlcpy( Client->host, Hostname, sizeof( Client->host ));
338 2c5da58d 2001-12-29 alex } /* Client_SetHostname */
341 c2f60abe 2002-05-27 alex GLOBAL VOID
342 c2f60abe 2002-05-27 alex Client_SetID( CLIENT *Client, CHAR *ID )
344 b5c16c22 2002-03-25 alex /* Hostname eines Clients setzen, Hash-Wert berechnen */
346 f7551900 2002-01-04 alex assert( Client != NULL );
347 c68c092c 2002-03-06 alex assert( ID != NULL );
349 0ced4181 2002-12-26 alex strlcpy( Client->id, ID, sizeof( Client->id ));
352 b5c16c22 2002-03-25 alex Client->hash = Hash( Client->id );
353 f7551900 2002-01-04 alex } /* Client_SetID */
356 c2f60abe 2002-05-27 alex GLOBAL VOID
357 c2f60abe 2002-05-27 alex Client_SetUser( CLIENT *Client, CHAR *User, BOOLEAN Idented )
359 f7551900 2002-01-04 alex /* Username eines Clients setzen */
361 f7551900 2002-01-04 alex assert( Client != NULL );
362 c68c092c 2002-03-06 alex assert( User != NULL );
364 0ced4181 2002-12-26 alex if( Idented ) strlcpy( Client->user, User, sizeof( Client->user ));
367 904d5e5b 2002-01-05 alex Client->user[0] = '~';
368 0ced4181 2002-12-26 alex strlcpy( Client->user + 1, User, sizeof( Client->user ) - 1 );
370 f7551900 2002-01-04 alex } /* Client_SetUser */
373 c2f60abe 2002-05-27 alex GLOBAL VOID
374 c2f60abe 2002-05-27 alex Client_SetInfo( CLIENT *Client, CHAR *Info )
376 f7551900 2002-01-04 alex /* Hostname eines Clients setzen */
378 f7551900 2002-01-04 alex assert( Client != NULL );
379 c68c092c 2002-03-06 alex assert( Info != NULL );
381 0ced4181 2002-12-26 alex strlcpy( Client->info, Info, sizeof( Client->info ));
382 f7551900 2002-01-04 alex } /* Client_SetInfo */
385 c2f60abe 2002-05-27 alex GLOBAL VOID
386 c2f60abe 2002-05-27 alex Client_SetModes( CLIENT *Client, CHAR *Modes )
388 e62ad979 2002-09-03 alex /* Modes eines Clients setzen */
390 f7551900 2002-01-04 alex assert( Client != NULL );
391 c68c092c 2002-03-06 alex assert( Modes != NULL );
393 0ced4181 2002-12-26 alex strlcpy( Client->modes, Modes, sizeof( Client->modes ));
394 f7551900 2002-01-04 alex } /* Client_SetModes */
397 e62ad979 2002-09-03 alex GLOBAL VOID
398 e62ad979 2002-09-03 alex Client_SetFlags( CLIENT *Client, CHAR *Flags )
400 e62ad979 2002-09-03 alex /* Flags eines Clients setzen */
402 e62ad979 2002-09-03 alex assert( Client != NULL );
403 e62ad979 2002-09-03 alex assert( Flags != NULL );
405 0ced4181 2002-12-26 alex strlcpy( Client->flags, Flags, sizeof( Client->flags ));
406 e62ad979 2002-09-03 alex } /* Client_SetFlags */
409 c2f60abe 2002-05-27 alex GLOBAL VOID
410 c2f60abe 2002-05-27 alex Client_SetPassword( CLIENT *Client, CHAR *Pwd )
412 f7551900 2002-01-04 alex /* Von einem Client geliefertes Passwort */
414 f7551900 2002-01-04 alex assert( Client != NULL );
415 c68c092c 2002-03-06 alex assert( Pwd != NULL );
417 0ced4181 2002-12-26 alex strlcpy( Client->pwd, Pwd, sizeof( Client->pwd ));
418 f7551900 2002-01-04 alex } /* Client_SetPassword */
421 c2f60abe 2002-05-27 alex GLOBAL VOID
422 c2f60abe 2002-05-27 alex Client_SetAway( CLIENT *Client, CHAR *Txt )
424 51e1a2e0 2003-01-08 alex /* Set AWAY reason of client */
426 c4850124 2002-02-27 alex assert( Client != NULL );
427 51e1a2e0 2003-01-08 alex assert( Txt != NULL );
429 51e1a2e0 2003-01-08 alex strlcpy( Client->away, Txt, sizeof( Client->away ));
430 51e1a2e0 2003-01-08 alex Log( LOG_DEBUG, "User \"%s\" is away: %s", Client_Mask( Client ), Txt );
431 c4850124 2002-02-27 alex } /* Client_SetAway */
434 c2f60abe 2002-05-27 alex GLOBAL VOID
435 c2f60abe 2002-05-27 alex Client_SetType( CLIENT *Client, INT Type )
437 f7551900 2002-01-04 alex assert( Client != NULL );
438 f7551900 2002-01-04 alex Client->type = Type;
439 a53857b4 2002-01-07 alex if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
440 d0304b19 2002-12-22 alex Adjust_Counters( Client );
441 f7551900 2002-01-04 alex } /* Client_SetType */
444 c2f60abe 2002-05-27 alex GLOBAL VOID
445 c2f60abe 2002-05-27 alex Client_SetHops( CLIENT *Client, INT Hops )
447 f7551900 2002-01-04 alex assert( Client != NULL );
448 f7551900 2002-01-04 alex Client->hops = Hops;
449 f7551900 2002-01-04 alex } /* Client_SetHops */
452 c2f60abe 2002-05-27 alex GLOBAL VOID
453 c2f60abe 2002-05-27 alex Client_SetToken( CLIENT *Client, INT Token )
455 f7551900 2002-01-04 alex assert( Client != NULL );
456 f7551900 2002-01-04 alex Client->token = Token;
457 f7551900 2002-01-04 alex } /* Client_SetToken */
460 c2f60abe 2002-05-27 alex GLOBAL VOID
461 c2f60abe 2002-05-27 alex Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
463 f7551900 2002-01-04 alex assert( Client != NULL );
464 c68c092c 2002-03-06 alex assert( Introducer != NULL );
465 f7551900 2002-01-04 alex Client->introducer = Introducer;
466 f7551900 2002-01-04 alex } /* Client_SetIntroducer */
469 c2f60abe 2002-05-27 alex GLOBAL VOID
470 c2f60abe 2002-05-27 alex Client_SetOperByMe( CLIENT *Client, BOOLEAN OperByMe )
472 f7551900 2002-01-04 alex assert( Client != NULL );
473 f7551900 2002-01-04 alex Client->oper_by_me = OperByMe;
474 f7551900 2002-01-04 alex } /* Client_SetOperByMe */
477 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
478 c2f60abe 2002-05-27 alex Client_ModeAdd( CLIENT *Client, CHAR Mode )
480 f7551900 2002-01-04 alex /* Mode soll gesetzt werden. TRUE wird geliefert, wenn der
481 f7551900 2002-01-04 alex * Mode neu gesetzt wurde, FALSE, wenn der Client den Mode
482 f7551900 2002-01-04 alex * bereits hatte. */
486 f7551900 2002-01-04 alex assert( Client != NULL );
488 f7551900 2002-01-04 alex x[0] = Mode; x[1] = '\0';
489 f7551900 2002-01-04 alex if( ! strchr( Client->modes, x[0] ))
491 f7551900 2002-01-04 alex /* Client hat den Mode noch nicht -> setzen */
492 6626395c 2002-12-26 alex strlcat( Client->modes, x, sizeof( Client->modes ));
493 f7551900 2002-01-04 alex return TRUE;
495 f7551900 2002-01-04 alex else return FALSE;
496 f7551900 2002-01-04 alex } /* Client_ModeAdd */
499 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
500 c2f60abe 2002-05-27 alex Client_ModeDel( CLIENT *Client, CHAR Mode )
502 f7551900 2002-01-04 alex /* Mode soll geloescht werden. TRUE wird geliefert, wenn der
503 f7551900 2002-01-04 alex * Mode entfernt wurde, FALSE, wenn der Client den Mode
504 f7551900 2002-01-04 alex * ueberhaupt nicht hatte. */
506 f7551900 2002-01-04 alex CHAR x[2], *p;
508 f7551900 2002-01-04 alex assert( Client != NULL );
510 f7551900 2002-01-04 alex x[0] = Mode; x[1] = '\0';
512 f7551900 2002-01-04 alex p = strchr( Client->modes, x[0] );
513 f7551900 2002-01-04 alex if( ! p ) return FALSE;
515 f7551900 2002-01-04 alex /* Client hat den Mode -> loeschen */
516 f7551900 2002-01-04 alex while( *p )
518 f7551900 2002-01-04 alex *p = *(p + 1);
521 f7551900 2002-01-04 alex return TRUE;
522 f7551900 2002-01-04 alex } /* Client_ModeDel */
525 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
526 c2f60abe 2002-05-27 alex Client_GetFromConn( CONN_ID Idx )
528 804b1ec4 2001-12-31 alex /* Client-Struktur, die zur lokalen Verbindung Idx gehoert,
529 d0ac1e9c 2001-12-23 alex * liefern. Wird keine gefunden, so wird NULL geliefert. */
533 b7a18e9f 2001-12-24 alex assert( Idx >= 0 );
535 d0ac1e9c 2001-12-23 alex c = My_Clients;
538 d0ac1e9c 2001-12-23 alex if( c->conn_id == Idx ) return c;
539 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
541 d0ac1e9c 2001-12-23 alex return NULL;
542 d0ac1e9c 2001-12-23 alex } /* Client_GetFromConn */
545 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
546 c2f60abe 2002-05-27 alex Client_Search( CHAR *Nick )
548 10363b39 2002-03-03 alex /* Client-Struktur, die den entsprechenden Nick hat, liefern.
549 10363b39 2002-03-03 alex * Wird keine gefunden, so wird NULL geliefert. */
551 b5c16c22 2002-03-25 alex CHAR search_id[CLIENT_ID_LEN], *ptr;
552 40c9fd26 2002-01-27 alex CLIENT *c = NULL;
553 b5c16c22 2002-03-25 alex UINT32 search_hash;
555 804b1ec4 2001-12-31 alex assert( Nick != NULL );
557 40c9fd26 2002-01-27 alex /* Nick kopieren und ggf. Host-Mask abschneiden */
558 0ced4181 2002-12-26 alex strlcpy( search_id, Nick, sizeof( search_id ));
559 b5c16c22 2002-03-25 alex ptr = strchr( search_id, '!' );
560 d17748e9 2002-01-27 alex if( ptr ) *ptr = '\0';
562 b5c16c22 2002-03-25 alex search_hash = Hash( search_id );
564 804b1ec4 2001-12-31 alex c = My_Clients;
567 b5c16c22 2002-03-25 alex if( c->hash == search_hash )
569 b5c16c22 2002-03-25 alex /* lt. Hash-Wert: Treffer! */
570 b5c16c22 2002-03-25 alex if( strcasecmp( c->id, search_id ) == 0 ) return c;
572 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
574 804b1ec4 2001-12-31 alex return NULL;
575 b5c16c22 2002-03-25 alex } /* Client_Search */
578 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
579 c2f60abe 2002-05-27 alex Client_GetFromToken( CLIENT *Client, INT Token )
581 f7551900 2002-01-04 alex /* Client-Struktur, die den entsprechenden Introducer (=Client)
582 f7551900 2002-01-04 alex * und das gegebene Token hat, liefern. Wird keine gefunden,
583 f7551900 2002-01-04 alex * so wird NULL geliefert. */
587 90676129 2001-12-26 alex assert( Client != NULL );
588 f7551900 2002-01-04 alex assert( Token > 0 );
590 f7551900 2002-01-04 alex c = My_Clients;
593 f7551900 2002-01-04 alex if(( c->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c->token == Token )) return c;
594 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
596 f7551900 2002-01-04 alex return NULL;
597 f7551900 2002-01-04 alex } /* Client_GetFromToken */
601 c2f60abe 2002-05-27 alex Client_Type( CLIENT *Client )
603 f7551900 2002-01-04 alex assert( Client != NULL );
604 f7551900 2002-01-04 alex return Client->type;
605 f7551900 2002-01-04 alex } /* Client_Type */
608 c2f60abe 2002-05-27 alex GLOBAL CONN_ID
609 c2f60abe 2002-05-27 alex Client_Conn( CLIENT *Client )
611 f7551900 2002-01-04 alex assert( Client != NULL );
612 f7551900 2002-01-04 alex return Client->conn_id;
613 f7551900 2002-01-04 alex } /* Client_Conn */
616 c2f60abe 2002-05-27 alex GLOBAL CHAR *
617 c2f60abe 2002-05-27 alex Client_ID( CLIENT *Client )
619 f7551900 2002-01-04 alex assert( Client != NULL );
621 c68c092c 2002-03-06 alex #ifdef DEBUG
622 c68c092c 2002-03-06 alex if( Client->type == CLIENT_USER ) assert( strlen( Client->id ) < CLIENT_NICK_LEN );
625 f7551900 2002-01-04 alex if( Client->id[0] ) return Client->id;
626 90676129 2001-12-26 alex else return "*";
627 f7551900 2002-01-04 alex } /* Client_ID */
630 c2f60abe 2002-05-27 alex GLOBAL CHAR *
631 c2f60abe 2002-05-27 alex Client_Info( CLIENT *Client )
633 f7551900 2002-01-04 alex assert( Client != NULL );
634 f7551900 2002-01-04 alex return Client->info;
635 f7551900 2002-01-04 alex } /* Client_Info */
638 c2f60abe 2002-05-27 alex GLOBAL CHAR *
639 c2f60abe 2002-05-27 alex Client_User( CLIENT *Client )
641 f7551900 2002-01-04 alex assert( Client != NULL );
642 95a4b1b1 2002-03-25 alex if( Client->user[0] ) return Client->user;
643 f7551900 2002-01-04 alex else return "~";
644 f7551900 2002-01-04 alex } /* Client_User */
647 c2f60abe 2002-05-27 alex GLOBAL CHAR *
648 c2f60abe 2002-05-27 alex Client_Hostname( CLIENT *Client )
650 f7551900 2002-01-04 alex assert( Client != NULL );
651 f7551900 2002-01-04 alex return Client->host;
652 f7551900 2002-01-04 alex } /* Client_Hostname */
655 c2f60abe 2002-05-27 alex GLOBAL CHAR *
656 c2f60abe 2002-05-27 alex Client_Password( CLIENT *Client )
658 f7551900 2002-01-04 alex assert( Client != NULL );
659 f7551900 2002-01-04 alex return Client->pwd;
660 f7551900 2002-01-04 alex } /* Client_Password */
663 c2f60abe 2002-05-27 alex GLOBAL CHAR *
664 c2f60abe 2002-05-27 alex Client_Modes( CLIENT *Client )
666 f7551900 2002-01-04 alex assert( Client != NULL );
667 f7551900 2002-01-04 alex return Client->modes;
668 f7551900 2002-01-04 alex } /* Client_Modes */
671 e62ad979 2002-09-03 alex GLOBAL CHAR *
672 e62ad979 2002-09-03 alex Client_Flags( CLIENT *Client )
674 e62ad979 2002-09-03 alex assert( Client != NULL );
675 e62ad979 2002-09-03 alex return Client->flags;
676 e62ad979 2002-09-03 alex } /* Client_Flags */
679 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
680 c2f60abe 2002-05-27 alex Client_OperByMe( CLIENT *Client )
682 f7551900 2002-01-04 alex assert( Client != NULL );
683 f7551900 2002-01-04 alex return Client->oper_by_me;
684 f7551900 2002-01-04 alex } /* Client_OperByMe */
688 c2f60abe 2002-05-27 alex Client_Hops( CLIENT *Client )
690 f7551900 2002-01-04 alex assert( Client != NULL );
691 f7551900 2002-01-04 alex return Client->hops;
692 f7551900 2002-01-04 alex } /* Client_Hops */
696 c2f60abe 2002-05-27 alex Client_Token( CLIENT *Client )
698 f7551900 2002-01-04 alex assert( Client != NULL );
699 f7551900 2002-01-04 alex return Client->token;
700 f7551900 2002-01-04 alex } /* Client_Token */
704 c2f60abe 2002-05-27 alex Client_MyToken( CLIENT *Client )
706 a53857b4 2002-01-07 alex assert( Client != NULL );
707 a53857b4 2002-01-07 alex return Client->mytoken;
708 a53857b4 2002-01-07 alex } /* Client_MyToken */
711 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
712 c2f60abe 2002-05-27 alex Client_NextHop( CLIENT *Client )
716 e7be3a01 2002-01-05 alex assert( Client != NULL );
718 e7be3a01 2002-01-05 alex c = Client;
719 e7be3a01 2002-01-05 alex while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server )) c = c->introducer;
721 e7be3a01 2002-01-05 alex } /* Client_NextHop */
724 c2f60abe 2002-05-27 alex GLOBAL CHAR *
725 c2f60abe 2002-05-27 alex Client_Mask( CLIENT *Client )
727 f7551900 2002-01-04 alex /* Client-"ID" liefern, wie sie z.B. fuer
728 f7551900 2002-01-04 alex * Prefixe benoetigt wird. */
730 f7551900 2002-01-04 alex assert( Client != NULL );
732 f7551900 2002-01-04 alex if( Client->type == CLIENT_SERVER ) return Client->id;
734 467e76aa 2002-10-04 alex snprintf( GetID_Buffer, GETID_LEN, "%s!%s@%s", Client->id, Client->user, Client->host );
735 f7551900 2002-01-04 alex return GetID_Buffer;
736 f7551900 2002-01-04 alex } /* Client_Mask */
739 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
740 c2f60abe 2002-05-27 alex Client_Introducer( CLIENT *Client )
742 f7551900 2002-01-04 alex assert( Client != NULL );
743 f7551900 2002-01-04 alex return Client->introducer;
744 f7551900 2002-01-04 alex } /* Client_Introducer */
747 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
748 c2f60abe 2002-05-27 alex Client_TopServer( CLIENT *Client )
750 1ab92bb9 2002-01-29 alex assert( Client != NULL );
751 1ab92bb9 2002-01-29 alex return Client->topserver;
752 1ab92bb9 2002-01-29 alex } /* Client_TopServer */
755 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
756 c2f60abe 2002-05-27 alex Client_HasMode( CLIENT *Client, CHAR Mode )
758 f7551900 2002-01-04 alex assert( Client != NULL );
759 f7551900 2002-01-04 alex return strchr( Client->modes, Mode ) != NULL;
760 f7551900 2002-01-04 alex } /* Client_HasMode */
763 c2f60abe 2002-05-27 alex GLOBAL CHAR *
764 c2f60abe 2002-05-27 alex Client_Away( CLIENT *Client )
766 c4850124 2002-02-27 alex /* AWAY-Text liefern */
768 c4850124 2002-02-27 alex assert( Client != NULL );
769 c4850124 2002-02-27 alex return Client->away;
770 c4850124 2002-02-27 alex } /* Client_Away */
773 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
774 c2f60abe 2002-05-27 alex Client_CheckNick( CLIENT *Client, CHAR *Nick )
776 08cf5607 2001-12-26 alex /* Nick ueberpruefen */
778 08cf5607 2001-12-26 alex assert( Client != NULL );
779 08cf5607 2001-12-26 alex assert( Nick != NULL );
781 33944e8c 2002-02-06 alex /* Nick ungueltig? */
782 9f3a9df2 2002-02-17 alex if( ! Client_IsValidNick( Nick ))
784 9f3a9df2 2002-02-17 alex IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
785 9f3a9df2 2002-02-17 alex return FALSE;
788 08cf5607 2001-12-26 alex /* Nick bereits vergeben? */
789 b5c16c22 2002-03-25 alex if( Client_Search( Nick ))
791 b5c16c22 2002-03-25 alex /* den Nick gibt es bereits */
792 b5c16c22 2002-03-25 alex IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
793 b5c16c22 2002-03-25 alex return FALSE;
796 08cf5607 2001-12-26 alex return TRUE;
797 08cf5607 2001-12-26 alex } /* Client_CheckNick */
800 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
801 c2f60abe 2002-05-27 alex Client_CheckID( CLIENT *Client, CHAR *ID )
803 07903baa 2002-01-03 alex /* Nick ueberpruefen */
805 07903baa 2002-01-03 alex CHAR str[COMMAND_LEN];
808 07903baa 2002-01-03 alex assert( Client != NULL );
809 07903baa 2002-01-03 alex assert( Client->conn_id > NONE );
810 07903baa 2002-01-03 alex assert( ID != NULL );
812 07903baa 2002-01-03 alex /* Nick zu lang? */
813 9f3a9df2 2002-02-17 alex if( strlen( ID ) > CLIENT_ID_LEN )
815 9f3a9df2 2002-02-17 alex IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), ID );
816 9f3a9df2 2002-02-17 alex return FALSE;
819 07903baa 2002-01-03 alex /* ID bereits vergeben? */
820 07903baa 2002-01-03 alex c = My_Clients;
823 f7551900 2002-01-04 alex if( strcasecmp( c->id, ID ) == 0 )
825 07903baa 2002-01-03 alex /* die Server-ID gibt es bereits */
826 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), "ID \"%s\" already registered", ID );
827 9f122037 2002-12-03 alex if( Client->conn_id != c->conn_id ) Log( LOG_ERR, "%s (on connection %d)!", str, c->conn_id );
828 9f122037 2002-12-03 alex else Log( LOG_ERR, "%s (via network)!", str );
829 79809118 2002-01-06 alex Conn_Close( Client->conn_id, str, str, TRUE );
830 07903baa 2002-01-03 alex return FALSE;
832 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
835 07903baa 2002-01-03 alex return TRUE;
836 07903baa 2002-01-03 alex } /* Client_CheckID */
839 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
840 c2f60abe 2002-05-27 alex Client_First( VOID )
842 fb9d6ce1 2001-12-31 alex /* Ersten Client liefern. */
844 fb9d6ce1 2001-12-31 alex return My_Clients;
845 fb9d6ce1 2001-12-31 alex } /* Client_First */
848 c2f60abe 2002-05-27 alex GLOBAL CLIENT *
849 c2f60abe 2002-05-27 alex Client_Next( CLIENT *c )
851 fb9d6ce1 2001-12-31 alex /* Naechsten Client liefern. Existiert keiner,
852 fb9d6ce1 2001-12-31 alex * so wird NULL geliefert. */
854 fb9d6ce1 2001-12-31 alex assert( c != NULL );
855 95a4b1b1 2002-03-25 alex return (CLIENT *)c->next;
856 fb9d6ce1 2001-12-31 alex } /* Client_Next */
859 c7b55aa6 2002-10-09 alex GLOBAL LONG
860 c2f60abe 2002-05-27 alex Client_UserCount( VOID )
862 b9d701db 2002-01-16 alex return Count( CLIENT_USER );
863 b9d701db 2002-01-16 alex } /* Client_UserCount */
866 c7b55aa6 2002-10-09 alex GLOBAL LONG
867 c2f60abe 2002-05-27 alex Client_ServiceCount( VOID )
869 b9d701db 2002-01-16 alex return Count( CLIENT_SERVICE );;
870 b9d701db 2002-01-16 alex } /* Client_ServiceCount */
873 c7b55aa6 2002-10-09 alex GLOBAL LONG
874 c2f60abe 2002-05-27 alex Client_ServerCount( VOID )
876 b9d701db 2002-01-16 alex return Count( CLIENT_SERVER );
877 b9d701db 2002-01-16 alex } /* Client_ServerCount */
880 c7b55aa6 2002-10-09 alex GLOBAL LONG
881 c2f60abe 2002-05-27 alex Client_MyUserCount( VOID )
883 b9d701db 2002-01-16 alex return MyCount( CLIENT_USER );
884 b9d701db 2002-01-16 alex } /* Client_MyUserCount */
887 c7b55aa6 2002-10-09 alex GLOBAL LONG
888 c2f60abe 2002-05-27 alex Client_MyServiceCount( VOID )
890 b9d701db 2002-01-16 alex return MyCount( CLIENT_SERVICE );
891 b9d701db 2002-01-16 alex } /* Client_MyServiceCount */
894 c7b55aa6 2002-10-09 alex GLOBAL LONG
895 c2f60abe 2002-05-27 alex Client_MyServerCount( VOID )
901 3be7b9ef 2002-04-14 alex c = My_Clients;
904 3be7b9ef 2002-04-14 alex if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
905 3be7b9ef 2002-04-14 alex c = (CLIENT *)c->next;
907 3be7b9ef 2002-04-14 alex return cnt;
908 b9d701db 2002-01-16 alex } /* Client_MyServerCount */
911 c7b55aa6 2002-10-09 alex GLOBAL LONG
912 c2f60abe 2002-05-27 alex Client_OperCount( VOID )
918 b9d701db 2002-01-16 alex c = My_Clients;
921 b9d701db 2002-01-16 alex if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
922 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
924 b9d701db 2002-01-16 alex return cnt;
925 b9d701db 2002-01-16 alex } /* Client_OperCount */
928 c7b55aa6 2002-10-09 alex GLOBAL LONG
929 c2f60abe 2002-05-27 alex Client_UnknownCount( VOID )
935 b9d701db 2002-01-16 alex c = My_Clients;
938 b9d701db 2002-01-16 alex if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
939 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
941 b9d701db 2002-01-16 alex return cnt;
942 b9d701db 2002-01-16 alex } /* Client_UnknownCount */
945 d0304b19 2002-12-22 alex GLOBAL LONG
946 d0304b19 2002-12-22 alex Client_MaxUserCount( VOID )
948 d0304b19 2002-12-22 alex return Max_Users;
949 d0304b19 2002-12-22 alex } /* Client_MaxUserCount */
952 d0304b19 2002-12-22 alex GLOBAL LONG
953 d0304b19 2002-12-22 alex Client_MyMaxUserCount( VOID )
955 d0304b19 2002-12-22 alex return My_Max_Users;
956 d0304b19 2002-12-22 alex } /* Client_MyMaxUserCount */
959 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
960 c2f60abe 2002-05-27 alex Client_IsValidNick( CHAR *Nick )
962 33944e8c 2002-02-06 alex /* Ist der Nick gueltig? */
964 f7327524 2002-05-30 alex CHAR *ptr, goodchars[20];
966 33944e8c 2002-02-06 alex assert( Nick != NULL );
968 f7327524 2002-05-30 alex strcpy( goodchars, ";0123456789-" );
970 33944e8c 2002-02-06 alex if( Nick[0] == '#' ) return FALSE;
971 7157d936 2002-03-02 alex if( strchr( goodchars, Nick[0] )) return FALSE;
972 7157d936 2002-03-02 alex if( strlen( Nick ) >= CLIENT_NICK_LEN ) return FALSE;
974 7157d936 2002-03-02 alex ptr = Nick;
975 7157d936 2002-03-02 alex while( *ptr )
977 7157d936 2002-03-02 alex if(( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return FALSE;
978 7157d936 2002-03-02 alex if(( *ptr > '}' ) && ( ! strchr( goodchars, *ptr ))) return FALSE;
982 33944e8c 2002-02-06 alex return TRUE;
983 33944e8c 2002-02-06 alex } /* Client_IsValidNick */
987 c2f60abe 2002-05-27 alex Count( CLIENT_TYPE Type )
993 b9d701db 2002-01-16 alex c = My_Clients;
996 3be7b9ef 2002-04-14 alex if( c->type == Type ) cnt++;
997 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
999 b9d701db 2002-01-16 alex return cnt;
1000 b9d701db 2002-01-16 alex } /* Count */
1003 c7b55aa6 2002-10-09 alex LOCAL LONG
1004 c2f60abe 2002-05-27 alex MyCount( CLIENT_TYPE Type )
1006 b9d701db 2002-01-16 alex CLIENT *c;
1010 b9d701db 2002-01-16 alex c = My_Clients;
1011 b9d701db 2002-01-16 alex while( c )
1013 3be7b9ef 2002-04-14 alex if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
1014 95a4b1b1 2002-03-25 alex c = (CLIENT *)c->next;
1016 b9d701db 2002-01-16 alex return cnt;
1017 b9d701db 2002-01-16 alex } /* MyCount */
1020 c2f60abe 2002-05-27 alex LOCAL CLIENT *
1021 c2f60abe 2002-05-27 alex New_Client_Struct( VOID )
1023 d0ac1e9c 2001-12-23 alex /* Neue CLIENT-Struktur pre-initialisieren */
1025 38b9cb88 2001-12-14 alex CLIENT *c;
1027 cb76d96e 2004-03-11 alex c = (CLIENT *)malloc( sizeof( CLIENT ));
1030 e6d1bcdf 2002-06-10 alex Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
1031 38b9cb88 2001-12-14 alex return NULL;
1034 d16ce5a7 2005-01-20 alex memset( c, 0, sizeof ( CLIENT ));
1036 38b9cb88 2001-12-14 alex c->type = CLIENT_UNKNOWN;
1037 38b9cb88 2001-12-14 alex c->conn_id = NONE;
1038 804b1ec4 2001-12-31 alex c->oper_by_me = FALSE;
1039 f7551900 2002-01-04 alex c->hops = -1;
1040 f7551900 2002-01-04 alex c->token = -1;
1041 a53857b4 2002-01-07 alex c->mytoken = -1;
1044 38b9cb88 2001-12-14 alex } /* New_Client */
1047 c2f60abe 2002-05-27 alex LOCAL VOID
1048 c2f60abe 2002-05-27 alex Generate_MyToken( CLIENT *Client )
1050 a53857b4 2002-01-07 alex CLIENT *c;
1051 a53857b4 2002-01-07 alex INT token;
1053 a53857b4 2002-01-07 alex c = My_Clients;
1054 a53857b4 2002-01-07 alex token = 2;
1055 a53857b4 2002-01-07 alex while( c )
1057 a53857b4 2002-01-07 alex if( c->mytoken == token )
1059 a53857b4 2002-01-07 alex /* Das Token wurde bereits vergeben */
1061 a53857b4 2002-01-07 alex c = My_Clients;
1064 95a4b1b1 2002-03-25 alex else c = (CLIENT *)c->next;
1066 a53857b4 2002-01-07 alex Client->mytoken = token;
1067 a53857b4 2002-01-07 alex Log( LOG_DEBUG, "Assigned token %d to server \"%s\".", token, Client->id );
1068 a53857b4 2002-01-07 alex } /* Generate_MyToken */
1071 d0304b19 2002-12-22 alex LOCAL VOID
1072 d0304b19 2002-12-22 alex Adjust_Counters( CLIENT *Client )
1074 d0304b19 2002-12-22 alex LONG count;
1076 d0304b19 2002-12-22 alex assert( Client != NULL );
1078 d0304b19 2002-12-22 alex if( Client->type != CLIENT_USER ) return;
1080 d0304b19 2002-12-22 alex if( Client->conn_id != NONE )
1082 d0304b19 2002-12-22 alex /* Local connection */
1083 d0304b19 2002-12-22 alex count = Client_MyUserCount( );
1084 d0304b19 2002-12-22 alex if( count > My_Max_Users ) My_Max_Users = count;
1086 d0304b19 2002-12-22 alex count = Client_UserCount( );
1087 d0304b19 2002-12-22 alex if( count > Max_Users ) Max_Users = count;
1088 d0304b19 2002-12-22 alex } /* Adjust_Counters */
1091 38b9cb88 2001-12-14 alex /* -eof- */