X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fngircd%2Firc-channel.c;h=514af7fa99aac3cec11fe993b6d4b55d28a819b1;hb=c634303765c20083c8f554f4d4084526d3e58fef;hp=7b92c2b009bd165594a3272d60428fcd4dea9af1;hpb=fa7bb2790a1588e49d05cf3404220c3a63669514;p=ngircd-alex.git diff --git a/src/ngircd/irc-channel.c b/src/ngircd/irc-channel.c index 7b92c2b0..514af7fa 100644 --- a/src/ngircd/irc-channel.c +++ b/src/ngircd/irc-channel.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-channel.c,v 1.39 2006/12/07 17:57:20 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 @@ -40,6 +40,29 @@ static char UNUSED id[] = "$Id: irc-channel.c,v 1.39 2006/12/07 17:57:20 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]; @@ -267,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 ); @@ -276,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 */