]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-channel.c
Remove duplicate Channel_FirstChannelOf().
[ngircd-alex.git] / src / ngircd / irc-channel.c
index 7e21c1308c496dd6a55651d9d1833ec92b5ac960..514af7fa99aac3cec11fe993b6d4b55d28a819b1 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-channel.c,v 1.35 2006/03/16 20:14:16 fw Exp $";
+static char UNUSED id[] = "$Id: irc-channel.c,v 1.43 2008/02/05 19:00:52 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -40,6 +40,29 @@ static char UNUSED id[] = "$Id: irc-channel.c,v 1.35 2006/03/16 20:14:16 fw Exp
 #include "irc-channel.h"
 
 
+/*
+ * RFC 2812, (3.2.1 Join message Command):
+ *  Note that this message
+ *  accepts a special argument ("0"), which is a special request to leave all
+ *  channels the user is currently a member of. The server will process this
+ *  message as if the user had sent a PART command (See Section 3.2.2) for
+ *  each channel he is a member of.
+ */
+static bool
+part_from_all_channels(CLIENT* client, CLIENT *target)
+{
+       CL2CHAN *cl2chan;
+       CHANNEL *chan;
+
+       while ((cl2chan = Channel_FirstChannelOf(target))) {
+               chan = Channel_GetChannel(cl2chan);
+               assert( chan != NULL );
+               Channel_Part(target, client, Channel_Name(chan), Client_ID(target));
+       }
+       return CONNECTED;
+}
+
+
 GLOBAL bool
 IRC_JOIN( CLIENT *Client, REQUEST *Req )
 {
@@ -47,18 +70,24 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
        bool is_new_chan, is_invited, is_banned;
        CLIENT *target;
        CHANNEL *chan;
-       
+
        assert( Client != NULL );
        assert( Req != NULL );
 
        /* Bad number of arguments? */
-       if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+       if (Req->argc < 1 || Req->argc > 2)
+               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+                                         Client_ID(Client), Req->command);
 
        /* Who is the sender? */
        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 );
 
+       /* Is argument "0"? */
+       if (Req->argc == 1 && !strncmp("0", Req->argv[0], 2))
+               return part_from_all_channels(Client, target);
+
        /* Are channel keys given? */
        if (Req->argc > 1) {
                key = Req->argv[1];
@@ -78,8 +107,17 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                chan = NULL; flags = NULL;
 
                /* wird der Channel neu angelegt? */
-               if( Channel_Search( channame )) is_new_chan = false;
-               else is_new_chan = true;
+               if( Channel_Search( channame )) {
+                       is_new_chan = false;
+               } else {
+                       if (Conf_PredefChannelsOnly) { /* this server does not allow creation of channels */
+                               IRC_WriteStrClient( Client, ERR_BANNEDFROMCHAN_MSG, Client_ID( Client ), channame );
+                               /* Try next name, if any */
+                               channame = strchr(channame, ',');
+                               continue;
+                       }
+                       is_new_chan = true;
+               }
 
                /* Hat ein Server Channel-User-Modes uebergeben? */
                if( Client_Type( Client ) == CLIENT_SERVER )
@@ -113,8 +151,8 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                                chan = Channel_Search( channame );
                                assert( chan != NULL );
 
-                               is_banned = Lists_CheckBanned( target, chan );
-                               is_invited = Lists_CheckInvited( target, chan );
+                               is_banned = Lists_Check(Channel_GetListBans(chan), target );
+                               is_invited = Lists_Check(Channel_GetListInvites(chan), target );
 
                                /* Testen, ob Client gebanned ist */
                                if(( is_banned == true) &&  ( is_invited == false ))
@@ -123,7 +161,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                                        IRC_WriteStrClient( Client, ERR_BANNEDFROMCHAN_MSG, Client_ID( Client ), channame );
 
                                        /* Try next name, if any */
-                                       channame = strtok( NULL, "," );
+                                       channame = strchr(channame, ',');
                                        continue;
                                }
 
@@ -134,7 +172,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                                        IRC_WriteStrClient( Client, ERR_INVITEONLYCHAN_MSG, Client_ID( Client ), channame );
 
                                        /* Try next name, if any */
-                                       channame = strtok( NULL, "," );
+                                       channame = strchr(channame, ',');
                                        continue;
                                }
 
@@ -145,7 +183,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                                        IRC_WriteStrClient( Client, ERR_BADCHANNELKEY_MSG, Client_ID( Client ), channame );
 
                                        /* Try next name, if any */
-                                       channame = strtok( NULL, "," );
+                                       channame = strchr(channame, ',');
                                        continue;
                                }
 
@@ -156,7 +194,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                                        IRC_WriteStrClient( Client, ERR_CHANNELISFULL_MSG, Client_ID( Client ), channame );
 
                                        /* Try next name, if any */
-                                       channame = strtok( NULL, "," );
+                                       channame = strchr(channame, ',');
                                        continue;
                                }
                        }
@@ -169,14 +207,14 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                         * commands) in this list become deleted when a user
                         * joins a channel this way. */
                        chan = Channel_Search( channame );
-                       if( chan != NULL ) (void)Lists_CheckInvited( target, chan );
+                       if( chan != NULL ) (void)Lists_Check(Channel_GetListInvites(chan), target);
                }
 
                /* Channel joinen (und ggf. anlegen) */
                if( ! Channel_Join( target, channame ))
                {
                        /* naechsten Namen ermitteln */
-                       channame = strtok( NULL, "," );
+                       channame = strchr(channame, ',');
                        continue;
                }
                if( ! chan ) chan = Channel_Search( channame );
@@ -258,8 +296,9 @@ IRC_PART( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-       /* Falsche Anzahl Parameter? */
-       if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+       if (Req->argc < 1 || 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_Search( Req->prefix );
@@ -267,18 +306,11 @@ IRC_PART( CLIENT *Client, REQUEST *Req )
        if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
 
        /* Channel-Namen durchgehen */
-       chan = strtok( Req->argv[0], "," );
-       while( chan )
-       {
-               if( ! Channel_Part( target, Client, chan, Req->argc > 1 ? Req->argv[1] : Client_ID( target )))
-               {
-                       /* naechsten Namen ermitteln */
-                       chan = strtok( NULL, "," );
-                       continue;
-               }
+       chan = strtok(Req->argv[0], ",");
+       while (chan) {
+               Channel_Part(target, Client, chan, Req->argc > 1 ? Req->argv[1] : Client_ID(target));
 
-               /* naechsten Namen ermitteln */
-               chan = strtok( NULL, "," );
+               chan = strtok(NULL, ",");
        }
        return CONNECTED;
 } /* IRC_PART */
@@ -491,7 +523,7 @@ IRC_CHANINFO( CLIENT *Client, REQUEST *Req )
                        {
                                if( *ptr == 'l' )
                                {
-                                       snprintf( l, sizeof( l ), " %ld", Channel_MaxUsers( chan ));
+                                       snprintf( l, sizeof( l ), " %lu", Channel_MaxUsers( chan ));
                                        strlcat( modes_add, l, sizeof( modes_add ));
                                }
                                if( *ptr == 'k' )