[srvx-commits] CVS: services/src modcmd.c,1.30,1.31 modcmd.help,1.5,1.6 opserv.help,1.50,1.51
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-09-24 19:21:07
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv31099/src
Modified Files:
modcmd.c modcmd.help opserv.help
Log Message:
add ?stats modules, ?stats services, and update documentation
Index: modcmd.c
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** modcmd.c 23 Sep 2002 00:19:08 -0000 1.30
--- modcmd.c 24 Sep 2002 19:20:58 -0000 1.31
***************
*** 35,39 ****
#define MCMSG_CHAN_NOT_REGISTERED "%s has not been registered with $C."
#define MCMSG_NO_CHANNEL_ACCESS "You lack access to %s."
! #define MCMSG_LOW_CHANNEL_ACCESS "You lack sufficient access to %s to use this command."
#define MCMSG_REQUIRES_JOINABLE "You must be in %s (or on its userlist) to use this command."
#define MCMSG_MUST_BE_HELPING "You must have security override (helping mode) on to use this command."
--- 35,39 ----
#define MCMSG_CHAN_NOT_REGISTERED "%s has not been registered with $C."
#define MCMSG_NO_CHANNEL_ACCESS "You lack access to %s."
! #define MCMSG_LOW_CHANNEL_ACCESS "You lack sufficient access in %s to use this command."
#define MCMSG_REQUIRES_JOINABLE "You must be in %s (or on its userlist) to use this command."
#define MCMSG_MUST_BE_HELPING "You must have security override (helping mode) on to use this command."
***************
*** 45,48 ****
--- 45,49 ----
#define MCMSG_ALIAS_ERROR "Error in alias expansion for %s; check the error log for details."
#define MCMSG_INTERNAL_COMMAND "$b%s$b is an internal command and cannot be called directly; please check command bindings."
+ #define MCMSG_UNKNOWN_MODULE "Unknown module %s."
#define MCMSG_UNKNOWN_SERVICE "Unknown service %s."
#define MCMSG_ALREADY_BOUND "%s already has a command bound as %s."
***************
*** 79,82 ****
--- 80,85 ----
#define MSMSG_NOW_NOT_HELPING "Security override has been disabled."
#define MCMSG_JOINER_CHOICES "Subcommands of %s: %s"
+ #define MCMSG_MODULE_INFO "Commands exported by module $b%s$b:"
+ #define MCMSG_SERVICE_INFO "Commands bound to service $b%s$b:"
#define MCMSG_TOYS_DISABLED "Toys are disabled in %s."
#define MCMSG_NO_TEMPLATE_SELF "You cannot make a command its own template."
***************
*** 91,96 ****
static int in_setup;
! static dict_t modules;
! static dict_t services;
static struct pending_template *pending_templates;
static struct module *modcmd_module;
--- 94,99 ----
static int in_setup;
! static struct dict *modules;
! static struct dict *services;
static struct pending_template *pending_templates;
static struct module *modcmd_module;
***************
*** 1308,1313 ****
}
! static MODCMD_FUNC(cmd_joiner)
! {
char cmdname[80];
--- 1311,1315 ----
}
! static MODCMD_FUNC(cmd_joiner) {
char cmdname[80];
***************
*** 1334,1337 ****
--- 1336,1458 ----
}
+ static MODCMD_FUNC(cmd_stats_modules) {
+ struct helpfile_table tbl;
+ dict_iterator_t it;
+ unsigned int ii;
+ struct module *mod;
+
+ if (argc < 2) {
+ tbl.length = dict_size(modules) + 1;
+ tbl.width = 4;
+ tbl.flags = TABLE_PAD_LEFT;
+ tbl.contents = calloc(tbl.length, sizeof(tbl.contents[0]));
+ tbl.contents[0] = calloc(tbl.width, sizeof(tbl.contents[0][0]));
+ tbl.contents[0][0] = "Module";
+ tbl.contents[0][1] = "Commands";
+ tbl.contents[0][2] = "Logfile";
+ tbl.contents[0][3] = "Helpfile";
+ for (ii=1, it=dict_first(modules); it; it=iter_next(it), ii++) {
+ mod = iter_data(it);
+ tbl.contents[ii] = calloc(tbl.width, sizeof(tbl.contents[ii][0]));
+ tbl.contents[ii][0] = mod->name;
+ tbl.contents[ii][1] = strtab(dict_size(mod->commands));
+ tbl.contents[ii][2] = "(unknown)"; /* TODO: find logfile name */
+ tbl.contents[ii][3] = mod->helpfile_name ? mod->helpfile_name : "(none)";
+ }
+ } else {
+ struct modcmd *modcmd;
+
+ if (!(mod = dict_find(modules, argv[1], NULL))) {
+ reply(MCMSG_UNKNOWN_MODULE, argv[1]);
+ return 0;
+ }
+ reply(MCMSG_MODULE_INFO, mod->name);
+ tbl.length = dict_size(mod->commands) + 1;
+ tbl.width = 3;
+ tbl.flags = TABLE_NO_FREE | TABLE_PAD_LEFT;
+ tbl.contents = calloc(tbl.length, sizeof(tbl.contents[0]));
+ tbl.contents[0] = calloc(tbl.width, sizeof(tbl.contents[0][0]));
+ tbl.contents[0][0] = "Command";
+ tbl.contents[0][1] = "Min. Args";
+ tbl.contents[0][2] = "Bind Count";
+ for (ii=1, it=dict_first(mod->commands); it; it=iter_next(it), ii++) {
+ modcmd = iter_data(it);
+ tbl.contents[ii] = calloc(tbl.width, sizeof(tbl.contents[ii][0]));
+ tbl.contents[ii][0] = modcmd->name;
+ tbl.contents[ii][1] = strtab(modcmd->min_argc);
+ tbl.contents[ii][2] = strtab(modcmd->bind_count);
+ }
+ }
+ table_send(cmd->parent->bot, user->nick, 0, 0, tbl);
+ return 0;
+ }
+
+ static MODCMD_FUNC(cmd_stats_services) {
+ struct helpfile_table tbl;
+ dict_iterator_t it;
+ unsigned int ii;
+ struct service *service;
+ char *extra;
+
+ if (argc < 2) {
+ tbl.length = dict_size(services) + 1;
+ tbl.width = 4;
+ tbl.flags = TABLE_PAD_LEFT;
+ tbl.contents = calloc(tbl.length, sizeof(tbl.contents[0]));
+ tbl.contents[0] = calloc(tbl.width, sizeof(tbl.contents[0][0]));
+ tbl.contents[0][0] = "Service";
+ tbl.contents[0][1] = "Commands";
+ tbl.contents[0][2] = "Priv'd?";
+ tbl.contents[0][3] = "Trigger";
+ extra = calloc(2, tbl.length);
+ for (ii=1, it=dict_first(services); it; it=iter_next(it), ii++) {
+ service = iter_data(it);
+ tbl.contents[ii] = calloc(tbl.width, sizeof(tbl.contents[ii][0]));
+ tbl.contents[ii][0] = service->bot->nick;
+ tbl.contents[ii][1] = strtab(dict_size(service->commands));
+ tbl.contents[ii][2] = service->privileged ? "yes" : "";
+ extra[ii*2] = service->trigger;
+ tbl.contents[ii][3] = extra+ii*2;
+ }
+ table_send(cmd->parent->bot, user->nick, 0, 0, tbl);
+ return 0;
+ } else {
+ struct svccmd *svccmd;
+
+ if (!(service = dict_find(services, argv[1], NULL))) {
+ reply(MCMSG_UNKNOWN_SERVICE, argv[1]);
+ return 0;
+ }
+ tbl.length = dict_size(service->commands) + 1;
+ tbl.width = 5;
+ tbl.flags = TABLE_PAD_LEFT | TABLE_NO_FREE;
+ tbl.contents = calloc(tbl.length, sizeof(tbl.contents[0]));
+ tbl.contents[0] = calloc(tbl.width, sizeof(tbl.contents[0][0]));
+ tbl.contents[0][0] = "Command";
+ tbl.contents[0][1] = "Module";
+ tbl.contents[0][2] = "ModCmd";
+ tbl.contents[0][3] = "Alias?";
+ tbl.contents[0][4] = strdup("Uses");
+ for (ii=1, it=dict_first(service->commands); it; it=iter_next(it), ii++) {
+ svccmd = iter_data(it);
+ tbl.contents[ii] = calloc(tbl.width, sizeof(tbl.contents[ii][0]));
+ tbl.contents[ii][0] = svccmd->name;
+ tbl.contents[ii][1] = svccmd->command->parent->name;
+ tbl.contents[ii][2] = svccmd->command->name;
+ tbl.contents[ii][3] = svccmd->alias.used ? "Yes" : "";
+ tbl.contents[ii][4] = extra = malloc(12);
+ sprintf(extra, "%u", svccmd->uses);
+ }
+ reply(MCMSG_SERVICE_INFO, service->bot->nick);
+ table_send(cmd->parent->bot, user->nick, 0, 0, tbl);
+ for (ii=0; ii<tbl.length; ii++) {
+ free((char*)tbl.contents[ii][4]);
+ free(tbl.contents[ii]);
+ }
+ free(tbl.contents);
+ return 0;
+ }
+ }
+
void
modcmd_nick_change(struct userNode *user, const char *new_nick) {
***************
*** 1440,1447 ****
modcmd_register(modcmd_module, "unbind", cmd_unbind, 3, 0, "template", "bind", NULL);
modcmd_register(modcmd_module, "joiner", cmd_joiner, 1, 0, NULL);
}
static void
! modcmd_db_load_command(struct service *service, const char *cmdname, dict_t obj) {
struct svccmd *svccmd;
struct module *module;
--- 1561,1570 ----
modcmd_register(modcmd_module, "unbind", cmd_unbind, 3, 0, "template", "bind", NULL);
modcmd_register(modcmd_module, "joiner", cmd_joiner, 1, 0, NULL);
+ modcmd_register(modcmd_module, "stats modules", cmd_stats_modules, 1, 0, "access", "0", NULL);
+ modcmd_register(modcmd_module, "stats services", cmd_stats_services, 1, 0, "access", "0", NULL);
}
static void
! modcmd_db_load_command(struct service *service, const char *cmdname, struct dict *obj) {
struct svccmd *svccmd;
struct module *module;
Index: modcmd.help
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.help,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** modcmd.help 18 Sep 2002 14:52:50 -0000 1.5
--- modcmd.help 24 Sep 2002 19:21:01 -0000 1.6
***************
*** 1,4 ****
"bind" ("/msg $S BIND <service> <bindname> <command> [additional args..]",
! "Binds a command to an existing service. $bbindname$b is the name of the new command for the service. $bcommand$b may be:",
" CommandName To refer to a command on the same service.",
" ServiceNick.CommandName To refer to a command bound on a different service.",
--- 1,4 ----
"bind" ("/msg $S BIND <service> <bindname> <command> [additional args..]",
! "Binds (adds) a command to an existing service. $bbindname$b is the name of the new command for the service. $bcommand$b may be one of:",
" CommandName To refer to a command on the same service.",
" ServiceNick.CommandName To refer to a command bound on a different service.",
***************
*** 55,56 ****
--- 55,64 ----
"joiner" ("/msg $S JOINER [subcmd ...]",
"Magically looks up subcommands and redirects to them. Use the command by itself to see what subcommands are known.");
+ "stats modules" ("/msg $S STATS MODULES [modulename]",
+ "With no module name argument, shows a list of loaded modules and brief statistics for each.",
+ "When a module name is given, shows commands exported by that module.",
+ "$uSee Also:$u stats services, command, modcmd, bind");
+ "stats services" ("/msg $S STATS SERVICES [botnick]",
+ "With no bot nick argument, shows a list of the service bots using the unified command framework, and brief statistics for each.",
+ "When a bot nick is given, shows commands bound to that service.",
+ "$uSee Also:$u stats modules, command, modcmd, bind, unbind");
Index: opserv.help
===================================================================
RCS file: /cvsroot/srvx/services/src/opserv.help,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -r1.50 -r1.51
*** opserv.help 18 Sep 2002 14:55:05 -0000 1.50
--- opserv.help 24 Sep 2002 19:21:01 -0000 1.51
***************
*** 9,13 ****
" LOGS - Log control and searching",
" PROXY - Proxy checking controls",
- " LEVELS - Controlling access to $O commands",
" RUNNING - Control srvx's run-time state",
" SERVICES - Control of the other services in srvx",
--- 9,12 ----
***************
*** 341,362 ****
"$uSee Also:$u log, loginfo, modlog");
- "LEVELS" ("$bCOMMAND COMMANDS$b",
- "These commands control access to $O commands.",
- " CHLEVEL [${level/chlevel}]",
- " DISABLECOM [${level/disablecom}]",
- " ENABLECOM [${level/enablecom}]",
- " SHOWDISCOM [${level/showdiscom}]");
- "CHLEVEL" ("/msg $O CHLEVEL <command> <new level>",
- "Changes the access level an oper must have on $b$O$b to use the specified command.");
- "DISABLECOM" ("/msg $O DISABLECOM <command>",
- "Disables an $b$O$b command completely. You cannot disable the $benablecom$b command (for the obvious reason).",
- "$uSee Also:$u enablecom, showdiscom");
- "ENABLECOM" ("/msg $O ENABLECOM <command>",
- "Enables the specified disabled $b$O$b command.",
- "$uSee Also:$u disablecom, showdiscom");
- "SHOWDISCOM" ("/msg $O SHOWDISCOM ",
- "Displays the list of disabled $b$O$b commands.",
- "$uSee Also:$u disablecom, enablecom");
-
"RUNNING" ("$bRUNNING COMMANDS$b",
"These commands control srvx's runtime state.",
--- 340,343 ----
***************
*** 462,466 ****
"$bTRUSTED$b: The list of currently trusted hosts.",
"$bUPTIME$b: Srvx uptime, lines processed, and CPU time.",
! "$bWARN$b: The list of channels with activity warnings.");
"VERSION" ("/msg $O VERSION ",
"Sends you the srvx version and all version information for $b$C$b, $b$O$b, $b$N$b, and $b$G$b.");
--- 443,449 ----
"$bTRUSTED$b: The list of currently trusted hosts.",
"$bUPTIME$b: Srvx uptime, lines processed, and CPU time.",
! "$bWARN$b: The list of channels with activity warnings.",
! "$bMODULES$b: Shows loaded modules that implement commands.",
! "$bSERVICES$b: Shows active service bots.");
"VERSION" ("/msg $O VERSION ",
"Sends you the srvx version and all version information for $b$C$b, $b$O$b, $b$N$b, and $b$G$b.");
|