#include "portab.h"
-static char UNUSED id[] = "$Id: client.c,v 1.66 2002/12/19 04:33:27 alex Exp $";
+static char UNUSED id[] = "$Id: client.c,v 1.71 2002/12/26 17:14:48 alex Exp $";
#include "imp.h"
#include <assert.h>
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
gethostname( This_Server->host, CLIENT_HOST_LEN );
h = gethostbyname( This_Server->host );
- if( h ) strcpy( This_Server->host, h->h_name );
+ if( h ) strlcpy( This_Server->host, h->h_name, sizeof( This_Server->host ));
Client_SetID( This_Server, Conf_ServerName );
Client_SetInfo( This_Server, Conf_ServerInfo );
if( Type == CLIENT_SERVER ) Generate_MyToken( client );
/* ist der User away? */
- if( strchr( client->modes, 'a' )) strcpy( client->away, DEFAULT_AWAY_MSG );
+ if( strchr( client->modes, 'a' )) strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away ));
/* Verketten */
client->next = (POINTER *)My_Clients;
My_Clients = client;
+ /* Adjust counters */
+ Adjust_Counters( client );
+
return client;
} /* Client_New */
if( ! txt ) txt = "Reason unknown.";
/* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */
- if( Client->type == CLIENT_SERVER ) sprintf( msg, "%s: lost server %s", This_Server->id, Client->id );
+ if( Client->type == CLIENT_SERVER ) snprintf( msg, sizeof( msg ), "%s: lost server %s", This_Server->id, Client->id );
last = NULL;
c = My_Clients;
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 */
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 );
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 */
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 */
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 */
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 */
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 */
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 );
}
assert( Client != NULL );
Client->type = Type;
if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
+ Adjust_Counters( Client );
} /* Client_SetType */
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;
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';
if( strcasecmp( c->id, ID ) == 0 )
{
/* die Server-ID gibt es bereits */
- sprintf( str, "ID \"%s\" already registered", ID );
+ snprintf( str, sizeof( 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 );
} /* 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 )
{
} /* 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- */