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

* Added cmd_suicide. (#80)

svn: 2131
Bryan Drewery 21 лет назад
Родитель
Сommit
c2905d187a
5 измененных файлов с 48 добавлено и 21 удалено
  1. 1 0
      doc/UPDATES
  2. 9 1
      misc/help.txt
  3. 8 1
      src/cmds.c
  4. 29 19
      src/shell.c
  5. 1 0
      src/shell.h

+ 1 - 0
doc/UPDATES

@@ -134,6 +134,7 @@ Lines prefixed with '-' were disabled before release and are not finishsed, or a
 * Fixed wrong spacing in cmd_status
 * Fixed cmd_boot attempting to boot a remote simulated dcc created by .botcmd. (#90)
 * Fixed bots with '`' in nick not spawning correctly. (#88)
+* Added cmd_suicide. (#80)
 
 1.2.2
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.

+ 9 - 1
misc/help.txt

@@ -881,6 +881,8 @@ See also: op, console
    This kills the bot. The bot goes offline immediately, logging who issued
    the 'die' command. You shouldn't have to use this too often. If you specify
    a reason, it is logged, otherwise the reason is "authorized by <handle>".
+ 
+See also: suicide, conf
 ::dns
 ###  $bdns$b <hostname/ip/flush>
    Resolves the given hostname/ip
@@ -1413,7 +1415,7 @@ See also: save
    if an odd bug causes the channel information to get scrambled.
    unfortunately this command used to get a lot of use.  you can omit
    the channel name to make it reset ALL channels.
-
+ 
 See also: resetbans, resetexempts, resetinvites
 :leaf:resetbans
 ###  $bresetbans$b [channel]
@@ -1564,6 +1566,12 @@ See also: fixcodes, color, echo, login, page
    Lets you assume the identity of another user. If you are a global owner,
    this does not require a password. Otherwise, you will be asked for the
    user's password. $b%dquit$b returns you to your original handle.
+::suicide
+###  $bsuicide$b [reason]
+   Makes bot remove itself and then dies. If bot is first bot in it's binary
+   it will kill all bots running for that binary.
+ 
+See also: die, conf
 :leaf:swhois
 ###  $bswhois$b [server/nick] <nick>
    Displays a server /whois for the specified nick. Specifying

+ 8 - 1
src/cmds.c

@@ -1418,7 +1418,7 @@ static void cmd_botcmd(int idx, char *par)
   putlog(LOG_CMDS, "*", "#%s# botcmd %s %s ...", dcc[idx].nick, botm, cmd);	
 
   if (!strcmp(botm, "*")) {
-    if (!egg_strncasecmp(cmd, "di", 2) || !egg_strncasecmp(cmd, "res", 3)) {
+    if (!egg_strncasecmp(cmd, "di", 2) || !egg_strncasecmp(cmd, "res", 3) || !egg_strncasecmp(cmd, "sui", 3)) {
       dprintf(idx, "Not a good idea.\n");
       return;
     } else if (!(dcc[idx].user->flags & USER_OWNER)) {
@@ -1972,6 +1972,12 @@ static void cmd_die(int idx, char *par)
   kill_bot(s1, s2);
 }
 
+static void cmd_suicide(int idx, char *par)
+{
+  putlog(LOG_CMDS, "*", "#%s# suicide %s", dcc[idx].nick, par);
+  suicide(par);
+}
+
 static void cmd_debug(int idx, char *par)
 {
   char *cmd = NULL;
@@ -4292,6 +4298,7 @@ cmd_t C_dcc[] =
   {"debug",		"a",	(Function) cmd_debug,		NULL, 0},
   {"timers",		"a",	(Function) cmd_timers,		NULL, 0},
   {"die",		"n",	(Function) cmd_die,		NULL, 0},
+  {"suicide",		"a",	(Function) cmd_suicide,		NULL, 0},
   {"echo",		"",	(Function) cmd_echo,		NULL, 0},
   {"login",		"",	(Function) cmd_login,		NULL, 0},
   {"fixcodes",		"",	(Function) cmd_fixcodes,	NULL, 0},

+ 29 - 19
src/shell.c

@@ -552,14 +552,37 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
   }
 }
 
+void suicide(const char *msg)
+{
+  char tmp[512] = "";
+
+  putlog(LOG_WARN, "*", "Comitting suicide: %s", msg);
+  simple_sprintf(tmp, "Suicide: %s", msg);
+  set_user(&USERENTRY_COMMENT, conf.bot->u, tmp);
+  if (!conf.bot->hub) {
+    nuke_server("HARAKIRI!!");
+    sleep(1);
+  } else {
+    unlink(userfile);
+    simple_sprintf(tmp, "%s~", userfile);
+    unlink(tmp);
+  }
+  unlink(binname);
+
+  if (conf.bot->localhub) {
+    conf_checkpids();
+    conf_killbot(NULL, NULL, SIGKILL);
+  }
+
+  fatal(msg, 0);
+}
+
 void detected(int code, char *msg)
 {
   char *p = NULL, tmp[512] = "";
-  struct userrec *u = NULL;
   struct flag_record fr = { FR_GLOBAL, 0, 0, 0 };
   int act, do_fatal = 0, killbots = 0;
   
-  u = get_user_by_handle(userlist, conf.bot->nick);
   if (code == DETECT_LOGIN)
     p = (char *) (CFG_LOGIN.ldata ? CFG_LOGIN.ldata : (CFG_LOGIN.gdata ? CFG_LOGIN.gdata : NULL));
   if (code == DETECT_TRACE)
@@ -593,16 +616,16 @@ void detected(int code, char *msg)
     do_fork();
     putlog(LOG_WARN, "*", "Setting myself +d: %s", msg);
     simple_sprintf(tmp, "+d: %s", msg);
-    set_user(&USERENTRY_COMMENT, u, tmp);
+    set_user(&USERENTRY_COMMENT, conf.bot->u, tmp);
     fr.global = USER_DEOP;
     fr.bot = 1;
-    set_user_flagrec(u, &fr, 0);
+    set_user_flagrec(conf.bot->u, &fr, 0);
     sleep(1);
     break;
   case DET_DIE:
     putlog(LOG_WARN, "*", "Dying: %s", msg);
     simple_sprintf(tmp, "Dying: %s", msg);
-    set_user(&USERENTRY_COMMENT, u, tmp);
+    set_user(&USERENTRY_COMMENT, conf.bot->u, tmp);
     if (!conf.bot->hub)
       nuke_server("BBL");
     sleep(1);
@@ -610,20 +633,7 @@ void detected(int code, char *msg)
     do_fatal++;
     break;
   case DET_SUICIDE:
-    putlog(LOG_WARN, "*", "Comitting suicide: %s", msg);
-    simple_sprintf(tmp, "Suicide: %s", msg);
-    set_user(&USERENTRY_COMMENT, u, tmp);
-    if (!conf.bot->hub) {
-      nuke_server("HARAKIRI!!");
-      sleep(1);
-    } else {
-      unlink(userfile);
-      simple_sprintf(tmp, "%s~", userfile);
-      unlink(tmp);
-    }
-    unlink(binname);
-    killbots++;
-    do_fatal++;
+    suicide(msg);
     break;
   }
   if (killbots && conf.bot->localhub) {

+ 1 - 0
src/shell.h

@@ -58,6 +58,7 @@ void check_crontab();
 void crontab_del();
 int crontab_exists();
 void crontab_create(int);
+void suicide(const char *);
 void detected(int, char *);
 #endif /* !CYGWIN_HACKS */
 void werr(int) __attribute__((noreturn));