Thread: [srvx-commits] CVS: services/src modcmd.h,1.5,1.6 modcmd.c,1.9,1.10 helpfile.h,1.22,1.23 helpfile.c,
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-08-05 01:26:59
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv8318/src
Modified Files:
modcmd.h modcmd.c helpfile.h helpfile.c
Log Message:
fix "/msg chanserv #channel command"
make *modcmd.help work right for non-command topics
Index: modcmd.h
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** modcmd.h 4 Aug 2002 23:17:12 -0000 1.5
--- modcmd.h 5 Aug 2002 01:26:56 -0000 1.6
***************
*** 88,91 ****
--- 88,92 ----
struct service {
struct userNode *bot;
+ dict_t modules; /* contains struct module* */
dict_t commands; /* contains struct svccmd* */
struct helpserv_bot *hs;
***************
*** 157,161 ****
int svccmd_send_help(struct userNode *user, struct userNode *bot, struct svccmd *cmd);
/* .. and if somebody doesn't have a modcmd handy .. */
! int svccmd_send_help_2(struct userNode *user, struct userNode *bot, struct service *service, const char *topic);
/* Check whether a user may invoke a command or not. If they can,
* return non-zero. If they cannot, tell them why not and return 0.
--- 158,162 ----
int svccmd_send_help(struct userNode *user, struct userNode *bot, struct svccmd *cmd);
/* .. and if somebody doesn't have a modcmd handy .. */
! int svccmd_send_help_2(struct userNode *user, struct service *service, const char *topic);
/* Check whether a user may invoke a command or not. If they can,
* return non-zero. If they cannot, tell them why not and return 0.
Index: modcmd.c
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** modcmd.c 4 Aug 2002 23:17:12 -0000 1.9
--- modcmd.c 5 Aug 2002 01:26:56 -0000 1.10
***************
*** 572,581 ****
* it as a channel name, and hide it from logging.
*/
! if ((cmd_arg == 0)
! && (argc > 1)
&& (cmd.flags & MODCMD_ACCEPT_CHANNEL)
&& IsChannelName(argv[1])
&& ((argv[1][0] != '+') || (cmd.flags & MODCMD_ACCEPT_PCHANNEL))) {
! if (!(channel = dict_find(channels, argv[1-cmd_arg], NULL))) {
send_message(user, service->bot, MSG_INVALID_CHANNEL);
return 0;
--- 572,580 ----
* it as a channel name, and hide it from logging.
*/
! if ((argc > 1)
&& (cmd.flags & MODCMD_ACCEPT_CHANNEL)
&& IsChannelName(argv[1])
&& ((argv[1][0] != '+') || (cmd.flags & MODCMD_ACCEPT_PCHANNEL))) {
! if (!(channel = dict_find(channels, argv[1], NULL))) {
send_message(user, service->bot, MSG_INVALID_CHANNEL);
return 0;
***************
*** 648,658 ****
int
! svccmd_send_help_2(struct userNode *user, struct userNode *bot, struct service *service, const char *topic) {
struct svccmd *cmd;
if ((cmd = dict_find(service->commands, topic, NULL))) {
! return svccmd_send_help(user, bot, cmd);
} else {
! /* TODO: try to send from the default helpfile (or default module's helpfile) instead */
! send_message(user, bot, MSG_TOPIC_UNKNOWN);
return 0;
}
--- 647,666 ----
int
! svccmd_send_help_2(struct userNode *user, struct service *service, const char *topic) {
struct svccmd *cmd;
if ((cmd = dict_find(service->commands, topic, NULL))) {
! 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)) {
! return send_help(user, service->bot, module->helpfile, topic);
! }
! }
! send_message(user, service->bot, MSG_TOPIC_UNKNOWN);
return 0;
}
***************
*** 704,707 ****
--- 712,716 ----
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;
***************
*** 719,722 ****
--- 728,743 ----
}
+ static struct svccmd *
+ svccmd_insert(struct service *service, char *name, struct svccmd *svccmd, struct modcmd *modcmd) {
+ svccmd->parent = service;
+ svccmd->name = name;
+ svccmd->command = modcmd;
+ svccmd->command->bind_count++;
+ dict_insert(service->commands, svccmd->name, svccmd);
+ dict_insert(service->modules, svccmd->command->parent->name, svccmd->command->parent);
+ return svccmd;
+ }
+
+
struct svccmd *
service_bind_modcmd(struct service *service, struct modcmd *cmd, const char *name) {
***************
*** 728,738 ****
}
svccmd = calloc(1, sizeof(*svccmd));
- svccmd->name = strdup(name);
- svccmd->command = cmd;
- svccmd->parent = service;
svccmd->weight = 1.0;
svccmd->template = cmd->defaults;
! dict_insert(service->commands, svccmd->name, svccmd);
! return svccmd;
}
--- 749,755 ----
}
svccmd = calloc(1, sizeof(*svccmd));
svccmd->weight = 1.0;
svccmd->template = cmd->defaults;
! return svccmd_insert(service, strdup(name), svccmd, cmd);
}
***************
*** 826,832 ****
return 0;
}
! newcmd->template = template;
! newcmd->command = template->command;
!
if (argc > 4) {
/* a more complicated alias; fix it up */
--- 843,847 ----
return 0;
}
!
if (argc > 4) {
/* a more complicated alias; fix it up */
***************
*** 847,856 ****
}
! newcmd->command->bind_count++;
! dict_insert(newcmd->parent->commands, newcmd->name, newcmd);
send_message(user, cmd->parent->bot, MCMSG_COMMAND_BOUND, newcmd->name, newcmd->parent->bot->nick);
return 1;
}
static MODCMD_FUNC(cmd_unbind) {
struct service *service;
--- 862,884 ----
}
! newcmd->template = template;
! svccmd_insert(service, newcmd->name, newcmd, template->command);
send_message(user, cmd->parent->bot, MCMSG_COMMAND_BOUND, newcmd->name, newcmd->parent->bot->nick);
return 1;
}
+ 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);
+ }
+ }
+
static MODCMD_FUNC(cmd_unbind) {
struct service *service;
***************
*** 875,878 ****
--- 903,907 ----
}
dict_remove(service->commands, bound->name);
+ service_rebuild_modules(service);
send_message(user, cmd->parent->bot, MCMSG_COMMAND_UNBOUND, cmdname, service->bot->nick);
return 1;
***************
*** 1022,1026 ****
unsplit_string(argv+1, argc-1);
}
! return svccmd_send_help_2(user, cmd->parent->bot, cmd->parent, topic);
}
--- 1051,1055 ----
unsplit_string(argv+1, argc-1);
}
! return svccmd_send_help_2(user, cmd->parent, topic);
}
***************
*** 1227,1233 ****
/* Now that we know we have a command to use, fill in the basics. */
svccmd = calloc(1, sizeof(*svccmd));
! svccmd->name = strdup(cmdname);
! svccmd->parent = service;
! svccmd->command = modcmd;
if ((str = database_get_data(obj, "template", RECDB_QSTRING))) {
svccmd_configure(svccmd, NULL, service->bot, "template", str);
--- 1256,1260 ----
/* Now that we know we have a command to use, fill in the basics. */
svccmd = calloc(1, sizeof(*svccmd));
! svccmd_insert(service, strdup(cmdname), svccmd, modcmd);
if ((str = database_get_data(obj, "template", RECDB_QSTRING))) {
svccmd_configure(svccmd, NULL, service->bot, "template", str);
***************
*** 1255,1259 ****
}
}
- dict_insert(service->commands, svccmd->name, svccmd);
}
--- 1282,1285 ----
***************
*** 1274,1279 ****
va_end(args);
svccmd = calloc(1, sizeof(*svccmd));
- svccmd->name = strdup(alias);
- svccmd->parent = service;
svccmd->template = svccmd_resolve_name(svccmd, argv[0]);
if (!svccmd->template) {
--- 1300,1303 ----
***************
*** 1283,1287 ****
return NULL;
}
- svccmd->command = svccmd->template->command;
if (argc > 1) {
svccmd->alias.used = svccmd->alias.size = argc;
--- 1307,1310 ----
***************
*** 1289,1294 ****
for (nn=0; nn<argc; nn++) svccmd->alias.list[nn] = strdup(argv[nn]);
}
! dict_insert(service->commands, svccmd->name, svccmd);
! return svccmd;
}
--- 1312,1316 ----
for (nn=0; nn<argc; nn++) svccmd->alias.list[nn] = strdup(argv[nn]);
}
! return svccmd_insert(service, strdup(alias), svccmd, svccmd->template->command);
}
Index: helpfile.h
===================================================================
RCS file: /cvsroot/srvx/services/src/helpfile.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** helpfile.h 2 Jul 2002 00:25:16 -0000 1.22
--- helpfile.h 5 Aug 2002 01:26:56 -0000 1.23
***************
*** 22,27 ****
#define HELPFILE_H
- struct helpfile;
-
struct userNode;
struct handle_info;
--- 22,25 ----
***************
*** 56,59 ****
--- 54,62 ----
typedef struct helpfile_expansion (*expand_func_t)(char *variable);
typedef void (*irc_send_func)(struct userNode *from, const char *to, const char *msg);
+
+ struct helpfile {
+ struct dict *db;
+ expand_func_t expand;
+ };
#ifdef __GNUC__
Index: helpfile.c
===================================================================
RCS file: /cvsroot/srvx/services/src/helpfile.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -r1.53 -r1.54
*** helpfile.c 4 Aug 2002 18:10:02 -0000 1.53
--- helpfile.c 5 Aug 2002 01:26:56 -0000 1.54
***************
*** 28,36 ****
#define HFMSG_HELP_NOT_STRING "Help file error (help data was not a string)."
- struct helpfile {
- dict_t db;
- expand_func_t expand;
- };
-
extern struct userNode *global, *chanserv, *opserv, *nickserv;
struct userNode *message_dest;
--- 28,31 ----
|