]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-server.c
- new allocated connection structures will be initialized correctly now.
[ngircd-alex.git] / src / ngircd / irc-server.c
index 3cefaa1b50b3766d6e9b8cfb174fb5277a6fcf67..e5846dd4a038af7bc5a654ce7a74e761a4731ab0 100644 (file)
@@ -2,21 +2,20 @@
  * ngIRCd -- The Next Generation IRC Daemon
  * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
  *
- * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
- * der GNU General Public License (GPL), wie von der Free Software Foundation
- * 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 ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: irc-server.c,v 1.11 2002/05/30 16:52:21 alex Exp $
- *
- * irc-server.c: IRC-Befehle fuer Server-Links
+ * IRC commands for server links
  */
 
 
 #include "portab.h"
 
+static char UNUSED id[] = "$Id: irc-server.c,v 1.24 2002/12/12 12:24:18 alex Exp $";
+
 #include "imp.h"
 #include <assert.h>
 #include <stdio.h>
@@ -32,6 +31,7 @@
 #include "log.h"
 #include "messages.h"
 #include "parse.h"
+#include "ngircd.h"
 
 #include "exp.h"
 #include "irc-server.h"
@@ -46,6 +46,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
        INT max_hops, i;
        CHANNEL *chan;
        BOOLEAN ok;
+       CONN_ID con;
        
        assert( Client != NULL );
        assert( Req != NULL );
@@ -70,10 +71,10 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                        Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", TRUE );
                        return DISCONNECTED;
                }
-               if( strcmp( Client_Password( Client ), Conf_Server[i].pwd ) != 0 )
+               if( strcmp( Client_Password( Client ), Conf_Server[i].pwd_in ) != 0 )
                {
                        /* Falsches Passwort */
-                       Log( LOG_ERR, "Connection %d: Bad password for server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
+                       Log( LOG_ERR, "Connection %d: Got bad password from server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
                        Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
                        return DISCONNECTED;
                }
@@ -85,18 +86,19 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                Client_SetID( Client, Req->argv[0] );
                Client_SetHops( Client, 1 );
                Client_SetInfo( Client, Req->argv[Req->argc - 1] );
-               
+
                /* Meldet sich der Server bei uns an (d.h., bauen nicht wir
                 * selber die Verbindung zu einem anderen Server auf)? */
+               con = Client_Conn( Client );
                if( Client_Token( Client ) != TOKEN_OUTBOUND )
                {
                        /* Eingehende Verbindung: Unseren SERVER- und PASS-Befehl senden */
                        ok = TRUE;
-                       if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd, PASSSERVERADD )) ok = FALSE;
+                       if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd_out, NGIRCd_ProtoID )) ok = FALSE;
                        else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo );
                        if( ! ok )
                        {
-                               Conn_Close( Client_Conn( Client ), "Unexpected server behavior!", NULL, FALSE );
+                               Conn_Close( con, "Unexpected server behavior!", NULL, FALSE );
                                return DISCONNECTED;
                        }
                        Client_SetIntroducer( Client, Client );
@@ -109,9 +111,23 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                        Client_SetToken( Client, atoi( Req->argv[1] ));
                }
 
-               Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), Client_Conn( Client ));
+               Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), con );
 
                Client_SetType( Client, CLIENT_SERVER );
+               Conn_SetServer( con, i );
+
+#ifdef USE_ZLIB
+               /* Kompression initialisieren, wenn erforderlich */
+               if( strchr( Client_Flags( Client ), 'Z' ))
+               {
+                       if( ! Conn_InitZip( con ))
+                       {
+                               /* Fehler! */
+                               Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, FALSE );
+                               return DISCONNECTED;
+                       }
+               }
+#endif
 
                /* maximalen Hop Count ermitteln */
                max_hops = 0;
@@ -161,6 +177,15 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                chan = Channel_First( );
                while( chan )
                {
+#ifdef IRCPLUS
+                       /* Wenn unterstuetzt, CHANINFO senden */
+                       if( strchr( Client_Flags( Client ), 'C' ))
+                       {
+                               /* CHANINFO senden */
+                               if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s :%s", Channel_Name( chan ), Channel_Modes( chan ), Channel_Topic( chan ))) return DISCONNECTED;
+                       }
+#endif
+
                        /* alle Member suchen */
                        cl2chan = Channel_FirstMember( chan );
                        sprintf( str, "NJOIN %s :", Channel_Name( chan ));
@@ -178,7 +203,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                                if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 8 ))
                                {
                                        /* Zeile senden */
-                                       if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED;
+                                       if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
                                        sprintf( str, "NJOIN %s :", Channel_Name( chan ));
                                }
                                
@@ -189,7 +214,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                        if( str[strlen( str ) - 1] != ':')
                        {
                                /* Ja; Also senden ... */
-                               if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED;
+                               if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
                        }
 
                        /* naechsten Channel suchen */
@@ -248,7 +273,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
 GLOBAL BOOLEAN
 IRC_NJOIN( CLIENT *Client, REQUEST *Req )
 {
-       CHAR *channame, *ptr, modes[8];
+       CHAR str[COMMAND_LEN], *channame, *ptr, modes[8];
        BOOLEAN is_op, is_voiced;
        CHANNEL *chan;
        CLIENT *c;
@@ -256,13 +281,14 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-       if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTEREDSERVER_MSG, Client_ID( Client ));
-
        /* Falsche Anzahl Parameter? */
        if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
 
+       strncpy( str, Req->argv[1], COMMAND_LEN - 1 );
+       str[COMMAND_LEN - 1] = '\0';
+
        channame = Req->argv[0];
-       ptr = strtok( Req->argv[1], "," );
+       ptr = strtok( str, "," );
        while( ptr )
        {
                is_op = is_voiced = FALSE;
@@ -318,17 +344,11 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-       /* SQUIT ist nur fuer Server erlaubt */
-       if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
-
        /* Falsche Anzahl Parameter? */
        if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
 
        Log( LOG_DEBUG, "Got SQUIT from %s for \"%s\": \"%s\" ...", Client_ID( Client ), Req->argv[0], Req->argv[1] );
 
-       /* SQUIT an alle Server weiterleiten */
-       IRC_WriteStrServers( Client, "SQUIT %s :%s", Req->argv[0], Req->argv[1] );
-
        target = Client_Search( Req->argv[0] );
        if( ! target )
        {