#include "portab.h"
-static char UNUSED id[] = "$Id: irc-mode.c,v 1.43 2005/06/17 19:14:58 fw Exp $";
+static char UNUSED id[] = "$Id: irc-mode.c,v 1.51 2008/02/16 11:27:49 fw Exp $";
#include "imp.h"
#include <assert.h>
#include "irc-mode.h"
-LOCAL bool Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ));
-LOCAL bool Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ));
+static bool Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ));
+static bool Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ));
-LOCAL bool Add_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
-LOCAL bool Add_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
+static bool Add_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
+static bool Add_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
-LOCAL bool Del_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
-LOCAL bool Del_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
+static bool Del_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
+static bool Del_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
-LOCAL bool Send_ListChange PARAMS(( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask ));
+static bool Send_ListChange PARAMS(( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask ));
GLOBAL bool
if( ! origin ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
}
else origin = Client;
-
+
/* Channel or user mode? */
- cl = chan = NULL;
- if( Client_IsValidNick( Req->argv[0] )) cl = Client_Search( Req->argv[0] );
- if( Channel_IsValidName( Req->argv[0] )) chan = Channel_Search( Req->argv[0] );
+ cl = NULL; chan = NULL;
+ if (Client_IsValidNick(Req->argv[0]))
+ cl = Client_Search(Req->argv[0]);
+ if (Channel_IsValidName(Req->argv[0]))
+ chan = Channel_Search(Req->argv[0]);
- if( cl ) return Client_Mode( Client, Req, origin, cl );
- if( chan ) return Channel_Mode( Client, Req, origin, chan );
+ if (cl)
+ return Client_Mode(Client, Req, origin, cl);
+ if (chan)
+ return Channel_Mode(Client, Req, origin, chan);
/* No target found! */
- return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
+ return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
+ Client_ID(Client), Req->argv[0]);
} /* IRC_MODE */
-LOCAL bool
+static bool
Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
{
/* Handle client mode requests */
{
case 'i': /* Invisible */
case 's': /* Server messages */
+ case 'w': /* Wallops messages */
x[0] = *mode_ptr;
break;
} /* Client_Mode */
-LOCAL bool
+static bool
Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
{
/* Handle channel and channel-user modes */
switch( *mode_ptr )
{
case 'l':
- snprintf( argadd, sizeof( argadd ), " %ld", Channel_MaxUsers( Channel ));
+ snprintf( argadd, sizeof( argadd ), " %lu", Channel_MaxUsers( Channel ));
strlcat( the_args, argadd, sizeof( the_args ));
break;
case 'k':
/* Prepare reply string */
if( set ) strcpy( the_modes, "+" );
else strcpy( the_modes, "-" );
- strcpy( the_args, " " );
+ the_args[0] = '\0';
x[1] = '\0';
ok = CONNECTED;
break;
case 'P': /* Persistent channel */
- if( modeok )
- {
- if( set && ( ! Client_OperByMe( Client )))
- {
- /* Only IRC operators are allowed to set P mode */
- ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
- }
- else x[0] = 'P';
- }
- else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
+ if (modeok) {
+ /* Only IRC operators are allowed to
+ * set the 'P' channel mode! */
+ if (set && ! (Client_OperByMe(Client)
+ || Client_Type(Client) == CLIENT_SERVER)) {
+ ok = IRC_WriteStrClient(Origin,
+ ERR_NOPRIVILEGES_MSG,
+ Client_ID(Origin));
+ } else
+ x[0] = 'P';
+ } else
+ ok = IRC_WriteStrClient(Origin,
+ ERR_CHANOPRIVSNEEDED_MSG,
+ Client_ID(Origin),
+ Channel_Name(Channel));
break;
/* --- Channel user modes --- */
Req->argv[arg_arg][0] = '\0';
arg_arg++;
}
- else Lists_ShowInvites( Origin, Channel );
+ else Channel_ShowInvites( Origin, Channel );
break;
case 'b': /* Ban lists */
Req->argv[arg_arg][0] = '\0';
arg_arg++;
}
- else Lists_ShowBans( Origin, Channel );
+ else Channel_ShowBans( Origin, Channel );
break;
default:
/* Channel-User-Mode */
if( Channel_UserModeAdd( Channel, client, x[0] ))
{
- strlcat( the_args, Client_ID( client ), sizeof( the_args ));
strlcat( the_args, " ", sizeof( the_args ));
+ strlcat( the_args, Client_ID( client ), sizeof( the_args ));
strlcat( the_modes, x, sizeof( the_modes ));
Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
}
/* Channel-User-Mode */
if( Channel_UserModeDel( Channel, client, x[0] ))
{
- strlcat( the_args, Client_ID( client ), sizeof( the_args ));
strlcat( the_args, " ", sizeof( the_args ));
+ strlcat( the_args, Client_ID( client ), sizeof( the_args ));
strlcat( the_modes, x, sizeof( the_modes ));
Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
}
/* Are there additional arguments to add? */
if( argadd[0] )
{
- len = strlen( the_args ) - 1;
- if( the_args[len] != ' ' ) strlcat( the_args, " ", sizeof( the_args ));
+ strlcat( the_args, " ", sizeof( the_args ));
strlcat( the_args, argadd, sizeof( the_args ));
}
}
len = strlen( the_modes ) - 1;
if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' )) the_modes[len] = '\0';
- /* Clean up argument string if there are none */
- if( ! the_args[1] ) the_args[0] = '\0';
-
if( Client_Type( Client ) == CLIENT_SERVER )
{
/* Forward mode changes to channel users and other servers */
} /* IRC_AWAY */
-LOCAL bool
+static bool
Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
{
char *mask;
mask = Lists_MakeMask( Pattern );
- already = Lists_IsInviteEntry( mask, Channel );
-
- if( ! Lists_AddInvited( mask, Channel, false )) return CONNECTED;
-
- if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
+ already = Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask );
+ if (!already) {
+ if( ! Channel_AddInvite(Channel, mask, false ))
+ return CONNECTED;
+ }
+ if ( already && ( Client_Type( Prefix ) == CLIENT_SERVER ))
+ return CONNECTED;
return Send_ListChange( "+I", Prefix, Client, Channel, mask );
} /* Add_Invite */
-LOCAL bool
+static bool
Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
{
char *mask;
mask = Lists_MakeMask( Pattern );
- already = Lists_IsBanEntry( mask, Channel );
-
- if( ! Lists_AddBanned( mask, Channel )) return CONNECTED;
-
- if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
+ already = Lists_CheckDupeMask(Channel_GetListBans(Channel), mask );
+ if (!already) {
+ if( ! Channel_AddBan(Channel, mask))
+ return CONNECTED;
+ }
+ if ( already && ( Client_Type( Prefix ) == CLIENT_SERVER ))
+ return CONNECTED;
return Send_ListChange( "+b", Prefix, Client, Channel, mask );
} /* Add_Ban */
-LOCAL bool
+static bool
Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
{
char *mask;
assert( Pattern != NULL );
mask = Lists_MakeMask( Pattern );
- Lists_DelInvited( mask, Channel );
+ Lists_Del(Channel_GetListInvites(Channel), mask);
return Send_ListChange( "-I", Prefix, Client, Channel, mask );
} /* Del_Invite */
-LOCAL bool
+static bool
Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
{
char *mask;
assert( Pattern != NULL );
mask = Lists_MakeMask( Pattern );
- Lists_DelBanned( mask, Channel );
+ Lists_Del(Channel_GetListBans(Channel), mask);
return Send_ListChange( "-b", Prefix, Client, Channel, mask );
} /* Del_Ban */
-LOCAL bool
+static bool
Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask )
{
/* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */