Bladeren bron

* Added cmdline option 'k' for killing a bot

svn: 713
Bryan Drewery 22 jaren geleden
bovenliggende
commit
7f87452eb3
4 gewijzigde bestanden met toevoegingen van 35 en 5 verwijderingen
  1. 1 0
      doc/UPDATES
  2. 13 0
      src/conf.c
  3. 1 0
      src/conf.h
  4. 20 5
      src/main.c

+ 1 - 0
doc/UPDATES

@@ -18,6 +18,7 @@ This is a summary of ChangeLog basically.
 15.Invalid cmdline options are now silently ignored.
 16.Bad cmdline passwords now spoof an error.
 17.A long-standing bug with updating channel lists has been fixed, MAY cause "max sendq" quits.
+18.Added -k <botnick> for cmdline (to kill botnick)
 
 1.0.15 (Non-Release Version)
 1.cmd_randstring is now limited to 300.

+ 13 - 0
src/conf.c

@@ -56,6 +56,19 @@ void spawnbots() {
     }
   }
 }
+
+int killbot(char *botnick) {
+  conf_bot *bot = NULL;
+
+  for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+    if (bot->nick[0] == '/') continue;
+    else if (!egg_strcasecmp(botnick, bot->nick)) {
+      if (bot->pid)
+        return kill(bot->pid, SIGKILL);
+    }
+  }
+  return -1;
+}
 #endif /* LEAF */
 
 #ifdef S_CONFEDIT

+ 1 - 0
src/conf.h

@@ -48,6 +48,7 @@ enum {
 
 #ifdef LEAF
 void spawnbots();
+int killbot(char *);
 #endif /* LEAF */
 #ifdef S_CONFEDIT
 void confedit(char *);

+ 20 - 5
src/main.c

@@ -69,6 +69,9 @@ const char	egg_version[1024] = "1.1.0";
 #ifdef S_CONFEDIT
 int	do_confedit = 0;		/* show conf menu if -C */
 #endif /* S_CONFEDIT */
+#ifdef LEAF
+char    do_killbot[21] = "";
+#endif /* LEAF */
 int 	localhub = 1; 		/* we set this to 0 if we get a -B */
 int 	role;
 int 	loading = 0;
@@ -210,7 +213,7 @@ static void show_help()
   printf(format, STR("-G <file>"), STR("Generates a custom config for the box"));
 */
   printf(format, STR("-h"), STR("Display this help listing"));
-/*   printf(format, STR("-k <botname>"), STR("Terminates (botname) with kill -9")); */
+  printf(format, STR("-k <botname>"), STR("Terminates (botname) with kill -9")); */
   printf(format, STR("-n"), STR("Disables backgrounding first bot in conf"));
   printf(format, STR("-s"), STR("Disables checking for ptrace/strace during startup (no pass needed)"));
   printf(format, STR("-t"), STR("Enables \"Partyline\" emulation (requires -n)"));
@@ -220,11 +223,11 @@ static void show_help()
 
 
 #ifdef LEAF
-# define PARSE_FLAGS "2B:Cd:De:Eg:G:L:P:hnstv"
+# define PARSE_FLAGS "2B:Cd:De:Eg:G:k:L:P:hnstv"
 #else /* !LEAF */
 # define PARSE_FLAGS "2Cd:De:Eg:G:hnstv"
 #endif /* HUB */
-#define FLAGS_CHECKPASS "dDeEgGhntv"
+#define FLAGS_CHECKPASS "dDeEgGhkntv"
 static void dtx_arg(int argc, char *argv[])
 {
   int i;
@@ -253,6 +256,10 @@ static void dtx_arg(int argc, char *argv[])
 #endif /* S_CONFEDIT */
       case 'h':
         show_help();
+#ifdef LEAF
+      case 'k':		/* kill bot */
+        strncpyz(do_killbot, optarg, sizeof do_killbot);
+#endif /* LEAF */
       case 'n':
 	backgrd = 0;
 	break;
@@ -676,8 +683,16 @@ int main(int argc, char **argv)
   fillconf(&conf);
 #ifdef LEAF
   if (localhub) {
-    spawnbots();
-    if (updating) exit(0); /* just let cron restart us bleh */
+    if (do_killbot[0]) {
+      if (killbot(do_killbot) == 0)
+          printf("'%s' successfully killed.\n", do_killbot);
+      else
+        printf("Error killing '%s'\n", do_killbot);
+      exit(0);
+    } else {
+      spawnbots();
+      if (updating) exit(0); /* just let cron restart us bleh */
+    }
   }
 #endif /* LEAF */
   free_conf();