Thread: [srvx-commits] CVS: services/src modcmd.c,1.3,1.4 modcmd.h,1.1,1.2
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-07-31 02:40:18
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv21633/src
Modified Files:
modcmd.c modcmd.h
Log Message:
add new MODCMD_KEEP_BOUND flag, to prevent a command from being totally unbound
when registering module commands, imply some default flags based on required flags
in svccmd_can_invoke:
force some prerequisites for the CHANUSER and HELPER tests
fix flag tests
implement missing tests (JOINABLE, OPER, *_HELPER)
make ?unbind remove the *correct* command
Index: modcmd.c
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** modcmd.c 30 Jul 2002 21:04:35 -0000 1.3
--- modcmd.c 31 Jul 2002 02:40:15 -0000 1.4
***************
*** 59,62 ****
--- 59,63 ----
{ "disabled", MODCMD_DISABLED },
{ "joinable", MODCMD_REQUIRE_JOINABLE },
+ { "keepbound", MODCMD_KEEP_BOUND },
{ "nolog", MODCMD_NO_LOG },
{ "networkhelper", MODCMD_REQUIRE_NETWORK_HELPER },
***************
*** 159,162 ****
--- 160,169 ----
newcmd->defaults->command = newcmd;
dict_insert(module->commands, newcmd->name, newcmd);
+ if (newcmd->flags & (MODCMD_REQUIRE_REGCHAN|MODCMD_REQUIRE_CHANNEL|MODCMD_REQUIRE_CHANUSER|MODCMD_REQUIRE_JOINABLE)) {
+ newcmd->defaults->flags |= MODCMD_ACCEPT_CHANNEL;
+ }
+ if (newcmd->flags & (MODCMD_REQUIRE_CHANUSER|MODCMD_REQUIRE_NETWORK_HELPER|MODCMD_REQUIRE_SUPPORT_HELPER)) {
+ newcmd->defaults->flags |= MODCMD_REQUIRE_AUTHED;
+ }
va_start(args, flags);
while ((param = va_arg(args, const char*))) {
***************
*** 305,309 ****
* having the permission check vary based on the command itself,
* or having a more generic rule system. */
- unsigned int flags = base_cmd->command->flags | base_cmd->flags;
unsigned int res = (MODCMD_EXECUTE|MODCMD_LOG_COMMAND);
unsigned int uData_checked = 0;
--- 312,315 ----
***************
*** 317,333 ****
}
! memcpy(&cmd, base_cmd, sizeof(*base_cmd));
! for(cmd2 = base_cmd->template; cmd2; cmd2 = cmd2->template)
{
cmd.flags |= cmd2->flags;
cmd.req_account_flags |= cmd2->req_account_flags;
cmd.deny_account_flags |= cmd2->deny_account_flags;
! if(cmd2->min_opserv_level > cmd.min_opserv_level) {
cmd.min_opserv_level = cmd2->min_opserv_level;
}
! if(cmd2->min_channel_access > cmd.min_channel_access) {
cmd.min_channel_access = cmd2->min_channel_access;
}
}
if (cmd.min_opserv_level > 0) {
--- 323,347 ----
}
! memset(&cmd, 0, sizeof(cmd));
! cmd.name = base_cmd->name;
! cmd.flags = base_cmd->command->flags;
! for(cmd2 = base_cmd; cmd2; cmd2 = cmd2->template)
{
cmd.flags |= cmd2->flags;
cmd.req_account_flags |= cmd2->req_account_flags;
cmd.deny_account_flags |= cmd2->deny_account_flags;
! if (cmd2->min_opserv_level > cmd.min_opserv_level) {
cmd.min_opserv_level = cmd2->min_opserv_level;
}
! if (cmd2->min_channel_access > cmd.min_channel_access) {
cmd.min_channel_access = cmd2->min_channel_access;
}
+ if (cmd2->weight > cmd.weight) {
+ cmd.weight = cmd2->weight;
+ }
}
+ if (cmd.min_channel_access > ulNone) cmd.flags |= MODCMD_REQUIRE_CHANUSER;
+ if (cmd.flags & MODCMD_REQUIRE_CHANUSER) cmd.flags |= MODCMD_REQUIRE_REGCHAN | MODCMD_REQUIRE_AUTHED;
+ if (cmd.flags & (MODCMD_REQUIRE_NETWORK_HELPER|MODCMD_REQUIRE_SUPPORT_HELPER)) cmd.flags |= MODCMD_REQUIRE_AUTHED;
if (cmd.min_opserv_level > 0) {
***************
*** 346,368 ****
}
}
- if (cmd.min_channel_access > ulNone) flags |= MODCMD_REQUIRE_CHANUSER;
! if (flags & MODCMD_DISABLED) {
send_message(user, bot, MSG_COMMAND_DISABLED, cmd.name);
goto refuse;
}
! if ((flags & MODCMD_REQUIRE_QUALIFIED) && !server_qualified) {
send_message(user, bot, "You $bMUST$b \"/msg $S@$s %s\" (not just $S) for that command.", cmd.name);
goto refuse;
}
! if ((flags & MODCMD_REQUIRE_AUTHED) && !user->handle_info) {
send_message(user, bot, MSG_AUTHENTICATE);
goto refuse;
}
! if ((flags & MODCMD_REQUIRE_CHANNEL) && !channel) {
send_message(user, bot, MSG_INVALID_CHANNEL);
goto refuse;
}
! if (flags & MODCMD_REQUIRE_REGCHAN) {
if (!channel) {
/* XXX: could maybe figure out better way to handle this case */
--- 360,381 ----
}
}
! if (cmd.flags & MODCMD_DISABLED) {
send_message(user, bot, MSG_COMMAND_DISABLED, cmd.name);
goto refuse;
}
! if ((cmd.flags & MODCMD_REQUIRE_QUALIFIED) && !server_qualified) {
send_message(user, bot, "You $bMUST$b \"/msg $S@$s %s\" (not just $S) for that command.", cmd.name);
goto refuse;
}
! if ((cmd.flags & MODCMD_REQUIRE_AUTHED) && !user->handle_info) {
send_message(user, bot, MSG_AUTHENTICATE);
goto refuse;
}
! if ((cmd.flags & MODCMD_REQUIRE_CHANNEL) && !channel) {
send_message(user, bot, MSG_INVALID_CHANNEL);
goto refuse;
}
! if (cmd.flags & MODCMD_REQUIRE_REGCHAN) {
if (!channel) {
/* XXX: could maybe figure out better way to handle this case */
***************
*** 376,380 ****
}
}
! if (flags & MODCMD_REQUIRE_CHANUSER) {
if (!channel) goto refuse;
if (!uData_checked) uData = _GetChannelUser(channel->channel_info, user->handle_info, 1, 0), uData_checked = 1;
--- 389,393 ----
}
}
! if (cmd.flags & MODCMD_REQUIRE_CHANUSER) {
if (!channel) goto refuse;
if (!uData_checked) uData = _GetChannelUser(channel->channel_info, user->handle_info, 1, 0), uData_checked = 1;
***************
*** 387,393 ****
}
}
postaccess:
! if (flags & MODCMD_NO_LOG) res &= ~MODCMD_LOG_COMMAND;
return res;
--- 400,427 ----
}
}
+ if (cmd.flags & MODCMD_REQUIRE_JOINABLE) {
+ if (!channel) goto refuse;
+ if (!uData_checked) uData = _GetChannelUser(channel->channel_info, user->handle_info, 1, 0), uData_checked = 1;
+ if ((channel->modes & (MODE_INVITEONLY|MODE_KEY))
+ && (!channel->channel_info || !uData)
+ && !IsService(user)
+ && !GetUserMode(channel, user)) {
+ send_message(user, bot, "You must be in $b%s$b (or on its userlist) to use the $b%s$b command.", channel->name, cmd.name);
+ goto refuse;
+ }
+ }
+ if (cmd.flags & (MODCMD_REQUIRE_OPER|MODCMD_REQUIRE_NETWORK_HELPER|MODCMD_REQUIRE_SUPPORT_HELPER)) {
+ if (((cmd.flags & MODCMD_REQUIRE_OPER) && IsOper(user))
+ || ((cmd.flags & MODCMD_REQUIRE_NETWORK_HELPER) && IsNetworkHelper(user))
+ || ((cmd.flags & MODCMD_REQUIRE_SUPPORT_HELPER) && IsSupportHelper(user))) {
+ /* allow it */
+ } else {
+ send_message(user, bot, MSG_COMMAND_PRIVILEGED, base_cmd->name);
+ goto refuse;
+ }
+ }
postaccess:
! if (cmd.flags & MODCMD_NO_LOG) res &= ~MODCMD_LOG_COMMAND;
return res;
***************
*** 786,794 ****
return 0;
}
! if ((bound->command == expand_alias_command) && (bound->command->bind_count == 1)) {
! send_message(user, cmd->parent->bot, "It wouldn't be very much fun to unbind the last bind command, now would it?");
return 0;
}
! dict_remove(service->commands, cmd->name);
send_message(user, cmd->parent->bot, "Unbound command %s from service %s", cmdname, service->bot->nick);
return 1;
--- 820,828 ----
return 0;
}
! if ((bound->command->flags & MODCMD_KEEP_BOUND) && (bound->command->bind_count == 1)) {
! send_message(user, cmd->parent->bot, "It wouldn't be very much fun to unbind the last %s command, now would it?", bound->command->name);
return 0;
}
! dict_remove(service->commands, bound->name);
send_message(user, cmd->parent->bot, "Unbound command %s from service %s", cmdname, service->bot->nick);
return 1;
***************
*** 1002,1009 ****
modcmd_module = module_register("modcmd", MAIN_LOG, "modcmd.help", NULL);
! bind_command = modcmd_register(modcmd_module, "bind", cmd_bind, 4, 0, "access", "800", NULL);
expand_alias_command = modcmd_register(modcmd_module, "expand alias", cmd_expand_alias, 0, 0, NULL);
help_command = modcmd_register(modcmd_module, "help", cmd_help, 1, 0, NULL);
! modcmd_register(modcmd_module, "modcmd", cmd_modcmd, 4, 0, "access", "999", NULL);
modcmd_register(modcmd_module, "readhelp", cmd_readhelp, 2, 0, "access", "650", NULL);
modcmd_register(modcmd_module, "timecmd", cmd_timecmd, 2, 0, "access", "1", NULL);
--- 1036,1043 ----
modcmd_module = module_register("modcmd", MAIN_LOG, "modcmd.help", NULL);
! bind_command = modcmd_register(modcmd_module, "bind", cmd_bind, 4, MODCMD_KEEP_BOUND, "access", "800", NULL);
expand_alias_command = modcmd_register(modcmd_module, "expand alias", cmd_expand_alias, 0, 0, NULL);
help_command = modcmd_register(modcmd_module, "help", cmd_help, 1, 0, NULL);
! modcmd_register(modcmd_module, "modcmd", cmd_modcmd, 4, MODCMD_KEEP_BOUND, "access", "999", NULL);
modcmd_register(modcmd_module, "readhelp", cmd_readhelp, 2, 0, "access", "650", NULL);
modcmd_register(modcmd_module, "timecmd", cmd_timecmd, 2, 0, "access", "1", NULL);
***************
*** 1227,1230 ****
--- 1261,1265 ----
}
ptempl->cmd->template = svccmd;
+ free(ptempl->base);
free(ptempl);
}
Index: modcmd.h
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** modcmd.h 30 Jul 2002 02:15:11 -0000 1.1
--- modcmd.h 31 Jul 2002 02:40:15 -0000 1.2
***************
*** 48,51 ****
--- 48,52 ----
#define MODCMD_REQUIRE_JOINABLE 0x200
#define MODCMD_REQUIRE_QUALIFIED 0x0400
+ #define MODCMD_KEEP_BOUND 0x0800
#define MODCMD_REQUIRE_OPER 0x1000
#define MODCMD_REQUIRE_NETWORK_HELPER 0x2000
***************
*** 74,78 ****
* need "extra" data.
*
! * When checking to see if a user may invoke a command,
*/
--- 75,82 ----
* need "extra" data.
*
! * When checking to see if a user may invoke a command, the "template"
! * chain is followed, and the user must meet all the requirements
! * before the command is executed. [This is not how it should be;
! * staff access should be any-of instead of all-of.]
*/
***************
*** 126,131 ****
struct modcmd *modcmd_register(struct module *module, const char *name, modcmd_func_t func, unsigned int min_argc, unsigned int flags, ...);
! /* Register a command-providing module.
! * clog is where to log commands without the MODCMD_NO_LOG flag.
*/
struct module *module_register(const char *name, enum log_type clog, const char *helpfile_name, expand_func_t expand_help);
--- 130,135 ----
struct modcmd *modcmd_register(struct module *module, const char *name, modcmd_func_t func, unsigned int min_argc, unsigned int flags, ...);
! /* Register a command-providing module. clog is where to log loggable
! * commands (those without the MODCMD_NO_LOG flag and which succeed).
*/
struct module *module_register(const char *name, enum log_type clog, const char *helpfile_name, expand_func_t expand_help);
***************
*** 156,160 ****
void modcmd_init(void);
/* Finalize the command mappings, read aliases, etc. Do this after
! * all other services and modules have registered their commands. */
void modcmd_finalize(void);
--- 160,165 ----
void modcmd_init(void);
/* Finalize the command mappings, read aliases, etc. Do this after
! * all other modules have registered their commands.
! */
void modcmd_finalize(void);
|