Clean up the mode handling code: remove redundant parts ...

This commit is contained in:
Alexander Barton 2005-02-27 20:09:44 +00:00
parent 3da942e237
commit 8579b2a1e5
1 changed files with 60 additions and 76 deletions

View File

@ -1,6 +1,6 @@
/* /*
* ngIRCd -- The Next Generation IRC Daemon * ngIRCd -- The Next Generation IRC Daemon
* Copyright (c)2001,2002 by Alexander Barton (alex@barton.de) * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -14,7 +14,7 @@
#include "portab.h" #include "portab.h"
static char UNUSED id[] = "$Id: irc-mode.c,v 1.35 2004/04/25 15:42:05 alex Exp $"; static char UNUSED id[] = "$Id: irc-mode.c,v 1.36 2005/02/27 20:09:44 alex Exp $";
#include "imp.h" #include "imp.h"
#include <assert.h> #include <assert.h>
@ -155,8 +155,12 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
x[0] = '\0'; x[0] = '\0';
switch( *mode_ptr ) switch( *mode_ptr )
{ {
case 'a': case 'i': /* Invisible */
/* Away */ case 's': /* Server messages */
x[0] = *mode_ptr;
break;
case 'a': /* Away */
if( Client_Type( Client ) == CLIENT_SERVER ) if( Client_Type( Client ) == CLIENT_SERVER )
{ {
x[0] = 'a'; x[0] = 'a';
@ -164,12 +168,8 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
} }
else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin )); else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
break; break;
case 'i':
/* Invisible */ case 'o': /* IRC operator (only unsettable!) */
x[0] = 'i';
break;
case 'o':
/* IRC operator (only unsetable!) */
if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER )) if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER ))
{ {
Client_SetOperByMe( Target, FALSE ); Client_SetOperByMe( Target, FALSE );
@ -177,15 +177,12 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
} }
else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin )); else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
break; break;
case 'r':
/* Restricted (only setable) */ case 'r': /* Restricted (only settable) */
if(( set ) || ( Client_Type( Client ) == CLIENT_SERVER )) x[0] = 'r'; if(( set ) || ( Client_Type( Client ) == CLIENT_SERVER )) x[0] = 'r';
else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin )); else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin ));
break; break;
case 's':
/* Server messages */
x[0] = 's';
break;
default: default:
Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin )); Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ));
if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr ); if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
@ -360,62 +357,17 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
client = NULL; client = NULL;
switch( *mode_ptr ) switch( *mode_ptr )
{ {
/* Channel modes */ /* --- Channel modes --- */
case 'i':
/* Invite-Only */ case 'i': /* Invite only */
if( modeok ) x[0] = 'i'; case 'm': /* Moderated */
else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel )); case 'n': /* Only members can write */
break; case 't': /* Topic locked */
case 'm': if( modeok ) x[0] = *mode_ptr;
/* Moderated */
if( modeok ) x[0] = 'm';
else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
break;
case 'n':
/* kein Schreiben in den Channel von aussen */
if( modeok ) x[0] = 'n';
else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
break;
case 't':
/* Topic Lock */
if( modeok ) x[0] = 't';
else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
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 )); else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
break; break;
/* Channel user modes */ case 'k': /* Channel key */
case 'o':
/* Channel operator */
case 'v':
/* Voice */
if( arg_arg > mode_arg )
{
if( modeok )
{
client = Client_Search( Req->argv[arg_arg] );
if( client ) x[0] = *mode_ptr;
else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
}
else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
Req->argv[arg_arg][0] = '\0';
arg_arg++;
}
else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
break;
case 'k':
/* Channel key */
if( ! set ) if( ! set )
{ {
if( modeok ) x[0] = *mode_ptr; if( modeok ) x[0] = *mode_ptr;
@ -437,8 +389,8 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
} }
else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command ); else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
break; break;
case 'l':
/* Member limit */ case 'l': /* Member limit */
if( ! set ) if( ! set )
{ {
if( modeok ) x[0] = *mode_ptr; if( modeok ) x[0] = *mode_ptr;
@ -465,9 +417,41 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command ); else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
break; break;
/* Channel lists */ case 'P': /* Persistent channel */
case 'I': if( modeok )
/* Invite lists */ {
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 ));
break;
/* --- Channel user modes --- */
case 'o': /* Channel operator */
case 'v': /* Voice */
if( arg_arg > mode_arg )
{
if( modeok )
{
client = Client_Search( Req->argv[arg_arg] );
if( client ) x[0] = *mode_ptr;
else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
}
else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
Req->argv[arg_arg][0] = '\0';
arg_arg++;
}
else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
break;
/* --- Channel lists --- */
case 'I': /* Invite lists */
if( arg_arg > mode_arg ) if( arg_arg > mode_arg )
{ {
/* modify list */ /* modify list */
@ -482,8 +466,8 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
} }
else Lists_ShowInvites( Origin, Channel ); else Lists_ShowInvites( Origin, Channel );
break; break;
case 'b':
/* Ban lists */ case 'b': /* Ban lists */
if( arg_arg > mode_arg ) if( arg_arg > mode_arg )
{ {
/* modify list */ /* modify list */