- Client_SetID() berechnet Hash-Wert ueber ID/Nick.
- Client_GetFromID() heisst nun Client_Search(), zudem wird via Hash gesucht. - Client_CheckNick() sucht nicht mehr selber. - altes Client_Search() ist entfallen (s.o.).
This commit is contained in:
parent
cec0e2a4d7
commit
b5c16c228b
|
@ -9,7 +9,7 @@
|
||||||
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
||||||
* der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
|
* der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
|
||||||
*
|
*
|
||||||
* $Id: client.c,v 1.50 2002/03/12 23:43:56 alex Exp $
|
* $Id: client.c,v 1.51 2002/03/25 16:59:36 alex Exp $
|
||||||
*
|
*
|
||||||
* client.c: Management aller Clients
|
* client.c: Management aller Clients
|
||||||
*
|
*
|
||||||
|
@ -43,6 +43,7 @@
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "conn.h"
|
#include "conn.h"
|
||||||
|
#include "hash.h"
|
||||||
#include "irc-write.h"
|
#include "irc-write.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
|
@ -85,8 +86,8 @@ GLOBAL VOID Client_Init( VOID )
|
||||||
h = gethostbyname( This_Server->host );
|
h = gethostbyname( This_Server->host );
|
||||||
if( h ) strcpy( This_Server->host, h->h_name );
|
if( h ) strcpy( This_Server->host, h->h_name );
|
||||||
|
|
||||||
strcpy( This_Server->id, Conf_ServerName );
|
Client_SetID( This_Server, Conf_ServerName );
|
||||||
strcpy( This_Server->info, Conf_ServerInfo );
|
Client_SetInfo( This_Server, Conf_ServerInfo );
|
||||||
|
|
||||||
My_Clients = This_Server;
|
My_Clients = This_Server;
|
||||||
} /* Client_Init */
|
} /* Client_Init */
|
||||||
|
@ -292,13 +293,16 @@ GLOBAL VOID Client_SetHostname( CLIENT *Client, CHAR *Hostname )
|
||||||
|
|
||||||
GLOBAL VOID Client_SetID( CLIENT *Client, CHAR *ID )
|
GLOBAL VOID Client_SetID( CLIENT *Client, CHAR *ID )
|
||||||
{
|
{
|
||||||
/* Hostname eines Clients setzen */
|
/* Hostname eines Clients setzen, Hash-Wert berechnen */
|
||||||
|
|
||||||
assert( Client != NULL );
|
assert( Client != NULL );
|
||||||
assert( ID != NULL );
|
assert( ID != NULL );
|
||||||
|
|
||||||
strncpy( Client->id, ID, CLIENT_ID_LEN - 1 );
|
strncpy( Client->id, ID, CLIENT_ID_LEN - 1 );
|
||||||
Client->id[CLIENT_ID_LEN - 1] = '\0';
|
Client->id[CLIENT_ID_LEN - 1] = '\0';
|
||||||
|
|
||||||
|
/* Hash */
|
||||||
|
Client->hash = Hash( Client->id );
|
||||||
} /* Client_SetID */
|
} /* Client_SetID */
|
||||||
|
|
||||||
|
|
||||||
|
@ -480,30 +484,37 @@ GLOBAL CLIENT *Client_GetFromConn( CONN_ID Idx )
|
||||||
} /* Client_GetFromConn */
|
} /* Client_GetFromConn */
|
||||||
|
|
||||||
|
|
||||||
GLOBAL CLIENT *Client_GetFromID( CHAR *Nick )
|
GLOBAL CLIENT *Client_Search( CHAR *Nick )
|
||||||
{
|
{
|
||||||
/* Client-Struktur, die den entsprechenden Nick hat, liefern.
|
/* Client-Struktur, die den entsprechenden Nick hat, liefern.
|
||||||
* Wird keine gefunden, so wird NULL geliefert. */
|
* Wird keine gefunden, so wird NULL geliefert. */
|
||||||
|
|
||||||
CHAR n[CLIENT_ID_LEN], *ptr;
|
CHAR search_id[CLIENT_ID_LEN], *ptr;
|
||||||
CLIENT *c = NULL;
|
CLIENT *c = NULL;
|
||||||
|
UINT32 search_hash;
|
||||||
|
|
||||||
assert( Nick != NULL );
|
assert( Nick != NULL );
|
||||||
|
|
||||||
/* Nick kopieren und ggf. Host-Mask abschneiden */
|
/* Nick kopieren und ggf. Host-Mask abschneiden */
|
||||||
strncpy( n, Nick, CLIENT_ID_LEN - 1 );
|
strncpy( search_id, Nick, CLIENT_ID_LEN - 1 );
|
||||||
n[CLIENT_ID_LEN - 1] = '\0';
|
search_id[CLIENT_ID_LEN - 1] = '\0';
|
||||||
ptr = strchr( n, '!' );
|
ptr = strchr( search_id, '!' );
|
||||||
if( ptr ) *ptr = '\0';
|
if( ptr ) *ptr = '\0';
|
||||||
|
|
||||||
|
search_hash = Hash( search_id );
|
||||||
|
|
||||||
c = My_Clients;
|
c = My_Clients;
|
||||||
while( c )
|
while( c )
|
||||||
{
|
{
|
||||||
if( strcasecmp( c->id, n ) == 0 ) return c;
|
if( c->hash == search_hash )
|
||||||
|
{
|
||||||
|
/* lt. Hash-Wert: Treffer! */
|
||||||
|
if( strcasecmp( c->id, search_id ) == 0 ) return c;
|
||||||
|
}
|
||||||
c = c->next;
|
c = c->next;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
} /* Client_GetFromID */
|
} /* Client_Search */
|
||||||
|
|
||||||
|
|
||||||
GLOBAL CLIENT *Client_GetFromToken( CLIENT *Client, INT Token )
|
GLOBAL CLIENT *Client_GetFromToken( CLIENT *Client, INT Token )
|
||||||
|
@ -678,8 +689,6 @@ GLOBAL BOOLEAN Client_CheckNick( CLIENT *Client, CHAR *Nick )
|
||||||
{
|
{
|
||||||
/* Nick ueberpruefen */
|
/* Nick ueberpruefen */
|
||||||
|
|
||||||
CLIENT *c;
|
|
||||||
|
|
||||||
assert( Client != NULL );
|
assert( Client != NULL );
|
||||||
assert( Nick != NULL );
|
assert( Nick != NULL );
|
||||||
|
|
||||||
|
@ -691,17 +700,12 @@ GLOBAL BOOLEAN Client_CheckNick( CLIENT *Client, CHAR *Nick )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Nick bereits vergeben? */
|
/* Nick bereits vergeben? */
|
||||||
c = My_Clients;
|
if( Client_Search( Nick ))
|
||||||
while( c )
|
|
||||||
{
|
|
||||||
if( strcasecmp( c->id, Nick ) == 0 )
|
|
||||||
{
|
{
|
||||||
/* den Nick gibt es bereits */
|
/* den Nick gibt es bereits */
|
||||||
IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
|
IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
c = c->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} /* Client_CheckNick */
|
} /* Client_CheckNick */
|
||||||
|
@ -744,25 +748,6 @@ GLOBAL BOOLEAN Client_CheckID( CLIENT *Client, CHAR *ID )
|
||||||
} /* Client_CheckID */
|
} /* Client_CheckID */
|
||||||
|
|
||||||
|
|
||||||
GLOBAL CLIENT *Client_Search( CHAR *ID )
|
|
||||||
{
|
|
||||||
/* Client suchen, auf den ID passt */
|
|
||||||
|
|
||||||
CLIENT *c;
|
|
||||||
|
|
||||||
assert( ID != NULL );
|
|
||||||
|
|
||||||
c = My_Clients;
|
|
||||||
while( c )
|
|
||||||
{
|
|
||||||
if( strcasecmp( c->id, ID ) == 0 ) return c;
|
|
||||||
c = c->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
} /* Client_Search */
|
|
||||||
|
|
||||||
|
|
||||||
GLOBAL CLIENT *Client_First( VOID )
|
GLOBAL CLIENT *Client_First( VOID )
|
||||||
{
|
{
|
||||||
/* Ersten Client liefern. */
|
/* Ersten Client liefern. */
|
||||||
|
@ -919,6 +904,7 @@ LOCAL CLIENT *New_Client_Struct( VOID )
|
||||||
}
|
}
|
||||||
|
|
||||||
c->next = NULL;
|
c->next = NULL;
|
||||||
|
c->hash = 0;
|
||||||
c->type = CLIENT_UNKNOWN;
|
c->type = CLIENT_UNKNOWN;
|
||||||
c->conn_id = NONE;
|
c->conn_id = NONE;
|
||||||
c->introducer = NULL;
|
c->introducer = NULL;
|
||||||
|
|
Loading…
Reference in New Issue