Просмотр исходного кода

* After editing binary with -C, new bots/hosts are automatically added if first bot is linked.
Plus, bots are automatically killed/started now.
* Fixedbug with bots not being disabled correctly
* Fixed cmd_conf not correctly writing settings back to the binary
* Added options 'enable' and 'disable' to cmd_conf for bots


svn: 2008

Bryan Drewery 21 лет назад
Родитель
Сommit
df14fb2f47
9 измененных файлов с 141 добавлено и 20 удалено
  1. 5 0
      doc/UPDATES
  2. 11 2
      misc/help.txt
  3. 6 1
      src/binary.c
  4. 30 11
      src/cmds.c
  5. 64 5
      src/conf.c
  6. 1 0
      src/conf.h
  7. 23 0
      src/userrec.c
  8. 0 1
      src/userrec.h
  9. 1 0
      src/users.h

+ 5 - 0
doc/UPDATES

@@ -74,6 +74,11 @@ Lines prefixxed with '-' were disabled before release and are not finishsed, or
 * Fixed unsetting a global ban when the same ban is local to a chan causes the bots to unban it. (#24)
 * +O now implies +o
 * Combined kick reasons for +k and .kickban
+* Fixed cmd_conf not correctly writing settings back to the binary
+* After editing binary with -C, new bots/hosts are automatically added if first bot is linked.
+  Plus, bots are automatically killed/started now.
+* Added options 'enable' and 'disable' to cmd_conf for bots
+
 
 1.2.2
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.

+ 11 - 2
misc/help.txt

@@ -687,7 +687,7 @@ See also: console, echo, login, page, strip
    be seen via 'whois' or 'match'. Non-masters cannot see the comment field.
    Using the comment 'none' will clear a user's comment.
 ::conf:
-###  $bconf$b <add|del|change|list|set> [options]
+###  $bconf$b <add|del|change|disable|enable|list|set> [options]
  
    This command is used to modify the bot's local shell config. Only
    the first bot listed will be able to perform this command. Using the cmd
@@ -703,12 +703,21 @@ See also: console, echo, login, page, strip
       ip/host/ipv6-ip are all optional and/or can be replaced with '.'
      Newly added bots will start immediately, don't forget to 'newleaf'.
  
-    'del' syntax is simply:
+    'del' syntax is:
       del <bot>
     Deleted bots that are running will be killed.
   
     'change' syntax is the same as 'add'
  
+    'disable' syntax is:
+      disable <bot>
+    The bot will be killed, but not removed from userlist. It will not start again
+    until you use 'enable' oni t.
+
+    'enable' syntax is:
+      enable <bot>
+    The bot is enabled. (Only relevant for disabled bots designated via a prefix of '/')
+
     'list' shows all the bots currently in the config.
  
     'set' allows changing some variables in the config.

+ 6 - 1
src/binary.c

@@ -482,7 +482,8 @@ void conf_to_bin(conf_t *in, bool move, int die)
   strlcpy(settings.homedir, in->homedir, 350);
   strlcpy(settings.binpath, in->binpath, 350);
   for (bot = in->bots; bot && bot->nick; bot = bot->next) {
-    simple_sprintf(settings.bots, "%s%s %s %s%s %s,", settings.bots && settings.bots[0] ? settings.bots : "",
+    simple_sprintf(settings.bots, "%s%s%s %s %s%s %s,", settings.bots && settings.bots[0] ? settings.bots : "",
+                           bot->disabled ? "/" : "",
                            bot->nick,
                            bot->net.ip ? bot->net.ip : ".", 
                            bot->net.host6 ? "+" : "", 
@@ -508,6 +509,10 @@ void reload_bin_data() {
     fill_conf_bot();
     if (!conf.bot->localhub)
       free_conf_bots();
+    else {
+      conf_add_userlist_bots();
+      spawnbots();
+    }
   }
 }
 

+ 30 - 11
src/cmds.c

@@ -1706,7 +1706,7 @@ static void cmd_conf(int idx, char *par)
 
   if (!cmd) {
     if (!conf.bot->hub)
-      dprintf(idx, "Usage: conf <add|del|change|list|set> [options]\n");
+      dprintf(idx, "Usage: conf <add|del|change|disable|enable|list|set> [options]\n");
     else
       dprintf(idx, "Usage: conf <set> [options]\n");
     return;
@@ -1759,6 +1759,28 @@ static void cmd_conf(int idx, char *par)
       save++;
     } else
       dprintf(idx, "Error trying to remove bot '%s'\n", par);
+  } else if (!egg_strcasecmp(cmd, "disable") || !egg_strcasecmp(cmd, "enable")) {
+    conf_bot *bot = NULL;
+
+    for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
+      if (!egg_strcasecmp(bot->nick, par)) {
+        if (!egg_strcasecmp(cmd, "enable")) {
+          if (bot->disabled) {
+            dprintf(idx, "Enabled '%s'.\n", bot->nick);
+            bot->disabled = 0;
+            save++;
+          } else
+            dprintf(idx, "'%s' was already enabled!\n", bot->nick);            
+        } else {
+          if (!bot->disabled) {
+            dprintf(idx, "Disabled '%s'.\n", bot->nick);
+            bot->disabled = 1;
+            save++;
+          } else
+            dprintf(idx, "'%s' was already disabled!\n", bot->nick);
+        }
+      }
+    }
   }
 #ifndef CYGWIN_HACKS
   if (!egg_strcasecmp(cmd, "set")) {
@@ -1817,7 +1839,7 @@ static void cmd_conf(int idx, char *par)
 
     for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
       i++;
-      if (!listbot || (listbot && !strcmp(listbot, bot->nick)))
+      if (!listbot || (listbot && !egg_strcasecmp(listbot, bot->nick)))
         dprintf(idx, "%d: %s IP: %s HOST: %s IP6: %s HOST6: %s HUB: %d PID: %d\n", i,
                       bot->nick,
                       bot->net.ip ? bot->net.ip : "",
@@ -1832,7 +1854,7 @@ static void cmd_conf(int idx, char *par)
     free(listbot);
 
   if (save) {
-    write_settings(binname, -1, 1);
+    conf_to_bin(&conf, 0, -1);
     if (!conf.bot->hub)
       spawnbots();			/* parse conf struct and spawn/kill as needed */
   }
@@ -3115,7 +3137,7 @@ static void cmd_newleaf(int idx, char *par)
     bi->address = (char *) my_calloc(1, 1);
     bi->telnet_port = 3333;
     bi->relay_port = 3333;
-    bi->hublevel = 0;
+    bi->hublevel = 999;
     set_user(&USERENTRY_BOTADDR, u1, bi);
     /* set_user(&USERENTRY_PASS, u1, settings.salt2); */
     sprintf(tmp, "%li %s", now, dcc[idx].nick);
@@ -3420,13 +3442,10 @@ static void cmd_pls_host(int idx, char *par)
     return;
   }
   
-  struct list_type *q = NULL;
-
-  for (q = (struct list_type *) get_user(&USERENTRY_HOSTS, dcc[idx].user); q; q = q->next)
-    if (!egg_strcasecmp(q->extra, host)) {
-      dprintf(idx, "That hostmask is already there.\n");
-      return;
-    }
+  if (user_has_host(NULL, dcc[idx].user, host)) {
+    dprintf(idx, "That hostmask is already there.\n");
+    return;
+  }
   addhost_by_handle(handle, host);
   update_mod(handle, dcc[idx].nick, "+host", host);
   dprintf(idx, "Added host '%s' to %s.\n", host, handle);

+ 64 - 5
src/conf.c

@@ -18,7 +18,7 @@
 #include "users.h"
 #include "misc_file.h"
 #include "socket.h"
-
+#include "userrec.h"
 #include <errno.h>
 #ifdef HAVE_PATHS_H
 #  include <paths.h>
@@ -55,8 +55,8 @@ tellconf()
   for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
     i++;
     sdprintf("%d: %s%s IP: %s HOST: %s IP6: %s HOST6: %s v6: %d HUB: %d PID: %d\n", i,
-             bot->nick,
              bot->disabled ? "/" : "",
+             bot->nick,
              bot->net.ip ? bot->net.ip : "",
              bot->net.host ? bot->net.host : "", bot->net.ip6 ? bot->net.ip6 : "", bot->net.host6 ? bot->net.host6 : "", 
              bot->net.v6,
@@ -66,8 +66,8 @@ tellconf()
   if (conf.bot && ((bot = conf.bot))) {
     sdprintf("me:\n");
     sdprintf("%s%s IP: %s HOST: %s IP6: %s HOST6: %s v6: %d HUB: %d PID: %d\n",
-             bot->nick,
              bot->disabled ? "/" : "",
+             bot->nick,
              bot->net.ip ? bot->net.ip : "",
              bot->net.host ? bot->net.host : "", bot->net.ip6 ? bot->net.ip6 : "", bot->net.host6 ? bot->net.host6 : "", 
              bot->net.v6,
@@ -369,6 +369,7 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
   if (nick[0] == '/') {
     bot->disabled = 1;
     nick++;
+    sdprintf("%s is disabled.", nick);
   }
   bot->nick = strdup(nick);
   bot->net.ip = NULL;
@@ -768,7 +769,8 @@ writeconf(char *filename, FILE * stream, int bits)
   comment("#[/]BOT IP|. [+]HOST|. [IPV6-IP]");
 #endif /* CYGWIN_HACKS */
   for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
-    my_write(f, "%s %s %s%s %s\n", bot->nick,
+    my_write(f, "%s%s %s %s%s %s\n", 
+             bot->disabled ? "/" : "", bot->nick,
              bot->net.ip ? bot->net.ip : ".", bot->net.host6 ? "+" : "",
              bot->net.host ? bot->net.host : (bot->net.host6 ? bot->net.host6 : "."), bot->net.ip6 ? bot->net.ip6 : "");
   }
@@ -795,6 +797,7 @@ conf_bot_dup(conf_bot *dest, conf_bot *src)
     dest->pid = src->pid;
     dest->hub = src->hub;
     dest->localhub = src->localhub;
+    dest->disabled = src->disabled;
     dest->next = NULL;
   }
 }
@@ -849,7 +852,7 @@ bin_to_conf(void)
   /* BOTS */
   {
     char *p = NULL, *tmp = NULL, *tmpp = NULL;
-
+ 
     tmp = tmpp = strdup(settings.bots);
     while ((p = strchr(tmp, ','))) {
       char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
@@ -892,3 +895,59 @@ bin_to_conf(void)
 
   tellconf();
 }
+
+void conf_add_userlist_bots()
+{
+  conf_bot *bot = NULL;
+  struct userrec *u = NULL;
+  struct bot_addr *bi = NULL;
+  char tmp[81] = "", uhost[UHOSTLEN] = "";
+
+  for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
+    /* Don't auto-add hubs. */
+    if (!bot->hub) {
+      u = get_user_by_handle(userlist, bot->nick);
+      if (!u) {
+        userlist = adduser(userlist, bot->nick, "none", "-", USER_OP, 1);
+        u = get_user_by_handle(userlist, bot->nick);
+
+        egg_snprintf(tmp, sizeof(tmp), "%li [internal]", now);
+        set_user(&USERENTRY_ADDED, u, tmp);
+
+        bi = (struct bot_addr *) my_calloc(1, sizeof(struct bot_addr));
+
+        bi->address = (char *) my_calloc(1, 1);
+        bi->uplink = (char *) my_calloc(1, 1);
+        bi->telnet_port = bi->relay_port = 3333;
+        bi->hublevel = 999;
+        set_user(&USERENTRY_BOTADDR, u, bi);
+
+      }
+      if (bot->net.ip) {
+        simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.ip);
+        if (!user_has_host(NULL, u, uhost))
+          addhost_by_handle(bot->nick, uhost);
+
+        simple_snprintf(uhost, sizeof(uhost), "*!~%s@%s", bot->nick, bot->net.ip);
+        if (!user_has_host(NULL, u, uhost))
+          addhost_by_handle(bot->nick, uhost);
+      }
+      if (bot->net.host) {
+        simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.host);
+        if (!user_has_host(NULL, u, uhost))
+          addhost_by_handle(bot->nick, uhost);
+      }
+      if (bot->net.host6) {
+        simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.host6);
+        if (!user_has_host(NULL, u, uhost))
+          addhost_by_handle(bot->nick, uhost);
+      }
+      if (bot->net.ip6) {
+        simple_snprintf(uhost, sizeof(uhost), "*!%s@%s", conf.username, bot->net.ip6);
+        if (!user_has_host(NULL, u, uhost))
+          addhost_by_handle(bot->nick, uhost);
+      }
+    }
+  }
+
+}

+ 1 - 0
src/conf.h

@@ -69,6 +69,7 @@ int writeconf(char *, FILE *, int);
 void fill_conf_bot();
 void bin_to_conf(void);
 void conf_checkpids();
+void conf_add_userlist_bots();
 
 #ifdef CYGWIN_HACKS
 extern char		cfile[DIRMAX];

+ 23 - 0
src/userrec.c

@@ -212,6 +212,29 @@ struct userrec *get_user_by_host(char *host)
   return ret;
 }
 
+bool user_has_host(const char *handle, struct userrec *u, char *host)
+{
+  if (host == NULL)
+    return 0;
+  rmspace(host);
+  if (!host[0])
+    return 0;
+
+  if (!u && handle)
+    get_user_by_handle(userlist, (char *) handle);
+
+  if (!u)
+    return 0;
+
+  struct list_type *q = NULL;
+
+  for (q = (struct list_type *) get_user(&USERENTRY_HOSTS, u); q; q = q->next)
+    if (!egg_strcasecmp(q->extra, host))
+      return 1;
+
+  return 0;
+}
+
 /* Try: pass_match_by_host("-",host)
  * will return 1 if no password is set for that host
  */

+ 0 - 1
src/userrec.h

@@ -7,7 +7,6 @@ void clear_masks(struct maskrec *);
 void clear_userlist(struct userrec *);
 int u_pass_match(struct userrec *, char *);
 int delhost_by_handle(char *, char *);
-int ishost_for_handle(char *, char *);
 int count_users(struct userrec *);
 int deluser(char *);
 int change_handle(struct userrec *, char *);

+ 1 - 0
src/users.h

@@ -92,6 +92,7 @@ bool add_entry_type(struct user_entry_type *);
 struct user_entry_type *find_entry_type(char *);
 struct user_entry *find_user_entry(struct user_entry_type *, struct userrec *);
 void *get_user(struct user_entry_type *, struct userrec *);
+bool user_has_host(const char *, struct userrec *, char *);
 bool set_user(struct user_entry_type *, struct userrec *, void *);
 
 #define is_bot(u)	((u) && (u)->bot)