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 if (strlen(Conf_ClientHost)) {
323 strlcpy( Client->host, Conf_ClientHost, sizeof( Client->host ));
325 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 ));
338 if (Conf_ClientUserNick)
339 strlcpy( Client->user, ID, sizeof( Client->user ));
342 Client->hash = Hash( Client->id );
347 Client_SetUser( CLIENT *Client, const char *User, bool Idented )
349 /* set clients username */
351 assert( Client != NULL );
352 assert( User != NULL );
354 if (Conf_ClientUserNick) return;
357 strlcpy(Client->user, User, sizeof(Client->user));
359 Client->user[0] = '~';
360 strlcpy(Client->user + 1, User, sizeof(Client->user) - 1);
362 } /* Client_SetUser */
366 * Set "original" user name of a client.
367 * This function saves the "original" user name, the user name specified by
368 * the peer using the USER command, into the CLIENT structure. This user
369 * name may be used for authentication, for example.
370 * @param Client The client.
371 * @param User User name to set.
374 Client_SetOrigUser(CLIENT UNUSED *Client, const char UNUSED *User)
376 assert(Client != NULL);
377 assert(User != NULL);
379 #if defined(PAM) && defined(IDENTAUTH)
380 strlcpy(Client->orig_user, User, sizeof(Client->orig_user));
382 } /* Client_SetOrigUser */
386 Client_SetInfo( CLIENT *Client, const char *Info )
388 /* set client hostname */
390 assert( Client != NULL );
391 assert( Info != NULL );
393 strlcpy(Client->info, Info, sizeof(Client->info));
394 } /* Client_SetInfo */
398 Client_SetModes( CLIENT *Client, const char *Modes )
400 assert( Client != NULL );
401 assert( Modes != NULL );
403 strlcpy(Client->modes, Modes, sizeof( Client->modes ));
404 } /* Client_SetModes */
408 Client_SetFlags( CLIENT *Client, const char *Flags )
410 assert( Client != NULL );
411 assert( Flags != NULL );
413 strlcpy(Client->flags, Flags, sizeof(Client->flags));
414 } /* Client_SetFlags */
418 Client_SetPassword( CLIENT *Client, const char *Pwd )
420 /* set password sent by client */
422 assert( Client != NULL );
423 assert( Pwd != NULL );
425 strlcpy(Client->pwd, Pwd, sizeof(Client->pwd));
426 } /* Client_SetPassword */
430 Client_SetAway( CLIENT *Client, const char *Txt )
432 /* Set AWAY reason of client */
434 assert( Client != NULL );
435 assert( Txt != NULL );
437 strlcpy( Client->away, Txt, sizeof( Client->away ));
438 LogDebug("%s \"%s\" is away: %s", Client_TypeText(Client),
439 Client_Mask(Client), Txt);
440 } /* Client_SetAway */
444 Client_SetType( CLIENT *Client, int Type )
446 assert( Client != NULL );
448 if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
449 Adjust_Counters( Client );
450 } /* Client_SetType */
454 Client_SetHops( CLIENT *Client, int Hops )
456 assert( Client != NULL );
458 } /* Client_SetHops */
462 Client_SetToken( CLIENT *Client, int Token )
464 assert( Client != NULL );
465 Client->token = Token;
466 } /* Client_SetToken */
470 Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
472 assert( Client != NULL );
473 assert( Introducer != NULL );
474 Client->introducer = Introducer;
475 } /* Client_SetIntroducer */
479 Client_SetOperByMe( CLIENT *Client, bool OperByMe )
481 assert( Client != NULL );
482 Client->oper_by_me = OperByMe;
483 } /* Client_SetOperByMe */
487 Client_ModeAdd( CLIENT *Client, char Mode )
490 * If Client already alread had Mode, return false.
491 * If the Mode was newly set, return true.
496 assert( Client != NULL );
498 x[0] = Mode; x[1] = '\0';
499 if (!strchr( Client->modes, x[0])) {
500 strlcat( Client->modes, x, sizeof( Client->modes ));
504 } /* Client_ModeAdd */
508 Client_ModeDel( CLIENT *Client, char Mode )
511 * If Mode was removed, return true.
512 * If Client did not have Mode, return false.
517 assert( Client != NULL );
519 x[0] = Mode; x[1] = '\0';
521 p = strchr( Client->modes, x[0] );
522 if( ! p ) return false;
524 /* Client has Mode -> delete */
531 } /* Client_ModeDel */
535 Client_Search( const char *Nick )
537 /* return Client-Structure that has the corresponding Nick.
538 * If none is found, return NULL.
541 char search_id[CLIENT_ID_LEN], *ptr;
545 assert( Nick != NULL );
547 /* copy Nick and truncate hostmask if necessary */
548 strlcpy( search_id, Nick, sizeof( search_id ));
549 ptr = strchr( search_id, '!' );
550 if( ptr ) *ptr = '\0';
552 search_hash = Hash(search_id);
556 if (c->hash == search_hash && strcasecmp(c->id, search_id) == 0)
558 c = (CLIENT *)c->next;
561 } /* Client_Search */
565 * Get client structure ("introducer") identfied by a server token.
566 * @return CLIENT structure or NULL if none could be found.
569 Client_GetFromToken( CLIENT *Client, int Token )
573 assert( Client != NULL );
580 if ((c->type == CLIENT_SERVER) && (c->introducer == Client) &&
583 c = (CLIENT *)c->next;
586 } /* Client_GetFromToken */
590 Client_Type( CLIENT *Client )
592 assert( Client != NULL );
598 Client_Conn( CLIENT *Client )
600 assert( Client != NULL );
601 return Client->conn_id;
606 Client_ID( CLIENT *Client )
608 assert( Client != NULL );
611 if(Client->type == CLIENT_USER)
612 assert(strlen(Client->id) < Conf_MaxNickLength);
615 if( Client->id[0] ) return Client->id;
621 Client_Info( CLIENT *Client )
623 assert( Client != NULL );
629 Client_User( CLIENT *Client )
631 assert( Client != NULL );
632 return Client->user[0] ? Client->user : "~";
639 * Get the "original" user name as supplied by the USER command.
640 * The user name as given by the client is used for authentication instead
641 * of the one detected using IDENT requests.
642 * @param Client The client.
643 * @return Original user name.
646 Client_OrigUser(CLIENT *Client) {
648 char *user = Client->user;
654 return Client->orig_user;
656 } /* Client_OrigUser */
662 * Return the hostname of a client.
663 * @param Client Pointer to client structure
664 * @return Pointer to client hostname
667 Client_Hostname(CLIENT *Client)
669 assert (Client != NULL);
671 } /* Client_Hostname */
675 * Get potentially cloaked hostname of a client.
676 * If the client has not enabled cloaking, the real hostname is used.
677 * @param Client Pointer to client structure
678 * @return Pointer to client hostname
681 Client_HostnameCloaked(CLIENT *Client)
683 assert(Client != NULL);
684 if (Client_HasMode(Client, 'x'))
685 return Client_ID(Client->introducer);
687 return Client_Hostname(Client);
688 } /* Client_HostnameCloaked */
692 Client_Password( CLIENT *Client )
694 assert( Client != NULL );
696 } /* Client_Password */
700 Client_Modes( CLIENT *Client )
702 assert( Client != NULL );
703 return Client->modes;
708 Client_Flags( CLIENT *Client )
710 assert( Client != NULL );
711 return Client->flags;
716 Client_OperByMe( CLIENT *Client )
718 assert( Client != NULL );
719 return Client->oper_by_me;
720 } /* Client_OperByMe */
724 Client_Hops( CLIENT *Client )
726 assert( Client != NULL );
732 Client_Token( CLIENT *Client )
734 assert( Client != NULL );
735 return Client->token;
740 Client_MyToken( CLIENT *Client )
742 assert( Client != NULL );
743 return Client->mytoken;
744 } /* Client_MyToken */
748 Client_NextHop( CLIENT *Client )
752 assert( Client != NULL );
755 while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server ))
759 } /* Client_NextHop */
763 * Return ID of a client: "client!user@host"
764 * This client ID is used for IRC prefixes, for example.
765 * Please note that this function uses a global static buffer, so you can't
766 * nest invocations without overwriting erlier results!
767 * @param Client Pointer to client structure
768 * @return Pointer to global buffer containing the client ID
771 Client_Mask( CLIENT *Client )
773 static char Mask_Buffer[GETID_LEN];
775 assert (Client != NULL);
777 /* Servers: return name only, there is no "mask" */
778 if (Client->type == CLIENT_SERVER)
781 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
782 Client->id, Client->user, Client->host);
788 * Return ID of a client with cloaked hostname: "client!user@server-name"
789 * This client ID is used for IRC prefixes, for example.
790 * Please note that this function uses a global static buffer, so you can't
791 * nest invocations without overwriting erlier results!
792 * If the client has not enabled cloaking, the real hostname is used.
793 * @param Client Pointer to client structure
794 * @return Pointer to global buffer containing the client ID
797 Client_MaskCloaked(CLIENT *Client)
799 static char Mask_Buffer[GETID_LEN];
801 assert (Client != NULL);
803 /* Is the client using cloaking at all? */
804 if (!Client_HasMode(Client, 'x'))
805 return Client_Mask(Client);
807 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
808 Client->id, Client->user, Client_ID(Client->introducer));
810 } /* Client_MaskCloaked */
814 Client_Introducer( CLIENT *Client )
816 assert( Client != NULL );
817 return Client->introducer;
818 } /* Client_Introducer */
822 Client_TopServer( CLIENT *Client )
824 assert( Client != NULL );
825 return Client->topserver;
826 } /* Client_TopServer */
830 Client_HasMode( CLIENT *Client, char Mode )
832 assert( Client != NULL );
833 return strchr( Client->modes, Mode ) != NULL;
834 } /* Client_HasMode */
838 Client_Away( CLIENT *Client )
840 assert( Client != NULL );
846 Client_CheckNick( CLIENT *Client, char *Nick )
848 assert( Client != NULL );
849 assert( Nick != NULL );
851 if (! Client_IsValidNick( Nick ))
853 IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
857 /* Nick bereits vergeben? */
858 if( Client_Search( Nick ))
860 /* den Nick gibt es bereits */
861 IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
866 } /* Client_CheckNick */
870 Client_CheckID( CLIENT *Client, char *ID )
872 char str[COMMAND_LEN];
875 assert( Client != NULL );
876 assert( Client->conn_id > NONE );
877 assert( ID != NULL );
880 if (strlen(ID) > CLIENT_ID_LEN) {
881 IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID);
885 /* ID already in use? */
888 if (strcasecmp(c->id, ID) == 0) {
889 snprintf(str, sizeof(str), "ID \"%s\" already registered", ID);
890 if (c->conn_id != NONE)
891 Log(LOG_ERR, "%s (on connection %d)!", str, c->conn_id);
893 Log(LOG_ERR, "%s (via network)!", str);
894 Conn_Close(Client->conn_id, str, str, true);
897 c = (CLIENT *)c->next;
901 } /* Client_CheckID */
912 Client_Next( CLIENT *c )
915 return (CLIENT *)c->next;
920 Client_UserCount( void )
922 return Count( CLIENT_USER );
923 } /* Client_UserCount */
927 Client_ServiceCount( void )
929 return Count( CLIENT_SERVICE );;
930 } /* Client_ServiceCount */
934 Client_ServerCount( void )
936 return Count( CLIENT_SERVER );
937 } /* Client_ServerCount */
941 Client_MyUserCount( void )
943 return MyCount( CLIENT_USER );
944 } /* Client_MyUserCount */
948 Client_MyServiceCount( void )
950 return MyCount( CLIENT_SERVICE );
951 } /* Client_MyServiceCount */
955 Client_MyServerCount( void )
958 unsigned long cnt = 0;
963 if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
964 c = (CLIENT *)c->next;
967 } /* Client_MyServerCount */
971 Client_OperCount( void )
974 unsigned long cnt = 0;
979 if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
980 c = (CLIENT *)c->next;
983 } /* Client_OperCount */
987 Client_UnknownCount( void )
990 unsigned long cnt = 0;
995 if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
996 c = (CLIENT *)c->next;
1000 } /* Client_UnknownCount */
1004 Client_MaxUserCount( void )
1007 } /* Client_MaxUserCount */
1011 Client_MyMaxUserCount( void )
1013 return My_Max_Users;
1014 } /* Client_MyMaxUserCount */
1018 Client_IsValidNick( const char *Nick )
1021 static const char goodchars[] = ";0123456789-";
1023 assert( Nick != NULL );
1025 if( Nick[0] == '#' ) return false;
1026 if( strchr( goodchars, Nick[0] )) return false;
1027 if( strlen( Nick ) >= Conf_MaxNickLength) return false;
1032 if (( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return false;
1033 if ( *ptr > '}' ) return false;
1038 } /* Client_IsValidNick */
1042 * Return pointer to "My_Whowas" structure.
1045 Client_GetWhowas( void )
1048 } /* Client_GetWhowas */
1051 * Return the index of the last used WHOWAS entry.
1054 Client_GetLastWhowasIndex( void )
1057 } /* Client_GetLastWhowasIndex */
1061 * Get the start time of this client.
1062 * The result is the start time in seconds since 1970-01-01, as reported
1063 * by the C function time(NULL).
1066 Client_StartTime(CLIENT *Client)
1068 assert( Client != NULL );
1069 return Client->starttime;
1070 } /* Client_Uptime */
1073 static unsigned long
1074 Count( CLIENT_TYPE Type )
1077 unsigned long cnt = 0;
1082 if( c->type == Type ) cnt++;
1083 c = (CLIENT *)c->next;
1089 static unsigned long
1090 MyCount( CLIENT_TYPE Type )
1093 unsigned long cnt = 0;
1098 if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
1099 c = (CLIENT *)c->next;
1106 New_Client_Struct( void )
1108 /* Neue CLIENT-Struktur pre-initialisieren */
1112 c = (CLIENT *)malloc( sizeof( CLIENT ));
1115 Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
1119 memset( c, 0, sizeof ( CLIENT ));
1121 c->type = CLIENT_UNKNOWN;
1123 c->oper_by_me = false;
1133 Generate_MyToken( CLIENT *Client )
1142 if( c->mytoken == token )
1144 /* Das Token wurde bereits vergeben */
1149 else c = (CLIENT *)c->next;
1151 Client->mytoken = token;
1152 LogDebug("Assigned token %d to server \"%s\".", token, Client->id);
1153 } /* Generate_MyToken */
1157 Adjust_Counters( CLIENT *Client )
1161 assert( Client != NULL );
1163 if( Client->type != CLIENT_USER ) return;
1165 if( Client->conn_id != NONE )
1167 /* Local connection */
1168 count = Client_MyUserCount( );
1169 if( count > My_Max_Users ) My_Max_Users = count;
1171 count = Client_UserCount( );
1172 if( count > Max_Users ) Max_Users = count;
1173 } /* Adjust_Counters */
1177 * Register client in My_Whowas structure for further recall by WHOWAS.
1178 * Note: Only clients that have been connected at least 30 seconds will be
1179 * registered to prevent automated IRC bots to "destroy" a nice server
1183 Client_RegisterWhowas( CLIENT *Client )
1188 assert( Client != NULL );
1191 /* Don't register clients that were connected less than 30 seconds. */
1192 if( now - Client->starttime < 30 )
1195 slot = Last_Whowas + 1;
1196 if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;
1199 Log( LOG_DEBUG, "Saving WHOWAS information to slot %d ...", slot );
1202 My_Whowas[slot].time = now;
1203 strlcpy( My_Whowas[slot].id, Client_ID( Client ),
1204 sizeof( My_Whowas[slot].id ));
1205 strlcpy( My_Whowas[slot].user, Client_User( Client ),
1206 sizeof( My_Whowas[slot].user ));
1207 strlcpy( My_Whowas[slot].host, Client_HostnameCloaked( Client ),
1208 sizeof( My_Whowas[slot].host ));
1209 strlcpy( My_Whowas[slot].info, Client_Info( Client ),
1210 sizeof( My_Whowas[slot].info ));
1211 strlcpy( My_Whowas[slot].server, Client_ID( Client_Introducer( Client )),
1212 sizeof( My_Whowas[slot].server ));
1215 } /* Client_RegisterWhowas */
1219 Client_TypeText(CLIENT *Client)
1221 assert(Client != NULL);
1222 switch (Client_Type(Client)) {
1226 case CLIENT_SERVICE:
1235 } /* Client_TypeText */
1239 * Destroy user or service client.
1242 Destroy_UserOrService(CLIENT *Client, const char *Txt, const char *FwdMsg, bool SendQuit)
1244 if(Client->conn_id != NONE) {
1245 /* Local (directly connected) client */
1247 "%s \"%s\" unregistered (connection %d): %s",
1248 Client_TypeText(Client), Client_Mask(Client),
1249 Client->conn_id, Txt);
1250 Log_ServerNotice('c', "Client exiting: %s (%s@%s) [%s]",
1251 Client_ID(Client), Client_User(Client),
1252 Client_Hostname(Client), Txt);
1255 /* Inforam all the other servers */
1257 IRC_WriteStrServersPrefix(NULL,
1258 Client, "QUIT :%s", FwdMsg );
1260 IRC_WriteStrServersPrefix(NULL,
1265 LogDebug("%s \"%s\" unregistered: %s",
1266 Client_TypeText(Client), Client_Mask(Client), Txt);
1269 /* Inform all the other servers, but the ones in the
1270 * direction we got the QUIT from */
1272 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1273 Client, "QUIT :%s", FwdMsg );
1275 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1280 /* Unregister client from channels */
1281 Channel_Quit(Client, FwdMsg ? FwdMsg : Client->id);
1283 /* Register client in My_Whowas structure */
1284 Client_RegisterWhowas(Client);
1285 } /* Destroy_UserOrService */
1291 Client_DebugDump(void)
1295 Log(LOG_DEBUG, "Client status:");
1299 " - %s: type=%d, host=%s, user=%s, conn=%d, start=%ld, flags=%s",
1300 Client_ID(c), Client_Type(c), Client_Hostname(c),
1301 Client_User(c), Client_Conn(c), Client_StartTime(c),
1303 c = (CLIENT *)c->next;
1305 } /* Client_DumpClients */