[srvx-commits] CVS: services/src modcmd.c,1.35,1.36 modcmd.h,1.12,1.13 modcmd.help,1.7,1.8
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-10-29 04:31:32
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv6215/src
Modified Files:
modcmd.c modcmd.h modcmd.help
Log Message:
fix the tendency to use the wrong helpfile for non-command help requests
Index: modcmd.c
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -r1.35 -r1.36
*** modcmd.c 29 Oct 2002 01:57:10 -0000 1.35
--- modcmd.c 29 Oct 2002 04:31:29 -0000 1.36
***************
*** 59,62 ****
--- 59,63 ----
#define MCMSG_UNBIND_PROHIBITED "It wouldn't be very much fun to unbind the last %s command, now would it?"
#define MCMSG_COMMAND_UNBOUND "Unbound command %s from %s."
+ #define MCMSG_HELPFILE_UNBOUND "Since that was the last command from module %s on the service, the helpfile for %s was removed."
#define MCMSG_NO_HELPFILE "Module %s does not have a help file."
#define MCMSG_HELPFILE_ERROR "Syntax error reading %s; help contents not changed."
***************
*** 86,89 ****
--- 87,92 ----
#define MCMSG_RESOLVE_LOOP "Invalid template loop detected: %s"
#define MCMSG_RESOLVE_TOO_DEEP "Takes more than %d steps to resolve command templates; giving up."
+ #define MCMSG_HELPFILE_SEQUENCE "Help priority %d: %s"
+ #define MCMSG_HELPFILE_SEQUENCE_SET "Set helpfile priority sequence for %s."
struct pending_template {
***************
*** 145,148 ****
--- 148,152 ----
DEFINE_LIST(svccmd_list, struct svccmd*);
+ DEFINE_LIST(module_list, struct module*);
static void
***************
*** 164,168 ****
struct service *service = data;
dict_delete(service->commands);
! dict_delete(service->modules);
free(service);
}
--- 168,172 ----
struct service *service = data;
dict_delete(service->commands);
! module_list_clean(&service->modules);
free(service);
}
***************
*** 703,711 ****
return svccmd_send_help(user, service->bot, cmd);
} else {
! dict_iterator_t it;
struct module *module;
if (!topic) topic = "<index>";
! for (it = dict_first(service->modules); it; it = iter_next(it)) {
! module = iter_data(it);
if (!module->helpfile) continue;
if (dict_find(module->helpfile->db, topic, NULL)) {
--- 707,715 ----
return svccmd_send_help(user, service->bot, cmd);
} else {
! unsigned int ii;
struct module *module;
if (!topic) topic = "<index>";
! for (ii = 0; ii < service->modules.used; ++ii) {
! module = service->modules.list[ii];
if (!module->helpfile) continue;
if (dict_find(module->helpfile->db, topic, NULL)) {
***************
*** 765,769 ****
service_register(struct userNode *bot, unsigned char trigger) {
struct service *service = calloc(1, sizeof(*service));
! service->modules = dict_new();
service->commands = dict_new();
service->bot = bot;
--- 769,773 ----
service_register(struct userNode *bot, unsigned char trigger) {
struct service *service = calloc(1, sizeof(*service));
! module_list_init(&service->modules);
service->commands = dict_new();
service->bot = bot;
***************
*** 783,786 ****
--- 787,791 ----
static struct svccmd *
svccmd_insert(struct service *service, char *name, struct svccmd *svccmd, struct modcmd *modcmd) {
+ unsigned int ii;
svccmd->parent = service;
svccmd->name = name;
***************
*** 788,792 ****
svccmd->command->bind_count++;
dict_insert(service->commands, svccmd->name, svccmd);
! dict_insert(service->modules, svccmd->command->parent->name, svccmd->command->parent);
return svccmd;
}
--- 793,802 ----
svccmd->command->bind_count++;
dict_insert(service->commands, svccmd->name, svccmd);
! for (ii=0; ii<service->modules.used; ++ii) {
! if (service->modules.list[ii] == svccmd->command->parent) break;
! }
! if (ii == service->modules.used) {
! module_list_append(&service->modules, svccmd->command->parent);
! }
return svccmd;
}
***************
*** 966,980 ****
}
! static void
! service_rebuild_modules(struct service *service) {
dict_iterator_t it;
struct svccmd *cmd;
- dict_delete(service->modules);
- service->modules = dict_new();
for (it = dict_first(service->commands); it; it = iter_next(it)) {
cmd = iter_data(it);
! dict_insert(service->modules, cmd->command->parent->name, cmd->command->parent);
}
}
--- 976,991 ----
}
! static int
! service_recheck_bindings(struct service *service, struct module *module) {
dict_iterator_t it;
struct svccmd *cmd;
for (it = dict_first(service->commands); it; it = iter_next(it)) {
cmd = iter_data(it);
! if (cmd->command->parent == module) return 0;
}
+ /* No more bindings, remove it from our list. */
+ module_list_remove(&service->modules, module);
+ return 1;
}
***************
*** 1000,1003 ****
--- 1011,1015 ----
struct userNode *bot;
struct svccmd *bound;
+ struct module *module;
const char *svcname;
unsigned int arg, ii;
***************
*** 1031,1038 ****
*/
bot = cmd->parent->bot;
dict_remove(service->commands, bound->name);
- service_rebuild_modules(service);
send_message(user, bot, MCMSG_COMMAND_UNBOUND, cmdname, service->bot->nick);
!
return 1;
}
--- 1043,1052 ----
*/
bot = cmd->parent->bot;
+ module = cmd->command->parent;
dict_remove(service->commands, bound->name);
send_message(user, bot, MCMSG_COMMAND_UNBOUND, cmdname, service->bot->nick);
! if (service_recheck_bindings(service, module)) {
! send_message(user, bot, MCMSG_HELPFILE_UNBOUND, module->name, module->name);
! }
return 1;
}
***************
*** 1104,1108 ****
static MODCMD_FUNC(cmd_command) {
! struct svccmd *svccmd;
unsigned int flags, shown_flags, nn, pos;
char buf[MAXLEN];
--- 1118,1122 ----
static MODCMD_FUNC(cmd_command) {
! struct svccmd *svccmd, *other;
unsigned int flags, shown_flags, nn, pos;
char buf[MAXLEN];
***************
*** 1113,1118 ****
return 0;
}
! snprintf(buf, sizeof(buf), "*%s.%s", svccmd->command->parent->name, svccmd->command->name);
if (svccmd->alias.used) {
reply(MCMSG_COMMAND_ALIASES, svccmd->name, buf);
} else {
--- 1127,1139 ----
return 0;
}
! other = dict_find(svccmd->parent->commands, svccmd->command->name, NULL);
! if (other && !other->alias.used && (other->command == svccmd->command)) {
! pos = snprintf(buf, sizeof(buf), "%s", other->name);
! } else {
! pos = snprintf(buf, sizeof(buf), "*%s.%s", svccmd->command->parent->name, svccmd->command->name);
! }
if (svccmd->alias.used) {
+ buf[pos++] = ' ';
+ unsplit_string((unsigned char**)svccmd->alias.list+1, svccmd->alias.used-1, buf+pos);
reply(MCMSG_COMMAND_ALIASES, svccmd->name, buf);
} else {
***************
*** 1228,1237 ****
}
changed = 0;
! log(MAIN_LOG, LOG_OTHER, "Parsing command modifiers, starting at %d of %d\n", arg, argc);
! for (; arg+1 < argc; arg += 2) {
if (svccmd_configure(svccmd, user, cmd->parent->bot, argv[arg], argv[arg+1])) {
reply(MCMSG_COMMAND_MODIFIED, argv[arg], svccmd->name);
changed = 1;
}
}
if (changed) modcmd_set_effective_flags(svccmd);
--- 1249,1258 ----
}
changed = 0;
! while (arg+1 < argc) {
if (svccmd_configure(svccmd, user, cmd->parent->bot, argv[arg], argv[arg+1])) {
reply(MCMSG_COMMAND_MODIFIED, argv[arg], svccmd->name);
changed = 1;
}
+ arg += 2;
}
if (changed) modcmd_set_effective_flags(svccmd);
***************
*** 1502,1505 ****
--- 1523,1555 ----
}
+ static MODCMD_FUNC(cmd_helpfiles) {
+ struct service *service;
+ unsigned int ii;
+
+ if (!(service = dict_find(services, argv[1], NULL))) {
+ reply(MCMSG_UNKNOWN_SERVICE, argv[1]);
+ return 0;
+ }
+
+ if (argc < 3) {
+ for (ii=0; ii<service->modules.used; ++ii) {
+ reply(MCMSG_HELPFILE_SEQUENCE, ii+1, service->modules.list[ii]->name);
+ }
+ return 0;
+ }
+
+ service->modules.used = 0;
+ for (ii=0; ii<argc-2; ii++) {
+ struct module *module = dict_find(modules, argv[ii+2], NULL);
+ if (!module) {
+ reply(MCMSG_UNKNOWN_MODULE, argv[ii+2]);
+ continue;
+ }
+ module_list_append(&service->modules, module);
+ }
+ reply(MCMSG_HELPFILE_SEQUENCE_SET, service->bot->nick);
+ return 1;
+ }
+
void
modcmd_nick_change(struct userNode *user, const char *new_nick) {
***************
*** 1577,1585 ****
static int
modcmd_saxdb_write(struct saxdb_context *ctx) {
dict_iterator_t it, it2;
saxdb_start_record(ctx, "services", 1);
for (it = dict_first(services); it; it = iter_next(it)) {
! struct service *service = iter_data(it);
saxdb_start_record(ctx, service->bot->nick, 1);
for (it2 = dict_first(service->commands); it2; it2 = iter_next(it2)) {
--- 1627,1638 ----
static int
modcmd_saxdb_write(struct saxdb_context *ctx) {
+ struct string_list slist;
dict_iterator_t it, it2;
+ struct service *service;
+ unsigned int ii;
saxdb_start_record(ctx, "services", 1);
for (it = dict_first(services); it; it = iter_next(it)) {
! service = iter_data(it);
saxdb_start_record(ctx, service->bot->nick, 1);
for (it2 = dict_first(service->commands); it2; it2 = iter_next(it2)) {
***************
*** 1589,1592 ****
--- 1642,1657 ----
}
saxdb_end_record(ctx);
+ saxdb_start_record(ctx, "helpfiles", 1);
+ slist.size = 0;
+ for (it = dict_first(services); it; it = iter_next(it)) {
+ service = iter_data(it);
+ slist.used = 0;
+ for (ii = 0; ii < service->modules.used; ++ii) {
+ string_list_append(&slist, service->modules.list[ii]->name);
+ }
+ saxdb_write_string_list(ctx, iter_key(it), &slist);
+ }
+ if (slist.list) free(slist.list);
+ saxdb_end_record(ctx);
return 0;
}
***************
*** 1606,1610 ****
help_command = modcmd_register(modcmd_module, "help", cmd_help, 1, 0, NULL);
modcmd_register(modcmd_module, "command", cmd_command, 2, 0, NULL);
! modcmd_register(modcmd_module, "modcmd", cmd_modcmd, 4, MODCMD_KEEP_BOUND, "access", "999", NULL);
modcmd_register(modcmd_module, "god", cmd_god, 0, MODCMD_REQUIRE_AUTHED, "flags", "+oper,+networkhelper", NULL);
modcmd_register(modcmd_module, "readhelp", cmd_readhelp, 2, 0, "access", "650", NULL);
--- 1671,1675 ----
help_command = modcmd_register(modcmd_module, "help", cmd_help, 1, 0, NULL);
modcmd_register(modcmd_module, "command", cmd_command, 2, 0, NULL);
! modcmd_register(modcmd_module, "modcmd", cmd_modcmd, 4, MODCMD_KEEP_BOUND, "template", "bind", NULL);
modcmd_register(modcmd_module, "god", cmd_god, 0, MODCMD_REQUIRE_AUTHED, "flags", "+oper,+networkhelper", NULL);
modcmd_register(modcmd_module, "readhelp", cmd_readhelp, 2, 0, "access", "650", NULL);
***************
*** 1615,1618 ****
--- 1680,1684 ----
modcmd_register(modcmd_module, "stats services", cmd_stats_services, 1, 0, "access", "0", NULL);
modcmd_register(modcmd_module, "showcommands", cmd_showcommands, 1, 0, "flags", "+acceptchan", NULL);
+ modcmd_register(modcmd_module, "helpfiles", cmd_helpfiles, 2, 0, "template", "bind", NULL);
}
***************
*** 1743,1746 ****
--- 1809,1837 ----
}
modcmd_db_load_command(service, iter_key(it2), rd2->d.object);
+ }
+ }
+ db2 = database_get_data(db, "helpfiles", RECDB_OBJECT);
+ for (it = dict_first(db2); it; it = iter_next(it)) {
+ struct module *module;
+ struct string_list *slist;
+ unsigned int ii;
+
+ rd = iter_data(it);
+ if (rd->type != RECDB_STRING_LIST) {
+ log(MAIN_LOG, LOG_ERROR, "Bad type for 'helpfiles/%s' in modcmd db (expected string list)\n", iter_key(it));
+ continue;
+ }
+ slist = rd->d.slist;
+ if (!(service = service_find(iter_key(it)))) {
+ /* We probably whined about the service being missing above. */
+ continue;
+ }
+ service->modules.used = 0;
+ for (ii=0; ii<slist->used; ++ii) {
+ if (!(module = dict_find(modules, slist->list[ii], NULL))) {
+ log(MAIN_LOG, LOG_ERROR, "Unknown module '%s' listed in modcmd 'helpfiles/%s'\n", slist->list[ii], iter_key(it));
+ continue;
+ }
+ module_list_append(&service->modules, module);
}
}
Index: modcmd.h
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** modcmd.h 29 Oct 2002 01:57:10 -0000 1.12
--- modcmd.h 29 Oct 2002 04:31:29 -0000 1.13
***************
*** 39,42 ****
--- 39,43 ----
DECLARE_LIST(svccmd_list, struct svccmd*);
+ DECLARE_LIST(module_list, struct module*);
#if defined(__GNUC__) && (__GNUC__ < 3)
***************
*** 94,98 ****
struct service {
struct userNode *bot;
! dict_t modules; /* contains struct module* */
dict_t commands; /* contains struct svccmd* */
struct helpserv_bot *hs;
--- 95,99 ----
struct service {
struct userNode *bot;
! struct module_list modules;
dict_t commands; /* contains struct svccmd* */
struct helpserv_bot *hs;
Index: modcmd.help
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.help,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** modcmd.help 26 Oct 2002 22:51:41 -0000 1.7
--- modcmd.help 29 Oct 2002 04:31:29 -0000 1.8
***************
*** 66,67 ****
--- 66,71 ----
"Shows commands which you can execute (with their required access levels). If you give a numeric $O access level or text $C access name, it further restricts output to only show commands which can be executed by users with that access.",
"$uSee Also:$u command");
+ "helpfiles" ("/msg $S HELPFILES <service> [module list]",
+ "With only a service nick, shows the helpfiles used by that service.",
+ "With a list of modules, sets the order that the service will look up non-command help entries.",
+ "$uSee Also:$u bind, unbind");
|