Thread: [srvx-commits] CVS: services/src modcmd.c,1.7,1.8
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-08-04 21:11:39
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv21377/src
Modified Files:
modcmd.c
Log Message:
allow setting a command's template to * (meaning none)
fix another stupid aliasing bug
fix a logging bug
report MODCMD_REQUIRE_QUALIFIED in *modcmd.command
Index: modcmd.c
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** modcmd.c 3 Aug 2002 04:27:03 -0000 1.7
--- modcmd.c 4 Aug 2002 21:11:36 -0000 1.8
***************
*** 35,39 ****
#define MCMSG_BAD_WEIGHT "Invalid command weight %s."
#define MCMSG_BAD_OPTION "Unknown option %s."
! #define MCMSG_MUST_QUALIFY "You $bMUST$b \"/msg $S@$s %s\" (not just /msg $S)."
#define MCMSG_CHAN_NOT_REGISTERED "%s has not been registered with $C."
#define MCMSG_NO_CHANNEL_ACCESS "You lack access to %s."
--- 35,39 ----
#define MCMSG_BAD_WEIGHT "Invalid command weight %s."
#define MCMSG_BAD_OPTION "Unknown option %s."
! #define MCMSG_MUST_QUALIFY "You $bMUST$b \"/msg %s@$s %s\" (not just /msg %s)."
#define MCMSG_CHAN_NOT_REGISTERED "%s has not been registered with $C."
#define MCMSG_NO_CHANNEL_ACCESS "You lack access to %s."
***************
*** 243,246 ****
--- 243,273 ----
}
+ static void
+ svccmd_collapse(struct svccmd *from, struct svccmd *to, int omit_command) {
+ struct svccmd *cmd2;
+
+ memcpy(to, from, sizeof(*to));
+ if (!omit_command) to->flags |= from->command->flags;
+ for (cmd2 = from->template; cmd2; cmd2 = cmd2->template) {
+ to->flags |= cmd2->flags;
+ to->req_account_flags |= cmd2->req_account_flags;
+ to->deny_account_flags |= cmd2->deny_account_flags;
+ if (cmd2->min_opserv_level > to->min_opserv_level) {
+ to->min_opserv_level = cmd2->min_opserv_level;
+ }
+ if (cmd2->min_channel_access > to->min_channel_access) {
+ to->min_channel_access = cmd2->min_channel_access;
+ }
+ if (cmd2->weight > to->weight) {
+ to->weight = cmd2->weight;
+ }
+ }
+ if (to->min_opserv_level > 0) to->flags |= MODCMD_REQUIRE_OPER;
+ if (to->min_channel_access > ulNone) to->flags |= MODCMD_REQUIRE_CHANUSER;
+ if (to->flags & MODCMD_REQUIRE_CHANUSER) to->flags |= MODCMD_REQUIRE_REGCHAN;
+ if (to->flags & MODCMD_REQUIRE_JOINABLE) to->flags |= MODCMD_REQUIRE_CHANNEL;
+ if (to->flags & MODCMD_REQUIRE_STAFF) to->flags |= MODCMD_REQUIRE_AUTHED;
+ }
+
int
svccmd_configure(struct svccmd *cmd, struct userNode *user, struct userNode *bot, const char *param, const char *value) {
***************
*** 315,319 ****
return 1;
} else {
! if (!(cmd->template = svccmd_resolve_name(cmd, value))) {
if (user) {
send_message(user, bot, MCMSG_UNKNOWN_COMMAND, value, cmd->name, cmd->parent->bot->nick);
--- 342,351 ----
return 1;
} else {
! if (!strcmp(value, "*")) {
! struct svccmd newvals;
! svccmd_collapse(cmd, &newvals, 1);
! newvals.template = NULL;
! memcpy(cmd, &newvals, sizeof(*cmd));
! } else if (!(cmd->template = svccmd_resolve_name(cmd, value))) {
if (user) {
send_message(user, bot, MCMSG_UNKNOWN_COMMAND, value, cmd->name, cmd->parent->bot->nick);
***************
*** 349,379 ****
}
- static void
- svccmd_collapse(struct svccmd *from, struct svccmd *to, int omit_command) {
- struct svccmd *cmd2;
-
- memcpy(to, from, sizeof(*to));
- if (!omit_command) to->flags |= from->command->flags;
- for (cmd2 = from->template; cmd2; cmd2 = cmd2->template) {
- to->flags |= cmd2->flags;
- to->req_account_flags |= cmd2->req_account_flags;
- to->deny_account_flags |= cmd2->deny_account_flags;
- if (cmd2->min_opserv_level > to->min_opserv_level) {
- to->min_opserv_level = cmd2->min_opserv_level;
- }
- if (cmd2->min_channel_access > to->min_channel_access) {
- to->min_channel_access = cmd2->min_channel_access;
- }
- if (cmd2->weight > to->weight) {
- to->weight = cmd2->weight;
- }
- }
- if (to->min_opserv_level > 0) to->flags |= MODCMD_REQUIRE_OPER;
- if (to->min_channel_access > ulNone) to->flags |= MODCMD_REQUIRE_CHANUSER;
- if (to->flags & MODCMD_REQUIRE_CHANUSER) to->flags |= MODCMD_REQUIRE_REGCHAN;
- if (to->flags & MODCMD_REQUIRE_JOINABLE) to->flags |= MODCMD_REQUIRE_CHANNEL;
- if (to->flags & MODCMD_REQUIRE_STAFF) to->flags |= MODCMD_REQUIRE_AUTHED;
- }
-
/* This is kind of a lame hack, but it is actually simpler than having
* the permission check vary based on the command itself, or having a
--- 381,384 ----
***************
*** 390,394 ****
}
if ((cmd->flags & MODCMD_REQUIRE_QUALIFIED) && !server_qualified) {
! send_message(user, bot, MCMSG_MUST_QUALIFY, cmd->name);
return 0;
}
--- 395,399 ----
}
if ((cmd->flags & MODCMD_REQUIRE_QUALIFIED) && !server_qualified) {
! send_message(user, bot, MCMSG_MUST_QUALIFY, bot->nick, cmd->name, bot->nick);
return 0;
}
***************
*** 478,483 ****
unsigned char *arg;
! for (ii=new_argc=0; ii<old_argc; ++ii) {
! arg = old_argv[ii];
if (arg[0] != '$') {
new_argv[new_argc++] = arg;
--- 483,488 ----
unsigned char *arg;
! for (ii=new_argc=0; ii<cmd->alias.used; ++ii) {
! arg = cmd->alias.list[ii];
if (arg[0] != '$') {
new_argv[new_argc++] = arg;
***************
*** 519,523 ****
struct svccmd cmd, *pcmd;
unsigned int cmd_arg;
- char logbuf[2*MAXLEN];
/* Find the command argument. */
--- 524,527 ----
***************
*** 561,564 ****
--- 565,569 ----
return 0;
}
+ argv = new_argv;
}
***************
*** 566,570 ****
* it as a channel name, and hide it from logging.
*/
! if ((argc > 1)
&& (cmd.flags & MODCMD_ACCEPT_CHANNEL)
&& IsChannelName(argv[1])
--- 571,576 ----
* it as a channel name, and hide it from logging.
*/
! if ((cmd_arg == 0)
! && (argc > 1)
&& (cmd.flags & MODCMD_ACCEPT_CHANNEL)
&& IsChannelName(argv[1])
***************
*** 585,590 ****
if (!svccmd_can_invoke_real(user, service->bot, &cmd, channel, server_qualified, 1)) return 0;
pcmd->uses++;
if (!(cmd.flags & MODCMD_NO_LOG)) {
! unsigned int pos=0, ii, jj;
/* We reassemble the input line here. This lets services do
--- 591,598 ----
if (!svccmd_can_invoke_real(user, service->bot, &cmd, channel, server_qualified, 1)) return 0;
pcmd->uses++;
+ if (!cmd.command->func(user, channel, argc, argv, pcmd)) return 0;
if (!(cmd.flags & MODCMD_NO_LOG)) {
! unsigned int pos, ii, jj;
! char logbuf[2*MAXLEN];
/* We reassemble the input line here. This lets services do
***************
*** 592,595 ****
--- 600,604 ----
* while still having the commands logged uniformly.
*/
+ pos = 0;
if (channel) pos += sprintf(logbuf+pos, "(%s) ", channel->name);
pos += sprintf(logbuf+pos, "[%s:%s]: ", user->nick, (user->handle_info ? user->handle_info->handle : ""));
***************
*** 601,607 ****
}
logbuf[--pos] = 0;
- }
- if (!cmd.command->func(user, channel, argc, argv, pcmd)) return 0;
- if (!(cmd.flags & MODCMD_NO_LOG)) {
log(cmd.command->parent->clog, LOG_INFO, "%s\n", logbuf);
}
--- 610,613 ----
***************
*** 611,623 ****
int
svccmd_send_help(struct userNode *user, struct userNode *bot, struct svccmd *cmd) {
/* Show command name (in bold). */
! send_message(user, bot, "$b%s$b", cmd->name);
/* If it's an alias, show what it's an alias for. */
if (cmd->alias.used) {
char display[MAXLEN], *word;
! unsigned int pos, arg, len;
! for (arg = pos = 0; arg < cmd->alias.used; ++arg) {
! word = cmd->alias.list[arg];
len = strlen(word);
memcpy(display+pos, word, len);
--- 617,633 ----
int
svccmd_send_help(struct userNode *user, struct userNode *bot, struct svccmd *cmd) {
+ char cmdname[MAXLEN];
+ unsigned int nn;
/* Show command name (in bold). */
! for (nn=0; cmd->name[nn]; nn++) cmdname[nn] = toupper(cmd->name[nn]);
! cmdname[nn] = 0;
! send_message(user, bot, "$b%s$b", cmdname);
/* If it's an alias, show what it's an alias for. */
if (cmd->alias.used) {
char display[MAXLEN], *word;
! unsigned int pos, len;
! for (nn = pos = 0; nn < cmd->alias.used; ++nn) {
! word = cmd->alias.list[nn];
len = strlen(word);
memcpy(display+pos, word, len);
***************
*** 917,921 ****
}
if (cmd->template != modcmd->defaults) {
! if (cmd->template->parent == cmd->parent) {
sprintf(buf, "%s", cmd->template->name);
} else if (cmd->template->parent) {
--- 927,933 ----
}
if (cmd->template != modcmd->defaults) {
! if (!cmd->template) {
! strcpy(buf, "*");
! } else if (cmd->template->parent == cmd->parent) {
sprintf(buf, "%s", cmd->template->name);
} else if (cmd->template->parent) {
***************
*** 1113,1116 ****
--- 1125,1132 ----
send_message(user, cmd->parent->bot, MCMSG_NEED_AUTHED);
}
+ if (collapsed.flags & ~shown_flags & MODCMD_REQUIRE_QUALIFIED) {
+ const char *botnick = collapsed.parent ? collapsed.parent->bot->nick : "SomeBot";
+ send_message(user, cmd->parent->bot, MCMSG_MUST_QUALIFY, botnick, collapsed.name, botnick);
+ }
if (svccmd->template) {
if (svccmd->template->parent) {
***************
*** 1135,1139 ****
return 0;
}
! for (arg = 2; arg+2 < argc; arg += 2) {
if (svccmd_configure(svccmd, user, cmd->parent->bot, argv[arg], argv[arg+1])) changed = 1;
}
--- 1151,1155 ----
return 0;
}
! for (arg = 2; arg+1 < argc; arg += 2) {
if (svccmd_configure(svccmd, user, cmd->parent->bot, argv[arg], argv[arg+1])) changed = 1;
}
***************
*** 1209,1215 ****
svccmd->parent = service;
svccmd->command = modcmd;
- svccmd->template = modcmd->defaults;
if ((str = database_get_data(obj, "template", RECDB_QSTRING))) {
svccmd_configure(svccmd, NULL, service->bot, "template", str);
}
if ((str = database_get_data(obj, "account_flags", RECDB_QSTRING))) {
--- 1225,1232 ----
svccmd->parent = service;
svccmd->command = modcmd;
if ((str = database_get_data(obj, "template", RECDB_QSTRING))) {
svccmd_configure(svccmd, NULL, service->bot, "template", str);
+ } else {
+ svccmd->template = modcmd->defaults;
}
if ((str = database_get_data(obj, "account_flags", RECDB_QSTRING))) {
***************
*** 1380,1384 ****
pending_templates = ptempl->next;
/* Only overwrite the current template if we have a valid template. */
! if (!(svccmd = svccmd_resolve_name(ptempl->cmd, ptempl->base))) {
if (ptempl->cmd->parent) {
log(MAIN_LOG, LOG_ERROR, "Unable to resolve template name %s for command %s in service %s.\n", ptempl->base, ptempl->cmd->name, ptempl->cmd->parent->bot->nick);
--- 1397,1405 ----
pending_templates = ptempl->next;
/* Only overwrite the current template if we have a valid template. */
! if (!strcmp(ptempl->base, "*")) {
! ptempl->cmd->template = NULL;
! } else if ((svccmd = svccmd_resolve_name(ptempl->cmd, ptempl->base))) {
! ptempl->cmd->template = svccmd;
! } else {
if (ptempl->cmd->parent) {
log(MAIN_LOG, LOG_ERROR, "Unable to resolve template name %s for command %s in service %s.\n", ptempl->base, ptempl->cmd->name, ptempl->cmd->parent->bot->nick);
***************
*** 1386,1392 ****
log(MAIN_LOG, LOG_ERROR, "Unable to resolve template name %s for command %s in module %s.\n", ptempl->base, ptempl->cmd->name, ptempl->cmd->command->parent->name);
}
- continue;
}
- ptempl->cmd->template = svccmd;
free(ptempl->base);
free(ptempl);
--- 1407,1411 ----
|