#include "portab.h"
-static char UNUSED id[] = "$Id: irc-channel.c,v 1.19 2002/12/13 17:53:32 alex Exp $";
+static char UNUSED id[] = "$Id: irc-channel.c,v 1.27 2004/04/09 20:46:48 alex Exp $";
#include "imp.h"
#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include "defines.h"
GLOBAL BOOLEAN
IRC_JOIN( CLIENT *Client, REQUEST *Req )
{
- CHAR *channame, *flags, *topic, modes[8];
+ CHAR *channame, *key, *flags, *topic, modes[8];
BOOLEAN is_new_chan, is_invited, is_banned;
CLIENT *target;
CHANNEL *chan;
assert( Client != NULL );
assert( Req != NULL );
- /* Falsche Anzahl Parameter? */
- if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+ /* Bad number of arguments? */
+ if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
- /* Wer ist der Absender? */
+ /* 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 );
+ /* Are channel keys given? */
+ if( Req->argc > 1 ) key = Req->argv[1];
+ else key = NULL;
+
/* Channel-Namen durchgehen */
chan = NULL;
channame = strtok( Req->argv[0], "," );
while( channame )
{
- chan = flags = NULL;
+ chan = NULL; flags = NULL;
/* wird der Channel neu angelegt? */
if( Channel_Search( channame )) is_new_chan = FALSE;
}
}
- /* Lokaler Client? */
+ /* Local client? */
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;
+ }
+ }
+
/* Existiert der Channel bereits, oder wird er im Moment neu erzeugt? */
if( is_new_chan )
{
chan = Channel_Search( channame );
assert( chan != NULL );
- /* Test if the user has reached his maximum channel count */
- if( Client_Type( Client ) == CLIENT_USER )
- {
- if(( Conf_MaxJoins > 0 ) && ( Channel_CountForUser( chan, Client ) > Conf_MaxJoins ))
- {
- IRC_WriteStrClient( Client, ERR_TOOMANYCHANNELS_MSG, Client_ID( Client ), channame );
- return CONNECTED;
- }
- }
-
-
is_banned = Lists_CheckBanned( target, chan );
is_invited = Lists_CheckInvited( target, chan );
/* Client ist gebanned (und nicht invited): */
IRC_WriteStrClient( Client, ERR_BANNEDFROMCHAN_MSG, Client_ID( Client ), channame );
- /* naechsten Namen ermitteln */
+ /* Try next name, if any */
channame = strtok( NULL, "," );
continue;
}
/* Ist der Channel "invite-only"? */
- if(( strchr( Channel_Modes( chan ), 'i' ) != NULL ) && ( is_invited == FALSE ))
+ if(( strchr( Channel_Modes( chan ), 'i' )) && ( is_invited == FALSE ))
{
/* Channel ist "invite-only" und Client wurde nicht invited: */
IRC_WriteStrClient( Client, ERR_INVITEONLYCHAN_MSG, Client_ID( Client ), channame );
- /* naechsten Namen ermitteln */
+ /* Try next name, if any */
+ channame = strtok( NULL, "," );
+ continue;
+ }
+
+ /* Is the channel protected by a key? */
+ if(( strchr( Channel_Modes( chan ), 'k' )) && ( strcmp( Channel_Key( chan ), key ? key : "" ) != 0 ))
+ {
+ /* Bad channel key! */
+ IRC_WriteStrClient( Client, ERR_BADCHANNELKEY_MSG, Client_ID( Client ), channame );
+
+ /* Try next name, if any */
+ channame = strtok( NULL, "," );
+ continue;
+ }
+
+ /* Are there already too many members? */
+ if(( strchr( Channel_Modes( chan ), 'l' )) && ( Channel_MaxUsers( chan ) <= Channel_MemberCount( chan )))
+ {
+ /* Bad channel key! */
+ IRC_WriteStrClient( Client, ERR_CHANNELISFULL_MSG, Client_ID( Client ), channame );
+
+ /* Try next name, if any */
channame = strtok( NULL, "," );
continue;
}
}
}
+ else
+ {
+ /* Remote server: we don't need to know whether the
+ * client is invited or not, but we have to make sure
+ * that the "one shot" entries (generated by INVITE
+ * 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 );
+ }
/* Channel joinen (und ggf. anlegen) */
if( ! Channel_Join( target, channame ))
if(( strchr( Channel_Modes( chan ), 'P' )) && ( strchr( Client_Modes( target ), 'o' ))) Channel_UserModeAdd( chan, target, 'o' );
/* Muessen Modes an andere Server gemeldet werden? */
- strcpy( &modes[1], Channel_UserModes( chan, target ));
+ strlcpy( &modes[1], Channel_UserModes( chan, target ), sizeof( modes ) - 1 );
if( modes[1] ) modes[0] = 0x7;
else modes[0] = '\0';
{
/* an anderen Server forwarden */
target = Client_Search( Req->argv[1] );
- if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
+ if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
if( target != Client_ThisServer( ))
{
GLOBAL BOOLEAN
IRC_CHANINFO( CLIENT *Client, REQUEST *Req )
{
+ CHAR modes_add[COMMAND_LEN], l[16], *ptr;
CLIENT *from;
CHANNEL *chan;
- CHAR *ptr;
+ INT arg_topic;
assert( Client != NULL );
assert( Req != NULL );
- /* Falsche Anzahl Parameter? */
- if(( Req->argc < 1 ) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+ /* Bad number of parameters? */
+ if(( Req->argc < 2 ) || ( Req->argc == 4 ) || ( Req->argc > 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
- /* From-Server suchen */
+ /* Compatibility kludge */
+ if( Req->argc == 5 ) arg_topic = 4;
+ else if( Req->argc == 3 ) arg_topic = 2;
+ else arg_topic = -1;
+
+ /* Search origin */
from = Client_Search( Req->prefix );
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
- /* Channel suchen bzw. erzeugen */
+ /* Search or create channel */
chan = Channel_Search( Req->argv[0] );
if( ! chan ) chan = Channel_Create( Req->argv[0] );
if( ! chan ) return CONNECTED;
ptr = Channel_Modes( chan );
if( ! *ptr )
{
- /* OK, es sind noch keine Modes gesetzt */
+ /* OK, this channel doesn't have modes jet, set the received ones: */
Channel_SetModes( chan, &Req->argv[1][1] );
- IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "MODE %s +%s", Req->argv[0], &Req->argv[1][1] );
+
+ if( Req->argc == 5 )
+ {
+ if( strchr( Channel_Modes( chan ), 'k' )) Channel_SetKey( chan, Req->argv[2] );
+ if( strchr( Channel_Modes( chan ), 'l' )) Channel_SetMaxUsers( chan, atol( Req->argv[3] ));
+ }
+ else
+ {
+ /* Delete modes which we never want to inherit */
+ Channel_ModeDel( chan, 'l' );
+ Channel_ModeDel( chan, 'k' );
+ }
+
+ strcpy( modes_add, "" );
+ ptr = Channel_Modes( chan );
+ while( *ptr )
+ {
+ if( *ptr == 'l' )
+ {
+ snprintf( l, sizeof( l ), " %ld", Channel_MaxUsers( chan ));
+ strlcat( modes_add, l, sizeof( modes_add ));
+ }
+ if( *ptr == 'k' )
+ {
+ strlcat( modes_add, " ", sizeof( modes_add ));
+ strlcat( modes_add, Channel_Key( chan ), sizeof( modes_add ));
+ }
+ ptr++;
+ }
+
+ /* Inform members of this channel */
+ IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "MODE %s +%s%s", Req->argv[0], Channel_Modes( chan ), modes_add );
}
}
- else Log( LOG_WARNING, "CHANNELINFO: invalid MODE format ignored!" );
+ else Log( LOG_WARNING, "CHANINFO: invalid MODE format ignored!" );
- if( Req->argc == 3 )
+ if( arg_topic > 0 )
{
- /* Es wurde auch ein Topic mit uebermittelt */
+ /* We got a topic */
ptr = Channel_Topic( chan );
- if( ! *ptr )
+ if(( ! *ptr ) && ( Req->argv[arg_topic][0] ))
{
- /* OK, es ist bisher kein Topic gesetzt */
- Channel_SetTopic( chan, Req->argv[2] );
- IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "TOPIC %s :%s", Req->argv[0], Req->argv[2] );
+ /* 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 ));
}
}
- /* an andere Server forwarden */
- IRC_WriteStrServersPrefixFlag( Client, from, 'C', "CHANINFO %s %s :%s", Req->argv[0], Req->argv[1], Req->argv[2] );
+ /* Forward CHANINFO to other serevrs */
+ if( Req->argc == 5 ) IRC_WriteStrServersPrefixFlag( Client, from, 'C', "CHANINFO %s %s %s %s :%s", Req->argv[0], Req->argv[1], Req->argv[2], Req->argv[3], Req->argv[4] );
+ else if( Req->argc == 3 ) IRC_WriteStrServersPrefixFlag( Client, from, 'C', "CHANINFO %s %s :%s", Req->argv[0], Req->argv[1], Req->argv[2] );
+ else IRC_WriteStrServersPrefixFlag( Client, from, 'C', "CHANINFO %s %s", Req->argv[0], Req->argv[1] );
+
return CONNECTED;
} /* IRC_CHANINFO */