#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 <assert.h>
#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 )
{
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];
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 );
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 */