Forráskód Böngészése

Merge branch 'deaf-and-callerid'

* deaf-and-callerid:
  * Assuming CALLERID=g and DEAF=D if the IRCD does not provide the flags
  * Fix sort of variables. flood-callerid was out of order.
  * Fix grammar error
  * Automatically accept messages from users when in CALLERID mode (fixes #45)
  * Rename set 'flood-g' to 'flood-callerid', which only takes affect if the server supports CALLERID.
  * Add set 'callerid' to run bot in CALLERID mode (+g). +c bots will automatically accept messages from known users. (fixes #45)
  * Set DEAF mode when appropriate.
  * Reset rare IRCD features back to default when disconnecting from server
  * Detect if DEAF is supported, and what character to use
  * Add set 'deaf' to run bot in DEAF mode on supporting IRCDs. This prevents channel conversations coming to the bot. On by default.
Bryan Drewery 16 éve
szülő
commit
f65c1ce3b0
7 módosított fájl, 89 hozzáadás és 23 törlés
  1. 3 0
      doc/UPDATES
  2. 9 1
      doc/help.txt
  3. 3 1
      src/mod/server.mod/server.c
  4. 2 2
      src/mod/server.mod/server.h
  5. 52 17
      src/mod/server.mod/servmsg.c
  6. 19 1
      src/set.c
  7. 1 1
      src/set.h

+ 3 - 0
doc/UPDATES

@@ -67,6 +67,9 @@
   * Fix +botbitch being very slow and inefficient
   * Better +bitch/+botbitch/+closed handling when in floodless mode.
 * Misc changes
+  * 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)
+  * Rename set 'flood-g' to 'flood-callerid', which only takes effect if the server supports CALLERID.
   * Relays are now encrypted between bots. Username is sent automatically. Just enter in pass now.
   * Added pseudo-channel 'default' which can be modified with 'chanset' and 'chaninfo'.
     This is used to modify what the default channel options will be for new channels.

+ 9 - 1
doc/help.txt

@@ -1586,7 +1586,8 @@ See also: reload, backup
                           (Resets PID/CPU)
 [R]  $bflood-msg$b       Msgs:Secs until a host is ignored. (0:0 to disable) 
 [R]  $bflood-ctcp$b      Ctcps:Secs until a host is ignored. (0:0 to disable) 
-[R]  $bflood-g$b         Msgs:Secs until triggering to set +g for 60 seconds (0:0 to disable)
+[R]  $bflood-callerid$b  Msgs:Secs until triggering to set CALLERID for
+                          60 seconds (0:0 to disable)
  
 [D]  $blogin$b           How to handle someone logging in to the shell.
 [D]  $btrace$b           How to handle someone tracing/debugging the bot.
@@ -1600,6 +1601,13 @@ See also: reload, backup
  
 [S]  $brealname$b        The bot's "real name" when connecting. (supports '$n' expansion)
 [S]  $busermode$b        The bot's usermode on IRC. (Set on connect/rehash)
+[B]  $bdeaf$b            Runs bot in DEAF mode if the IRCD supports it. This will stop
+                           the IRCD from sending any channel conversations to the bot.
+                           This will decrease bandwidth/CPU used, as well as prevent
+                           sniffing of channels.
+[B]  $bcallerid$b        Run bot in CALLERID mode. This is commonly known as +g on most
+                           servers. +c bots will automatically accept messages from
+                           known users. Note that this will break msg-ident.
  
 [S]  $baltchars$b        Define string of characters to cycle when generating alternative
                           nicks when nick is taken. Ie: _-`[].

+ 3 - 1
src/mod/server.mod/server.c

@@ -92,9 +92,11 @@ static time_t lastpingtime;	/* IRCNet LAGmeter support -- drummer */
 static char stackablecmds[511] = "";
 static char stackable2cmds[511] = "";
 static time_t last_time;
-static bool use_penalties;
+static bool use_penalties = 0;
 static int use_fastdeq;
 size_t nick_len = 9;			/* Maximal nick length allowed on the network. */
+char deaf_char = 0;
+char callerid_char = 0;
 
 static bool double_mode = 0;		/* allow a msgs to be twice in a queue? */
 static bool double_server = 0;

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

@@ -55,10 +55,10 @@ extern port_t		default_port, newserverport, curservport;
 extern time_t		server_online;
 extern interval_t	cycle_time;
 extern char		cursrvname[], botrealname[121], botuserhost[], ctcp_reply[1024],
-			newserver[], newserverpass[], curnetwork[], botuserip[], altnick_char;
+			newserver[], newserverpass[], curnetwork[], botuserip[], altnick_char, deaf_char, callerid_char;
 extern struct server_list *serverlist;
 extern struct dcc_table SERVER_SOCKET;
-extern rate_t		flood_msg, flood_ctcp, flood_g;
+extern rate_t		flood_msg, flood_ctcp, flood_callerid;
 
 int check_bind_ctcpr(char *, char *, struct userrec *, char *, char *, char *, bind_table_t *);
 

+ 52 - 17
src/mod/server.mod/servmsg.c

@@ -294,7 +294,15 @@ got005(char *from, char *msg)
       use_penalties = 1;
     else if (!strcasecmp(tmp, "WHOX"))
       use_354 = 1;
-    else if (!strcasecmp(tmp, "EXCEPTS"))
+    else if (!strcasecmp(tmp, "DEAF")) {
+      deaf_char = p ? p[0] : 'D';
+      if (use_deaf)
+        dprintf(DP_SERVER, "MODE %s +%c\n", botname, deaf_char);
+    } else if (!strcasecmp(tmp, "CALLERID")) {
+      callerid_char = p ? p[0] : 'g';
+      if (use_callerid)
+        dprintf(DP_SERVER, "MODE %s +%c\n", botname, callerid_char);
+    } else if (!strcasecmp(tmp, "EXCEPTS"))
       use_exempts = 1;
     else if (!strcasecmp(tmp, "INVEX"))
       use_invites = 1;
@@ -381,15 +389,15 @@ static char lastmsghost[FLOOD_GLOBAL_MAX][128];
 static time_t lastmsgtime[FLOOD_GLOBAL_MAX];
 static int dronemsgs;
 static time_t dronemsgtime;
-static bool set_pls_g;
-static interval_t flood_g_time = 60;
+static bool in_callerid = 0;
+static interval_t flood_callerid_time = 60;
 
-rate_t flood_g = { 6, 2 };
+rate_t flood_callerid = { 6, 2 };
 
-void unset_g(int data)
+void unset_callerid(int data)
 {
-  dprintf(DP_MODE, "MODE %s :-g\n", botname);
-  set_pls_g = 0;
+  dprintf(DP_MODE, "MODE %s :-%c\n", botname, callerid_char);
+  in_callerid = 0;
 }
 
 /* Do on NICK, PRIVMSG, NOTICE and JOIN.
@@ -428,9 +436,7 @@ static bool detect_flood(char *floodnick, char *floodhost, char *from, int which
   if (!strcasecmp(floodhost, botuserhost))
     return 0;			/* My user@host (?) */
 
-  //FIXME: hack for +g 
-
-  if (dronemsgtime < now - flood_g.time) {	//expired, reset counter
+  if (dronemsgtime < now - flood_callerid.time) {	//expired, reset counter
     dronemsgs = 0;
 //    dronemsgtime = now;
   }
@@ -438,17 +444,17 @@ static bool detect_flood(char *floodnick, char *floodhost, char *from, int which
   dronemsgs++;
   dronemsgtime = now;
 
-  if (!set_pls_g && dronemsgs >= flood_g.count) {  //flood from dronenet, let's attempt to set +g
+  if (!in_callerid && dronemsgs >= flood_callerid.count && callerid_char) {  //flood from dronenet, let's attempt to set +g
     egg_timeval_t howlong;
 
-    set_pls_g = 1;
+    in_callerid = 1;
     dronemsgs = 0;
     dronemsgtime = 0;
-    dprintf(DP_DUMP, "MODE %s :+g\n", botname);
-    howlong.sec = flood_g_time;
+    dprintf(DP_DUMP, "MODE %s :+%c\n", botname, callerid_char);
+    howlong.sec = flood_callerid_time;
     howlong.usec = 0;
-    timer_create(&howlong, "Unset umode +g", (Function) unset_g);
-    putlog(LOG_MISC, "*", "Drone flood detected! Setting +g for %d seconds.", flood_g_time);
+    timer_create(&howlong, "Unset CALLERID", (Function) unset_callerid);
+    putlog(LOG_MISC, "*", "Drone flood detected! Setting CALLERID for %d seconds.", flood_callerid_time);
     return 1;	//ignore the current msg
   }
 
@@ -1129,6 +1135,13 @@ static void disconnect_server(int idx, int dolost)
   floodless = 0;
   botuserhost[0] = 0;
   botuserip[0] = 0; 
+  use_penalties = 0;
+  use_354 = 0;
+  deaf_char = 0;
+  callerid_char = 0;
+  in_callerid = 0;
+  use_exempts = 0;
+  use_invites = 0;
   if (dolost) {
     Auth::DeleteAll();
     trying_server = 0;
@@ -1578,7 +1591,29 @@ static int got718(char *from, char *msg)
   uhost = newsplit(&msg);
   fixcolon(msg);
 
-  putlog(LOG_WALL, "*", "(+g) !%s!%s! %s", nick, uhost, msg);
+  if (ischanhub()) {
+    char s[UHOSTLEN + 2] = "";
+    struct userrec *u = NULL;
+
+    simple_snprintf(s, sizeof(s), "%s!%s", nick, uhost);
+    u = get_user_by_host(s);
+    if (u) {
+      struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
+
+      get_user_flagrec(u, &fr, NULL);
+      if (glob_op(fr) || chan_op(fr) || glob_voice(fr) || chan_voice(fr)) {
+        putlog(LOG_WALL, "*", "(CALLERID) !%s! (%s!%s) %s (Accepting user)", u->handle, nick, uhost, msg);
+        dprintf(DP_HELP, "ACCEPT %s\n", nick);
+        dprintf(DP_HELP, "PRIVMSG %s :You have been accepted. Please send your message again.\n", nick);
+      } else {
+        putlog(LOG_WALL, "*", "(CALLERID) !%s! (%s!%s) %s (User is not +o or +v)", u->handle, nick, uhost, msg);
+      }
+    } else {
+      putlog(LOG_WALL, "*", "(CALLERID) !*! (%s!%s) %s (User unknown)", nick, uhost, msg);
+    }
+  } else {
+    putlog(LOG_WALL, "*", "(CALLERID) (%s!%s) %s (I'm not a chathub (+c))", nick, uhost, msg);
+  }
 
   return 0;
 }

+ 19 - 1
src/set.c

@@ -40,6 +40,8 @@ int dcc_autoaway;
 bool irc_autoaway;
 bool link_cleartext;
 bool dccauth = 0;
+bool use_deaf = 0;
+bool use_callerid = 0;
 int cloak_script = 0;
 rate_t close_threshold;
 int fight_threshold;
@@ -74,13 +76,15 @@ static variable_t vars[] = {
  VAR("auth-key",	auth_key,		VAR_STRING|VAR_PERM,				0, 0, NULL),
  VAR("auth-obscure",	&auth_obscure,		VAR_INT|VAR_BOOL,				0, 1, "0"),
  VAR("auth-prefix",	auth_prefix,		VAR_WORD|VAR_NOLHUB|VAR_PERM,			0, 0, "+"),
+ VAR("callerid",	&use_callerid,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "1"),
  VAR("cloak-script",	&cloak_script,		VAR_INT|VAR_CLOAK|VAR_NOLHUB,			0, 10, "0"),
  VAR("close-threshold",	&close_threshold,	VAR_RATE|VAR_NOLOC,				0, 0, "0:0"),
  VAR("dcc-autoaway",	&dcc_autoaway,		VAR_INT|VAR_NOLOC,				0, (5*60*60), "1800"),
  VAR("dccauth",		&dccauth,		VAR_INT|VAR_BOOL,				0, 1, "0"),
+ VAR("deaf",		&use_deaf,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "1"),
  VAR("fight-threshold",	&fight_threshold,	VAR_INT|VAR_NOLOC,				0, 0, "0"),
+ VAR("flood-callerid",	&flood_callerid,	VAR_RATE|VAR_NOLHUB,				0, 0, "6:2"),
  VAR("flood-ctcp",	&flood_ctcp,		VAR_RATE|VAR_NOLHUB,				0, 0, "3:60"),
- VAR("flood-g",		&flood_g,		VAR_RATE|VAR_NOLHUB,				0, 0, "6:2"),
  VAR("flood-msg",	&flood_msg,		VAR_RATE|VAR_NOLHUB,				0, 0, "5:60"),
  VAR("fork-interval",	&fork_interval,		VAR_INT,					10, 0, "0"),
  VAR("hijack",		&hijack,		VAR_INT|VAR_DETECTED|VAR_PERM,			0, 4, "die"),
@@ -261,6 +265,7 @@ sdprintf("var (mem): %s -> %s", var->name, datain ? datain : "(NULL)");
 #endif
     *(int *) (var->mem) = number;
   } else if (var->flags & VAR_BOOL) {
+    bool olddata = *(bool*)(var->mem);
     bool num = 0;
     if (data[0] == '0')
       num = 0;
@@ -271,6 +276,19 @@ sdprintf("var (mem): %s -> %s", var->name, datain ? datain : "(NULL)");
 
     if (!strcmp(var->name, "ident-botnick"))
       strlcpy(botuser, conf.username && !num ? conf.username : origbotname, 21);
+    else if ((!strcmp(var->name, "deaf") && deaf_char) || (!strcmp(var->name, "callerid") && callerid_char)) {
+      if (server_online) {
+        char which = 0;
+        if (num == 1 && olddata == 0)
+          which = '+';
+        else if (num == 0 && olddata == 1)
+          which = '-';
+        if (which) {
+          char mode_char = strcmp(var->name, "deaf") == 0 ? deaf_char : callerid_char;
+          dprintf(DP_SERVER, "MODE %s %c%c\n", botname, which, mode_char);
+        }
+      }
+    }
   } else if (var->flags & (VAR_STRING|VAR_WORD)) {
     char *olddata = ((char*) var->mem) ? strdup((char*) var->mem) : NULL;
 

+ 1 - 1
src/set.h

@@ -70,7 +70,7 @@ typedef struct rate_b {
 extern char		auth_key[], auth_prefix[2], motd[], alias[], rbl_servers[1024],
 			msgident[], msginvite[], msgop[], msgpass[],
                         homechan[], altchars[];
-extern bool		dccauth, auth_obscure, manop_warn, auth_chan, oidentd, ident_botnick, irc_autoaway, link_cleartext;
+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,
 			kill_threshold, lag_threshold, op_bots, hijack, login, promisc, trace,
                         ison_time;