Ver código fonte

* Improved help system greatly
Now accepts */? wildcards
Individual cmd help support added.


svn: 340

Bryan Drewery 22 anos atrás
pai
commit
291cfb07d2
5 arquivos alterados com 187 adições e 59 exclusões
  1. 2 2
      src/Makefile.in
  2. 44 57
      src/cmds.c
  3. 72 0
      src/help.h
  4. 68 0
      src/misc.c
  5. 1 0
      src/proto.h

+ 2 - 2
src/Makefile.in

@@ -126,7 +126,7 @@ cmds.o: cmds.c stringfix main.h ../config.h ../pack/conf.h lang.h eggdrop.h flag
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
  compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
- tandem.h modules.h mod/modvals.h
+ tandem.h modules.h mod/modvals.h help.h
 config.o: config.c stringfix main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h proto.h \
  ../lush.h misc_file.h cmdt.h chan.h users.h compat/compat.h compat/inet_aton.h \
  compat/inet_ntop.h ../src/main.h compat/snprintf.h  compat/memset.h \
@@ -169,7 +169,7 @@ misc.o: misc.c stringfix main.h ../config.h ../pack/conf.h lang.h eggdrop.h flag
  ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h users.h \
  compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h compat/snprintf.h \
  compat/memset.h compat/memcpy.h compat/strcasecmp.h compat/strftime.h \
- stat.h
+ stat.h help.h
 misc_file.o: misc_file.c stringfix main.h ../config.h ../pack/conf.h lang.h eggdrop.h flags.h \
  proto.h ../lush.h misc_file.h cmdt.h tclegg.h tclhash.h chan.h \
  users.h compat/compat.h compat/inet_aton.h compat/inet_ntop.h ../src/main.h \

+ 44 - 57
src/cmds.c

@@ -8,6 +8,7 @@
 #include "main.h"
 #include "tandem.h"
 #include "modules.h"
+#include "help.h"
 #include <ctype.h>
 #include <stdlib.h>
 #include <pwd.h>
@@ -740,64 +741,52 @@ int my_cmp (const mycmds *c1, const mycmds *c2)
 static void cmd_help(struct userrec *u, int idx, char *par)
 {
   char flg[100];
-  int i = 0,
-    showall = 0,
-    fnd = 0,
-    n = 0,
-    done = 0,
-    first = 0, 
-    o = 0,
-    end;
+  int fnd = 0, done = 0, o = 0, nowild = 0;
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
-  char *fcats, *flag, temp[100], buf[2046];
+  char *fcats, temp[100], buf[2046], match[20];
 
-Context;
   egg_snprintf(temp, sizeof temp, "a|- a|a n|- n|n m|- m|m mo|o m|o i|- o|o o|- p|- -|-");
   fcats = temp;
 
   putlog(LOG_CMDS, "*", STR("#%s# help %s"), dcc[idx].nick, par);
   get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
+  build_flags(flg, &fr, NULL);
   if (!par[0]) {
-    showall = 1;
-    build_flags(flg, &fr, NULL);
-    dprintf(idx, STR("Showing help topics matching your flags: (%s)\n  "), flg);
+    sprintf(match, "*");
   } else {
-    dprintf(idx, "Not yet implemented.\n");
-    return;
-  }
-
-  for (o = 0; o < cmdi; o++)
-  ;
-  /* this displays help for old system
-  {
-    if (!flagrec_ok(&cmds[o].flags, &fr))
-      continue;
-    if (!showall && !egg_strcasecmp(par, cmds[o].name)) {
-      fnd = 1;
-      build_flags(flg, &(cmds[o].flags), NULL);
-      dprintf(idx, STR("### %s (required flags: %s)\n"), cmds[o].name, flg);
-      dprintf(idx, STR("Usage      : %s%s %s\n"), dcc_prefix, cmds[o].name, cmds[o].usage ? cmds[o].usage : "");
-      dprintf(idx, STR("Description: %s\n"), cmds[o].desc ? cmds[o].desc : "None");
-      break;
-    }
-  }
-  */
-  
-  if (showall) {
-    qsort(cmds, o, sizeof(mycmds), (int (*)()) &my_cmp);
-    end = 0;
-    buf[0] = '\0';
-    while (!done) {
-      flag = newsplit(&fcats);
-      if (!flag[0]) 
-	done = 1;
-
-      i = 0;
-      first = 1;
-      for (n = 0; n < o ; n++) { /* loop each command */
-        if (!flagrec_ok(&cmds[n].flags, &fr))
-          continue;
-        flg[0] = '\0';
+    if (!strchr(par, '*') && !strchr(par, '?'))
+      nowild++;
+    sprintf(match, "%s", newsplit(&par));
+  }
+  if (!nowild)
+    dprintf(idx, STR("Showing help topics matching '%s' for flags: (%s)\n"), match, flg);
+  o = cmdi - 1;  
+  qsort(cmds, o, sizeof(mycmds), (int (*)()) &my_cmp);
+  buf[0] = 0;
+  /* even if we have nowild, we loop to conserve code/space */
+  while (!done) {
+    int i = 0, end = 0, first = 1, n, hi;
+    char *flag;
+
+    flag = newsplit(&fcats);
+    if (!flag[0]) 
+      done = 1;
+
+    for (n = 0; n < o ; n++) { /* loop each command */
+      if (!flagrec_ok(&cmds[n].flags, &fr) || !wild_match(match,cmds[n].name))
+        continue;
+      fnd++;
+      if (nowild) {
+        dprintf(idx, STR("Showing you help for '%s':"), match);
+        for (hi = 0; (help[hi].cmd) && (help[hi].desc); hi++) {
+          if (!egg_strcasecmp(match, help[hi].cmd)) {
+            showhelp(idx, &fr, help[hi].desc);
+          }
+        }
+        done = 1;
+        break;
+      } else {
+        flg[0] = 0;
         build_flags(flg, &(cmds[n].flags), NULL);
         if (!strcmp(flg, flag)) {
           if (first) {
@@ -805,13 +794,11 @@ Context;
             dprintf(idx, STR("# DCC (%s)\n"), flag);
             sprintf(buf, "  ");
           }
-
           if (end && !first) {
             dprintf(idx, "%s\n", buf[0] ? buf : "");
             /* we dumped the buf to dprintf, now start a new one... */
             sprintf(buf, "  ");
           }
-        
           sprintf(buf, "%s%-14.14s", buf[0] ? buf : "", cmds[n].name);
           first = 0;
           end = 0;
@@ -823,15 +810,15 @@ Context;
         } 
       }
     }
-    dprintf(idx, "%s\n", buf[0] ? buf : "");
   }
-
-  if (showall) {
-    dprintf(idx, STR("End of list. For individual command help, type: %shelp <command>\n"), dcc_prefix);
-    dprintf(idx, STR("If you have flags on a channel, type %sconsole #chan to see more commands.\n"), dcc_prefix);
+  dprintf(idx, "%s\n", buf[0] ? buf : "");
+  dprintf(idx, STR("--End help listing\n"));
+  if (!strcmp(match, "*")) {
+    dprintf(idx, STR("For individual command help, type: %shelp <command>\n"), dcc_prefix);
   } else if (!fnd) {
-    dprintf(idx, STR("No help for nonexistant command '%s'.\n"), par);
+    dprintf(idx, STR("No match for '%s'.\n"), match);
   }
+  dprintf(idx, STR("If you have flags on a channel, type %sconsole #chan to possibly see more commands.\n"), dcc_prefix);
 }
 
 static void cmd_addlog(struct userrec *u, int idx, char *par)

+ 72 - 0
src/help.h

@@ -0,0 +1,72 @@
+#ifndef HELP_H
+#define HELP_H
+typedef struct {
+  int type;
+  char *cmd;
+  char *desc;
+} help_t;
+
+help_t help[] =
+{
+{2, "cmd",
+"Usage: cmd <blah> \n \
+	Help text goes here \n \
+	more here \n \
+	etc .... \n"},
+{2, "echo",
+"	Testing the help system \n \
+blah blah blah blah \n \
+[12:42:49] <drewballs> hey, would it be possible to create 3 more vhosts with drewballs.org with different nicks? \n \
+[12:43:20] <drewballs> but things like, got.0wned.at.drewballs.org \n"},
+{2, "whois",
+"Usage: whois <handle> \n \
+    will show you the bot information about a user record. there are \n \
+    five headings: \n \
+    HANDLE the handle (nickname) of the user \n \
+    PASS 'Yes' if they have a password set, 'No' if not \n \
+    NOTES number of notes stored waiting for the user \n \
+    FLAGS the list of flags for this user (see below) \n \
+    LAST the time or date that the user was last on the channel \n \
+    the valid flags under FLAGS are: \n \
+      a administrator (user is higher than an owner but not a perm owner) \n \
+      b bot (user is another bot) \n \
+      c leaf 'chat hub' (bot will accept MSG cmds and dcc chat from users) \n \
+      d global deop (user cannot get ops) \n \
+      i hub access (user can .relay to hubs) \n \
+      j leaf 'chat hub' access (user has DCC access to leaf 'chat hubs') \n \
+      k global auto-kick (user kicked & banned automatically) \n \
+      l bot flag - sets limit (bot will set limit in all chans) \n \
+      m master (user is a bot master) \n \
+      n owner (user is the bot owner) \n \
+      o global op (bot will op this user on any channel upon request) \n \
+      p party-line (user has party-line chat access [Not required for dcc, see: +j]) \n \
+      q quiet (user never gets +v on channels) \n \
+      v global voice (user get +v automatically on +autovoice channels - CelBots delayed) \n \
+      w wasop-test (needs wasop test for +stopnethack procedure) \n \
+      x flood exempt (user will not be punished for flooding) \n \
+      y bot flag - voices users (bot will voice +v users in all chans) \n \
+    each channel that the user has joined will have a specific record \n \
+    for it, with the channel-specific flags and possibly an info \n \
+    line. the channel-specific flags are: \n \
+      d deop (bot will not allow this user to become a chanop) \n \
+      k kick (user is auto kicked-banned from chan) \n \
+      l bot flag - sets limit (bot will set limit in all chans) \n \
+      m master (user is a master for the channel) \n \
+      n owner (user is an owner for the channel) \n \
+      o op (bot will give this user chanop) \n \
+      q quiet (user never gets +v in chan) \n \
+      v voice (user gets +v automatically on +autovoice channels - CelBots delayed) \n \
+      w wasop-test (needs wasop test for +stopnethack procedure) \n \
+      x flood exempt (user will not be punished for flooding) \n \
+      y bot flag - voices users (bot will voice +v users in all chans) \n \
+    hostmasks for the user are displayed on the following lines. \n \
+    (not on leaf bots though) \n \
+    if the user entry is for a bot, there will be a line below which \n \
+    says 'ADDRESS:' and gives the bot's telnet address. some user \n \
+    entries may have 'EMAIL:' and 'INFO:' entries too. \n \
+    %{+m} masters: if there is a comment, you will see it under 'COMMENT:' \n \
+      %{-} See also: match \n"},
+
+{0, NULL}	/* end of the list */
+};
+#endif /* HELP_H */

+ 68 - 0
src/misc.c

@@ -2016,3 +2016,71 @@ char *btoh(const unsigned char *md, int len)
   return ret;
 }
 
+void showhelp (int idx, struct flag_record *flags, char *string)
+{
+  struct flag_record tr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
+  static char helpstr[8092] = "", tmp[2] = "", flagstr[10] = "";
+  int ok = 1;
+Context;
+  helpstr[0] = 0;
+  while ( (string) && (string[0]) ) {
+    if ( (*string == '%') ) {
+      if ( !strncmp(string + 1, "{+", 2) ) {
+        while ( (*string) && (*string != '+') ) {
+          string++;
+        }
+        flagstr[0] = 0;
+        while ( (*string) && (*string != '}') ) {
+          sprintf(tmp, "%c", *string);
+          strcat(flagstr, tmp);
+          string++;
+        }
+        string++;
+        break_down_flags(flagstr, &tr, NULL);
+        if (flagrec_ok(&tr, flags)) {
+          ok = 1;
+          while ( (*string) && (*string != '%') ) {
+            sprintf(tmp, "%c", *string);
+            strcat(helpstr, tmp);
+            string++;
+          }
+          if ( !strncmp(string + 1, "{-", 2) ) {
+            ok = 1;
+            while ( (*string) && (*string != '}') ) {
+              string++;
+            }
+          }
+          string++;
+        } else {
+          ok = 0;
+        }
+      } else if ( !strncmp(string + 1, "{-", 2) ) {
+        ok = 1;
+        while ( (*string) && (*string != '}') ) {
+          string++;
+        }
+        string++;
+      } else if ( (*string == '{') ) {
+        while ( (*string) && (*string != '}') ) {
+          string++;
+        }
+      } else {
+        if (ok) {
+          sprintf(tmp, "%c", *string);
+          strcat(helpstr, tmp);
+        }
+        string++;
+      }
+    } else {
+      if (ok) {
+        sprintf(tmp, "%c", *string);
+        strcat(helpstr, tmp);
+      }
+      string++;
+    }
+  }
+  if (strchr(helpstr, '\0'))
+    *(char*)(strchr(helpstr, '\0')) = 0;
+  if (helpstr[0]) dumplots(idx, "", helpstr);
+}
+

+ 1 - 0
src/proto.h

@@ -230,6 +230,7 @@ void set_cmd_pass(char *, int);
 #endif /* S_DCCPASS */
 
 /* misc.c */
+void showhelp(int, struct flag_record *, char *);
 char *btoh(const unsigned char *, int);
 void local_check_should_lock();
 void werr(int);