2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
43 #include "irc-write.h"
50 #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
53 static CLIENT *This_Server, *My_Clients;
55 static WHOWAS My_Whowas[MAX_WHOWAS];
56 static int Last_Whowas = -1;
57 static long Max_Users, My_Max_Users;
60 static unsigned long Count PARAMS(( CLIENT_TYPE Type ));
61 static unsigned long MyCount PARAMS(( CLIENT_TYPE Type ));
63 static CLIENT *New_Client_Struct PARAMS(( void ));
64 static void Generate_MyToken PARAMS(( CLIENT *Client ));
65 static void Adjust_Counters PARAMS(( CLIENT *Client ));
67 static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer,
68 CLIENT *TopServer, int Type, const char *ID,
69 const char *User, const char *Hostname, const char *Info,
70 int Hops, int Token, const char *Modes,
73 static void Destroy_UserOrService PARAMS((CLIENT *Client,const char *Txt, const char *FwdMsg,
82 This_Server = New_Client_Struct( );
85 Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
86 Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
90 /* Client-Struktur dieses Servers */
91 This_Server->next = NULL;
92 This_Server->type = CLIENT_SERVER;
93 This_Server->conn_id = NONE;
94 This_Server->introducer = This_Server;
95 This_Server->mytoken = 1;
96 This_Server->hops = 0;
98 gethostname( This_Server->host, CLIENT_HOST_LEN );
100 h = gethostbyname( This_Server->host );
101 if (h) strlcpy(This_Server->host, h->h_name, sizeof(This_Server->host));
103 Client_SetID( This_Server, Conf_ServerName );
104 Client_SetInfo( This_Server, Conf_ServerInfo );
106 My_Clients = This_Server;
108 memset( &My_Whowas, 0, sizeof( My_Whowas ));
118 if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, false );
119 else Client_Destroy( This_Server, "Server going down.", NULL, false );
126 next = (CLIENT *)c->next;
130 if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
135 Client_ThisServer( void )
138 } /* Client_ThisServer */
142 * Initialize new local client; wrapper function for Init_New_Client().
143 * @return New CLIENT structure.
146 Client_NewLocal(CONN_ID Idx, const char *Hostname, int Type, bool Idented)
148 return Init_New_Client(Idx, This_Server, NULL, Type, NULL, NULL,
149 Hostname, NULL, 0, 0, NULL, Idented);
150 } /* Client_NewLocal */
154 * Initialize new remote server; wrapper function for Init_New_Client().
155 * @return New CLIENT structure.
158 Client_NewRemoteServer(CLIENT *Introducer, const char *Hostname, CLIENT *TopServer,
159 int Hops, int Token, const char *Info, bool Idented)
161 return Init_New_Client(NONE, Introducer, TopServer, CLIENT_SERVER,
162 Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented);
163 } /* Client_NewRemoteServer */
167 * Initialize new remote client; wrapper function for Init_New_Client().
168 * @return New CLIENT structure.
171 Client_NewRemoteUser(CLIENT *Introducer, const char *Nick, int Hops, const char *User,
172 const char *Hostname, int Token, const char *Modes, const char *Info, bool Idented)
174 return Init_New_Client(NONE, Introducer, NULL, CLIENT_USER, Nick,
175 User, Hostname, Info, Hops, Token, Modes, Idented);
176 } /* Client_NewRemoteUser */
180 * Initialize new client and set up the given parameters like client type,
181 * user name, host name, introducing server etc. ...
182 * @return New CLIENT structure.
185 Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
186 int Type, const char *ID, const char *User, const char *Hostname,
187 const char *Info, int Hops, int Token, const char *Modes, bool Idented)
192 assert(Introducer != NULL);
193 assert(Hostname != NULL);
195 client = New_Client_Struct();
199 client->starttime = time(NULL);
200 client->conn_id = Idx;
201 client->introducer = Introducer;
202 client->topserver = TopServer;
205 Client_SetID(client, ID);
207 Client_SetUser(client, User, Idented);
208 Client_SetOrigUser(client, User);
211 Client_SetHostname(client, Hostname);
213 Client_SetInfo(client, Info);
215 client->token = Token;
217 Client_SetModes(client, Modes);
218 if (Type == CLIENT_SERVER)
219 Generate_MyToken(client);
221 if (strchr(client->modes, 'a'))
222 strlcpy(client->away, DEFAULT_AWAY_MSG, sizeof(client->away));
224 client->next = (POINTER *)My_Clients;
227 Adjust_Counters(client);
230 } /* Init_New_Client */
234 Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit )
236 /* remove a client */
242 assert( Client != NULL );
244 if( LogMsg ) txt = LogMsg;
246 if( ! txt ) txt = "Reason unknown.";
248 /* netsplit message */
249 if( Client->type == CLIENT_SERVER ) {
250 strlcpy(msg, This_Server->id, sizeof (msg));
251 strlcat(msg, " ", sizeof (msg));
252 strlcat(msg, Client->id, sizeof (msg));
259 if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
262 * The client that is about to be removed is a server,
263 * the client we are checking right now is a child of that
264 * server and thus has to be removed, too.
266 * Call Client_Destroy() recursively with the server as the
267 * new "object to be removed". This starts the cycle again, until
268 * all servers that are linked via the original server have been
271 Client_Destroy( c, NULL, msg, false );
278 /* found the client: remove it */
279 if( last ) last->next = c->next;
280 else My_Clients = (CLIENT *)c->next;
282 if(c->type == CLIENT_USER || c->type == CLIENT_SERVICE)
283 Destroy_UserOrService(c, txt, FwdMsg, SendQuit);
284 else if( c->type == CLIENT_SERVER )
286 if( c != This_Server )
288 if( c->conn_id != NONE ) Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
289 else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
292 /* inform other servers */
293 if( ! NGIRCd_SignalQuit )
295 if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
296 else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
301 if( c->conn_id != NONE )
303 if( c->id[0] ) Log( LOG_NOTICE, "Client \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
304 else Log( LOG_NOTICE, "Client unregistered (connection %d): %s", c->conn_id, txt );
306 Log(LOG_WARNING, "Unregistered unknown client \"%s\": %s",
307 c->id[0] ? c->id : "(No Nick)", txt );
315 c = (CLIENT *)c->next;
317 } /* Client_Destroy */
321 Client_SetHostname( CLIENT *Client, const char *Hostname )
323 assert( Client != NULL );
324 assert( Hostname != NULL );
326 strlcpy( Client->host, Hostname, sizeof( Client->host ));
327 } /* Client_SetHostname */
331 Client_SetID( CLIENT *Client, const char *ID )
333 assert( Client != NULL );
334 assert( ID != NULL );
336 strlcpy( Client->id, ID, sizeof( Client->id ));
339 Client->hash = Hash( Client->id );
344 Client_SetUser( CLIENT *Client, const char *User, bool Idented )
346 /* set clients username */
348 assert( Client != NULL );
349 assert( User != NULL );
352 strlcpy(Client->user, User, sizeof(Client->user));
354 Client->user[0] = '~';
355 strlcpy(Client->user + 1, User, sizeof(Client->user) - 1);
357 } /* Client_SetUser */
361 * Set "original" user name of a client.
362 * This function saves the "original" user name, the user name specified by
363 * the peer using the USER command, into the CLIENT structure. This user
364 * name may be used for authentication, for example.
365 * @param Client The client.
366 * @param User User name to set.
369 Client_SetOrigUser(CLIENT UNUSED *Client, const char UNUSED *User)
371 assert(Client != NULL);
372 assert(User != NULL);
374 #if defined(PAM) && defined(IDENTAUTH)
375 strlcpy(Client->orig_user, User, sizeof(Client->orig_user));
377 } /* Client_SetOrigUser */
381 Client_SetInfo( CLIENT *Client, const char *Info )
383 /* set client hostname */
385 assert( Client != NULL );
386 assert( Info != NULL );
388 strlcpy(Client->info, Info, sizeof(Client->info));
389 } /* Client_SetInfo */
393 Client_SetModes( CLIENT *Client, const char *Modes )
395 assert( Client != NULL );
396 assert( Modes != NULL );
398 strlcpy(Client->modes, Modes, sizeof( Client->modes ));
399 } /* Client_SetModes */
403 Client_SetFlags( CLIENT *Client, const char *Flags )
405 assert( Client != NULL );
406 assert( Flags != NULL );
408 strlcpy(Client->flags, Flags, sizeof(Client->flags));
409 } /* Client_SetFlags */
413 Client_SetPassword( CLIENT *Client, const char *Pwd )
415 /* set password sent by client */
417 assert( Client != NULL );
418 assert( Pwd != NULL );
420 strlcpy(Client->pwd, Pwd, sizeof(Client->pwd));
421 } /* Client_SetPassword */
425 Client_SetAway( CLIENT *Client, const char *Txt )
427 /* Set AWAY reason of client */
429 assert( Client != NULL );
430 assert( Txt != NULL );
432 strlcpy( Client->away, Txt, sizeof( Client->away ));
433 LogDebug("%s \"%s\" is away: %s", Client_TypeText(Client),
434 Client_Mask(Client), Txt);
435 } /* Client_SetAway */
439 Client_SetType( CLIENT *Client, int Type )
441 assert( Client != NULL );
443 if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
444 Adjust_Counters( Client );
445 } /* Client_SetType */
449 Client_SetHops( CLIENT *Client, int Hops )
451 assert( Client != NULL );
453 } /* Client_SetHops */
457 Client_SetToken( CLIENT *Client, int Token )
459 assert( Client != NULL );
460 Client->token = Token;
461 } /* Client_SetToken */
465 Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
467 assert( Client != NULL );
468 assert( Introducer != NULL );
469 Client->introducer = Introducer;
470 } /* Client_SetIntroducer */
474 Client_SetOperByMe( CLIENT *Client, bool OperByMe )
476 assert( Client != NULL );
477 Client->oper_by_me = OperByMe;
478 } /* Client_SetOperByMe */
482 Client_ModeAdd( CLIENT *Client, char Mode )
485 * If Client already alread had Mode, return false.
486 * If the Mode was newly set, return true.
491 assert( Client != NULL );
493 x[0] = Mode; x[1] = '\0';
494 if (!strchr( Client->modes, x[0])) {
495 strlcat( Client->modes, x, sizeof( Client->modes ));
499 } /* Client_ModeAdd */
503 Client_ModeDel( CLIENT *Client, char Mode )
506 * If Mode was removed, return true.
507 * If Client did not have Mode, return false.
512 assert( Client != NULL );
514 x[0] = Mode; x[1] = '\0';
516 p = strchr( Client->modes, x[0] );
517 if( ! p ) return false;
519 /* Client has Mode -> delete */
526 } /* Client_ModeDel */
530 Client_Search( const char *Nick )
532 /* return Client-Structure that has the corresponding Nick.
533 * If none is found, return NULL.
536 char search_id[CLIENT_ID_LEN], *ptr;
540 assert( Nick != NULL );
542 /* copy Nick and truncate hostmask if necessary */
543 strlcpy( search_id, Nick, sizeof( search_id ));
544 ptr = strchr( search_id, '!' );
545 if( ptr ) *ptr = '\0';
547 search_hash = Hash(search_id);
551 if (c->hash == search_hash && strcasecmp(c->id, search_id) == 0)
553 c = (CLIENT *)c->next;
556 } /* Client_Search */
560 * Get client structure ("introducer") identfied by a server token.
561 * @return CLIENT structure or NULL if none could be found.
564 Client_GetFromToken( CLIENT *Client, int Token )
568 assert( Client != NULL );
575 if ((c->type == CLIENT_SERVER) && (c->introducer == Client) &&
578 c = (CLIENT *)c->next;
581 } /* Client_GetFromToken */
585 Client_Type( CLIENT *Client )
587 assert( Client != NULL );
593 Client_Conn( CLIENT *Client )
595 assert( Client != NULL );
596 return Client->conn_id;
601 Client_ID( CLIENT *Client )
603 assert( Client != NULL );
606 if(Client->type == CLIENT_USER)
607 assert(strlen(Client->id) < Conf_MaxNickLength);
610 if( Client->id[0] ) return Client->id;
616 Client_Info( CLIENT *Client )
618 assert( Client != NULL );
624 Client_User( CLIENT *Client )
626 assert( Client != NULL );
627 return Client->user[0] ? Client->user : "~";
634 * Get the "original" user name as supplied by the USER command.
635 * The user name as given by the client is used for authentication instead
636 * of the one detected using IDENT requests.
637 * @param Client The client.
638 * @return Original user name.
641 Client_OrigUser(CLIENT *Client) {
643 char *user = Client->user;
649 return Client->orig_user;
651 } /* Client_OrigUser */
657 * Return the hostname of a client.
658 * @param Client Pointer to client structure
659 * @return Pointer to client hostname
662 Client_Hostname(CLIENT *Client)
664 assert (Client != NULL);
666 } /* Client_Hostname */
670 * Get potentially cloaked hostname of a client.
671 * If the client has not enabled cloaking, the real hostname is used.
672 * @param Client Pointer to client structure
673 * @return Pointer to client hostname
676 Client_HostnameCloaked(CLIENT *Client)
678 assert(Client != NULL);
679 if (Client_HasMode(Client, 'x'))
680 return Client_ID(Client->introducer);
682 return Client_Hostname(Client);
683 } /* Client_HostnameCloaked */
687 Client_Password( CLIENT *Client )
689 assert( Client != NULL );
691 } /* Client_Password */
695 Client_Modes( CLIENT *Client )
697 assert( Client != NULL );
698 return Client->modes;
703 Client_Flags( CLIENT *Client )
705 assert( Client != NULL );
706 return Client->flags;
711 Client_OperByMe( CLIENT *Client )
713 assert( Client != NULL );
714 return Client->oper_by_me;
715 } /* Client_OperByMe */
719 Client_Hops( CLIENT *Client )
721 assert( Client != NULL );
727 Client_Token( CLIENT *Client )
729 assert( Client != NULL );
730 return Client->token;
735 Client_MyToken( CLIENT *Client )
737 assert( Client != NULL );
738 return Client->mytoken;
739 } /* Client_MyToken */
743 Client_NextHop( CLIENT *Client )
747 assert( Client != NULL );
750 while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server ))
754 } /* Client_NextHop */
758 * Return ID of a client: "client!user@host"
759 * This client ID is used for IRC prefixes, for example.
760 * Please note that this function uses a global static buffer, so you can't
761 * nest invocations without overwriting erlier results!
762 * @param Client Pointer to client structure
763 * @return Pointer to global buffer containing the client ID
766 Client_Mask( CLIENT *Client )
768 static char Mask_Buffer[GETID_LEN];
770 assert (Client != NULL);
772 /* Servers: return name only, there is no "mask" */
773 if (Client->type == CLIENT_SERVER)
776 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
777 Client->id, Client->user, Client->host);
783 * Return ID of a client with cloaked hostname: "client!user@server-name"
784 * This client ID is used for IRC prefixes, for example.
785 * Please note that this function uses a global static buffer, so you can't
786 * nest invocations without overwriting erlier results!
787 * If the client has not enabled cloaking, the real hostname is used.
788 * @param Client Pointer to client structure
789 * @return Pointer to global buffer containing the client ID
792 Client_MaskCloaked(CLIENT *Client)
794 static char Mask_Buffer[GETID_LEN];
796 assert (Client != NULL);
798 /* Is the client using cloaking at all? */
799 if (!Client_HasMode(Client, 'x'))
800 return Client_Mask(Client);
802 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
803 Client->id, Client->user, Client_ID(Client->introducer));
805 } /* Client_MaskCloaked */
809 Client_Introducer( CLIENT *Client )
811 assert( Client != NULL );
812 return Client->introducer;
813 } /* Client_Introducer */
817 Client_TopServer( CLIENT *Client )
819 assert( Client != NULL );
820 return Client->topserver;
821 } /* Client_TopServer */
825 Client_HasMode( CLIENT *Client, char Mode )
827 assert( Client != NULL );
828 return strchr( Client->modes, Mode ) != NULL;
829 } /* Client_HasMode */
833 Client_Away( CLIENT *Client )
835 assert( Client != NULL );
841 Client_CheckNick( CLIENT *Client, char *Nick )
843 assert( Client != NULL );
844 assert( Nick != NULL );
846 if (! Client_IsValidNick( Nick ))
848 IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
852 /* Nick bereits vergeben? */
853 if( Client_Search( Nick ))
855 /* den Nick gibt es bereits */
856 IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
861 } /* Client_CheckNick */
865 Client_CheckID( CLIENT *Client, char *ID )
867 char str[COMMAND_LEN];
870 assert( Client != NULL );
871 assert( Client->conn_id > NONE );
872 assert( ID != NULL );
875 if (strlen(ID) > CLIENT_ID_LEN) {
876 IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID);
880 /* ID already in use? */
883 if (strcasecmp(c->id, ID) == 0) {
884 snprintf(str, sizeof(str), "ID \"%s\" already registered", ID);
885 if (c->conn_id != NONE)
886 Log(LOG_ERR, "%s (on connection %d)!", str, c->conn_id);
888 Log(LOG_ERR, "%s (via network)!", str);
889 Conn_Close(Client->conn_id, str, str, true);
892 c = (CLIENT *)c->next;
896 } /* Client_CheckID */
907 Client_Next( CLIENT *c )
910 return (CLIENT *)c->next;
915 Client_UserCount( void )
917 return Count( CLIENT_USER );
918 } /* Client_UserCount */
922 Client_ServiceCount( void )
924 return Count( CLIENT_SERVICE );;
925 } /* Client_ServiceCount */
929 Client_ServerCount( void )
931 return Count( CLIENT_SERVER );
932 } /* Client_ServerCount */
936 Client_MyUserCount( void )
938 return MyCount( CLIENT_USER );
939 } /* Client_MyUserCount */
943 Client_MyServiceCount( void )
945 return MyCount( CLIENT_SERVICE );
946 } /* Client_MyServiceCount */
950 Client_MyServerCount( void )
953 unsigned long cnt = 0;
958 if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
959 c = (CLIENT *)c->next;
962 } /* Client_MyServerCount */
966 Client_OperCount( void )
969 unsigned long cnt = 0;
974 if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
975 c = (CLIENT *)c->next;
978 } /* Client_OperCount */
982 Client_UnknownCount( void )
985 unsigned long cnt = 0;
990 if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
991 c = (CLIENT *)c->next;
995 } /* Client_UnknownCount */
999 Client_MaxUserCount( void )
1002 } /* Client_MaxUserCount */
1006 Client_MyMaxUserCount( void )
1008 return My_Max_Users;
1009 } /* Client_MyMaxUserCount */
1013 Client_IsValidNick( const char *Nick )
1016 static const char goodchars[] = ";0123456789-";
1018 assert( Nick != NULL );
1020 if( Nick[0] == '#' ) return false;
1021 if( strchr( goodchars, Nick[0] )) return false;
1022 if( strlen( Nick ) >= Conf_MaxNickLength) return false;
1027 if (( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return false;
1028 if ( *ptr > '}' ) return false;
1033 } /* Client_IsValidNick */
1037 * Return pointer to "My_Whowas" structure.
1040 Client_GetWhowas( void )
1043 } /* Client_GetWhowas */
1046 * Return the index of the last used WHOWAS entry.
1049 Client_GetLastWhowasIndex( void )
1052 } /* Client_GetLastWhowasIndex */
1056 * Get the start time of this client.
1057 * The result is the start time in seconds since 1970-01-01, as reported
1058 * by the C function time(NULL).
1061 Client_StartTime(CLIENT *Client)
1063 assert( Client != NULL );
1064 return Client->starttime;
1065 } /* Client_Uptime */
1068 static unsigned long
1069 Count( CLIENT_TYPE Type )
1072 unsigned long cnt = 0;
1077 if( c->type == Type ) cnt++;
1078 c = (CLIENT *)c->next;
1084 static unsigned long
1085 MyCount( CLIENT_TYPE Type )
1088 unsigned long cnt = 0;
1093 if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
1094 c = (CLIENT *)c->next;
1101 New_Client_Struct( void )
1103 /* Neue CLIENT-Struktur pre-initialisieren */
1107 c = (CLIENT *)malloc( sizeof( CLIENT ));
1110 Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
1114 memset( c, 0, sizeof ( CLIENT ));
1116 c->type = CLIENT_UNKNOWN;
1118 c->oper_by_me = false;
1128 Generate_MyToken( CLIENT *Client )
1137 if( c->mytoken == token )
1139 /* Das Token wurde bereits vergeben */
1144 else c = (CLIENT *)c->next;
1146 Client->mytoken = token;
1147 LogDebug("Assigned token %d to server \"%s\".", token, Client->id);
1148 } /* Generate_MyToken */
1152 Adjust_Counters( CLIENT *Client )
1156 assert( Client != NULL );
1158 if( Client->type != CLIENT_USER ) return;
1160 if( Client->conn_id != NONE )
1162 /* Local connection */
1163 count = Client_MyUserCount( );
1164 if( count > My_Max_Users ) My_Max_Users = count;
1166 count = Client_UserCount( );
1167 if( count > Max_Users ) Max_Users = count;
1168 } /* Adjust_Counters */
1172 * Register client in My_Whowas structure for further recall by WHOWAS.
1173 * Note: Only clients that have been connected at least 30 seconds will be
1174 * registered to prevent automated IRC bots to "destroy" a nice server
1178 Client_RegisterWhowas( CLIENT *Client )
1183 assert( Client != NULL );
1186 /* Don't register clients that were connected less than 30 seconds. */
1187 if( now - Client->starttime < 30 )
1190 slot = Last_Whowas + 1;
1191 if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;
1194 Log( LOG_DEBUG, "Saving WHOWAS information to slot %d ...", slot );
1197 My_Whowas[slot].time = now;
1198 strlcpy( My_Whowas[slot].id, Client_ID( Client ),
1199 sizeof( My_Whowas[slot].id ));
1200 strlcpy( My_Whowas[slot].user, Client_User( Client ),
1201 sizeof( My_Whowas[slot].user ));
1202 strlcpy( My_Whowas[slot].host, Client_HostnameCloaked( Client ),
1203 sizeof( My_Whowas[slot].host ));
1204 strlcpy( My_Whowas[slot].info, Client_Info( Client ),
1205 sizeof( My_Whowas[slot].info ));
1206 strlcpy( My_Whowas[slot].server, Client_ID( Client_Introducer( Client )),
1207 sizeof( My_Whowas[slot].server ));
1210 } /* Client_RegisterWhowas */
1214 Client_TypeText(CLIENT *Client)
1216 assert(Client != NULL);
1217 switch (Client_Type(Client)) {
1221 case CLIENT_SERVICE:
1230 } /* Client_TypeText */
1234 * Destroy user or service client.
1237 Destroy_UserOrService(CLIENT *Client, const char *Txt, const char *FwdMsg, bool SendQuit)
1239 if(Client->conn_id != NONE) {
1240 /* Local (directly connected) client */
1242 "%s \"%s\" unregistered (connection %d): %s",
1243 Client_TypeText(Client), Client_Mask(Client),
1244 Client->conn_id, Txt);
1245 Log_ServerNotice('c', "Client exiting: %s (%s@%s) [%s]",
1246 Client_ID(Client), Client_User(Client),
1247 Client_Hostname(Client), Txt);
1250 /* Inforam all the other servers */
1252 IRC_WriteStrServersPrefix(NULL,
1253 Client, "QUIT :%s", FwdMsg );
1255 IRC_WriteStrServersPrefix(NULL,
1260 LogDebug("%s \"%s\" unregistered: %s",
1261 Client_TypeText(Client), Client_Mask(Client), Txt);
1264 /* Inform all the other servers, but the ones in the
1265 * direction we got the QUIT from */
1267 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1268 Client, "QUIT :%s", FwdMsg );
1270 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1275 /* Unregister client from channels */
1276 Channel_Quit(Client, FwdMsg ? FwdMsg : Client->id);
1278 /* Register client in My_Whowas structure */
1279 Client_RegisterWhowas(Client);
1280 } /* Destroy_UserOrService */
1286 Client_DebugDump(void)
1290 Log(LOG_DEBUG, "Client status:");
1294 " - %s: type=%d, host=%s, user=%s, conn=%d, start=%ld, flags=%s",
1295 Client_ID(c), Client_Type(c), Client_Hostname(c),
1296 Client_User(c), Client_Conn(c), Client_StartTime(c),
1298 c = (CLIENT *)c->next;
1300 } /* Client_DumpClients */