1
0
Эх сурвалжийг харах

Merge branch 'release'

* release:
  * Release nick after 5 seconds for msg-release to give time to type /NICK
  * Add cmd_netrelease
  * msg_release is now +m
  * Add cmd 'release' and msg-release for releasing a bot's jupenick on a 7 second timer.
  * Move nick release code into a common function
  * Log the release and use the common function for regaining jupenick
  * Add msg-release
Bryan Drewery 16 жил өмнө
parent
commit
a8eb983bd5

+ 1 - 0
doc/UPDATES

@@ -71,6 +71,7 @@
   * Fix +botbitch being very slow and inefficient
   * Better +bitch/+botbitch/+closed handling when in floodless mode.
 * Misc changes
+  * Add cmd 'release', 'netrelease' and msg-release for releasing a bot's jupenick on a 7 second timer.
   * Add MONITOR support. This speeds up NICK grabbing. (fixes #320)
   * Add set 'deaf' to run bot in DEAF mode on supporting IRCDs. This prevents channel conversations coming to the bot. On by default.
   * Add set 'callerid' to run bot in CALLERID mode (+g). +c bots will automatically accept messages from known users. (fixes #45)

+ 13 - 0
doc/help.txt

@@ -1392,6 +1392,12 @@ See also: botnick, nick
    on 'ps'.
  
 See also: ps
+:hub:netrelease
+###  $netrelease$b <nick>
+   Tells all bots to unjupe the specified nickname. They will wait 7 seconds
+   before attempting to regain the nickname.
+ 
+See also: set, release
 :hub:netrontab:
 ###  $bnetcrontab$b <status|delete|show|new> [interval]
    Runs the specified crontab command on all linked bots.
@@ -1489,6 +1495,12 @@ See also: restart
    relay to. Typing '%dquit' or "*bye*" on a line by itself will end the relay.
  
 See also: bots%{+n}, newleaf%{-}%{+a}, -bot%{-}
+:leaf:release
+###  $brelease$b
+   Releases the bot's nick if it is on the jupenick. It gives an estimated
+   7 seconds before it attempts to regain its jupenick.
+ 
+See also: set, netrelease
 ::reload
 ###  $breload$b
    Reloads the bot's user file, discarding any changes made since the last
@@ -1601,6 +1613,7 @@ See also: reload, backup
 [S]  $bmsg-pass$b        Defines the cmd for setting a pass via msging the bot.
 [S]  $bmsg-invite$b      Defines the cmd for requesting invite via msging the bot.
 [S]  $bmsg-ident$b       Defines the cmd for identing via msging the bot.
+[S]  $bmsg-release$b     Defines the cmd for releasing a nick.
  
 [N]  $bfork-interval$b   Number of seconds in between each fork() call made by the bot. 
                           (Resets PID/CPU)

+ 16 - 0
src/cmds.c

@@ -3915,6 +3915,21 @@ static void cmd_netnick (int idx, char *par) {
   botnet_send_cmd_broad(-1, conf.bot->nick, dcc[idx].nick, idx, "curnick");
 }
 
+static void cmd_netrelease (int idx, char* par) {
+  putlog(LOG_CMDS, "*", "#%s# netrelease %s", dcc[idx].nick, par);
+  if (!par || !par[0]) {
+    dprintf(idx, "Usage: netrelease <nick>\n");
+    return;
+  }
+
+  // Don't bother checking what bot has the nick, multiple bots may be trying to jupe it
+  // so instead, tell all bots to release the specified nick.
+  // Any bots trying to get it will stop for 7 seconds, and any bot on it will release it.
+  bd::String str;
+  str.printf("rn %s", par);
+  putallbots(str.c_str());
+}
+
 static void cmd_botnick(int idx, char * par) {
   putlog(LOG_CMDS, "*", "#%s# botnick %s", dcc[idx].nick, par);
   if (!par || !par[0]) {
@@ -4631,6 +4646,7 @@ cmd_t C_dcc[] =
   {"botmsg",		"o",    (Function) cmd_botmsg,          NULL, HUB},
   {"botnick", 		"m", 	(Function) cmd_botnick, 	NULL, HUB},
   {"netnick", 		"m", 	(Function) cmd_netnick, 	NULL, HUB},
+  {"netrelease", 	"m", 	(Function) cmd_netrelease, 	NULL, HUB},
   {"netw", 		"n", 	(Function) cmd_netw, 		NULL, HUB},
   {"netps", 		"n", 	(Function) cmd_netps, 		NULL, HUB},
   {"netlast", 		"n", 	(Function) cmd_netlast, 	NULL, HUB},

+ 2 - 0
src/eggdrop.h

@@ -62,6 +62,8 @@
 #define RANDSPECIAL     "#*+,-./;<=>?[]^_{}|"
 #define RANDSPECIALLEN  19
 
+#define RELEASE_TIME	7
+
 #define ESCAPESHELL	"`\\|#*()[]& "
 
 #if (NICKMAX < 9) || (NICKMAX > 32)

+ 6 - 0
src/mod/irc.mod/cmdsirc.c

@@ -476,6 +476,11 @@ static void cmd_devoice(int idx, char *par)
 
 }
 
+static void cmd_release(int idx, char *par) {
+  putlog(LOG_CMDS, "*", "#%s# release", dcc[idx].nick);
+  release_nick();
+}
+
 static void cmd_op(int idx, char *par)
 {
   struct chanset_t *chan = NULL;
@@ -1908,6 +1913,7 @@ static cmd_t irc_dcc[] =
   {"msg",		"o",	 (Function) cmd_msg,		NULL, LEAF|AUTH},
   {"nick",		"m",	 (Function) cmd_nick,		NULL, LEAF},
   {"op",		"o|o",	 (Function) cmd_op,		NULL, LEAF|AUTH},
+  {"release",		"m",	 (Function) cmd_release,	NULL, LEAF|AUTH},
   {"reset",		"m|m",	 (Function) cmd_reset,		NULL, LEAF|AUTH},
   {"resetbans",		"o|o",	 (Function) cmd_resetbans,	NULL, LEAF|AUTH},
   {"resetexempts",	"o|o",	 (Function) cmd_resetexempts,	NULL, LEAF|AUTH},

+ 5 - 0
src/mod/irc.mod/irc.c

@@ -1723,9 +1723,14 @@ do_nettype()
   }
 }
 
+static void bot_release_nick (char *botnick, char *code, char *par) {
+  release_nick(par);
+}
+
 static cmd_t irc_bot[] = {
   {"gi", "", (Function) getin_request, NULL, LEAF},
   {"mr", "", (Function) mass_request, NULL, LEAF},
+  {"rn", "", (Function) bot_release_nick, NULL, LEAF},
   {NULL, NULL, NULL, NULL, 0}
 };
 

+ 31 - 0
src/mod/irc.mod/msgcmds.c

@@ -418,6 +418,36 @@ static int msg_unauth(char *nick, char *host, struct userrec *u, char *par)
   return BIND_RET_BREAK;
 }
 
+static int msg_release(char *nick, char *host, struct userrec *u, char *par)
+{
+  char *pass = NULL;
+
+  if (match_my_nick(nick))
+    return BIND_RET_BREAK;
+  if (u && u->bot)
+    return BIND_RET_BREAK;
+
+  pass = newsplit(&par);
+
+  if (u && u_pass_match(u, pass) && !u_pass_match(u, "-")) {
+    struct flag_record fr = {FR_GLOBAL, 0, 0, 0 };
+    get_user_flagrec(u, &fr, NULL);
+
+    if (glob_master(fr)) {
+      putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! RELEASE"), nick, host, u->handle);
+      egg_timeval_t howlong;
+      howlong.sec = 5;
+      howlong.usec = 0;
+      timer_create(&howlong, "Release jupenick", (Function) release_nick);
+//      release_nick();
+    } else
+      putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! failed RELEASE (User it not +m)"), nick, host, u->handle);
+  } else
+    putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! failed RELEASE"), nick, host, u ? u->handle : "*");
+  return BIND_RET_BREAK;
+
+}
+
 /* MSG COMMANDS
  *
  * Function call should be:
@@ -437,6 +467,7 @@ static cmd_t C_msg[] =
   {"invite",		"",	(Function) msg_invite,		NULL, LEAF},
   {"op",		"",	(Function) msg_op,		NULL, LEAF},
   {"pass",		"",	(Function) msg_pass,		NULL, LEAF},
+  {"release",		"",	(Function) msg_release,		NULL, LEAF},
   {"bewm",		"",	(Function) msg_bewm,		NULL, LEAF},
   {NULL,		NULL,	NULL,				NULL, 0}
 };

+ 5 - 0
src/mod/server.mod/server.c

@@ -70,6 +70,7 @@ char botuserhost[UHOSTLEN] = "";	/* bot's user@host (refreshed whenever the bot
 					/* may not be correct user@host BUT it's how the server sees it */
 char botuserip[UHOSTLEN] = "";		/* bot's user@host with the ip. */
 
+time_t release_time = 0;
 bool keepnick = 1;		/* keep trying to regain my intended
 				   nickname? */
 static bool nick_juped = 0;	/* True if origbotname is juped(RPL437) (dw) */
@@ -1002,6 +1003,10 @@ static void server_secondly()
         ison_cnt = 0;
       } else
         ++ison_cnt;
+    } else if (!keepnick && ((now - release_time) >= RELEASE_TIME)) {
+      release_time = 0;
+      keepnick = 1;
+      nick_available(1, 0);
     }
 
     if (!loading) {

+ 2 - 1
src/mod/server.mod/server.h

@@ -50,7 +50,7 @@ extern bool		trigger_on_ignore, floodless, keepnick, deaf_set;
 extern int 		servidx, ctcp_mode, answer_ctcp, serv, curserv, default_alines;
 extern unsigned int     rolls;
 extern port_t		default_port, newserverport, curservport;
-extern time_t		server_online, tried_jupenick, tried_nick;
+extern time_t		server_online, tried_jupenick, tried_nick, release_time;
 extern interval_t	cycle_time;
 extern char		cursrvname[], botrealname[121], botuserhost[], ctcp_reply[1024],
 			newserver[], newserverpass[], curnetwork[], botuserip[], altnick_char, deaf_char, callerid_char;
@@ -60,6 +60,7 @@ extern rate_t		flood_msg, flood_ctcp, flood_callerid;
 
 int check_bind_ctcpr(char *, char *, struct userrec *, char *, char *, char *, bind_table_t *);
 void nicks_available(char* buf, char delim = 0, bool buf_contains_available = 1);
+void release_nick(const char* = NULL);
 
 #define check_bind_ctcp(a, b, c, d, e, f) check_bind_ctcpr(a, b, c, d, e, f, BT_ctcp)
 #define check_bind_ctcr(a, b, c, d, e, f) check_bind_ctcpr(a, b, c, d, e, f, BT_ctcr)

+ 21 - 3
src/mod/server.mod/servmsg.c

@@ -674,8 +674,8 @@ static int gotmsg(char *from, char *msg)
         bool doit = 1;
 
         if (!strcasecmp(my_code, "op") || !strcasecmp(my_code, "pass") || !strcasecmp(my_code, "invite")
-            || !strcasecmp(my_code, "ident")
-            || !strcasecmp(my_code, msgop) || !strcasecmp(my_code, msgpass)
+            || !strcasecmp(my_code, "ident") || !strcasecmp(my_code, "release")
+            || !strcasecmp(my_code, msgop) || !strcasecmp(my_code, msgpass) || !strcasecmp(my_code, msgrelease)
             || !strcasecmp(my_code, msginvite) || !strcasecmp(my_code, msgident)) {
           const char *buf2 = NULL;
 
@@ -688,6 +688,8 @@ static int gotmsg(char *from, char *msg)
             buf2 = "invite";
           else if (!strcasecmp(my_code, msgident))
             buf2 = "ident";
+          else if (!strcasecmp(my_code, msgrelease))
+            buf2 = "release";
 
           if (buf2)
             check_bind_msg(buf2, nick, uhost, my_u, msg);
@@ -910,6 +912,22 @@ void nicks_available(char* buf, char delim, bool buf_contains_available) {
   nick_available(is_jupe, is_orig);
 }
 
+void release_nick(const char* nick) {
+  // Only do this if currently on a jupenick
+  if (jupenick[0] && ((!nick && match_my_nick(jupenick)) || (nick && !rfc_casecmp(jupenick, nick)))) {
+    keepnick = 0;
+    release_time = now;
+
+    if (match_my_nick(jupenick)) {
+      altnick_char = rolls = 0;
+      tried_nick = now;
+      dprintf(DP_MODE, "NICK %s\n", origbotname);
+      putlog(LOG_MISC, "*", "Releasing jupenick '%s' and switching back to nick '%s'", jupenick, origbotname);
+    }
+  } else if (!nick)
+    putlog(LOG_CMDS, "*", "Not releasing nickname. (Not currently on a jupenick)");
+}
+
 /* This is a reply to MONITOR: Offline
  * RPL_MONOFFLINE
  * :<server> 731 <nick> :nick[,nick1]*
@@ -1130,7 +1148,7 @@ static int gotnick(char *from, char *msg)
       altnick_char = rolls = 0;
       putlog(LOG_SERV | LOG_MISC, "*", "Regained nickname '%s'.", msg);
       nick_juped = 0;
-    } else if (keepnick && strcmp(nick, msg)) {
+    } else if ((keepnick || release_time) && strcmp(nick, msg)) {
 
       // Was this an attempt at a nick thru rotation?
       if (!strcmp(rnick, msg)) {

+ 2 - 0
src/set.c

@@ -58,6 +58,7 @@ char msgident[21] = "";
 char msginvite[21] = "";
 char msgop[21] = "";
 char msgpass[21] = "";
+char msgrelease[21] = "";
 int op_bots;
 rate_t op_requests;
 int promisc;
@@ -103,6 +104,7 @@ static variable_t vars[] = {
  VAR("msg-invite",	msginvite,		VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
  VAR("msg-op",		msgop,			VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
  VAR("msg-pass",	msgpass,		VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
+ VAR("msg-release",	msgrelease,		VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
  VAR("nick",		origbotname,		VAR_WORD|VAR_NOHUB|VAR_NICK|VAR_NODEF,	0, 0, NULL),
  VAR("notify-time",	&ison_time,		VAR_INT|VAR_NOLHUB,				1, 30, "10"),
  VAR("oidentd",		&oidentd,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "0"),

+ 1 - 1
src/set.h

@@ -68,7 +68,7 @@ typedef struct rate_b {
 } rate_t;
 
 extern char		auth_key[], auth_prefix[2], motd[], alias[], rbl_servers[1024],
-			msgident[], msginvite[], msgop[], msgpass[],
+			msgident[], msginvite[], msgop[], msgpass[], msgrelease[],
                         homechan[], altchars[];
 extern bool		dccauth, auth_obscure, manop_warn, auth_chan, oidentd, ident_botnick, irc_autoaway, link_cleartext, use_deaf, use_callerid;
 extern int		cloak_script, fight_threshold, fork_interval, in_bots, set_noshare, dcc_autoaway,