]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-channel.c
channel maxusers now unsigned long
[ngircd-alex.git] / src / ngircd / irc-channel.c
index 4708af1d7fbcff86560e4d4af2e3fc05444464a1..f30df91acdadb984be809d00c3032becdb9a0eb8 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-channel.c,v 1.30 2005/06/12 18:23:59 alex Exp $";
+static char UNUSED id[] = "$Id: irc-channel.c,v 1.37 2006/10/06 21:32:58 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -43,11 +43,11 @@ static char UNUSED id[] = "$Id: irc-channel.c,v 1.30 2005/06/12 18:23:59 alex Ex
 GLOBAL bool
 IRC_JOIN( CLIENT *Client, REQUEST *Req )
 {
-       char *channame, *key, *flags, *topic, modes[8];
+       char *channame, *channame_ptr, *key, *key_ptr, *flags, *topic, modes[8];
        bool is_new_chan, is_invited, is_banned;
        CLIENT *target;
        CHANNEL *chan;
-
+       
        assert( Client != NULL );
        assert( Req != NULL );
 
@@ -60,13 +60,20 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
        if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
 
        /* Are channel keys given? */
-       if( Req->argc > 1 ) key = Req->argv[1];
-       else key = NULL;
+       if (Req->argc > 1) {
+               key = Req->argv[1];
+               key_ptr = strchr(key, ',');
+               if (key_ptr) *key_ptr = '\0';
+       }
+       else
+               key = key_ptr = NULL;
+
+       channame = Req->argv[0];
+       channame_ptr = strchr(channame, ',');
+       if (channame_ptr) *channame_ptr = '\0';
 
        /* Channel-Namen durchgehen */
-       chan = NULL;
-       channame = strtok( Req->argv[0], "," );
-       while( channame )
+       while (channame)
        {
                chan = NULL; flags = NULL;
 
@@ -90,14 +97,9 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                if( Client_Type( Client ) == CLIENT_USER )
                {
                        /* Test if the user has reached his maximum channel count */
-                       if( Client_Type( Client ) == CLIENT_USER )
-                       {
-                               if(( Conf_MaxJoins > 0 ) && ( Channel_CountForUser( Client ) >= Conf_MaxJoins ))
-                               {
-                                       IRC_WriteStrClient( Client, ERR_TOOMANYCHANNELS_MSG, Client_ID( Client ), channame );
-                                       return CONNECTED;
-                               }
-                       }
+                       if(( Conf_MaxJoins > 0 ) && ( Channel_CountForUser( Client ) >= Conf_MaxJoins ))
+                               return IRC_WriteStrClient( Client, ERR_TOOMANYCHANNELS_MSG,
+                                                       Client_ID( Client ), channame );
 
                        /* Existiert der Channel bereits, oder wird er im Moment neu erzeugt? */
                        if( is_new_chan )
@@ -121,7 +123,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;
                                }
 
@@ -132,7 +134,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;
                                }
 
@@ -143,7 +145,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;
                                }
 
@@ -154,7 +156,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;
                                }
                        }
@@ -174,7 +176,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                if( ! Channel_Join( target, channame ))
                {
                        /* naechsten Namen ermitteln */
-                       channame = strtok( NULL, "," );
+                       channame = strchr(channame, ',');
                        continue;
                }
                if( ! chan ) chan = Channel_Search( channame );
@@ -211,17 +213,37 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
                        /* an Client bestaetigen */
                        IRC_WriteStrClientPrefix( Client, target, "JOIN :%s", channame );
 
-                       /* Topic an Client schicken */
-                       topic = Channel_Topic( chan );
-                       if( *topic ) IRC_WriteStrClient( Client, RPL_TOPIC_MSG, Client_ID( Client ), channame, topic );
+                       /* Send topic to client, if any */
+                       topic = Channel_Topic(chan);
+                       if (*topic) {
+                               IRC_WriteStrClient(Client, RPL_TOPIC_MSG,
+                                       Client_ID(Client), channame, topic);
+#ifndef STRICT_RFC
+                               IRC_WriteStrClient(Client, RPL_TOPICSETBY_MSG,
+                                       Client_ID(Client), channame,
+                                       Channel_TopicWho(chan),
+                                       Channel_TopicTime(chan));
+#endif
+                       }
 
                        /* Mitglieder an Client Melden */
                        IRC_Send_NAMES( Client, chan );
                        IRC_WriteStrClient( Client, RPL_ENDOFNAMES_MSG, Client_ID( Client ), Channel_Name( chan ));
                }
 
-               /* naechsten Namen ermitteln */
-               channame = strtok( NULL, "," );
+               /* 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';
+                       }
+               }
        }
        return CONNECTED;
 } /* IRC_JOIN */
@@ -268,6 +290,7 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req )
        CHANNEL *chan;
        CLIENT *from;
        char *topic;
+       bool r;
 
        assert( Client != NULL );
        assert( Req != NULL );
@@ -288,10 +311,22 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req )
 
        if( Req->argc == 1 )
        {
-               /* Topic erfragen */
-               topic = Channel_Topic( chan );
-               if( *topic ) return IRC_WriteStrClient( from, RPL_TOPIC_MSG, Client_ID( from ), Channel_Name( chan ), topic );
-               else return IRC_WriteStrClient( from, RPL_NOTOPIC_MSG, Client_ID( from ), Channel_Name( chan ));
+               /* Request actual topic */
+               topic = Channel_Topic(chan);
+               if (*topic) {
+                       r = IRC_WriteStrClient(from, RPL_TOPIC_MSG,
+                               Client_ID(Client), Channel_Name(chan), topic);
+#ifndef STRICT_RFC
+                       r = IRC_WriteStrClient(from, RPL_TOPICSETBY_MSG,
+                               Client_ID(Client), Channel_Name(chan),
+                               Channel_TopicWho(chan),
+                               Channel_TopicTime(chan));
+#endif
+                       return r;
+               }
+               else
+                        return IRC_WriteStrClient(from, RPL_NOTOPIC_MSG,
+                                       Client_ID(from), Channel_Name(chan));
        }
 
        if( strchr( Channel_Modes( chan ), 't' ))
@@ -300,9 +335,11 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req )
                if( ! strchr( Channel_UserModes( chan, from ), 'o' )) return IRC_WriteStrClient( from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( from ), Channel_Name( chan ));
        }
 
-       /* Topic setzen */
-       Channel_SetTopic( chan, 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>" );
+       /* 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>");
 
        /* im Channel bekannt machen und an Server weiterleiten */
        IRC_WriteStrServersPrefix( Client, from, "TOPIC %s :%s", Req->argv[0], Req->argv[1] );
@@ -454,7 +491,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' )
@@ -478,8 +515,9 @@ IRC_CHANINFO( CLIENT *Client, REQUEST *Req )
                if(( ! *ptr ) && ( Req->argv[arg_topic][0] ))
                {
                        /* OK, there is no topic jet */
-                       Channel_SetTopic( chan, Req->argv[arg_topic] );
-                       IRC_WriteStrChannelPrefix( Client, chan, from, false, "TOPIC %s :%s", Req->argv[0], Channel_Topic( chan ));
+                       Channel_SetTopic(chan, Client, Req->argv[arg_topic]);
+                       IRC_WriteStrChannelPrefix(Client, chan, from, false,
+                            "TOPIC %s :%s", Req->argv[0], Channel_Topic(chan));
                }
        }