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.
40 #include "irc-write.h"
47 #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
50 static CLIENT *This_Server, *My_Clients;
52 static WHOWAS My_Whowas[MAX_WHOWAS];
53 static int Last_Whowas = -1;
54 static long Max_Users, My_Max_Users;
57 static unsigned long Count PARAMS(( CLIENT_TYPE Type ));
58 static unsigned long MyCount PARAMS(( CLIENT_TYPE Type ));
60 static CLIENT *New_Client_Struct PARAMS(( void ));
61 static void Generate_MyToken PARAMS(( CLIENT *Client ));
62 static void Adjust_Counters PARAMS(( CLIENT *Client ));
64 static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer,
65 CLIENT *TopServer, int Type, const char *ID,
66 const char *User, const char *Hostname, const char *Info,
67 int Hops, int Token, const char *Modes,
70 static void Destroy_UserOrService PARAMS((CLIENT *Client,const char *Txt, const char *FwdMsg,
79 This_Server = New_Client_Struct( );
82 Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
83 Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
87 /* Client-Struktur dieses Servers */
88 This_Server->next = NULL;
89 This_Server->type = CLIENT_SERVER;
90 This_Server->conn_id = NONE;
91 This_Server->introducer = This_Server;
92 This_Server->mytoken = 1;
93 This_Server->hops = 0;
95 gethostname( This_Server->host, CLIENT_HOST_LEN );
97 h = gethostbyname( This_Server->host );
98 if (h) strlcpy(This_Server->host, h->h_name, sizeof(This_Server->host));
100 Client_SetID( This_Server, Conf_ServerName );
101 Client_SetInfo( This_Server, Conf_ServerInfo );
103 My_Clients = This_Server;
105 memset( &My_Whowas, 0, sizeof( My_Whowas ));
115 if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, false );
116 else Client_Destroy( This_Server, "Server going down.", NULL, false );
123 next = (CLIENT *)c->next;
127 if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
132 Client_ThisServer( void )
135 } /* Client_ThisServer */
139 * Initialize new local client; wrapper function for Init_New_Client().
140 * @return New CLIENT structure.
143 Client_NewLocal(CONN_ID Idx, const char *Hostname, int Type, bool Idented)
145 return Init_New_Client(Idx, This_Server, NULL, Type, NULL, NULL,
146 Hostname, NULL, 0, 0, NULL, Idented);
147 } /* Client_NewLocal */
151 * Initialize new remote server; wrapper function for Init_New_Client().
152 * @return New CLIENT structure.
155 Client_NewRemoteServer(CLIENT *Introducer, const char *Hostname, CLIENT *TopServer,
156 int Hops, int Token, const char *Info, bool Idented)
158 return Init_New_Client(NONE, Introducer, TopServer, CLIENT_SERVER,
159 Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented);
160 } /* Client_NewRemoteServer */
164 * Initialize new remote client; wrapper function for Init_New_Client().
165 * @return New CLIENT structure.
168 Client_NewRemoteUser(CLIENT *Introducer, const char *Nick, int Hops, const char *User,
169 const char *Hostname, int Token, const char *Modes, const char *Info, bool Idented)
171 return Init_New_Client(NONE, Introducer, NULL, CLIENT_USER, Nick,
172 User, Hostname, Info, Hops, Token, Modes, Idented);
173 } /* Client_NewRemoteUser */
177 * Initialize new client and set up the given parameters like client type,
178 * user name, host name, introducing server etc. ...
179 * @return New CLIENT structure.
182 Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
183 int Type, const char *ID, const char *User, const char *Hostname,
184 const char *Info, int Hops, int Token, const char *Modes, bool Idented)
189 assert(Introducer != NULL);
190 assert(Hostname != NULL);
192 client = New_Client_Struct();
196 client->starttime = time(NULL);
197 client->conn_id = Idx;
198 client->introducer = Introducer;
199 client->topserver = TopServer;
202 Client_SetID(client, ID);
204 Client_SetUser(client, User, Idented);
205 Client_SetOrigUser(client, User);
208 Client_SetHostname(client, Hostname);
210 Client_SetInfo(client, Info);
212 client->token = Token;
214 Client_SetModes(client, Modes);
215 if (Type == CLIENT_SERVER)
216 Generate_MyToken(client);
218 if (strchr(client->modes, 'a'))
219 strlcpy(client->away, DEFAULT_AWAY_MSG, sizeof(client->away));
221 client->next = (POINTER *)My_Clients;
224 Adjust_Counters(client);
227 } /* Init_New_Client */
231 Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit )
233 /* remove a client */
239 assert( Client != NULL );
241 if( LogMsg ) txt = LogMsg;
243 if( ! txt ) txt = "Reason unknown.";
245 /* netsplit message */
246 if( Client->type == CLIENT_SERVER ) {
247 strlcpy(msg, This_Server->id, sizeof (msg));
248 strlcat(msg, " ", sizeof (msg));
249 strlcat(msg, Client->id, sizeof (msg));
256 if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
259 * The client that is about to be removed is a server,
260 * the client we are checking right now is a child of that
261 * server and thus has to be removed, too.
263 * Call Client_Destroy() recursively with the server as the
264 * new "object to be removed". This starts the cycle again, until
265 * all servers that are linked via the original server have been
268 Client_Destroy( c, NULL, msg, false );
275 /* found the client: remove it */
276 if( last ) last->next = c->next;
277 else My_Clients = (CLIENT *)c->next;
279 if(c->type == CLIENT_USER || c->type == CLIENT_SERVICE)
280 Destroy_UserOrService(c, txt, FwdMsg, SendQuit);
281 else if( c->type == CLIENT_SERVER )
283 if( c != This_Server )
285 if( c->conn_id != NONE ) Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
286 else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
289 /* inform other servers */
290 if( ! NGIRCd_SignalQuit )
292 if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
293 else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
298 if( c->conn_id != NONE )
300 if( c->id[0] ) Log( LOG_NOTICE, "Client \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
301 else Log( LOG_NOTICE, "Client unregistered (connection %d): %s", c->conn_id, txt );
303 Log(LOG_WARNING, "Unregistered unknown client \"%s\": %s",
304 c->id[0] ? c->id : "(No Nick)", txt );
312 c = (CLIENT *)c->next;
314 } /* Client_Destroy */
318 Client_SetHostname( CLIENT *Client, const char *Hostname )
320 assert( Client != NULL );
321 assert( Hostname != NULL );
323 strlcpy( Client->host, Hostname, sizeof( Client->host ));
324 } /* Client_SetHostname */
328 Client_SetID( CLIENT *Client, const char *ID )
330 assert( Client != NULL );
331 assert( ID != NULL );
333 strlcpy( Client->id, ID, sizeof( Client->id ));
336 Client->hash = Hash( Client->id );
341 Client_SetUser( CLIENT *Client, const char *User, bool Idented )
343 /* set clients username */
345 assert( Client != NULL );
346 assert( User != NULL );
349 strlcpy(Client->user, User, sizeof(Client->user));
351 Client->user[0] = '~';
352 strlcpy(Client->user + 1, User, sizeof(Client->user) - 1);
354 } /* Client_SetUser */
358 * Set "original" user name of a client.
359 * This function saves the "original" user name, the user name specified by
360 * the peer using the USER command, into the CLIENT structure. This user
361 * name may be used for authentication, for example.
362 * @param Client The client.
363 * @param User User name to set.
366 Client_SetOrigUser(CLIENT UNUSED *Client, const char UNUSED *User)
368 assert(Client != NULL);
369 assert(User != NULL);
371 #if defined(PAM) && defined(IDENTAUTH)
372 strlcpy(Client->orig_user, User, sizeof(Client->orig_user));
374 } /* Client_SetOrigUser */
378 Client_SetInfo( CLIENT *Client, const char *Info )
380 /* set client hostname */
382 assert( Client != NULL );
383 assert( Info != NULL );
385 strlcpy(Client->info, Info, sizeof(Client->info));
386 } /* Client_SetInfo */
390 Client_SetModes( CLIENT *Client, const char *Modes )
392 assert( Client != NULL );
393 assert( Modes != NULL );
395 strlcpy(Client->modes, Modes, sizeof( Client->modes ));
396 } /* Client_SetModes */
400 Client_SetFlags( CLIENT *Client, const char *Flags )
402 assert( Client != NULL );
403 assert( Flags != NULL );
405 strlcpy(Client->flags, Flags, sizeof(Client->flags));
406 } /* Client_SetFlags */
410 Client_SetPassword( CLIENT *Client, const char *Pwd )
412 /* set password sent by client */
414 assert( Client != NULL );
415 assert( Pwd != NULL );
417 strlcpy(Client->pwd, Pwd, sizeof(Client->pwd));
418 } /* Client_SetPassword */
422 Client_SetAway( CLIENT *Client, const char *Txt )
424 /* Set AWAY reason of client */
426 assert( Client != NULL );
427 assert( Txt != NULL );
429 strlcpy( Client->away, Txt, sizeof( Client->away ));
430 LogDebug("%s \"%s\" is away: %s", Client_TypeText(Client),
431 Client_Mask(Client), Txt);
432 } /* Client_SetAway */
436 Client_SetType( CLIENT *Client, int Type )
438 assert( Client != NULL );
440 if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
441 Adjust_Counters( Client );
442 } /* Client_SetType */
446 Client_SetHops( CLIENT *Client, int Hops )
448 assert( Client != NULL );
450 } /* Client_SetHops */
454 Client_SetToken( CLIENT *Client, int Token )
456 assert( Client != NULL );
457 Client->token = Token;
458 } /* Client_SetToken */
462 Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
464 assert( Client != NULL );
465 assert( Introducer != NULL );
466 Client->introducer = Introducer;
467 } /* Client_SetIntroducer */
471 Client_SetOperByMe( CLIENT *Client, bool OperByMe )
473 assert( Client != NULL );
474 Client->oper_by_me = OperByMe;
475 } /* Client_SetOperByMe */
479 Client_ModeAdd( CLIENT *Client, char Mode )
482 * If Client already alread had Mode, return false.
483 * If the Mode was newly set, return true.
488 assert( Client != NULL );
490 x[0] = Mode; x[1] = '\0';
491 if (!strchr( Client->modes, x[0])) {
492 strlcat( Client->modes, x, sizeof( Client->modes ));
496 } /* Client_ModeAdd */
500 Client_ModeDel( CLIENT *Client, char Mode )
503 * If Mode was removed, return true.
504 * If Client did not have Mode, return false.
509 assert( Client != NULL );
511 x[0] = Mode; x[1] = '\0';
513 p = strchr( Client->modes, x[0] );
514 if( ! p ) return false;
516 /* Client has Mode -> delete */
523 } /* Client_ModeDel */
527 Client_Search( const char *Nick )
529 /* return Client-Structure that has the corresponding Nick.
530 * If none is found, return NULL.
533 char search_id[CLIENT_ID_LEN], *ptr;
537 assert( Nick != NULL );
539 /* copy Nick and truncate hostmask if necessary */
540 strlcpy( search_id, Nick, sizeof( search_id ));
541 ptr = strchr( search_id, '!' );
542 if( ptr ) *ptr = '\0';
544 search_hash = Hash(search_id);
548 if (c->hash == search_hash && strcasecmp(c->id, search_id) == 0)
550 c = (CLIENT *)c->next;
553 } /* Client_Search */
557 * Get client structure ("introducer") identfied by a server token.
558 * @return CLIENT structure or NULL if none could be found.
561 Client_GetFromToken( CLIENT *Client, int Token )
565 assert( Client != NULL );
572 if ((c->type == CLIENT_SERVER) && (c->introducer == Client) &&
575 c = (CLIENT *)c->next;
578 } /* Client_GetFromToken */
582 Client_Type( CLIENT *Client )
584 assert( Client != NULL );
590 Client_Conn( CLIENT *Client )
592 assert( Client != NULL );
593 return Client->conn_id;
598 Client_ID( CLIENT *Client )
600 assert( Client != NULL );
603 if(Client->type == CLIENT_USER)
604 assert(strlen(Client->id) < Conf_MaxNickLength);
607 if( Client->id[0] ) return Client->id;
613 Client_Info( CLIENT *Client )
615 assert( Client != NULL );
621 Client_User( CLIENT *Client )
623 assert( Client != NULL );
624 return Client->user[0] ? Client->user : "~";
631 * Get the "original" user name as supplied by the USER command.
632 * The user name as given by the client is used for authentication instead
633 * of the one detected using IDENT requests.
634 * @param Client The client.
635 * @return Original user name.
638 Client_OrigUser(CLIENT *Client) {
640 char *user = Client->user;
646 return Client->orig_user;
648 } /* Client_OrigUser */
654 * Return the hostname of a client.
655 * @param Client Pointer to client structure
656 * @return Pointer to client hostname
659 Client_Hostname(CLIENT *Client)
661 assert (Client != NULL);
663 } /* Client_Hostname */
667 * Get potentially cloaked hostname of a client.
668 * If the client has not enabled cloaking, the real hostname is used.
669 * @param Client Pointer to client structure
670 * @return Pointer to client hostname
673 Client_HostnameCloaked(CLIENT *Client)
675 assert(Client != NULL);
676 if (Client_HasMode(Client, 'x'))
677 return Client_ID(Client->introducer);
679 return Client_Hostname(Client);
680 } /* Client_HostnameCloaked */
684 Client_Password( CLIENT *Client )
686 assert( Client != NULL );
688 } /* Client_Password */
692 Client_Modes( CLIENT *Client )
694 assert( Client != NULL );
695 return Client->modes;
700 Client_Flags( CLIENT *Client )
702 assert( Client != NULL );
703 return Client->flags;
708 Client_OperByMe( CLIENT *Client )
710 assert( Client != NULL );
711 return Client->oper_by_me;
712 } /* Client_OperByMe */
716 Client_Hops( CLIENT *Client )
718 assert( Client != NULL );
724 Client_Token( CLIENT *Client )
726 assert( Client != NULL );
727 return Client->token;
732 Client_MyToken( CLIENT *Client )
734 assert( Client != NULL );
735 return Client->mytoken;
736 } /* Client_MyToken */
740 Client_NextHop( CLIENT *Client )
744 assert( Client != NULL );
747 while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server ))
751 } /* Client_NextHop */
755 * Return ID of a client: "client!user@host"
756 * This client ID is used for IRC prefixes, for example.
757 * Please note that this function uses a global static buffer, so you can't
758 * nest invocations without overwriting erlier results!
759 * @param Client Pointer to client structure
760 * @return Pointer to global buffer containing the client ID
763 Client_Mask( CLIENT *Client )
765 static char Mask_Buffer[GETID_LEN];
767 assert (Client != NULL);
769 /* Servers: return name only, there is no "mask" */
770 if (Client->type == CLIENT_SERVER)
773 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
774 Client->id, Client->user, Client->host);
780 * Return ID of a client with cloaked hostname: "client!user@server-name"
781 * This client ID is used for IRC prefixes, for example.
782 * Please note that this function uses a global static buffer, so you can't
783 * nest invocations without overwriting erlier results!
784 * If the client has not enabled cloaking, the real hostname is used.
785 * @param Client Pointer to client structure
786 * @return Pointer to global buffer containing the client ID
789 Client_MaskCloaked(CLIENT *Client)
791 static char Mask_Buffer[GETID_LEN];
793 assert (Client != NULL);
795 /* Is the client using cloaking at all? */
796 if (!Client_HasMode(Client, 'x'))
797 return Client_Mask(Client);
799 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
800 Client->id, Client->user, Client_ID(Client->introducer));
802 } /* Client_MaskCloaked */
806 Client_Introducer( CLIENT *Client )
808 assert( Client != NULL );
809 return Client->introducer;
810 } /* Client_Introducer */
814 Client_TopServer( CLIENT *Client )
816 assert( Client != NULL );
817 return Client->topserver;
818 } /* Client_TopServer */
822 Client_HasMode( CLIENT *Client, char Mode )
824 assert( Client != NULL );
825 return strchr( Client->modes, Mode ) != NULL;
826 } /* Client_HasMode */
830 Client_Away( CLIENT *Client )
832 assert( Client != NULL );
838 Client_CheckNick( CLIENT *Client, char *Nick )
840 assert( Client != NULL );
841 assert( Nick != NULL );
843 if (! Client_IsValidNick( Nick ))
845 IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
849 /* Nick bereits vergeben? */
850 if( Client_Search( Nick ))
852 /* den Nick gibt es bereits */
853 IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
858 } /* Client_CheckNick */
862 Client_CheckID( CLIENT *Client, char *ID )
864 char str[COMMAND_LEN];
867 assert( Client != NULL );
868 assert( Client->conn_id > NONE );
869 assert( ID != NULL );
872 if (strlen(ID) > CLIENT_ID_LEN) {
873 IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID);
877 /* ID already in use? */
880 if (strcasecmp(c->id, ID) == 0) {
881 snprintf(str, sizeof(str), "ID \"%s\" already registered", ID);
882 if (c->conn_id != NONE)
883 Log(LOG_ERR, "%s (on connection %d)!", str, c->conn_id);
885 Log(LOG_ERR, "%s (via network)!", str);
886 Conn_Close(Client->conn_id, str, str, true);
889 c = (CLIENT *)c->next;
893 } /* Client_CheckID */
904 Client_Next( CLIENT *c )
907 return (CLIENT *)c->next;
912 Client_UserCount( void )
914 return Count( CLIENT_USER );
915 } /* Client_UserCount */
919 Client_ServiceCount( void )
921 return Count( CLIENT_SERVICE );;
922 } /* Client_ServiceCount */
926 Client_ServerCount( void )
928 return Count( CLIENT_SERVER );
929 } /* Client_ServerCount */
933 Client_MyUserCount( void )
935 return MyCount( CLIENT_USER );
936 } /* Client_MyUserCount */
940 Client_MyServiceCount( void )
942 return MyCount( CLIENT_SERVICE );
943 } /* Client_MyServiceCount */
947 Client_MyServerCount( void )
950 unsigned long cnt = 0;
955 if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
956 c = (CLIENT *)c->next;
959 } /* Client_MyServerCount */
963 Client_OperCount( void )
966 unsigned long cnt = 0;
971 if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
972 c = (CLIENT *)c->next;
975 } /* Client_OperCount */
979 Client_UnknownCount( void )
982 unsigned long cnt = 0;
987 if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
988 c = (CLIENT *)c->next;
992 } /* Client_UnknownCount */
996 Client_MaxUserCount( void )
999 } /* Client_MaxUserCount */
1003 Client_MyMaxUserCount( void )
1005 return My_Max_Users;
1006 } /* Client_MyMaxUserCount */
1010 Client_IsValidNick( const char *Nick )
1013 static const char goodchars[] = ";0123456789-";
1015 assert( Nick != NULL );
1017 if( Nick[0] == '#' ) return false;
1018 if( strchr( goodchars, Nick[0] )) return false;
1019 if( strlen( Nick ) >= Conf_MaxNickLength) return false;
1024 if (( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return false;
1025 if ( *ptr > '}' ) return false;
1030 } /* Client_IsValidNick */
1034 * Return pointer to "My_Whowas" structure.
1037 Client_GetWhowas( void )
1040 } /* Client_GetWhowas */
1043 * Return the index of the last used WHOWAS entry.
1046 Client_GetLastWhowasIndex( void )
1049 } /* Client_GetLastWhowasIndex */
1053 * Get the start time of this client.
1054 * The result is the start time in seconds since 1970-01-01, as reported
1055 * by the C function time(NULL).
1058 Client_StartTime(CLIENT *Client)
1060 assert( Client != NULL );
1061 return Client->starttime;
1062 } /* Client_Uptime */
1065 static unsigned long
1066 Count( CLIENT_TYPE Type )
1069 unsigned long cnt = 0;
1074 if( c->type == Type ) cnt++;
1075 c = (CLIENT *)c->next;
1081 static unsigned long
1082 MyCount( CLIENT_TYPE Type )
1085 unsigned long cnt = 0;
1090 if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
1091 c = (CLIENT *)c->next;
1098 New_Client_Struct( void )
1100 /* Neue CLIENT-Struktur pre-initialisieren */
1104 c = (CLIENT *)malloc( sizeof( CLIENT ));
1107 Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
1111 memset( c, 0, sizeof ( CLIENT ));
1113 c->type = CLIENT_UNKNOWN;
1115 c->oper_by_me = false;
1125 Generate_MyToken( CLIENT *Client )
1134 if( c->mytoken == token )
1136 /* Das Token wurde bereits vergeben */
1141 else c = (CLIENT *)c->next;
1143 Client->mytoken = token;
1144 LogDebug("Assigned token %d to server \"%s\".", token, Client->id);
1145 } /* Generate_MyToken */
1149 Adjust_Counters( CLIENT *Client )
1153 assert( Client != NULL );
1155 if( Client->type != CLIENT_USER ) return;
1157 if( Client->conn_id != NONE )
1159 /* Local connection */
1160 count = Client_MyUserCount( );
1161 if( count > My_Max_Users ) My_Max_Users = count;
1163 count = Client_UserCount( );
1164 if( count > Max_Users ) Max_Users = count;
1165 } /* Adjust_Counters */
1169 * Register client in My_Whowas structure for further recall by WHOWAS.
1170 * Note: Only clients that have been connected at least 30 seconds will be
1171 * registered to prevent automated IRC bots to "destroy" a nice server
1175 Client_RegisterWhowas( CLIENT *Client )
1180 assert( Client != NULL );
1183 /* Don't register clients that were connected less than 30 seconds. */
1184 if( now - Client->starttime < 30 )
1187 slot = Last_Whowas + 1;
1188 if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;
1191 Log( LOG_DEBUG, "Saving WHOWAS information to slot %d ...", slot );
1194 My_Whowas[slot].time = now;
1195 strlcpy( My_Whowas[slot].id, Client_ID( Client ),
1196 sizeof( My_Whowas[slot].id ));
1197 strlcpy( My_Whowas[slot].user, Client_User( Client ),
1198 sizeof( My_Whowas[slot].user ));
1199 strlcpy( My_Whowas[slot].host, Client_HostnameCloaked( Client ),
1200 sizeof( My_Whowas[slot].host ));
1201 strlcpy( My_Whowas[slot].info, Client_Info( Client ),
1202 sizeof( My_Whowas[slot].info ));
1203 strlcpy( My_Whowas[slot].server, Client_ID( Client_Introducer( Client )),
1204 sizeof( My_Whowas[slot].server ));
1207 } /* Client_RegisterWhowas */
1211 Client_TypeText(CLIENT *Client)
1213 assert(Client != NULL);
1214 switch (Client_Type(Client)) {
1218 case CLIENT_SERVICE:
1227 } /* Client_TypeText */
1231 * Destroy user or service client.
1234 Destroy_UserOrService(CLIENT *Client, const char *Txt, const char *FwdMsg, bool SendQuit)
1236 if(Client->conn_id != NONE) {
1237 /* Local (directly connected) client */
1239 "%s \"%s\" unregistered (connection %d): %s",
1240 Client_TypeText(Client), Client_Mask(Client),
1241 Client->conn_id, Txt);
1242 Log_ServerNotice('c', "Client exiting: %s (%s@%s) [%s]",
1243 Client_ID(Client), Client_User(Client),
1244 Client_Hostname(Client), Txt);
1247 /* Inforam all the other servers */
1249 IRC_WriteStrServersPrefix(NULL,
1250 Client, "QUIT :%s", FwdMsg );
1252 IRC_WriteStrServersPrefix(NULL,
1257 LogDebug("%s \"%s\" unregistered: %s",
1258 Client_TypeText(Client), Client_Mask(Client), Txt);
1261 /* Inform all the other servers, but the ones in the
1262 * direction we got the QUIT from */
1264 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1265 Client, "QUIT :%s", FwdMsg );
1267 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1272 /* Unregister client from channels */
1273 Channel_Quit(Client, FwdMsg ? FwdMsg : Client->id);
1275 /* Register client in My_Whowas structure */
1276 Client_RegisterWhowas(Client);
1277 } /* Destroy_UserOrService */
1283 Client_DebugDump(void)
1287 Log(LOG_DEBUG, "Client status:");
1291 " - %s: type=%d, host=%s, user=%s, conn=%d, start=%ld, flags=%s",
1292 Client_ID(c), Client_Type(c), Client_Hostname(c),
1293 Client_User(c), Client_Conn(c), Client_StartTime(c),
1295 c = (CLIENT *)c->next;
1297 } /* Client_DumpClients */