]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/client.c
- neue Funktion Client_Search(), besseres Logging.
[ngircd-alex.git] / src / ngircd / client.c
index 15d83c0a56ac09bf7edbb9313ec0111d341b8e17..6ce42397790d628edcb500aa5c84c75ecc5a30a3 100644 (file)
@@ -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.7 2001/12/26 14:45:37 alex Exp $
+ * $Id: client.c,v 1.10 2001/12/27 19:13:47 alex Exp $
  *
  * client.c: Management aller Clients
  *
  * 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".
  *
@@ -51,7 +60,9 @@
 #include <imp.h>
 #include <assert.h>
 #include <unistd.h>
+#include <stdio.h>
 #include <string.h>
+#include <netdb.h>
 
 #include <exp.h>
 #include "client.h"
@@ -66,7 +77,8 @@
 #include <exp.h>
 
 
-GLOBAL CLIENT *My_Clients;
+LOCAL CLIENT *My_Clients;
+LOCAL CHAR GetID_Buffer[CLIENT_ID_LEN];
 
 
 LOCAL CLIENT *New_Client_Struct( VOID );
@@ -74,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 )
        {
@@ -86,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;
@@ -155,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;
                }
@@ -221,6 +242,39 @@ GLOBAL BOOLEAN Client_CheckNick( CLIENT *Client, CHAR *Nick )
 } /* 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 */