[X2serv-cvs] [CVS] Module x3: Change committed
Brought to you by:
sirvulcan
From: Alex S. <ru...@us...> - 2005-03-16 05:17:20
|
Committer : Alex Schumann <ru...@us...> CVSROOT : /cvsroot/x2serv Module : x3 Commit time: 2005-03-16 05:17:03 UTC Modified files: src/chanserv.c src/helpfile.c src/helpfile.h src/main.c src/modcmd.c src/modcmd.h Log message: better error messages when insuficient params ---------------------- diff included ---------------------- Index: x3/src/chanserv.c diff -u x3/src/chanserv.c:1.15 x3/src/chanserv.c:1.16 --- x3/src/chanserv.c:1.15 Sat Mar 12 12:13:14 2005 +++ x3/src/chanserv.c Tue Mar 15 21:16:50 2005 @@ -467,7 +467,7 @@ #define CSFUNC_ARGS user, channel, argc, argv, cmd #define CHANSERV_FUNC(NAME) MODCMD_FUNC(NAME) -#define CHANSERV_SYNTAX() svccmd_send_help(user, chanserv, cmd) +#define CHANSERV_SYNTAX() svccmd_send_help_breef(user, chanserv, cmd) #define REQUIRE_PARAMS(N) if(argc < (N)) { \ reply("MSG_MISSING_PARAMS", argv[0]); \ CHANSERV_SYNTAX(); \ @@ -1742,7 +1742,13 @@ } else { - if((argc < 2) || !IsChannelName(argv[1])) + if(argc < 2) + { + reply("MSG_MISSING_PARAMS", cmd->name); + svccmd_send_help_breef(user, chanserv, cmd); + return 0; + } + if(!IsChannelName(argv[1])) { reply("MSG_NOT_CHANNEL_NAME"); return 0; Index: x3/src/helpfile.c diff -u x3/src/helpfile.c:1.3 x3/src/helpfile.c:1.4 --- x3/src/helpfile.c:1.3 Sat Mar 12 12:13:14 2005 +++ x3/src/helpfile.c Tue Mar 15 21:16:51 2005 @@ -703,6 +703,28 @@ return res; } + +int +_send_help_breef(struct userNode *dest, struct userNode *src, expand_func_t expand, const char *format, ...) +{ + int res; + char* buf; + char* ptr; + va_list ap; + + buf = (char *) malloc(strlen(format) +1); + sprintf(buf, format); + ptr = strchr(buf, '\n'); + *ptr = '\0'; + printf("buf is: %s", buf); + va_start(ap, buf); + res = vsend_message(dest->nick, src, dest->handle_info, 12, expand, buf, ap); + va_end(ap); + free(buf); + return res; +} + + int send_help(struct userNode *dest, struct userNode *src, struct helpfile *hf, const char *topic) { @@ -734,6 +756,37 @@ return _send_help(dest, src, hf->expand, rec->d.qstring); } +int +send_help_breef(struct userNode *dest, struct userNode *src, struct helpfile *hf, const char *topic) +{ + struct helpfile *lang_hf; + struct record_data *rec; + struct language *curr; + + if (!topic) + topic = "<index>"; + if (!hf) { + _send_help(dest, src, NULL, "HFMSG_MISSING_HELPFILE"); + return 0; + } + for (curr = (dest->handle_info ? dest->handle_info->language : lang_C); + curr; + curr = curr->parent) { + lang_hf = dict_find(curr->helpfiles, hf->name, NULL); + if (!lang_hf) + continue; + rec = dict_find(lang_hf->db, topic, NULL); + if (rec && rec->type == RECDB_QSTRING) + return _send_help_breef(dest, src, hf->expand, rec->d.qstring); + } + rec = dict_find(hf->db, "<missing>", NULL); + if (!rec) + return send_message(dest, src, "MSG_TOPIC_UNKNOWN"); + if (rec->type != RECDB_QSTRING) + return send_message(dest, src, "HFMSG_HELP_NOT_STRING"); + return _send_help(dest, src, hf->expand, rec->d.qstring); +} + /* Grammar supported by this parser: * condition = expr | prefix expr * expr = atomicexpr | atomicexpr op atomicexpr Index: x3/src/helpfile.h diff -u x3/src/helpfile.h:1.3 x3/src/helpfile.h:1.4 --- x3/src/helpfile.h:1.3 Sat Mar 12 12:13:14 2005 +++ x3/src/helpfile.h Tue Mar 15 21:16:51 2005 @@ -82,6 +82,7 @@ int send_message_type(int msg_type, struct userNode *dest, struct userNode *src, const char *message, ...); int send_target_message(int msg_type, const char *dest, struct userNode *src, const char *format, ...); int send_help(struct userNode *dest, struct userNode *src, struct helpfile *hf, const char *topic); +int send_help_breef(struct userNode *dest, struct userNode *src, struct helpfile *hf, const char *topic); /* size is maximum line width (up to MAX_LINE_SIZE); 0 means figure it out. * irc_send is either irc_privmsg or irc_notice; NULL means figure it out. */ void table_send(struct userNode *from, const char *to, unsigned int size, irc_send_func irc_send, struct helpfile_table table); Index: x3/src/main.c diff -u x3/src/main.c:1.4 x3/src/main.c:1.5 --- x3/src/main.c:1.4 Sat Mar 12 12:13:14 2005 +++ x3/src/main.c Tue Mar 15 21:16:51 2005 @@ -96,8 +96,8 @@ { "MSG_INVALID_GLINE", "Invalid G-line '%s'." }, { "MSG_INVALID_DURATION", "Invalid time span '%s'." }, { "MSG_NOT_TARGET_NAME", "You must provide the name of a channel or user." }, - { "MSG_NOT_CHANNEL_NAME", "You must provide a valid channel name." }, - { "MSG_INVALID_CHANNEL", "You must provide the name of a channel that exists." }, + { "MSG_NOT_CHANNEL_NAME", "The channel name you specified is not a valid channel name." }, + { "MSG_INVALID_CHANNEL", "The channel name you specified does not exist." }, { "MSG_CHANNEL_ABSENT", "You aren't currently in $b%s$b." }, { "MSG_CHANNEL_USER_ABSENT", "$b%s$b isn't currently in $b%s$b." }, { "MSG_MISSING_PARAMS", "$b%s$b requires more parameters." }, Index: x3/src/modcmd.c diff -u x3/src/modcmd.c:1.10 x3/src/modcmd.c:1.11 --- x3/src/modcmd.c:1.10 Sat Mar 12 12:13:14 2005 +++ x3/src/modcmd.c Tue Mar 15 21:16:51 2005 @@ -721,6 +721,7 @@ } if (argc < cmd->command->min_argc) { send_message(user, service->bot, "MSG_MISSING_PARAMS", cmd->name); + svccmd_send_help_breef(user, service->bot, cmd); return 0; } if (!cmd->command->func) { @@ -784,6 +785,28 @@ } int +svccmd_send_help_breef(struct userNode *user, struct userNode *bot, struct svccmd *cmd) { + char cmdname[MAXLEN]; + unsigned int nn; + int r; + /* Show command name (in bold). */ + for (nn=0; cmd->name[nn]; nn++) + cmdname[nn] = toupper(cmd->name[nn]); + cmdname[nn] = 0; + + /* Show the help entry for the underlying command. */ + /* Lets not show help for a parent command, thats not what + * they asked for! + * return send_help(user, bot, cmd->command->parent->helpfile, cmd->command->name); + * TODO: We actually DO want to show the parent IF there is no other help. + */ + r = send_help_breef(user, bot, cmd->command->parent->helpfile, cmd->name); + + return r; +} + + +int svccmd_send_help_2(struct userNode *user, struct service *service, const char *topic) { struct module *module; struct svccmd *cmd; Index: x3/src/modcmd.h diff -u x3/src/modcmd.h:1.2 x3/src/modcmd.h:1.3 --- x3/src/modcmd.h:1.2 Sat Mar 12 12:13:14 2005 +++ x3/src/modcmd.h Tue Mar 15 21:16:52 2005 @@ -167,6 +167,8 @@ 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); +/* Send breef help for a command to a user. */ +int svccmd_send_help_breef(struct userNode *user, struct userNode *bot, struct svccmd *cmd); /* Check whether a user may invoke a command or not. If they can, * return non-zero. If they cannot (and noisy is non-zero), tell them * why not and return 0. ----------------------- End of diff ----------------------- |