X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fclient.c;h=6ce42397790d628edcb500aa5c84c75ecc5a30a3;hp=558ad983b4fac1caeabfd4c0833afa9bf6873786;hb=15764f98460764b4295fc089b0f7314237cd5f15;hpb=78a6e3c67136e32ba71abe58a7f755400db595e8 diff --git a/src/ngircd/client.c b/src/ngircd/client.c index 558ad983..6ce42397 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 comBase beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: client.c,v 1.4 2001/12/25 19:21:26 alex Exp $ + * $Id: client.c,v 1.10 2001/12/27 19:13:47 alex Exp $ * * client.c: Management aller Clients * @@ -21,6 +21,24 @@ * Server gewesen, so existiert eine entsprechende CONNECTION-Struktur. * * $Log: client.c,v $ + * Revision 1.10 2001/12/27 19:13:47 alex + * - neue Funktion Client_Search(), besseres Logging. + * + * Revision 1.9 2001/12/27 17:15:29 alex + * - der eigene Hostname wird nun komplet (als FQDN) ermittelt. + * + * Revision 1.8 2001/12/27 16:54:51 alex + * - neue Funktion Client_GetID(), liefert die "Client ID". + * + * Revision 1.7 2001/12/26 14:45:37 alex + * - "Code Cleanups". + * + * Revision 1.6 2001/12/26 03:19:16 alex + * - neue Funktion Client_Name(). + * + * Revision 1.5 2001/12/25 22:04:26 alex + * - Aenderungen an den Debug- und Logging-Funktionen. + * * Revision 1.4 2001/12/25 19:21:26 alex * - Client-Typ ("Status") besser unterteilt, My_Clients ist zudem nun global. * @@ -33,7 +51,6 @@ * * Revision 1.1 2001/12/14 08:13:43 alex * - neues Modul begonnen :-) - * */ @@ -43,14 +60,25 @@ #include #include #include +#include #include +#include + +#include +#include "client.h" +#include #include "channel.h" #include "conn.h" +#include "irc.h" #include "log.h" +#include "messages.h" #include -#include "client.h" + + +LOCAL CLIENT *My_Clients; +LOCAL CHAR GetID_Buffer[CLIENT_ID_LEN]; LOCAL CLIENT *New_Client_Struct( VOID ); @@ -58,6 +86,8 @@ LOCAL CLIENT *New_Client_Struct( VOID ); GLOBAL VOID Client_Init( VOID ) { + struct hostent *h; + This_Server = New_Client_Struct( ); if( ! This_Server ) { @@ -70,7 +100,11 @@ GLOBAL VOID Client_Init( VOID ) This_Server->type = CLIENT_SERVER; This_Server->conn_id = NONE; This_Server->introducer = This_Server; + gethostname( This_Server->host, CLIENT_HOST_LEN ); + h = gethostbyname( This_Server->host ); + if( h ) strcpy( This_Server->host, h->h_name ); + strcpy( This_Server->nick, This_Server->host ); My_Clients = This_Server; @@ -93,11 +127,11 @@ GLOBAL VOID Client_Exit( VOID ) free( c ); c = next; } - if( cnt ) Log( LOG_DEBUG, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" ); + if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" ); } /* Client Exit */ -GLOBAL CLIENT *Client_New_Local( CONN_ID Idx, CHAR *Hostname ) +GLOBAL CLIENT *Client_NewLocal( CONN_ID Idx, CHAR *Hostname ) { /* Neuen lokalen Client erzeugen. */ @@ -120,7 +154,7 @@ GLOBAL CLIENT *Client_New_Local( CONN_ID Idx, CHAR *Hostname ) My_Clients = client; return client; -} /* Client_New_Local */ +} /* Client_NewLocal */ GLOBAL VOID Client_Destroy( CLIENT *Client ) @@ -139,6 +173,9 @@ GLOBAL VOID Client_Destroy( CLIENT *Client ) { if( last ) last->next = c->next; else My_Clients = c->next; + + if( c->type == CLIENT_USER ) Log( LOG_INFO, "User \"%s!%s@%s\" (%s) exited.", c->nick, c->user, c->host, c->name ); + free( c ); break; } @@ -167,6 +204,77 @@ GLOBAL CLIENT *Client_GetFromConn( CONN_ID Idx ) } /* Client_GetFromConn */ +GLOBAL CHAR *Client_Name( CLIENT *Client ) +{ + assert( Client != NULL ); + + if( Client->nick[0] ) return Client->nick; + else return "*"; +} /* Client_Name */ + + +GLOBAL BOOLEAN Client_CheckNick( CLIENT *Client, CHAR *Nick ) +{ + /* Nick ueberpruefen */ + + CLIENT *c; + + assert( Client != NULL ); + assert( Nick != NULL ); + + /* Nick zu lang? */ + if( strlen( Nick ) > CLIENT_NICK_LEN ) return IRC_WriteStrClient( Client, This_Server, ERR_ERRONEUSNICKNAME_MSG, Client_Name( Client ), Nick ); + + /* Nick bereits vergeben? */ + c = My_Clients; + while( c ) + { + if( strcasecmp( c->nick, Nick ) == 0 ) + { + /* den Nick gibt es bereits */ + IRC_WriteStrClient( Client, This_Server, ERR_NICKNAMEINUSE_MSG, Client_Name( Client ), Nick ); + return FALSE; + } + c = c->next; + } + + return TRUE; +} /* Client_CheckNick */ + + +GLOBAL CHAR *Client_GetID( CLIENT *Client ) +{ + /* Client-"ID" liefern, wie sie z.B. fuer + * Prefixe benoetigt wird. */ + + assert( Client != NULL ); + + if( Client->type == CLIENT_SERVER ) return Client->host; + + sprintf( GetID_Buffer, "%s!%s@%s", Client->nick, Client->user, Client->host ); + return GetID_Buffer; +} /* Client_GetID */ + + +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->nick, ID ) == 0 ) return c; + c = c->next; + } + + return NULL; +} /* Client_Search */ + + LOCAL CLIENT *New_Client_Struct( VOID ) { /* Neue CLIENT-Struktur pre-initialisieren */