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_CloakHost)) {
323 strlcpy( Client->host, Conf_CloakHost, 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_CloakUserToNick) {
339 strlcpy( Client->user, ID, sizeof( Client->user ));
340 strlcpy( Client->info, ID, sizeof( Client->info ));
344 Client->hash = Hash( Client->id );
349 Client_SetUser( CLIENT *Client, const char *User, bool Idented )
351 /* set clients username */
353 assert( Client != NULL );
354 assert( User != NULL );
356 if (Conf_CloakUserToNick) {
357 strlcpy(Client->user, Client->id, sizeof(Client->user));
358 } else if (Idented) {
359 strlcpy(Client->user, User, sizeof(Client->user));
361 Client->user[0] = '~';
362 strlcpy(Client->user + 1, User, sizeof(Client->user) - 1);
364 } /* Client_SetUser */
368 * Set "original" user name of a client.
369 * This function saves the "original" user name, the user name specified by
370 * the peer using the USER command, into the CLIENT structure. This user
371 * name may be used for authentication, for example.
372 * @param Client The client.
373 * @param User User name to set.
376 Client_SetOrigUser(CLIENT UNUSED *Client, const char UNUSED *User)
378 assert(Client != NULL);
379 assert(User != NULL);
381 #if defined(PAM) && defined(IDENTAUTH)
382 strlcpy(Client->orig_user, User, sizeof(Client->orig_user));
384 } /* Client_SetOrigUser */
388 Client_SetInfo( CLIENT *Client, const char *Info )
390 /* set client hostname */
392 assert( Client != NULL );
393 assert( Info != NULL );
395 if (Conf_CloakUserToNick)
396 strlcpy(Client->info, Client->id, sizeof(Client->info));
398 strlcpy(Client->info, Info, sizeof(Client->info));
399 } /* Client_SetInfo */
403 Client_SetModes( CLIENT *Client, const char *Modes )
405 assert( Client != NULL );
406 assert( Modes != NULL );
408 strlcpy(Client->modes, Modes, sizeof( Client->modes ));
409 } /* Client_SetModes */
413 Client_SetFlags( CLIENT *Client, const char *Flags )
415 assert( Client != NULL );
416 assert( Flags != NULL );
418 strlcpy(Client->flags, Flags, sizeof(Client->flags));
419 } /* Client_SetFlags */
423 Client_SetPassword( CLIENT *Client, const char *Pwd )
425 /* set password sent by client */
427 assert( Client != NULL );
428 assert( Pwd != NULL );
430 strlcpy(Client->pwd, Pwd, sizeof(Client->pwd));
431 } /* Client_SetPassword */
435 Client_SetAway( CLIENT *Client, const char *Txt )
437 /* Set AWAY reason of client */
439 assert( Client != NULL );
440 assert( Txt != NULL );
442 strlcpy( Client->away, Txt, sizeof( Client->away ));
443 LogDebug("%s \"%s\" is away: %s", Client_TypeText(Client),
444 Client_Mask(Client), Txt);
445 } /* Client_SetAway */
449 Client_SetType( CLIENT *Client, int Type )
451 assert( Client != NULL );
453 if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
454 Adjust_Counters( Client );
455 } /* Client_SetType */
459 Client_SetHops( CLIENT *Client, int Hops )
461 assert( Client != NULL );
463 } /* Client_SetHops */
467 Client_SetToken( CLIENT *Client, int Token )
469 assert( Client != NULL );
470 Client->token = Token;
471 } /* Client_SetToken */
475 Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
477 assert( Client != NULL );
478 assert( Introducer != NULL );
479 Client->introducer = Introducer;
480 } /* Client_SetIntroducer */
484 Client_SetOperByMe( CLIENT *Client, bool OperByMe )
486 assert( Client != NULL );
487 Client->oper_by_me = OperByMe;
488 } /* Client_SetOperByMe */
492 Client_ModeAdd( CLIENT *Client, char Mode )
495 * If Client already alread had Mode, return false.
496 * If the Mode was newly set, return true.
501 assert( Client != NULL );
503 x[0] = Mode; x[1] = '\0';
504 if (!strchr( Client->modes, x[0])) {
505 strlcat( Client->modes, x, sizeof( Client->modes ));
509 } /* Client_ModeAdd */
513 Client_ModeDel( CLIENT *Client, char Mode )
516 * If Mode was removed, return true.
517 * If Client did not have Mode, return false.
522 assert( Client != NULL );
524 x[0] = Mode; x[1] = '\0';
526 p = strchr( Client->modes, x[0] );
527 if( ! p ) return false;
529 /* Client has Mode -> delete */
536 } /* Client_ModeDel */
540 Client_Search( const char *Nick )
542 /* return Client-Structure that has the corresponding Nick.
543 * If none is found, return NULL.
546 char search_id[CLIENT_ID_LEN], *ptr;
550 assert( Nick != NULL );
552 /* copy Nick and truncate hostmask if necessary */
553 strlcpy( search_id, Nick, sizeof( search_id ));
554 ptr = strchr( search_id, '!' );
555 if( ptr ) *ptr = '\0';
557 search_hash = Hash(search_id);
561 if (c->hash == search_hash && strcasecmp(c->id, search_id) == 0)
563 c = (CLIENT *)c->next;
566 } /* Client_Search */
570 * Get client structure ("introducer") identfied by a server token.
571 * @return CLIENT structure or NULL if none could be found.
574 Client_GetFromToken( CLIENT *Client, int Token )
578 assert( Client != NULL );
585 if ((c->type == CLIENT_SERVER) && (c->introducer == Client) &&
588 c = (CLIENT *)c->next;
591 } /* Client_GetFromToken */
595 Client_Type( CLIENT *Client )
597 assert( Client != NULL );
603 Client_Conn( CLIENT *Client )
605 assert( Client != NULL );
606 return Client->conn_id;
611 Client_ID( CLIENT *Client )
613 assert( Client != NULL );
616 if(Client->type == CLIENT_USER)
617 assert(strlen(Client->id) < Conf_MaxNickLength);
620 if( Client->id[0] ) return Client->id;
626 Client_Info( CLIENT *Client )
628 assert( Client != NULL );
634 Client_User( CLIENT *Client )
636 assert( Client != NULL );
637 return Client->user[0] ? Client->user : "~";
644 * Get the "original" user name as supplied by the USER command.
645 * The user name as given by the client is used for authentication instead
646 * of the one detected using IDENT requests.
647 * @param Client The client.
648 * @return Original user name.
651 Client_OrigUser(CLIENT *Client) {
653 char *user = Client->user;
659 return Client->orig_user;
661 } /* Client_OrigUser */
667 * Return the hostname of a client.
668 * @param Client Pointer to client structure
669 * @return Pointer to client hostname
672 Client_Hostname(CLIENT *Client)
674 assert (Client != NULL);
676 } /* Client_Hostname */
680 * Get potentially cloaked hostname of a client.
681 * If the client has not enabled cloaking, the real hostname is used.
682 * @param Client Pointer to client structure
683 * @return Pointer to client hostname
686 Client_HostnameCloaked(CLIENT *Client)
688 assert(Client != NULL);
689 if (Client_HasMode(Client, 'x'))
690 return Client_ID(Client->introducer);
692 return Client_Hostname(Client);
693 } /* Client_HostnameCloaked */
697 Client_Password( CLIENT *Client )
699 assert( Client != NULL );
701 } /* Client_Password */
705 Client_Modes( CLIENT *Client )
707 assert( Client != NULL );
708 return Client->modes;
713 Client_Flags( CLIENT *Client )
715 assert( Client != NULL );
716 return Client->flags;
721 Client_OperByMe( CLIENT *Client )
723 assert( Client != NULL );
724 return Client->oper_by_me;
725 } /* Client_OperByMe */
729 Client_Hops( CLIENT *Client )
731 assert( Client != NULL );
737 Client_Token( CLIENT *Client )
739 assert( Client != NULL );
740 return Client->token;
745 Client_MyToken( CLIENT *Client )
747 assert( Client != NULL );
748 return Client->mytoken;
749 } /* Client_MyToken */
753 Client_NextHop( CLIENT *Client )
757 assert( Client != NULL );
760 while( c->introducer && ( c->introducer != c ) && ( c->introducer != This_Server ))
764 } /* Client_NextHop */
768 * Return ID of a client: "client!user@host"
769 * This client ID is used for IRC prefixes, for example.
770 * Please note that this function uses a global static buffer, so you can't
771 * nest invocations without overwriting erlier results!
772 * @param Client Pointer to client structure
773 * @return Pointer to global buffer containing the client ID
776 Client_Mask( CLIENT *Client )
778 static char Mask_Buffer[GETID_LEN];
780 assert (Client != NULL);
782 /* Servers: return name only, there is no "mask" */
783 if (Client->type == CLIENT_SERVER)
786 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
787 Client->id, Client->user, Client->host);
793 * Return ID of a client with cloaked hostname: "client!user@server-name"
794 * This client ID is used for IRC prefixes, for example.
795 * Please note that this function uses a global static buffer, so you can't
796 * nest invocations without overwriting erlier results!
797 * If the client has not enabled cloaking, the real hostname is used.
798 * @param Client Pointer to client structure
799 * @return Pointer to global buffer containing the client ID
802 Client_MaskCloaked(CLIENT *Client)
804 static char Mask_Buffer[GETID_LEN];
806 assert (Client != NULL);
808 /* Is the client using cloaking at all? */
809 if (!Client_HasMode(Client, 'x'))
810 return Client_Mask(Client);
812 snprintf(Mask_Buffer, GETID_LEN, "%s!%s@%s",
813 Client->id, Client->user, Client_ID(Client->introducer));
815 } /* Client_MaskCloaked */
819 Client_Introducer( CLIENT *Client )
821 assert( Client != NULL );
822 return Client->introducer;
823 } /* Client_Introducer */
827 Client_TopServer( CLIENT *Client )
829 assert( Client != NULL );
830 return Client->topserver;
831 } /* Client_TopServer */
835 Client_HasMode( CLIENT *Client, char Mode )
837 assert( Client != NULL );
838 return strchr( Client->modes, Mode ) != NULL;
839 } /* Client_HasMode */
843 Client_Away( CLIENT *Client )
845 assert( Client != NULL );
851 Client_CheckNick( CLIENT *Client, char *Nick )
853 assert( Client != NULL );
854 assert( Nick != NULL );
856 if (! Client_IsValidNick( Nick ))
858 IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
862 /* Nick bereits vergeben? */
863 if( Client_Search( Nick ))
865 /* den Nick gibt es bereits */
866 IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
871 } /* Client_CheckNick */
875 Client_CheckID( CLIENT *Client, char *ID )
877 char str[COMMAND_LEN];
880 assert( Client != NULL );
881 assert( Client->conn_id > NONE );
882 assert( ID != NULL );
885 if (strlen(ID) > CLIENT_ID_LEN) {
886 IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID);
890 /* ID already in use? */
893 if (strcasecmp(c->id, ID) == 0) {
894 snprintf(str, sizeof(str), "ID \"%s\" already registered", ID);
895 if (c->conn_id != NONE)
896 Log(LOG_ERR, "%s (on connection %d)!", str, c->conn_id);
898 Log(LOG_ERR, "%s (via network)!", str);
899 Conn_Close(Client->conn_id, str, str, true);
902 c = (CLIENT *)c->next;
906 } /* Client_CheckID */
917 Client_Next( CLIENT *c )
920 return (CLIENT *)c->next;
925 Client_UserCount( void )
927 return Count( CLIENT_USER );
928 } /* Client_UserCount */
932 Client_ServiceCount( void )
934 return Count( CLIENT_SERVICE );;
935 } /* Client_ServiceCount */
939 Client_ServerCount( void )
941 return Count( CLIENT_SERVER );
942 } /* Client_ServerCount */
946 Client_MyUserCount( void )
948 return MyCount( CLIENT_USER );
949 } /* Client_MyUserCount */
953 Client_MyServiceCount( void )
955 return MyCount( CLIENT_SERVICE );
956 } /* Client_MyServiceCount */
960 Client_MyServerCount( void )
963 unsigned long cnt = 0;
968 if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++;
969 c = (CLIENT *)c->next;
972 } /* Client_MyServerCount */
976 Client_OperCount( void )
979 unsigned long cnt = 0;
984 if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
985 c = (CLIENT *)c->next;
988 } /* Client_OperCount */
992 Client_UnknownCount( void )
995 unsigned long cnt = 0;
1000 if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++;
1001 c = (CLIENT *)c->next;
1005 } /* Client_UnknownCount */
1009 Client_MaxUserCount( void )
1012 } /* Client_MaxUserCount */
1016 Client_MyMaxUserCount( void )
1018 return My_Max_Users;
1019 } /* Client_MyMaxUserCount */
1023 Client_IsValidNick( const char *Nick )
1026 static const char goodchars[] = ";0123456789-";
1028 assert( Nick != NULL );
1030 if( Nick[0] == '#' ) return false;
1031 if( strchr( goodchars, Nick[0] )) return false;
1032 if( strlen( Nick ) >= Conf_MaxNickLength) return false;
1037 if (( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return false;
1038 if ( *ptr > '}' ) return false;
1043 } /* Client_IsValidNick */
1047 * Return pointer to "My_Whowas" structure.
1050 Client_GetWhowas( void )
1053 } /* Client_GetWhowas */
1056 * Return the index of the last used WHOWAS entry.
1059 Client_GetLastWhowasIndex( void )
1062 } /* Client_GetLastWhowasIndex */
1066 * Get the start time of this client.
1067 * The result is the start time in seconds since 1970-01-01, as reported
1068 * by the C function time(NULL).
1071 Client_StartTime(CLIENT *Client)
1073 assert( Client != NULL );
1074 return Client->starttime;
1075 } /* Client_Uptime */
1078 static unsigned long
1079 Count( CLIENT_TYPE Type )
1082 unsigned long cnt = 0;
1087 if( c->type == Type ) cnt++;
1088 c = (CLIENT *)c->next;
1094 static unsigned long
1095 MyCount( CLIENT_TYPE Type )
1098 unsigned long cnt = 0;
1103 if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
1104 c = (CLIENT *)c->next;
1111 New_Client_Struct( void )
1113 /* Neue CLIENT-Struktur pre-initialisieren */
1117 c = (CLIENT *)malloc( sizeof( CLIENT ));
1120 Log( LOG_EMERG, "Can't allocate memory! [New_Client_Struct]" );
1124 memset( c, 0, sizeof ( CLIENT ));
1126 c->type = CLIENT_UNKNOWN;
1128 c->oper_by_me = false;
1138 Generate_MyToken( CLIENT *Client )
1147 if( c->mytoken == token )
1149 /* Das Token wurde bereits vergeben */
1154 else c = (CLIENT *)c->next;
1156 Client->mytoken = token;
1157 LogDebug("Assigned token %d to server \"%s\".", token, Client->id);
1158 } /* Generate_MyToken */
1162 Adjust_Counters( CLIENT *Client )
1166 assert( Client != NULL );
1168 if( Client->type != CLIENT_USER ) return;
1170 if( Client->conn_id != NONE )
1172 /* Local connection */
1173 count = Client_MyUserCount( );
1174 if( count > My_Max_Users ) My_Max_Users = count;
1176 count = Client_UserCount( );
1177 if( count > Max_Users ) Max_Users = count;
1178 } /* Adjust_Counters */
1182 * Register client in My_Whowas structure for further recall by WHOWAS.
1183 * Note: Only clients that have been connected at least 30 seconds will be
1184 * registered to prevent automated IRC bots to "destroy" a nice server
1188 Client_RegisterWhowas( CLIENT *Client )
1193 assert( Client != NULL );
1196 /* Don't register clients that were connected less than 30 seconds. */
1197 if( now - Client->starttime < 30 )
1200 slot = Last_Whowas + 1;
1201 if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;
1204 Log( LOG_DEBUG, "Saving WHOWAS information to slot %d ...", slot );
1207 My_Whowas[slot].time = now;
1208 strlcpy( My_Whowas[slot].id, Client_ID( Client ),
1209 sizeof( My_Whowas[slot].id ));
1210 strlcpy( My_Whowas[slot].user, Client_User( Client ),
1211 sizeof( My_Whowas[slot].user ));
1212 strlcpy( My_Whowas[slot].host, Client_HostnameCloaked( Client ),
1213 sizeof( My_Whowas[slot].host ));
1214 strlcpy( My_Whowas[slot].info, Client_Info( Client ),
1215 sizeof( My_Whowas[slot].info ));
1216 strlcpy( My_Whowas[slot].server, Client_ID( Client_Introducer( Client )),
1217 sizeof( My_Whowas[slot].server ));
1220 } /* Client_RegisterWhowas */
1224 Client_TypeText(CLIENT *Client)
1226 assert(Client != NULL);
1227 switch (Client_Type(Client)) {
1231 case CLIENT_SERVICE:
1240 } /* Client_TypeText */
1244 * Destroy user or service client.
1247 Destroy_UserOrService(CLIENT *Client, const char *Txt, const char *FwdMsg, bool SendQuit)
1249 if(Client->conn_id != NONE) {
1250 /* Local (directly connected) client */
1252 "%s \"%s\" unregistered (connection %d): %s",
1253 Client_TypeText(Client), Client_Mask(Client),
1254 Client->conn_id, Txt);
1255 Log_ServerNotice('c', "Client exiting: %s (%s@%s) [%s]",
1256 Client_ID(Client), Client_User(Client),
1257 Client_Hostname(Client), Txt);
1260 /* Inforam all the other servers */
1262 IRC_WriteStrServersPrefix(NULL,
1263 Client, "QUIT :%s", FwdMsg );
1265 IRC_WriteStrServersPrefix(NULL,
1270 LogDebug("%s \"%s\" unregistered: %s",
1271 Client_TypeText(Client), Client_Mask(Client), Txt);
1274 /* Inform all the other servers, but the ones in the
1275 * direction we got the QUIT from */
1277 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1278 Client, "QUIT :%s", FwdMsg );
1280 IRC_WriteStrServersPrefix(Client_NextHop(Client),
1285 /* Unregister client from channels */
1286 Channel_Quit(Client, FwdMsg ? FwdMsg : Client->id);
1288 /* Register client in My_Whowas structure */
1289 Client_RegisterWhowas(Client);
1290 } /* Destroy_UserOrService */
1296 Client_DebugDump(void)
1300 Log(LOG_DEBUG, "Client status:");
1304 " - %s: type=%d, host=%s, user=%s, conn=%d, start=%ld, flags=%s",
1305 Client_ID(c), Client_Type(c), Client_Hostname(c),
1306 Client_User(c), Client_Conn(c), Client_StartTime(c),
1308 c = (CLIENT *)c->next;
1310 } /* Client_DumpClients */