* 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.53 2002/03/27 20:52:58 alex Exp $
*
* client.c: Management aller Clients
*
#include "channel.h"
#include "conf.h"
#include "conn.h"
+#include "hash.h"
#include "irc-write.h"
#include "log.h"
#include "messages.h"
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 */
while( c )
{
cnt++;
- next = c->next;
+ next = (CLIENT *)c->next;
free( c );
c = next;
}
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;
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;
{
/* 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 )
{
{
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 */
break;
}
last = c;
- c = c->next;
+ c = (CLIENT *)c->next;
}
} /* Client_Destroy */
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 */
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 )
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 */
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 */
{
/* Nick ueberpruefen */
- CLIENT *c;
-
assert( Client != NULL );
assert( Nick != NULL );
}
/* 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;
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. */
* so wird NULL geliefert. */
assert( c != NULL );
- return c->next;
+ return (CLIENT *)c->next;
} /* Client_Next */
while( c )
{
if( c && ( c->type == CLIENT_USER ) && ( strchr( c->modes, 'o' ))) cnt++;
- c = c->next;
+ c = (CLIENT *)c->next;
}
return cnt;
} /* Client_OperCount */
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 */
while( c )
{
if( c && ( c->type == Type )) cnt++;
- c = c->next;
+ c = (CLIENT *)c->next;
}
return cnt;
} /* Count */
while( c )
{
if( c && ( c->introducer == This_Server ) && ( c->type == Type )) cnt++;
- c = c->next;
+ c = (CLIENT *)c->next;
}
return cnt;
} /* MyCount */
}
c->next = NULL;
+ c->hash = 0;
c->type = CLIENT_UNKNOWN;
c->conn_id = NONE;
c->introducer = NULL;
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 );