]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/client.c
- neuer Befehl NAMES, kleinere Bugfixes.
[ngircd-alex.git] / src / ngircd / client.c
index 8767c55f43f8811a0c2644dee7529e3b172e1826..0ef82662720e6be76900da58f57df66f293103b6 100644 (file)
@@ -7,9 +7,9 @@
  * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
  * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
- * der an comBase beteiligten Autoren finden Sie in der Datei AUTHORS.
+ * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: client.c,v 1.8 2001/12/27 16:54:51 alex Exp $
+ * $Id: client.c,v 1.15 2001/12/31 15:33:13 alex Exp $
  *
  * client.c: Management aller Clients
  *
  * Server gewesen, so existiert eine entsprechende CONNECTION-Struktur.
  *
  * $Log: client.c,v $
+ * Revision 1.15  2001/12/31 15:33:13  alex
+ * - neuer Befehl NAMES, kleinere Bugfixes.
+ * - Bug bei PING behoben: war zu restriktiv implementiert :-)
+ *
+ * Revision 1.14  2001/12/31 02:18:51  alex
+ * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART),
+ * - neuen Header "defines.h" mit (fast) allen Konstanten.
+ * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes.
+ *
+ * Revision 1.13  2001/12/30 19:26:11  alex
+ * - Unterstuetzung fuer die Konfigurationsdatei eingebaut.
+ *
+ * Revision 1.12  2001/12/29 20:18:18  alex
+ * - neue Funktion Client_SetHostname().
+ *
+ * Revision 1.11  2001/12/29 03:10:47  alex
+ * - Client-Modes implementiert; Loglevel mal wieder angepasst.
+ *
+ * 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".
  *
@@ -28,7 +52,7 @@
  * - "Code Cleanups".
  *
  * Revision 1.6  2001/12/26 03:19:16  alex
- * - neue Funktion Client_Name().
+ * - neue Funktion Client_Nick().
  *
  * Revision 1.5  2001/12/25 22:04:26  alex
  * - Aenderungen an den Debug- und Logging-Funktionen.
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
+#include <netdb.h>
 
 #include <exp.h>
 #include "client.h"
 
 #include <imp.h>
 #include "channel.h"
+#include "conf.h"
 #include "conn.h"
 #include "irc.h"
 #include "log.h"
@@ -79,10 +105,13 @@ LOCAL CLIENT *New_Client_Struct( VOID );
 
 GLOBAL VOID Client_Init( VOID )
 {
+       struct hostent *h;
+       
        This_Server = New_Client_Struct( );
        if( ! This_Server )
        {
                Log( LOG_EMERG, "Can't allocate client structure for server! Going down." );
+               Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
                exit( 1 );
        }
 
@@ -91,8 +120,13 @@ 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 );
-       strcpy( This_Server->nick, This_Server->host );
+       h = gethostbyname( This_Server->host );
+       if( h ) strcpy( This_Server->host, h->h_name );
+
+       strcpy( This_Server->nick, Conf_ServerName );
+       strcpy( This_Server->info, Conf_ServerInfo );
 
        My_Clients = This_Server;
 } /* Client_Init */
@@ -130,11 +164,10 @@ GLOBAL CLIENT *Client_NewLocal( CONN_ID Idx, CHAR *Hostname )
        client = New_Client_Struct( );
        if( ! client ) return NULL;
 
-       /* Initgialisieren */
+       /* Initialisieren */
        client->conn_id = Idx;
        client->introducer = This_Server;
-       strncpy( client->host, Hostname, CLIENT_HOST_LEN );
-       client->host[CLIENT_HOST_LEN] = '\0';
+       Client_SetHostname( client, Hostname );
 
        /* Verketten */
        client->next = My_Clients;
@@ -160,6 +193,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_NOTICE, "User \"%s!%s@%s\" (%s) exited (connection %d).", c->nick, c->user, c->host, c->name, c->conn_id );
+
                        free( c );
                        break;
                }
@@ -169,9 +205,19 @@ GLOBAL VOID Client_Destroy( CLIENT *Client )
 } /* Client_Destroy */
 
 
+GLOBAL VOID Client_SetHostname( CLIENT *Client, CHAR *Hostname )
+{
+       /* Hostname eines Clients setzen */
+       
+       assert( Client != NULL );
+       strncpy( Client->host, Hostname, CLIENT_HOST_LEN );
+       Client->host[CLIENT_HOST_LEN - 1] = '\0';
+} /* Client_SetHostname */
+
+
 GLOBAL CLIENT *Client_GetFromConn( CONN_ID Idx )
 {
-       /* Client-Struktur, die zur lokalen Verbindung Idx gehoert
+       /* Client-Struktur, die zur lokalen Verbindung Idx gehoert,
         * liefern. Wird keine gefunden, so wird NULL geliefert. */
 
        CLIENT *c;
@@ -188,7 +234,26 @@ GLOBAL CLIENT *Client_GetFromConn( CONN_ID Idx )
 } /* Client_GetFromConn */
 
 
-GLOBAL CHAR *Client_Name( CLIENT *Client )
+GLOBAL CLIENT *Client_GetFromNick( CHAR *Nick )
+{
+       /* Client-Struktur, die den entsprechenden Nick hat,
+       * liefern. Wird keine gefunden, so wird NULL geliefert. */
+
+       CLIENT *c;
+
+       assert( Nick != NULL );
+
+       c = My_Clients;
+       while( c )
+       {
+               if( strcasecmp( c->nick, Nick ) == 0 ) return c;
+               c = c->next;
+       }
+       return NULL;
+} /* Client_GetFromNick */
+
+
+GLOBAL CHAR *Client_Nick( CLIENT *Client )
 {
        assert( Client != NULL );
 
@@ -207,7 +272,7 @@ GLOBAL BOOLEAN Client_CheckNick( CLIENT *Client, CHAR *Nick )
        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 );
+       if( strlen( Nick ) > CLIENT_NICK_LEN ) return IRC_WriteStrClient( Client, This_Server, ERR_ERRONEUSNICKNAME_MSG, Client_Nick( Client ), Nick );
 
        /* Nick bereits vergeben? */
        c = My_Clients;
@@ -216,7 +281,7 @@ GLOBAL BOOLEAN Client_CheckNick( CLIENT *Client, CHAR *Nick )
                if( strcasecmp( c->nick, Nick ) == 0 )
                {
                        /* den Nick gibt es bereits */
-                       IRC_WriteStrClient( Client, This_Server, ERR_NICKNAMEINUSE_MSG, Client_Name( Client ), Nick );
+                       IRC_WriteStrClient( Client, This_Server, ERR_NICKNAMEINUSE_MSG, Client_Nick( Client ), Nick );
                        return FALSE;
                }
                c = c->next;
@@ -233,13 +298,50 @@ GLOBAL CHAR *Client_GetID( CLIENT *Client )
 
        assert( Client != NULL );
        
-       if( Client->type == CLIENT_SERVER ) return Client->host;
+       if( Client->type == CLIENT_SERVER ) return Client->nick;
 
        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 */
+
+
+GLOBAL CLIENT *Client_First( VOID )
+{
+       /* Ersten Client liefern. */
+
+       return My_Clients;
+} /* Client_First */
+
+
+GLOBAL CLIENT *Client_Next( CLIENT *c )
+{
+       /* Naechsten Client liefern. Existiert keiner,
+        * so wird NULL geliefert. */
+
+       assert( c != NULL );
+       return c->next;
+} /* Client_Next */
+
+
 LOCAL CLIENT *New_Client_Struct( VOID )
 {
        /* Neue CLIENT-Struktur pre-initialisieren */
@@ -263,7 +365,10 @@ LOCAL CLIENT *New_Client_Struct( VOID )
        strcpy( c->host, "" );
        strcpy( c->user, "" );
        strcpy( c->name, "" );
+       strcpy( c->info, "" );
        for( i = 0; i < MAX_CHANNELS; c->channels[i++] = NULL );
+       strcpy( c->modes, "" );
+       c->oper_by_me = FALSE;
 
        return c;
 } /* New_Client */