X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fclient.c;h=b3b6118172f6bdcaf3906c9b41890f179354740d;hp=bb0e87ef3d92d5bbc3a48e939de143a3a6a4e4df;hb=3be7b9ef59cf7425c87e4b44c7345287eb13c425;hpb=ca33cbda05902b0009058d369f88c0a7a43b1bbe diff --git a/src/ngircd/client.c b/src/ngircd/client.c index bb0e87ef..b3b61181 100644 --- a/src/ngircd/client.c +++ b/src/ngircd/client.c @@ -9,7 +9,7 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: client.c,v 1.48 2002/03/12 14:37:52 alex Exp $ + * $Id: client.c,v 1.54 2002/04/14 13:54:51 alex Exp $ * * client.c: Management aller Clients * @@ -43,6 +43,7 @@ #include "channel.h" #include "conf.h" #include "conn.h" +#include "hash.h" #include "irc-write.h" #include "log.h" #include "messages.h" @@ -85,8 +86,8 @@ GLOBAL VOID Client_Init( VOID ) h = gethostbyname( This_Server->host ); if( h ) strcpy( This_Server->host, h->h_name ); - strcpy( This_Server->id, Conf_ServerName ); - strcpy( This_Server->info, Conf_ServerInfo ); + Client_SetID( This_Server, Conf_ServerName ); + Client_SetInfo( This_Server, Conf_ServerInfo ); My_Clients = This_Server; } /* Client_Init */ @@ -104,7 +105,7 @@ GLOBAL VOID Client_Exit( VOID ) while( c ) { cnt++; - next = c->next; + next = (CLIENT *)c->next; free( c ); c = next; } @@ -168,7 +169,7 @@ GLOBAL CLIENT *Client_New( CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, I if( strchr( client->modes, 'a' )) strcpy( client->away, DEFAULT_AWAY_MSG ); /* Verketten */ - client->next = My_Clients; + client->next = (POINTER *)My_Clients; My_Clients = client; return client; @@ -188,11 +189,8 @@ GLOBAL VOID Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN else txt = FwdMsg; if( ! txt ) txt = "Reason unknown."; - if( Client->type == CLIENT_SERVER ) - { - /* Netz-Split-Nachricht vorbereiten */ - sprintf( msg, "%s | %s", Client_ID( Client ), Client_ID( Client_TopServer( Client ) ? Client_TopServer( Client ) : Client_ThisServer( ))); - } + /* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */ + if( Client->type == CLIENT_SERVER ) sprintf( msg, "%s: lost server %s", This_Server->id, Client->id ); last = NULL; c = My_Clients; @@ -211,7 +209,7 @@ GLOBAL VOID Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN { /* Wir haben den Client gefunden: entfernen */ if( last ) last->next = c->next; - else My_Clients = c->next; + else My_Clients = (CLIENT *)c->next; if( c->type == CLIENT_USER ) { @@ -247,8 +245,8 @@ GLOBAL VOID Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN { if( c != This_Server ) { - if( c->conn_id != NONE ) Log( LOG_NOTICE, "Server \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt ); - else Log( LOG_NOTICE, "Server \"%s\" unregistered: %s", c->id, txt ); + if( c->conn_id != NONE ) Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered (connection %d): %s", c->id, c->conn_id, txt ); + else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt ); } /* andere Server informieren */ @@ -276,7 +274,7 @@ GLOBAL VOID Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN break; } last = c; - c = c->next; + c = (CLIENT *)c->next; } } /* Client_Destroy */ @@ -295,13 +293,16 @@ GLOBAL VOID Client_SetHostname( CLIENT *Client, CHAR *Hostname ) GLOBAL VOID Client_SetID( CLIENT *Client, CHAR *ID ) { - /* Hostname eines Clients setzen */ + /* Hostname eines Clients setzen, Hash-Wert berechnen */ assert( Client != NULL ); assert( ID != NULL ); strncpy( Client->id, ID, CLIENT_ID_LEN - 1 ); Client->id[CLIENT_ID_LEN - 1] = '\0'; + + /* Hash */ + Client->hash = Hash( Client->id ); } /* Client_SetID */ @@ -477,36 +478,43 @@ GLOBAL CLIENT *Client_GetFromConn( CONN_ID Idx ) while( c ) { if( c->conn_id == Idx ) return c; - c = c->next; + c = (CLIENT *)c->next; } return NULL; } /* Client_GetFromConn */ -GLOBAL CLIENT *Client_GetFromID( CHAR *Nick ) +GLOBAL CLIENT *Client_Search( CHAR *Nick ) { /* Client-Struktur, die den entsprechenden Nick hat, liefern. * Wird keine gefunden, so wird NULL geliefert. */ - CHAR n[CLIENT_ID_LEN], *ptr; + CHAR search_id[CLIENT_ID_LEN], *ptr; CLIENT *c = NULL; + UINT32 search_hash; assert( Nick != NULL ); /* Nick kopieren und ggf. Host-Mask abschneiden */ - strncpy( n, Nick, CLIENT_ID_LEN - 1 ); - n[CLIENT_ID_LEN - 1] = '\0'; - ptr = strchr( n, '!' ); + strncpy( search_id, Nick, CLIENT_ID_LEN - 1 ); + search_id[CLIENT_ID_LEN - 1] = '\0'; + ptr = strchr( search_id, '!' ); if( ptr ) *ptr = '\0'; + search_hash = Hash( search_id ); + c = My_Clients; while( c ) { - if( strcasecmp( c->id, n ) == 0 ) return c; - c = c->next; + if( c->hash == search_hash ) + { + /* lt. Hash-Wert: Treffer! */ + if( strcasecmp( c->id, search_id ) == 0 ) return c; + } + c = (CLIENT *)c->next; } return NULL; -} /* Client_GetFromID */ +} /* Client_Search */ GLOBAL CLIENT *Client_GetFromToken( CLIENT *Client, INT Token ) @@ -524,7 +532,7 @@ GLOBAL CLIENT *Client_GetFromToken( CLIENT *Client, INT Token ) while( c ) { if(( c->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c->token == Token )) return c; - c = c->next; + c = (CLIENT *)c->next; } return NULL; } /* Client_GetFromToken */ @@ -567,7 +575,7 @@ GLOBAL CHAR *Client_Info( CLIENT *Client ) GLOBAL CHAR *Client_User( CLIENT *Client ) { assert( Client != NULL ); - if( Client->user ) return Client->user; + if( Client->user[0] ) return Client->user; else return "~"; } /* Client_User */ @@ -681,8 +689,6 @@ GLOBAL BOOLEAN Client_CheckNick( CLIENT *Client, CHAR *Nick ) { /* Nick ueberpruefen */ - CLIENT *c; - assert( Client != NULL ); assert( Nick != NULL ); @@ -694,16 +700,11 @@ GLOBAL BOOLEAN Client_CheckNick( CLIENT *Client, CHAR *Nick ) } /* Nick bereits vergeben? */ - c = My_Clients; - while( c ) + if( Client_Search( Nick )) { - if( strcasecmp( c->id, Nick ) == 0 ) - { - /* den Nick gibt es bereits */ - IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick ); - return FALSE; - } - c = c->next; + /* den Nick gibt es bereits */ + IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick ); + return FALSE; } return TRUE; @@ -740,32 +741,13 @@ GLOBAL BOOLEAN Client_CheckID( CLIENT *Client, CHAR *ID ) Conn_Close( Client->conn_id, str, str, TRUE ); return FALSE; } - c = c->next; + c = (CLIENT *)c->next; } return TRUE; } /* 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 ) { /* Ersten Client liefern. */ @@ -780,7 +762,7 @@ GLOBAL CLIENT *Client_Next( CLIENT *c ) * so wird NULL geliefert. */ assert( c != NULL ); - return c->next; + return (CLIENT *)c->next; } /* Client_Next */ @@ -816,7 +798,17 @@ GLOBAL INT Client_MyServiceCount( VOID ) GLOBAL INT Client_MyServerCount( VOID ) { - return MyCount( CLIENT_SERVER ); + CLIENT *c; + INT cnt; + + cnt = 0; + c = My_Clients; + while( c ) + { + if(( c->type == CLIENT_SERVER ) && ( c->hops == 1 )) cnt++; + c = (CLIENT *)c->next; + } + return cnt; } /* Client_MyServerCount */ @@ -830,7 +822,7 @@ GLOBAL INT Client_OperCount( VOID ) while( c ) { if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++; - c = c->next; + c = (CLIENT *)c->next; } return cnt; } /* Client_OperCount */ @@ -846,7 +838,7 @@ GLOBAL INT Client_UnknownCount( VOID ) while( c ) { if( c && ( c->type != CLIENT_USER ) && ( c->type != CLIENT_SERVICE ) && ( c->type != CLIENT_SERVER )) cnt++; - c = c->next; + c = (CLIENT *)c->next; } return cnt; } /* Client_UnknownCount */ @@ -885,8 +877,8 @@ LOCAL INT Count( CLIENT_TYPE Type ) c = My_Clients; while( c ) { - if( c && ( c->type == Type )) cnt++; - c = c->next; + if( c->type == Type ) cnt++; + c = (CLIENT *)c->next; } return cnt; } /* Count */ @@ -901,8 +893,8 @@ LOCAL INT MyCount( CLIENT_TYPE Type ) c = My_Clients; while( c ) { - if( c && ( c->introducer == This_Server ) && ( c->type == Type )) cnt++; - c = c->next; + if(( c->introducer == This_Server ) && ( c->type == Type )) cnt++; + c = (CLIENT *)c->next; } return cnt; } /* MyCount */ @@ -922,6 +914,7 @@ LOCAL CLIENT *New_Client_Struct( VOID ) } c->next = NULL; + c->hash = 0; c->type = CLIENT_UNKNOWN; c->conn_id = NONE; c->introducer = NULL; @@ -958,7 +951,7 @@ LOCAL VOID Generate_MyToken( CLIENT *Client ) c = My_Clients; continue; } - else c = c->next; + else c = (CLIENT *)c->next; } Client->mytoken = token; Log( LOG_DEBUG, "Assigned token %d to server \"%s\".", token, Client->id );