]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-server.c
moved invite/ban lists to channel structure
[ngircd-alex.git] / src / ngircd / irc-server.c
index 989e5787f6d386a25b31b39aec3febbf07540a19..da9ba978b8b8b8ab442a05d259d474a5f3f2ac06 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2006 Alexander Barton (alex@barton.de)
  *
  * 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
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-server.c,v 1.38 2005/03/19 18:43:49 fw Exp $";
+static char UNUSED id[] = "$Id: irc-server.c,v 1.43 2006/12/07 17:57:20 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -41,6 +41,54 @@ static char UNUSED id[] = "$Id: irc-server.c,v 1.38 2005/03/19 18:43:49 fw Exp $
 #include "irc-server.h"
 
 
+#ifdef IRCPLUS
+static bool
+Synchronize_Lists( CLIENT *Client )
+{
+       CHANNEL *c;
+       struct list_head *head;
+       struct list_elem *elem;
+
+       assert( Client != NULL );
+
+       c = Channel_First();
+
+       while (c) {
+               head = Channel_GetListBans(c);
+
+               elem = Lists_GetFirst(head);
+               while (elem) {
+                       if( ! IRC_WriteStrClient( Client, "MODE %s +b %s",
+                                       Channel_Name(c), Lists_GetMask(elem)))
+                       {
+                               return false;
+                       }
+                       elem = Lists_GetNext(elem);
+               }
+
+               head = Channel_GetListInvites(c);
+               elem = Lists_GetFirst(head);
+               while (elem) {
+                       if( ! IRC_WriteStrClient( Client, "MODE %s +I %s",
+                                       Channel_Name( c ), Lists_GetMask(elem)))
+                       {
+                               return false;
+                       }
+                       elem = Lists_GetNext(elem);
+               }
+               c = Channel_Next(c);
+       }
+       return true;
+}
+#endif
+
+
+
+
+/**
+ * Handler for the IRC command "SERVER".
+ * See RFC 2813 section 4.1.2.
+ */
 GLOBAL bool
 IRC_SERVER( CLIENT *Client, REQUEST *Req )
 {
@@ -55,13 +103,16 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-       /* Fehler liefern, wenn kein lokaler Client */
-       if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
+       /* Return an error if this is not a local client */
+       if (Client_Conn(Client) <= NONE)
+               return IRC_WriteStrClient(Client, ERR_UNKNOWNCOMMAND_MSG,
+                                         Client_ID(Client), Req->command);
 
-       if( Client_Type( Client ) == CLIENT_GOTPASSSERVER )
-       {
-               /* Verbindung soll als Server-Server-Verbindung registriert werden */
-               Log( LOG_DEBUG, "Connection %d: got SERVER command (new server link) ...", Client_Conn( Client ));
+       if (Client_Type(Client) == CLIENT_GOTPASS) {
+               /* We got a PASS command from the peer, and now a SERVER
+                * command: the peer tries to register itself as a server. */
+               LogDebug("Connection %d: got SERVER command (new server link) ...",
+                       Client_Conn(Client));
 
                /* Falsche Anzahl Parameter? */
                if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
@@ -207,7 +258,13 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                                        else
                                        {
                                                /* "CHANINFO <chan> +<modes> <key> <limit> :<topic>" */
-                                               if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s %s %ld :%s", Channel_Name( chan ), modes, strchr( Channel_Modes( chan ), 'k' ) ? Channel_Key( chan ) : "*", strchr( Channel_Modes( chan ), 'l' ) ? Channel_MaxUsers( chan ) : 0L, topic )) return DISCONNECTED;
+                                               if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s %s %lu :%s",
+                                                       Channel_Name( chan ), modes,
+                                                       strchr( Channel_Modes( chan ), 'k' ) ? Channel_Key( chan ) : "*",
+                                                       strchr( Channel_Modes( chan ), 'l' ) ? Channel_MaxUsers( chan ) : 0UL, topic ))
+                                               {
+                                                       return DISCONNECTED;
+                                               }
                                        }
                                }
                        }
@@ -244,22 +301,22 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                                if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
                        }
 
+                       /* Get next channel ... */
+                       chan = Channel_Next(chan);
+               }
+
 #ifdef IRCPLUS
-                       if( strchr( Client_Flags( Client ), 'L' ))
-                       {
+               if (strchr(Client_Flags(Client), 'L')) {
 #ifdef DEBUG
-                               Log( LOG_DEBUG, "Synchronizing INVITE- and BAN-lists ..." );
+                       Log(LOG_DEBUG,
+                           "Synchronizing INVITE- and BAN-lists ...");
 #endif
-                               /* Synchronize INVITE- and BAN-lists */
-                               if( ! Lists_SendInvites( Client )) return DISCONNECTED;
-                               if( ! Lists_SendBans( Client )) return DISCONNECTED;
-                       }
+                       /* Synchronize INVITE- and BAN-lists */
+                       if (!Synchronize_Lists(Client))
+                               return DISCONNECTED;
+               }
 #endif
 
-                       /* naechsten Channel suchen */
-                       chan = Channel_Next( chan );
-               }
-               
                return CONNECTED;
        }
        else if( Client_Type( Client ) == CLIENT_SERVER )