X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fclient.c;h=70f6be6c704dc94fb73daf855226f4b5b1bd90d6;hp=46736cc01be35eff1f307c563b380d70eff76133;hb=6626395c88fc46eeb110942b17eb9245a1d0021b;hpb=ad98f2c20d199f08714ed09fc3663516050cb4db diff --git a/src/ngircd/client.c b/src/ngircd/client.c index 46736cc0..70f6be6c 100644 --- a/src/ngircd/client.c +++ b/src/ngircd/client.c @@ -2,23 +2,13 @@ * ngIRCd -- The Next Generation IRC Daemon * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de) * - * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen - * der GNU General Public License (GPL), wie von der Free Software Foundation - * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2 - * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version. - * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste - * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: client.c,v 1.63 2002/11/26 08:36:34 alex Exp $ - * - * client.c: Management aller Clients - * - * Der Begriff "Client" ist in diesem Fall evtl. etwas verwirrend: Clients sind - * alle Verbindungen, die im gesamten(!) IRC-Netzwerk bekannt sind. Das sind IRC- - * Clients (User), andere Server und IRC-Services. - * Ueber welchen IRC-Server die Verbindung nun tatsaechlich in das Netzwerk her- - * gestellt wurde, muss der jeweiligen Struktur entnommen werden. Ist es dieser - * Server gewesen, so existiert eine entsprechende CONNECTION-Struktur. + * Client management. */ @@ -27,6 +17,8 @@ #include "portab.h" +static char UNUSED id[] = "$Id: client.c,v 1.69 2002/12/26 16:48:14 alex Exp $"; + #include "imp.h" #include #include @@ -65,6 +57,10 @@ LOCAL LONG MyCount PARAMS(( CLIENT_TYPE Type )); LOCAL CLIENT *New_Client_Struct PARAMS(( VOID )); LOCAL VOID Generate_MyToken PARAMS(( CLIENT *Client )); +LOCAL VOID Adjust_Counters PARAMS(( CLIENT *Client )); + + +LONG Max_Users = 0, My_Max_Users = 0; GLOBAL VOID @@ -105,7 +101,7 @@ Client_Exit( VOID ) CLIENT *c, *next; INT cnt; - if( NGIRCd_Restart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, FALSE ); + if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, FALSE ); else Client_Destroy( This_Server, "Server going down.", NULL, FALSE ); cnt = 0; @@ -185,6 +181,9 @@ Client_New( CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, INT Type, CHAR * client->next = (POINTER *)My_Clients; My_Clients = client; + /* Adjust counters */ + Adjust_Counters( client ); + return client; } /* Client_New */ @@ -264,7 +263,7 @@ Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN SendQuit ) } /* andere Server informieren */ - if( ! NGIRCd_Quit ) + if( ! NGIRCd_SignalQuit ) { if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg ); else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id ); @@ -301,8 +300,7 @@ Client_SetHostname( CLIENT *Client, CHAR *Hostname ) assert( Client != NULL ); assert( Hostname != NULL ); - strncpy( Client->host, Hostname, CLIENT_HOST_LEN - 1 ); - Client->host[CLIENT_HOST_LEN - 1] = '\0'; + strlcpy( Client->host, Hostname, sizeof( Client->host )); } /* Client_SetHostname */ @@ -314,8 +312,7 @@ Client_SetID( CLIENT *Client, CHAR *ID ) assert( Client != NULL ); assert( ID != NULL ); - strncpy( Client->id, ID, CLIENT_ID_LEN - 1 ); - Client->id[CLIENT_ID_LEN - 1] = '\0'; + strlcpy( Client->id, ID, sizeof( Client->id )); /* Hash */ Client->hash = Hash( Client->id ); @@ -330,13 +327,12 @@ Client_SetUser( CLIENT *Client, CHAR *User, BOOLEAN Idented ) assert( Client != NULL ); assert( User != NULL ); - if( Idented ) strncpy( Client->user, User, CLIENT_USER_LEN - 1 ); + if( Idented ) strlcpy( Client->user, User, sizeof( Client->user )); else { Client->user[0] = '~'; - strncpy( Client->user + 1, User, CLIENT_USER_LEN - 2 ); + strlcpy( Client->user + 1, User, sizeof( Client->user ) - 1 ); } - Client->user[CLIENT_USER_LEN - 1] = '\0'; } /* Client_SetUser */ @@ -348,8 +344,7 @@ Client_SetInfo( CLIENT *Client, CHAR *Info ) assert( Client != NULL ); assert( Info != NULL ); - strncpy( Client->info, Info, CLIENT_INFO_LEN - 1 ); - Client->info[CLIENT_INFO_LEN - 1] = '\0'; + strlcpy( Client->info, Info, sizeof( Client->info )); } /* Client_SetInfo */ @@ -361,8 +356,7 @@ Client_SetModes( CLIENT *Client, CHAR *Modes ) assert( Client != NULL ); assert( Modes != NULL ); - strncpy( Client->modes, Modes, CLIENT_MODE_LEN - 1 ); - Client->modes[CLIENT_MODE_LEN - 1] = '\0'; + strlcpy( Client->modes, Modes, sizeof( Client->modes )); } /* Client_SetModes */ @@ -374,8 +368,7 @@ Client_SetFlags( CLIENT *Client, CHAR *Flags ) assert( Client != NULL ); assert( Flags != NULL ); - strncpy( Client->flags, Flags, CLIENT_FLAGS_LEN - 1 ); - Client->flags[CLIENT_FLAGS_LEN - 1] = '\0'; + strlcpy( Client->flags, Flags, sizeof( Client->flags )); } /* Client_SetFlags */ @@ -387,8 +380,7 @@ Client_SetPassword( CLIENT *Client, CHAR *Pwd ) assert( Client != NULL ); assert( Pwd != NULL ); - strncpy( Client->pwd, Pwd, CLIENT_PASS_LEN - 1 ); - Client->pwd[CLIENT_PASS_LEN - 1] = '\0'; + strlcpy( Client->pwd, Pwd, sizeof( Client->pwd )); } /* Client_SetPassword */ @@ -402,8 +394,7 @@ Client_SetAway( CLIENT *Client, CHAR *Txt ) if( Txt ) { /* Client AWAY setzen */ - strncpy( Client->away, Txt, CLIENT_AWAY_LEN - 1 ); - Client->away[CLIENT_AWAY_LEN - 1] = '\0'; + strlcpy( Client->away, Txt, sizeof( Client->away )); Client_ModeAdd( Client, 'a' ); Log( LOG_DEBUG, "User \"%s\" is away: %s", Client_Mask( Client ), Txt ); } @@ -422,6 +413,7 @@ Client_SetType( CLIENT *Client, INT Type ) assert( Client != NULL ); Client->type = Type; if( Type == CLIENT_SERVER ) Generate_MyToken( Client ); + Adjust_Counters( Client ); } /* Client_SetType */ @@ -473,7 +465,7 @@ Client_ModeAdd( CLIENT *Client, CHAR Mode ) if( ! strchr( Client->modes, x[0] )) { /* Client hat den Mode noch nicht -> setzen */ - strcat( Client->modes, x ); + strlcat( Client->modes, x, sizeof( Client->modes )); return TRUE; } else return FALSE; @@ -539,8 +531,7 @@ Client_Search( CHAR *Nick ) assert( Nick != NULL ); /* Nick kopieren und ggf. Host-Mask abschneiden */ - strncpy( search_id, Nick, CLIENT_ID_LEN - 1 ); - search_id[CLIENT_ID_LEN - 1] = '\0'; + strlcpy( search_id, Nick, sizeof( search_id )); ptr = strchr( search_id, '!' ); if( ptr ) *ptr = '\0'; @@ -808,8 +799,9 @@ Client_CheckID( CLIENT *Client, CHAR *ID ) if( strcasecmp( c->id, ID ) == 0 ) { /* die Server-ID gibt es bereits */ - sprintf( str, "ID \"%s\" already registered!", ID ); - Log( LOG_ERR, "%s (on connection %d)", str, Client->conn_id ); + sprintf( str, "ID \"%s\" already registered", ID ); + if( Client->conn_id != c->conn_id ) Log( LOG_ERR, "%s (on connection %d)!", str, c->conn_id ); + else Log( LOG_ERR, "%s (via network)!", str ); Conn_Close( Client->conn_id, str, str, TRUE ); return FALSE; } @@ -926,6 +918,20 @@ Client_UnknownCount( VOID ) } /* Client_UnknownCount */ +GLOBAL LONG +Client_MaxUserCount( VOID ) +{ + return Max_Users; +} /* Client_MaxUserCount */ + + +GLOBAL LONG +Client_MyMaxUserCount( VOID ) +{ + return My_Max_Users; +} /* Client_MyMaxUserCount */ + + GLOBAL BOOLEAN Client_IsValidNick( CHAR *Nick ) { @@ -1048,4 +1054,24 @@ Generate_MyToken( CLIENT *Client ) } /* Generate_MyToken */ +LOCAL VOID +Adjust_Counters( CLIENT *Client ) +{ + LONG count; + + assert( Client != NULL ); + + if( Client->type != CLIENT_USER ) return; + + if( Client->conn_id != NONE ) + { + /* Local connection */ + count = Client_MyUserCount( ); + if( count > My_Max_Users ) My_Max_Users = count; + } + count = Client_UserCount( ); + if( count > Max_Users ) Max_Users = count; +} /* Adjust_Counters */ + + /* -eof- */