]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-channel.c
- an Clients wurden Modes mit fuehrendem ":" geliefert. Das ist zwar RFC-
[ngircd-alex.git] / src / ngircd / irc-channel.c
index 041073b542766d52ad055f1a603f6a252349dfe0..7ee157d9ed8322915d9d377e8928f17356a5829f 100644 (file)
@@ -9,7 +9,7 @@
  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
  *
- * $Id: irc-channel.c,v 1.2 2002/03/12 14:37:52 alex Exp $
+ * $Id: irc-channel.c,v 1.12 2002/08/27 13:57:03 alex Exp $
  *
  * irc-channel.c: IRC-Channel-Befehle
  */
 #include <string.h>
 
 #include "defines.h"
-#include "irc.h"
-#include "irc-write.h"
+#include "conn.h"
+#include "client.h"
+#include "channel.h"
+#include "lists.h"
 #include "log.h"
+#include "match.h"
 #include "messages.h"
+#include "parse.h"
+#include "irc.h"
+#include "irc-write.h"
 
 #include "exp.h"
 #include "irc-channel.h"
 
 
-GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
+GLOBAL BOOLEAN
+IRC_JOIN( CLIENT *Client, REQUEST *Req )
 {
        CHAR *channame, *flags, *topic, modes[8];
        BOOLEAN is_new_chan;
@@ -47,17 +54,18 @@ GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
        if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
 
        /* Wer ist der Absender? */
-       if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
+       if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
        else target = Client;
        if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
 
        /* Channel-Namen durchgehen */
+       chan = NULL;
        channame = strtok( Req->argv[0], "," );
        while( channame )
        {
-               /* wird der Channel neu angelegt? */
-               flags = NULL;
+               chan = flags = NULL;
 
+               /* wird der Channel neu angelegt? */
                if( Channel_Search( channame )) is_new_chan = FALSE;
                else is_new_chan = TRUE;
 
@@ -66,14 +74,54 @@ GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
                {
                        /* Channel-Flags extrahieren */
                        flags = strchr( channame, 0x7 );
-                       if( flags ) *flags++ = '\0';
+                       if( flags )
+                       {
+                               *flags = '\0';
+                               flags++;
+                       }
                }
 
-               /* neuer Channel udn lokaler Client? */
-               if( is_new_chan && ( Client_Type( Client ) == CLIENT_USER ))
+               /* Lokaler Client? */
+               if( Client_Type( Client ) == CLIENT_USER )
                {
-                       /* Dann soll der Client Channel-Operator werden! */
-                       flags = "o";
+                       /* Existiert der Channel bereits, oder wird er im Moment neu erzeugt? */
+                       if( is_new_chan )
+                       {
+                               /* Erster User im Channel: Operator-Flag setzen */
+                               flags = "o";
+                       }
+                       else
+                       {
+                               /* Existierenden Channel suchen */
+                               chan = Channel_Search( channame );
+                               assert( chan != NULL );
+
+                               /* Testen, ob Client gebanned ist */
+                               if( Lists_CheckBanned( target, chan ))
+                               {
+                                       /* Client ist gebanned: */
+                                       IRC_WriteStrClient( Client, ERR_BANNEDFROMCHAN_MSG, Client_ID( Client ), channame );
+
+                                       /* naechsten Namen ermitteln */
+                                       channame = strtok( NULL, "," );
+                                       continue;
+                               }
+
+                               /* Ist der Channel "invite-only"? */
+                               if( strchr( Channel_Modes( chan ), 'i' ))
+                               {
+                                       /* Wurde der Client invited? */
+                                       if( ! Lists_CheckInvited( target, chan ))
+                                       {
+                                               /* Client wurde nicht invited: */
+                                               IRC_WriteStrClient( Client, ERR_INVITEONLYCHAN_MSG, Client_ID( Client ), channame );
+
+                                               /* naechsten Namen ermitteln */
+                                               channame = strtok( NULL, "," );
+                                               continue;
+                                       }
+                               }
+                       }
                }
 
                /* Channel joinen (und ggf. anlegen) */
@@ -83,7 +131,7 @@ GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
                        channame = strtok( NULL, "," );
                        continue;
                }
-               chan = Channel_Search( channame );
+               if( ! chan ) chan = Channel_Search( channame );
                assert( chan != NULL );
 
                /* Modes setzen (wenn vorhanden) */
@@ -93,6 +141,9 @@ GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
                        flags++;
                }
 
+               /* Wenn persistenter Channel und IRC-Operator: zum Channel-OP machen */
+               if(( strchr( Channel_Modes( chan ), 'P' )) && ( strchr( Client_Modes( target ), 'o' ))) Channel_UserModeAdd( chan, target, 'o' );
+
                /* Muessen Modes an andere Server gemeldet werden? */
                strcpy( &modes[1], Channel_UserModes( chan, target ));
                if( modes[1] ) modes[0] = 0x7;
@@ -106,7 +157,7 @@ GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
                if( modes[1] )
                {
                        /* Modes im Channel bekannt machen */
-                       IRC_WriteStrChannelPrefix( Client, chan, target, FALSE, "MODE %s %s :%s", channame, modes, Client_ID( target ));
+                       IRC_WriteStrChannelPrefix( Client, chan, target, FALSE, "MODE %s +%s %s", channame, &modes[1], Client_ID( target ));
                }
 
                if( Client_Type( Client ) == CLIENT_USER )
@@ -130,7 +181,8 @@ GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
 } /* IRC_JOIN */
 
 
-GLOBAL BOOLEAN IRC_PART( CLIENT *Client, REQUEST *Req )
+GLOBAL BOOLEAN
+IRC_PART( CLIENT *Client, REQUEST *Req )
 {
        CLIENT *target;
        CHAR *chan;
@@ -144,7 +196,7 @@ GLOBAL BOOLEAN IRC_PART( CLIENT *Client, REQUEST *Req )
        if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
 
        /* Wer ist der Absender? */
-       if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
+       if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
        else target = Client;
        if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
 
@@ -166,7 +218,8 @@ GLOBAL BOOLEAN IRC_PART( CLIENT *Client, REQUEST *Req )
 } /* IRC_PART */
 
 
-GLOBAL BOOLEAN IRC_TOPIC( CLIENT *Client, REQUEST *Req )
+GLOBAL BOOLEAN
+IRC_TOPIC( CLIENT *Client, REQUEST *Req )
 {
        CHANNEL *chan;
        CLIENT *from;
@@ -180,13 +233,13 @@ GLOBAL BOOLEAN IRC_TOPIC( CLIENT *Client, REQUEST *Req )
        /* Falsche Anzahl Parameter? */
        if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
 
-       if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
+       if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
        else from = Client;
        if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
 
        /* Welcher Channel? */
        chan = Channel_Search( Req->argv[0] );
-       if( ! chan ) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
+       if( ! chan ) return IRC_WriteStrClient( from, ERR_NOSUCHCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
 
        /* Ist der User Mitglied in dem Channel? */
        if( ! Channel_IsMemberOf( chan, from )) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
@@ -218,4 +271,45 @@ GLOBAL BOOLEAN IRC_TOPIC( CLIENT *Client, REQUEST *Req )
 } /* IRC_TOPIC */
 
 
+GLOBAL BOOLEAN
+IRC_LIST( CLIENT *Client, REQUEST *Req )
+{
+       CHAR *pattern;
+       CHANNEL *chan;
+
+       assert( Client != NULL );
+       assert( Req != NULL );
+
+       if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
+
+       /* Falsche Anzahl Parameter? */
+       if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+
+       if( Req->argc > 0 ) pattern = strtok( Req->argv[0], "," );
+       else pattern = "*";
+       
+       while( pattern )
+       {
+               /* alle Channel durchgehen */
+               chan = Channel_First( );
+               while( chan )
+               {
+                       /* Passt die Suchmaske auf diesen Channel? */
+                       if( Match( pattern, Channel_Name( chan )))
+                       {
+                               /* Treffer! */
+                               if( ! IRC_WriteStrClient( Client, RPL_LIST_MSG, Client_ID( Client), Channel_Name( chan ), Channel_MemberCount( chan ), Channel_Topic( chan ))) return DISCONNECTED;
+                       }
+                       chan = Channel_Next( chan );
+               }
+               
+               /* naechsten Namen ermitteln */
+               if( Req->argc > 0 ) pattern = strtok( NULL, "," );
+               else pattern = NULL;
+       }
+       
+       return IRC_WriteStrClient( Client, RPL_LISTEND_MSG, Client_ID( Client ));
+} /* IRC_LIST */
+
+
 /* -eof- */