/*
* ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
*
* 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
#include "defines.h"
#include "conn.h"
#include "channel.h"
+#include "irc-macros.h"
#include "irc-write.h"
#include "lists.h"
#include "log.h"
#include "exp.h"
#include "irc-mode.h"
-
static bool Client_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
CLIENT *Target));
static bool Channel_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
CLIENT *Prefix, CLIENT *Client,
CHANNEL *Channel, const char *Mask));
-
/**
* Handler for the IRC "MODE" command.
*
- * See RFC 2812 section 3.1.5 ("user mode message") and section 3.2.3
- * ("channel mode message"), and RFC 2811 section 4 ("channel modes").
+ * This function detects whether user or channel modes should be modified
+ * and calls the appropriate sub-functions.
*
- * @param Client The client from which this command has been received.
- * @param Req Request structure with prefix and all parameters.
- * @returns CONNECTED or DISCONNECTED.
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @return CONNECTED or DISCONNECTED.
*/
GLOBAL bool
IRC_MODE( CLIENT *Client, REQUEST *Req )
assert(Client != NULL);
assert(Req != NULL);
- /* No parameters? */
- if (Req->argc < 1)
- return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
- Client_ID(Client), Req->command);
-
- /* Origin for answers */
- if (Client_Type(Client) == CLIENT_SERVER) {
- origin = Client_Search(Req->prefix);
- if (!origin)
- return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
- Client_ID(Client),
- Req->prefix);
- } else
- origin = Client;
+ _IRC_ARGC_GE_OR_RETURN_(Client, Req, 1)
+ _IRC_GET_SENDER_OR_RETURN_(origin, Req, Client)
/* Channel or user mode? */
cl = NULL; chan = NULL;
Client_ID(Client), Req->argv[0]);
} /* IRC_MODE */
-
/**
* Check if the "mode limit" for a client has been reached.
*
return true;
}
-
/**
* Handle client mode requests
*
- * @param Client The client from which this command has been received.
- * @param Req Request structure with prefix and all parameters.
- * @param Origin The originator of the MODE command (prefix).
- * @param Target The target (client) of this MODE command.
- * @returns CONNECTED or DISCONNECTED.
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @param Origin The originator of the MODE command (prefix).
+ * @param Target The target (client) of this MODE command.
+ * @return CONNECTED or DISCONNECTED.
*/
static bool
Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
}
if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
- /* A new (cloaked) hostname must be annoucned */
+ /* A new (cloaked) hostname must be announced */
IRC_WriteStrClientPrefix(Target, Origin,
RPL_HOSTHIDDEN_MSG,
Client_ID(Target),
return ok;
} /* Client_Mode */
-
+/*
+ * Reply to a channel mode request.
+ *
+ * @param Origin The originator of the MODE command (prefix).
+ * @param Channel The channel of which the modes should be sent.
+ * @return CONNECTED or DISCONNECTED.
+ */
static bool
Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
{
return CONNECTED;
}
-
/**
* Handle channel mode and channel-user mode changes
+ *
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @param Origin The originator of the MODE command (prefix).
+ * @param Channel The target channel of this MODE command.
+ * @return CONNECTED or DISCONNECTED.
*/
static bool
Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
{
char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
- argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
+ argadd[CLIENT_PASS_LEN], *mode_ptr;
bool connected, set, skiponce, retval, use_servermode,
is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
int mode_arg, arg_arg, mode_arg_count = 0;
arg_arg = -1;
if(!is_machine && !is_oper) {
- o_mode_ptr = Channel_UserModes(Channel, Client);
- while( *o_mode_ptr ) {
- if ( *o_mode_ptr == 'q')
- is_owner = true;
- if ( *o_mode_ptr == 'a')
- is_admin = true;
- if ( *o_mode_ptr == 'o')
- is_op = true;
- if ( *o_mode_ptr == 'h')
- is_halfop = true;
- o_mode_ptr++;
- }
+ if (Channel_UserHasMode(Channel, Client, 'q'))
+ is_owner = true;
+ if (Channel_UserHasMode(Channel, Client, 'a'))
+ is_admin = true;
+ if (Channel_UserHasMode(Channel, Client, 'o'))
+ is_op = true;
+ if (Channel_UserHasMode(Channel, Client, 'h'))
+ is_halfop = true;
}
/* Validate modes */
return connected;
} /* Channel_Mode */
-
+/**
+ * Handler for the IRC "AWAY" command.
+ *
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @return CONNECTED or DISCONNECTED.
+ */
GLOBAL bool
IRC_AWAY( CLIENT *Client, REQUEST *Req )
{
- assert( Client != NULL );
- assert( Req != NULL );
-
- if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
-
- if(( Req->argc == 1 ) && (Req->argv[0][0] ))
- {
- Client_SetAway( Client, Req->argv[0] );
- Client_ModeAdd( Client, 'a' );
- IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
- return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
- }
- else
- {
- Client_ModeDel( Client, 'a' );
- IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
- return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
+ assert (Client != NULL);
+ assert (Req != NULL);
+
+ _IRC_ARGC_LE_OR_RETURN_(Client, Req, 1)
+
+ if (Req->argc == 1 && Req->argv[0][0]) {
+ Client_SetAway(Client, Req->argv[0]);
+ Client_ModeAdd(Client, 'a');
+ IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
+ Client_ID( Client));
+ return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
+ Client_ID( Client));
+ } else {
+ Client_ModeDel(Client, 'a');
+ IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
+ Client_ID( Client));
+ return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
+ Client_ID( Client));
}
} /* IRC_AWAY */
-
/**
* Add entries to channel invite, ban and exception lists.
*
return Send_ListChange(true, what, Prefix, Client, Channel, mask);
}
-
/**
- * Delete entries from channel invite, ban and exeption lists.
+ * Delete entries from channel invite, ban and exception lists.
*
* @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
* @param Prefix The originator of the command.
return Send_ListChange(false, what, Prefix, Client, Channel, mask);
}
-
/**
* Send information about changed channel invite/ban/exception lists to clients.
*
return ok;
} /* Send_ListChange */
-
/* -eof- */