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.
41 #include "irc-write.h"
47 #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
49 static CLIENT *This_Server, *My_Clients;
51 static WHOWAS My_Whowas[MAX_WHOWAS];
52 static int Last_Whowas = -1;
53 static long Max_Users, My_Max_Users;
56 static unsigned long Count PARAMS(( CLIENT_TYPE Type ));
57 static unsigned long MyCount PARAMS(( CLIENT_TYPE Type ));
59 static CLIENT *New_Client_Struct PARAMS(( void ));
60 static void Generate_MyToken PARAMS(( CLIENT *Client ));
61 static void Adjust_Counters PARAMS(( CLIENT *Client ));
63 static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer,
64 CLIENT *TopServer, int Type, const char *ID,
65 const char *User, const char *Hostname, const char *Info,
66 int Hops, int Token, const char *Modes,
69 static void Destroy_UserOrService PARAMS((CLIENT *Client,const char *Txt, const char *FwdMsg,
78 This_Server = New_Client_Struct( );
81 Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
82 Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE_NAME );
86 /* Client-Struktur dieses Servers */
87 This_Server->next = NULL;
88 This_Server->type = CLIENT_SERVER;
89 This_Server->conn_id = NONE;
90 This_Server->introducer = This_Server;
91 This_Server->mytoken = 1;
92 This_Server->hops = 0;
94 gethostname( This_Server->host, CLIENT_HOST_LEN );
96 h = gethostbyname( This_Server->host );
97 if (h) strlcpy(This_Server->host, h->h_name, sizeof(This_Server->host));
99 Client_SetID( This_Server, Conf_ServerName );
100 Client_SetInfo( This_Server, Conf_ServerInfo );
102 My_Clients = This_Server;
104 memset( &My_Whowas, 0, sizeof( My_Whowas ));
114 if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, false );
115 else Client_Destroy( This_Server, "Server going down.", NULL, false );
122 next = (CLIENT *)c->next;
126 if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
131 Client_ThisServer( void )
134 } /* Client_ThisServer */
138 * Initialize new local client; wrapper function for Init_New_Client().
139 * @return New CLIENT structure.
142 Client_NewLocal(CONN_ID Idx, const char *Hostname, int Type, bool Idented)
144 return Init_New_Client(Idx, This_Server, NULL, Type, NULL, NULL,
145 Hostname, NULL, 0, 0, NULL, Idented);
146 } /* Client_NewLocal */
150 * Initialize new remote server; wrapper function for Init_New_Client().
151 * @return New CLIENT structure.
154 Client_NewRemoteServer(CLIENT *Introducer, const char *Hostname, CLIENT *TopServer,
155 int Hops, int Token, const char *Info, bool Idented)
157 return Init_New_Client(NONE, Introducer, TopServer, CLIENT_SERVER,
158 Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented);
159 } /* Client_NewRemoteServer */
163 * Initialize new remote client; wrapper function for Init_New_Client().
164 * @return New CLIENT structure.
167 Client_NewRemoteUser(CLIENT *Introducer, const char *Nick, int Hops, const char *User,
168 const char *Hostname, int Token, const char *Modes, const char *Info, bool Idented)
170 return Init_New_Client(NONE, Introducer, NULL, CLIENT_USER, Nick,
171 User, Hostname, Info, Hops, Token, Modes, Idented);
172 } /* Client_NewRemoteUser */
176 * Initialize new client and set up the given parameters like client type,
177 * user name, host name, introducing server etc. ...
178 * @return New CLIENT structure.
181 Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
182 int Type, const char *ID, const char *User, const char *Hostname,
183 const char *Info, int Hops, int Token, const char *Modes, bool Idented)
188 assert(Introducer != NULL);
189 assert(Hostname != NULL);
191 client = New_Client_Struct();
195 client->starttime = time(NULL);
196 client->conn_id = Idx;
197 client->introducer = Introducer;
198 client->topserver = TopServer;
201 Client_SetID(client, ID);
203 Client_SetUser(client, User, Idented);
204 Client_SetOrigUser(client, User);
207 Client_SetHostname(client, Hostname);
209 Client_SetInfo(client, Info);
211 client->token = Token;
213 Client_SetModes(client, Modes);
214 if (Type == CLIENT_SERVER)
215 Generate_MyToken(client);
217 if (strchr(client->modes, 'a'))
218 strlcpy(client->away, DEFAULT_AWAY_MSG, sizeof(client->away));
220 client->next = (POINTER *)My_Clients;
223 Adjust_Counters(client);
226 } /* Init_New_Client */
230 Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit )
232 /* remove a client */
238 assert( Client != NULL );
240 if( LogMsg ) txt = LogMsg;
242 if( ! txt ) txt = "Reason unknown.";
244 /* netsplit message */
245 if( Client->type == CLIENT_SERVER ) {
246 strlcpy(msg, This_Server->id, sizeof (msg));
247 strlcat(msg, " ", sizeof (msg));
248 strlcat(msg, Client->id, sizeof (msg));
255 if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client ))
258 * The client that is about to be removed is a server,
259 * the client we are checking right now is a child of that
260 * server and thus has to be removed, too.
262 * Call Client_Destroy() recursively with the server as the
263 * new "object to be removed". This starts the cycle again, until
264 * all servers that are linked via the original server have been
267 Client_Destroy( c, NULL, msg, false );
274 /* found the client: remove it */
275 if( last ) last->next = c->next;
276 else My_Clients = (CLIENT *)c->next;
278 if(c->type == CLIENT_USER || c->type == CLIENT_SERVICE)
279 Destroy_UserOrService(c, txt, FwdMsg, SendQuit);
280 else if( c->type == CLIENT_SERVER )
282 if( c != This_Server )
284 if( c->conn_id != NONE ) Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
285 else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt );
288 /* inform other servers */
289 if( ! NGIRCd_SignalQuit )
291 if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
292 else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
297 if( c->conn_id != NONE )
299 if( c->id[0] ) Log( LOG_NOTICE, "Client \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt );
300 else Log( LOG_NOTICE, "Client unregistered (connection %d): %s", c->conn_id, txt );
302 Log(LOG_WARNING, "Unregistered unknown client \"%s\": %s",
303 c->id[0] ? c->id : "(No Nick)", txt );
311 c = (CLIENT *)c->next;
313 } /* Client_Destroy */
317 Client_SetHostname( CLIENT *Client, const char *Hostname )
319 assert( Client != NULL );
320 assert( Hostname != NULL );
322 strlcpy( Client->host, Hostname, sizeof( Client->host ));
323 } /* Client_SetHostname */
327 Client_SetID( CLIENT *Client, const char *ID )
329 assert( Client != NULL );
330 assert( ID != NULL );
332 strlcpy( Client->id, ID, sizeof( Client->id ));
335 Client->hash = Hash( Client->id );
340 Client_SetUser( CLIENT *Client, const char *User, bool Idented )
342 /* set clients username */
344 assert( Client != NULL );
345 assert( User != NULL );
348 strlcpy(Client->user, User, sizeof(Client->user));
350 Client->user[0] = '~';
351 strlcpy(Client->user + 1, User, sizeof(Client->user) - 1);
353 } /* Client_SetUser */
357 * Set "original" user name of a client.
358 * This function saves the "original" user name, the user name specified by
359 * the peer using the USER command, into the CLIENT structure. This user
360 * name may be used for authentication, for example.
361 * @param Client The client.
362 * @param User User name to set.
365 Client_SetOrigUser(CLIENT UNUSED *Client, const char UNUSED *User)
367 assert(Client != NULL);
368 assert(User != NULL);
370 #if defined(PAM) && defined(IDENTAUTH)
371 strlcpy(Client->orig_user, User, sizeof(Client->orig_user));
373 } /* Client_SetOrigUser */
377 Client_SetInfo( CLIENT *Client, const char *Info )
379 /* set client hostname */
381 assert( Client != NULL );
382 assert( Info != NULL );
384 strlcpy(Client->info, Info, sizeof(Client->info));
385 } /* Client_SetInfo */
389 Client_SetModes( CLIENT *Client, const char *Modes )
391 assert( Client != NULL );
392 assert( Modes != NULL );
394 strlcpy(Client->modes, Modes, sizeof( Client->modes ));
395 } /* Client_SetModes */
399 Client_SetFlags( CLIENT *Client, const char *Flags )
401 assert( Client != NULL );
402 assert( Flags != NULL );
404 strlcpy(Client->flags, Flags, sizeof(Client->flags));
405 } /* Client_SetFlags */
409 Client_SetPassword( CLIENT *Client, const char *Pwd )
411 /* set password sent by client */
413 assert( Client != NULL );
414 assert( Pwd != NULL );
416 strlcpy(Client->pwd, Pwd, sizeof(Client->pwd));
417 } /* Client_SetPassword */
421 Client_SetAway( CLIENT *Client, const char *Txt )
423 /* Set AWAY reason of client */
425 assert( Client != NULL );
426 assert( Txt != NULL );
428 strlcpy( Client->away, Txt, sizeof( Client->away ));
429 LogDebug("%s \"%s\" is away: %s", Client_TypeText(Client),
430 Client_Mask(Client), Txt);
431 } /* Client_SetAway */
435 Client_SetType( CLIENT *Client, int Type )
437 assert( Client != NULL );
439 if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
440 Adjust_Counters( Client );
441 } /* Client_SetType */
445 Client_SetHops( CLIENT *Client, int Hops )
447 assert( Client != NULL );
449 } /* Client_SetHops */
453 Client_SetToken( CLIENT *Client, int Token )
455 assert( Client != NULL );
456 Client->token = Token;
457 } /* Client_SetToken */
461 Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
463 assert( Client != NULL );
464 assert( Introducer != NULL );
465 Client->introducer = Introducer;
466 } /* Client_SetIntroducer */
470 Client_SetOperByMe( CLIENT *Client, bool OperByMe )
472 assert( Client != NULL );
473 Client->oper_by_me = OperByMe;
474 } /* Client_SetOperByMe */
478 Client_ModeAdd( CLIENT *Client, char Mode )
481 * If Client already alread had Mode, return false.
482 * If the Mode was newly set, return true.
487 assert( Client != NULL );
489 x[0] = Mode; x[1] = '\0';
490 if (!strchr( Client->modes, x[0])) {
491 strlcat( Client->modes, x, sizeof( Client->modes ));
495 } /* Client_ModeAdd */
499 Client_ModeDel( CLIENT *Client, char Mode )
502 * If Mode was removed, return true.
503 * If Client did not have Mode, return false.
508 assert( Client != NULL );
510 x[0] = Mode; x[1] = '\0';
512 p = strchr( Client->modes, x[0] );
513 if( ! p ) return false;
515 /* Client has Mode -> delete */
522 } /* Client_ModeDel */
526 Client_Search( const char *Nick )
528 /* return Client-Structure that has the corresponding Nick.
529 * If none is found, return NULL.
532 char search_id[CLIENT_ID_LEN], *ptr;
536 assert( Nick != NULL );
538 /* copy Nick and truncate hostmask if necessary */
539 strlcpy( search_id, Nick, sizeof( search_id ));
540 ptr = strchr( search_id, '!' );
541 if( ptr ) *ptr = '\0';
543 search_hash = Hash(search_id);
547 if (c->hash == search_hash && strcasecmp(c->id, search_id) == 0)
549 c = (CLIENT *)c->next;
552 } /* Client_Search */
556 * Get client structure ("introducer") identfied by a server token.
557 * @return CLIENT structure or NULL if none could be found.
560 Client_GetFromToken( CLIENT *Client, int Token )
564 assert( Client != NULL );
571 if ((c->type == CLIENT_SERVER) && (c->introducer == Client) &&
574 c = (CLIENT *)c->next;
577 } /* Client_GetFromToken */
581 Client_Type( CLIENT *Client )
583 assert( Client != NULL );
589 Client_Conn( CLIENT *Client )
591 assert( Client != NULL );
592 return Client->conn_id;
597 Client_ID( CLIENT *Client )
599 assert( Client != NULL );
602 if(Client->type == CLIENT_USER)
603 assert(strlen(Client->id) < Conf_MaxNickLength);
606 if( Client->id[0] ) return Client->id;
612 Client_Info( CLIENT *Client )
614 assert( Client != NULL );
620 Client_User( CLIENT *Client )
622 assert( Client != NULL );
623 return Client->user[0] ? Client->user : "~";
630 * Get the "original" user name as supplied by the USER command.
631 * The user name as given by the client is used for authentication instead
632 * of the one detected using IDENT requests.
633 * @param Client The client.
634 * @return Original user name.
637 Client_OrigUser(CLIENT *Client) {
639 char *user = Client->user;
645 return Client->orig_user;
647 } /* Client_OrigUser */
653 * Return the hostname of a client.
654 * @param Client Pointer to client structure
655 * @return Pointer to client hostname
658 Client_Hostname(CLIENT *Client)
660 assert (Client != NULL);
662 } /* Client_Hostname */
666 * Get potentially cloaked hostname of a client.
667 * If the client has not enabled cloaking, the real hostname is used.
668 * @param Client Pointer to client structure
669 * @return Pointer to client hostname
672 Client_HostnameCloaked(CLIENT *Client)
674 assert(Client != NULL);
675 if (Client_HasMode(Client, 'x'))
676 return Client_ID(Client->introducer);
678 return Client_Hostname(Client);
679 } /* Client_HostnameCloaked */
683 Client_Password( CLIENT *Client )
685 assert( Client != NULL );
687 } /* Client_Password */
691 Client_Modes( CLIENT *Client )
693 assert( Client != NULL );
694 return Client->modes;
699 Client_Flags( CLIENT *Client )
701 assert( Client != NULL );
702 return Client->flags;
707 Client_OperByMe( CLIENT *Client )
709 assert( Client != NULL );
710 return Client->oper_by_me;
711 } /* Client_OperByMe */
715 Client_Hops( CLIENT *Client )
717 assert( Client != NULL );
723 Client_Token( CLIENT *Client )
725 assert( Client != NULL );
726 return Client->token;
731 Client_MyToken( CLIENT *Client )
733 assert( Client != NULL );
734 return Client->mytoken;
735 } /* Client_MyToken */
739 Client_NextHop( CLIENT *Client )
743 assert( Client != NULL );
746 while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server ))
750 } /* Client_NextHop */
754 * Return ID of a client: "client!user@host"
755 * This client ID is used for IRC prefixes, for example.
756 * Please note that this function uses a global static buffer, so you can't
757 * nest invocations without overwriting erlier results!
758 * @param Client Pointer to client structure
759 * @return Pointer to global buffer containing the client ID
762 Client_Mask( CLIENT *Client )
764 static char Mask_Buffer[GETID_LEN];
766 assert (Client != NULL);
768 /* Servers: return name only, there is no "mask" */
769 if (Client->type == CLIENT_SERVER)
772 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
773 Client->id, Client->user, Client->host);
779 * Return ID of a client with cloaked hostname: "client!user@server-name"
780 * This client ID is used for IRC prefixes, for example.
781 * Please note that this function uses a global static buffer, so you can't
782 * nest invocations without overwriting erlier results!
783 * If the client has not enabled cloaking, the real hostname is used.
784 * @param Client Pointer to client structure
785 * @return Pointer to global buffer containing the client ID
788 Client_MaskCloaked(CLIENT *Client)
790 static char Mask_Buffer[GETID_LEN];
792 assert (Client != NULL);
794 /* Is the client using cloaking at all? */
795 if (!Client_HasMode(Client, 'x'))
796 return Client_Mask(Client);
798 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
799 Client->id, Client->user, Client_ID(Client->introducer));
801 } /* Client_MaskCloaked */
805 Client_Introducer( CLIENT *Client )
807 assert( Client != NULL );
808 return Client->introducer;
809 } /* Client_Introducer */
813 Client_TopServer( CLIENT *Client )
815 assert( Client != NULL );
816 return Client->topserver;
817 } /* Client_TopServer */
821 Client_HasMode( CLIENT *Client, char Mode )
823 assert( Client != NULL );
824 return strchr( Client->modes, Mode ) != NULL;
825 } /* Client_HasMode */
829 Client_Away( CLIENT *Client )
831 assert( Client != NULL );
837 Client_CheckNick( CLIENT *Client, char *Nick )
839 assert( Client != NULL );
840 assert( Nick != NULL );
842 if (! Client_IsValidNick( Nick ))
844 IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
848 /* Nick bereits vergeben? */
849 if( Client_Search( Nick ))
851 /* den Nick gibt es bereits */
852 IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
857 } /* Client_CheckNick */
861 Client_CheckID( CLIENT *Client, char *ID )
863 char str[COMMAND_LEN];
866 assert( Client != NULL );
867 assert( Client->conn_id > NONE );
868 assert( ID != NULL );
871 if (strlen(ID) > CLIENT_ID_LEN) {
872 IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID);
876 /* ID already in use? */
879 if (strcasecmp(c->id, ID) == 0) {
880 snprintf(str, sizeof(str), "ID \"%s\" already registered", ID);
881 if (c->conn_id != NONE)
882 Log(LOG_ERR, "%s (on connection %d)!", str, c->conn_id);
884 Log(LOG_ERR, "%s (via network)!", str);
885 Conn_Close(Client->conn_id, str, str, true);
888 c = (CLIENT *)c->next;
892 } /* Client_CheckID */
903 Client_Next( CLIENT *c )
906 return (CLIENT *)c->next;
911 Client_UserCount( void )
913 return Count( CLIENT_USER );
914 } /* Client_UserCount */
918 Client_ServiceCount( void )
920 return Count( CLIENT_SERVICE );;
921 } /* Client_ServiceCount */
925 Client_ServerCount( void )
927 return Count( CLIENT_SERVER );
928 } /* Client_ServerCount */
932 Client_MyUserCount( void )
934 return MyCount( CLIENT_USER );
935 } /* Client_MyUserCount */
939 Client_MyServiceCount( void )
941 return MyCount( CLIENT_SERVICE );
942 } /* Client_MyServiceCount */
946 Client_MyServerCount( void )
949 unsigned long cnt = 0;
954 if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
955 c = (CLIENT *)c->next;
958 } /* Client_MyServerCount */
962 Client_OperCount( void )
965 unsigned long cnt = 0;
970 if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
971 c = (CLIENT *)c->next;
974 } /* Client_OperCount */
978 Client_UnknownCount( void )
981 unsigned long cnt = 0;
986 if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
987 c = (CLIENT *)c->next;
991 } /* Client_UnknownCount */
995 Client_MaxUserCount( void )
998 } /* Client_MaxUserCount */
1002 Client_MyMaxUserCount( void )
1004 return My_Max_Users;
1005 } /* Client_MyMaxUserCount */
1009 Client_IsValidNick( const char *Nick )
1012 static const char goodchars[] = ";0123456789-";
1014 assert( Nick != NULL );
1016 if( Nick[0] == '#' ) return false;
1017 if( strchr( goodchars, Nick[0] )) return false;
1018 if( strlen( Nick ) >= Conf_MaxNickLength) return false;
1023 if (( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return false;
1024 if ( *ptr > '}' ) return false;
1029 } /* Client_IsValidNick */
1033 * Return pointer to "My_Whowas" structure.
1036 Client_GetWhowas( void )
1039 } /* Client_GetWhowas */
1042 * Return the index of the last used WHOWAS entry.
1045 Client_GetLastWhowasIndex( void )
1048 } /* Client_GetLastWhowasIndex */
1052 * Get the start time of this client.
1053 * The result is the start time in seconds since 1970-01-01, as reported
1054 * by the C function time(NULL).
1057 Client_StartTime(CLIENT *Client)
1059 assert( Client != NULL );
1060 return Client->starttime;
1061 } /* Client_Uptime */
1064 static unsigned long
1065 Count( CLIENT_TYPE Type )
1068 unsigned long cnt = 0;
1073 if( c->type == Type ) cnt++;
1074 c = (CLIENT *)c->next;
1080 static unsigned long
1081 MyCount( CLIENT_TYPE Type )
1084 unsigned long cnt = 0;
1089 if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
1090 c = (CLIENT *)c->next;
1097 New_Client_Struct( void )
1099 /* Neue CLIENT-Struktur pre-initialisieren */
1103 c = (CLIENT *)malloc( sizeof( CLIENT ));
1106 Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
1110 memset( c, 0, sizeof ( CLIENT ));
1112 c->type = CLIENT_UNKNOWN;
1114 c->oper_by_me = false;
1124 Generate_MyToken( CLIENT *Client )
1133 if( c->mytoken == token )
1135 /* Das Token wurde bereits vergeben */
1140 else c = (CLIENT *)c->next;
1142 Client->mytoken = token;
1143 LogDebug("Assigned token %d to server \"%s\".", token, Client->id);
1144 } /* Generate_MyToken */
1148 Adjust_Counters( CLIENT *Client )
1152 assert( Client != NULL );
1154 if( Client->type != CLIENT_USER ) return;
1156 if( Client->conn_id != NONE )
1158 /* Local connection */
1159 count = Client_MyUserCount( );
1160 if( count > My_Max_Users ) My_Max_Users = count;
1162 count = Client_UserCount( );
1163 if( count > Max_Users ) Max_Users = count;
1164 } /* Adjust_Counters */
1168 * Register client in My_Whowas structure for further recall by WHOWAS.
1169 * Note: Only clients that have been connected at least 30 seconds will be
1170 * registered to prevent automated IRC bots to "destroy" a nice server
1174 Client_RegisterWhowas( CLIENT *Client )
1179 assert( Client != NULL );
1182 /* Don't register clients that were connected less than 30 seconds. */
1183 if( now - Client->starttime < 30 )
1186 slot = Last_Whowas + 1;
1187 if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;
1190 Log( LOG_DEBUG, "Saving WHOWAS information to slot %d ...", slot );
1193 My_Whowas[slot].time = now;
1194 strlcpy( My_Whowas[slot].id, Client_ID( Client ),
1195 sizeof( My_Whowas[slot].id ));
1196 strlcpy( My_Whowas[slot].user, Client_User( Client ),
1197 sizeof( My_Whowas[slot].user ));
1198 strlcpy( My_Whowas[slot].host, Client_HostnameCloaked( Client ),
1199 sizeof( My_Whowas[slot].host ));
1200 strlcpy( My_Whowas[slot].info, Client_Info( Client ),
1201 sizeof( My_Whowas[slot].info ));
1202 strlcpy( My_Whowas[slot].server, Client_ID( Client_Introducer( Client )),
1203 sizeof( My_Whowas[slot].server ));
1206 } /* Client_RegisterWhowas */
1210 Client_TypeText(CLIENT *Client)
1212 assert(Client != NULL);
1213 switch (Client_Type(Client)) {
1217 case CLIENT_SERVICE:
1226 } /* Client_TypeText */
1230 * Destroy user or service client.
1233 Destroy_UserOrService(CLIENT *Client, const char *Txt, const char *FwdMsg, bool SendQuit)
1235 if(Client->conn_id != NONE) {
1236 /* Local (directly connected) client */
1238 "%s \"%s\" unregistered (connection %d): %s",
1239 Client_TypeText(Client), Client_Mask(Client),
1240 Client->conn_id, Txt);
1241 Log_ServerNotice('c', "Client exiting: %s (%s@%s) [%s]",
1242 Client_ID(Client), Client_User(Client),
1243 Client_Hostname(Client), Txt);
1246 /* Inforam all the other servers */
1248 IRC_WriteStrServersPrefix(NULL,
1249 Client, "QUIT :%s", FwdMsg );
1251 IRC_WriteStrServersPrefix(NULL,
1256 LogDebug("%s \"%s\" unregistered: %s",
1257 Client_TypeText(Client), Client_Mask(Client), Txt);
1260 /* Inform all the other servers, but the ones in the
1261 * direction we got the QUIT from */
1263 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1264 Client, "QUIT :%s", FwdMsg );
1266 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1271 /* Unregister client from channels */
1272 Channel_Quit(Client, FwdMsg ? FwdMsg : Client->id);
1274 /* Register client in My_Whowas structure */
1275 Client_RegisterWhowas(Client);
1276 } /* Destroy_UserOrService */
1282 Client_DebugDump(void)
1286 Log(LOG_DEBUG, "Client status:");
1290 " - %s: type=%d, host=%s, user=%s, conn=%d, start=%ld, flags=%s",
1291 Client_ID(c), Client_Type(c), Client_Hostname(c),
1292 Client_User(c), Client_Conn(c), Client_StartTime(c),
1294 c = (CLIENT *)c->next;
1296 } /* Client_DumpClients */