]> arthur.barton.de Git - ngircd.git/blobdiff - src/ngircd/irc-channel.c
Make real use of the CLIENT_SERVICE client type.
[ngircd.git] / src / ngircd / irc-channel.c
index 3ffd85a0196ce035cff2e73d848bbe733bf29954..b557b531192b44074313dff3b74e372be4c96bb9 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-channel.c,v 1.44 2008/02/16 11:21:33 fw Exp $";
+static char UNUSED id[] = "$Id: irc-channel.c,v 1.45 2008/02/24 18:57:38 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -26,6 +26,7 @@ static char UNUSED id[] = "$Id: irc-channel.c,v 1.44 2008/02/16 11:21:33 fw Exp
 #include "conn.h"
 #include "client.h"
 #include "channel.h"
+#include "conn-func.h"
 #include "lists.h"
 #include "log.h"
 #include "match.h"
@@ -70,6 +71,10 @@ join_allowed(CLIENT *Client, CLIENT *target, CHANNEL *chan,
        bool is_invited, is_banned;
        const char *channel_modes;
 
+       /* Allow IRC operators to overwrite channel limits */
+       if (strchr(Client_Modes(Client), 'o'))
+               return true;
+
        is_banned = Lists_Check(Channel_GetListBans(chan), target);
        is_invited = Lists_Check(Channel_GetListInvites(chan), target);
 
@@ -177,7 +182,7 @@ join_send_topic(CLIENT *Client, CLIENT *target, CHANNEL *chan,
 GLOBAL bool
 IRC_JOIN( CLIENT *Client, REQUEST *Req )
 {
-       char *channame, *channame_ptr, *key, *key_ptr, *flags;
+       char *channame, *key = NULL, *flags, *lastkey = NULL, *lastchan = NULL;
        CLIENT *target;
        CHANNEL *chan;
 
@@ -203,27 +208,20 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                return part_from_all_channels(Client, target);
 
        /* Are channel keys given? */
-       if (Req->argc > 1) {
-               key = Req->argv[1];
-               key_ptr = strchr(key, ',');
-               if (key_ptr) *key_ptr = '\0';
-       } else {
-               key = key_ptr = NULL;
-       }
+       if (Req->argc > 1)
+               key = strtok_r(Req->argv[1], ",", &lastkey);
+
        channame = Req->argv[0];
-       channame_ptr = strchr(channame, ',');
-       if (channame_ptr) *channame_ptr = '\0';
+       channame = strtok_r(channame, ",", &lastchan);
+
+       /* Make sure that "channame" is not the empty string ("JOIN :") */
+       if (! channame)
+               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+                                         Client_ID(Client), Req->command);
 
        while (channame) {
                flags = NULL;
 
-               chan = Channel_Search(channame);
-               if (!chan && Conf_PredefChannelsOnly) {
-                        /* channel must be created, but server does not allow this */
-                       IRC_WriteStrClient(Client, ERR_BANNEDFROMCHAN_MSG, Client_ID(Client), channame);
-                       break;
-               }
-
                /* Did the server include channel-user-modes? */
                if (Client_Type(Client) == CLIENT_SERVER) {
                        flags = strchr(channame, 0x7);
@@ -233,17 +231,32 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                        }
                }
 
+               chan = Channel_Search(channame);
+               if (!chan && Conf_PredefChannelsOnly) {
+                        /* channel must be created, but server does not allow this */
+                       IRC_WriteStrClient(Client, ERR_BANNEDFROMCHAN_MSG, Client_ID(Client), channame);
+                       break;
+               }
+
                /* Local client? */
                if (Client_Type(Client) == CLIENT_USER) {
                        /* Test if the user has reached his maximum channel count */
                        if ((Conf_MaxJoins > 0) && (Channel_CountForUser(Client) >= Conf_MaxJoins))
                                return IRC_WriteStrClient(Client, ERR_TOOMANYCHANNELS_MSG,
                                                        Client_ID(Client), channame);
-                       if (!chan) /* New Channel: first user will be channel operator */
-                               flags = "o";
-                       else
+                       if (!chan) {
+                               /*
+                                * New Channel: first user will be channel operator
+                                * unless this is a modeless channel.
+                                */
+                               if (*channame != '+')
+                                       flags = "o";
+                       } else
                                if (!join_allowed(Client, target, chan, channame, key))
                                        break;
+
+                       /* Local client: update idle time */
+                       Conn_UpdateIdle(Client_Conn(Client));
                } else {
                        /* Remote server: we don't need to know whether the
                         * client is invited or not, but we have to make sure
@@ -257,8 +270,14 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                if (!Channel_Join(target, channame))
                        break;
 
-               if (!chan) /* channel is new; it has been created above */
+               if (!chan) /* channel is new; it has been created above */
                        chan = Channel_Search(channame);
+                       assert(chan != NULL);
+                       if (*channame == '+') { /* modeless channel... */
+                               Channel_ModeAdd(chan, 't'); /* /TOPIC not allowed */
+                               Channel_ModeAdd(chan, 'n'); /* no external msgs */
+                       }
+               }
                assert(chan != NULL);
 
                join_set_channelmodes(chan, target, flags);
@@ -269,48 +288,57 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                        break; /* write error */
 
                /* next channel? */
-               channame = channame_ptr;
-               if (channame) {
-                       channame++;
-                       channame_ptr = strchr(channame, ',');
-                       if (channame_ptr) *channame_ptr = '\0';
-
-                       if (key_ptr) {
-                               key = ++key_ptr;
-                               key_ptr = strchr(key, ',');
-                               if (key_ptr) *key_ptr = '\0';
-                       }
-               }
+               channame = strtok_r(NULL, ",", &lastchan);
+               if (channame && key)
+                       key = strtok_r(NULL, ",", &lastkey);
        }
        return CONNECTED;
 } /* IRC_JOIN */
 
 
+/**
+ * Handler for the IRC "PART" command.
+ */
 GLOBAL bool
-IRC_PART( CLIENT *Client, REQUEST *Req )
+IRC_PART(CLIENT * Client, REQUEST * Req)
 {
        CLIENT *target;
        char *chan;
 
-       assert( Client != NULL );
-       assert( Req != NULL );
+       assert(Client != NULL);
+       assert(Req != NULL);
 
        if (Req->argc < 1 || Req->argc > 2)
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
-                                       Client_ID(Client), Req->command);
+                                         Client_ID(Client), Req->command);
 
-       /* Wer ist der Absender? */
-       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 );
+       /* Get 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);
 
-       /* Channel-Namen durchgehen */
+       /* Loop over all the given channel names */
        chan = strtok(Req->argv[0], ",");
-       while (chan) {
-               Channel_Part(target, Client, chan, Req->argc > 1 ? Req->argv[1] : Client_ID(target));
 
+       /* Make sure that "chan" is not the empty string ("PART :") */
+       if (! chan)
+               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+                                         Client_ID(Client), Req->command);
+
+       while (chan) {
+               Channel_Part(target, Client, chan,
+                            Req->argc > 1 ? Req->argv[1] : Client_ID(target));
                chan = strtok(NULL, ",");
        }
+
+       /* Update idle time, if local client */
+       if (Client_Conn(Client) > NONE)
+               Conn_UpdateIdle(Client_Conn(Client));
+
        return CONNECTED;
 } /* IRC_PART */
 
@@ -326,8 +354,8 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-       /* Falsche Anzahl Parameter? */
-       if(( Req->argc < 1 ) || ( 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);
 
        if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
        else from = Client;
@@ -368,9 +396,9 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req )
 
        /* Set new topic */
        Channel_SetTopic(chan, from, Req->argv[1]);
-       Log(LOG_DEBUG, "User \"%s\" set topic on \"%s\": %s",
-               Client_Mask(from), Channel_Name(chan),
-               Req->argv[1][0] ? Req->argv[1] : "<none>");
+       LogDebug("%s \"%s\" set topic on \"%s\": %s",
+                Client_TypeText(from), Client_Mask(from), Channel_Name(chan),
+                Req->argv[1][0] ? Req->argv[1] : "<none>");
 
        /* im Channel bekannt machen und an Server weiterleiten */
        IRC_WriteStrServersPrefix( Client, from, "TOPIC %s :%s", Req->argv[0], Req->argv[1] );