[cvslog] (2007-11-06 00:05:52 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Mon Nov 5 18:05:52 CST 2007


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2007-11-06 00:05:50 UTC
Commited by: sven

Modified files:
     lib/eggdrop/Makefile.am lib/eggdrop/eggdrop.h
     lib/eggdrop/partyline.c modules/botnet/botnet.c
     modules/dccparty/dccparty.c modules/ircparty/ircparty.c
     modules/oldbotnet/events.c modules/oldbotnet/oldbotnet.c
     modules/telnetparty/telnetparty.c src/main.c

Log message:

 * Added a new socketfilter that provides a per socket timer for easy
   implementation of various timeouts.
 * All sockets that expect user logins now have a 60 second timeout for
   the user to supply a valid login.
 * All botnet sockets now have a 30 second timeout for the bot to do a
   successful login. After that it has a 90 second timeout after which
   a ping will be sent. After another 90 seconds the socket is closed.

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/Makefile.am
diff -u eggdrop1.9/lib/eggdrop/Makefile.am:1.43 eggdrop1.9/lib/eggdrop/Makefile.am:1.44
--- eggdrop1.9/lib/eggdrop/Makefile.am:1.43	Sat Aug 18 18:03:09 2007
+++ eggdrop1.9/lib/eggdrop/Makefile.am	Mon Nov  5 18:05:39 2007
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.43 2007-08-18 23:03:09 sven Exp $
+# $Id: Makefile.am,v 1.44 2007-11-06 00:05:39 sven Exp $
 
 MAINTAINERCLEANFILES	= Makefile.in
 
@@ -49,6 +49,7 @@
 			partymember.c partymember.h \
 			script.c script.h \
 			sockbuf.c sockbuf.h \
+			socktimer.c socktimer.h \
 			stat.h \
 			throttle.c throttle.h \
 			users.c users.h \
Index: eggdrop1.9/lib/eggdrop/eggdrop.h
diff -u eggdrop1.9/lib/eggdrop/eggdrop.h:1.48 eggdrop1.9/lib/eggdrop/eggdrop.h:1.49
--- eggdrop1.9/lib/eggdrop/eggdrop.h:1.48	Sun Jun  3 18:43:45 2007
+++ eggdrop1.9/lib/eggdrop/eggdrop.h	Mon Nov  5 18:05:39 2007
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Id: eggdrop.h,v 1.48 2007-06-03 23:43:45 sven Exp $
+ * $Id: eggdrop.h,v 1.49 2007-11-06 00:05:39 sven Exp $
  */
 
 #ifndef _EGG_EGGDROP_H_
@@ -60,6 +60,7 @@
 #include <eggdrop/botnet.h>
 #include <eggdrop/help.h>
 #include <eggdrop/sockbuf.h>
+#include <eggdrop/socktimer.h>
 #include <eggdrop/script.h>
 #include <eggdrop/throttle.h>
 #include <eggdrop/timeutil.h>
Index: eggdrop1.9/lib/eggdrop/partyline.c
diff -u eggdrop1.9/lib/eggdrop/partyline.c:1.29 eggdrop1.9/lib/eggdrop/partyline.c:1.30
--- eggdrop1.9/lib/eggdrop/partyline.c:1.29	Sat Aug 18 17:32:23 2007
+++ eggdrop1.9/lib/eggdrop/partyline.c	Mon Nov  5 18:05:40 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: partyline.c,v 1.29 2007-08-18 22:32:23 sven Exp $";
+static const char rcsid[] = "$Id: partyline.c,v 1.30 2007-11-06 00:05:40 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -222,12 +222,13 @@
 static int on_putlog(int flags, const char *chan, const char *text, int len)
 {
 	partychan_t *chanptr;
+	botnet_entity_t me = bot_entity(NULL);
 
 	chanptr = partychan_lookup_name(chan);
 	if (!chanptr)
 		return(0);
 
-	localchan_msg(chanptr, NULL, text, len);
+	localchan_msg(chanptr, &me, text, len);
 	return(0);
 }
 
Index: eggdrop1.9/modules/botnet/botnet.c
diff -u eggdrop1.9/modules/botnet/botnet.c:1.5 eggdrop1.9/modules/botnet/botnet.c:1.6
--- eggdrop1.9/modules/botnet/botnet.c:1.5	Sat Oct 27 14:55:51 2007
+++ eggdrop1.9/modules/botnet/botnet.c	Mon Nov  5 18:05:40 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: botnet.c,v 1.5 2007-10-27 19:55:51 sven Exp $";
+static const char rcsid[] = "$Id: botnet.c,v 1.6 2007-11-06 00:05:40 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -62,6 +62,8 @@
 static int got_newbot(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
 static int got_nick(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
 static int got_part(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
+static int got_ping(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
+static int got_pong(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
 static int got_privmsg(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
 static int got_quit(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
 static int got_unlink(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
@@ -85,6 +87,8 @@
 	{"newbot", ENTITY_BOT, 4, got_newbot},
 	{"nick", ENTITY_PARTYMEMBER, 1, got_nick},
 	{"part", ENTITY_PARTYMEMBER, 1, got_part},
+	{"ping", ENTITY_BOT, 0, got_ping},
+	{"pong", ENTITY_BOT, 0, got_pong},
 	{"privmsg", 0, 2, got_privmsg},
 	{"quit", ENTITY_PARTYMEMBER, 0, got_quit},
 	{"unlink", 0, 2, got_unlink}
@@ -258,11 +262,26 @@
 
 	sockbuf_set_handler(data->idx, &client_handler, data, &sock_owner);
 	netstring_on(data->idx);
+	socktimer_on(data->idx, 30, 0, NULL, NULL, &generic_owner);
 
 	putlog(LOG_MISC, "*", _("Linking to %s (%s %d) on idx %d."), user->handle, host, port, data->idx);
 	return BIND_RET_BREAK;
 }
 
+static void do_ping(int idx, void *client_data)
+{
+	bot_t *bot = client_data;
+
+	if (bot->idle == -1) {
+		botnet_delete(bot->bot, _("Ping timeout"));
+	} else if (bot->idle == 0) {
+		bot->idle = 1;
+	} else {
+		bot->idle = -1;
+		egg_iprintf(bot->idx, "ping\n");
+	}
+}
+
 static int got_bbroadcast(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len)
 {
 	if (argc <= 1) len = 0;
@@ -402,6 +421,18 @@
 	return 0;
 }
 
+static int got_ping(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len)
+{
+	egg_iprintf(bot->idx, "pong\n");
+
+	return 0;
+}
+
+static int got_pong(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len)
+{
+	return 0;
+}
+
 static int got_privmsg(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len)
 {
 	partymember_t *dst;
@@ -447,13 +478,20 @@
 
 	sockbuf_set_handler(newidx, &client_handler, session, &sock_owner);
 	netstring_on(newidx);
+	socktimer_on(newidx, 30, 0, NULL, NULL, &generic_owner);
 
 	return 0;
 }
 
 static int idx_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port)
 {
-	egg_iprintf(idx, ":%s proto", botnet_get_name());
+	bot_t *bot = client_data;
+
+	// no special features yet
+	// egg_iprintf(idx, "proto para1 para2");
+	bot->proto = malloc(sizeof(*bot->proto));
+	bot->proto->dummy = 0;
+	egg_iprintf(idx, ":%s hello %s", botnet_get_name(), bot->user->handle);
 
 	return 0;
 }
@@ -472,11 +510,8 @@
  */
 
 static int recving_login(bot_t *bot, char *src, char *cmd, int argc, char *argv[], int len) {
-	if (!bot->user) {
-		if (!src) {
-			sockbuf_delete(bot->idx);
-			return 0;
-		} else {
+	if (src) {
+		if (!bot->user) {
 			bot->user = user_lookup_by_handle(src);
 			if (!bot->user || !(bot->user->flags & USER_BOT) || !strcmp(src, botnet_get_name())) {
 				sockbuf_delete(bot->idx);
@@ -486,12 +521,13 @@
 				sockbuf_delete(bot->idx);
 				return 0;
 			}
+		} else {
+			if (src && strcmp(src, bot->user->handle)) {
+				sockbuf_delete(bot->idx);
+				return 0;
+			}
 		}
 	}
-	if (src && strcmp(src, bot->user->handle)) {
-		sockbuf_delete(bot->idx);
-		return 0;
-	}
 	if (!strcasecmp(cmd, "PROTO")) {
 		if (bot->proto) {
 			sockbuf_delete(bot->idx);
@@ -500,7 +536,18 @@
 		bot->proto = malloc(sizeof(*bot->proto));
 		bot->proto->dummy = 0;
 		egg_iprintf(bot->idx, "PROTO");
-	} else if (!strcasecmp(cmd, "HELLO")) {
+		return 0;
+	}
+	if (!bot->user) {
+		sockbuf_delete(bot->idx);
+		return 0;
+	}
+	if (!bot->proto) {
+		bot->proto = malloc(sizeof(*bot->proto));
+		bot->proto->dummy = 0;
+	}
+
+	if (!strcasecmp(cmd, "HELLO")) {
 		int i;
 		char salt[33], *pass = NULL;
 		unsigned char hash[16];
@@ -519,8 +566,8 @@
 		for (i = 0; i < 32; ++i) {
 			salt[i] = random() % 62;
 			if (salt[i] < 26) salt[i] += 'A';
-			else if (salt[i] < 52) salt[i] += 'a';
-			else salt[i] += '0';
+			else if (salt[i] < 52) salt[i] += 'a' - 26;
+			else salt[i] += '0' - 52;
 		}
 		salt[32] = 0;
 		MD5_Init(&md5);
@@ -554,6 +601,7 @@
 		xml_node_set_str(argv[2], info, "version", 0, (void *) 0);
 		
 		bot->bot = botnet_new(bot->user->handle, bot->user, NULL, NULL, info, &bothandler, bot, &bot_owner, 0);
+		socktimer_on(bot->idx, 90, TIMER_REPEAT, do_ping, bot, &generic_owner);
 		botnet_replay_net(bot->bot);
 		egg_iprintf(bot->idx, "el");
 	} else {
@@ -577,7 +625,7 @@
 		}
 		bot->proto = malloc(sizeof(*bot->proto));
 		bot->proto->dummy = 0;
-		egg_iprintf(bot->idx, "hello %s", bot->user->handle);
+		egg_iprintf(bot->idx, ":%s hello %s", botnet_get_name(), bot->user->handle);
 	} else if (!strcasecmp(cmd, "PASSREQ")) {
 		char buf[33];
 		unsigned char hash[16];
@@ -613,6 +661,7 @@
 		xml_node_set_str(argv[2], info, "version", 0, (void *) 0);
 
 		bot->bot = botnet_new(bot->user->handle, bot->user, NULL, NULL, info, &bothandler, bot, &bot_owner, 0);
+		socktimer_on(bot->idx, 90, TIMER_REPEAT, do_ping, bot, &generic_owner);
 		botnet_replay_net(bot->bot);
 		egg_iprintf(bot->idx, "el");
 	} else {
@@ -656,6 +705,14 @@
 
 	len -= argv[argc - 1] - start;
 	argv[argc] = NULL;
+
+	if (!strcasecmp(argv[0], "error")) {
+		putlog(LOG_MISC, "*", _("Botnet: Error from %s: %s"), bot->user ? bot->user->handle : "unknown", argv[1] ? argv[1] : "no reason");
+		if (bot->bot) botnet_delete(bot->bot, "Error from bot.");
+		else sockbuf_delete(bot->idx);
+		return 0;
+	}
+
 	if (!bot->bot) {
 		if (bot->incoming) return recving_login(bot, srcstr, argv[0], argc - 1, argv + 1, len);
 		else return sending_login(bot, srcstr, argv[0], argc - 1, argv + 1, len);
@@ -762,7 +819,7 @@
 	config_update_table(botnet_config_vars, config_root, "botnet", 0, NULL);
 
 	listen_idx = egg_server(botnet_config.ip, botnet_config.port, &real_port);
-	sockbuf_set_handler(listen_idx, &server_handler, NULL, &sock_owner);
+	sockbuf_set_handler(listen_idx, &server_handler, NULL, &generic_owner);
 
 	bind_add_simple(BTN_BOTNET_REQUEST_LINK, NULL, "eggdrop", do_link);
 }
Index: eggdrop1.9/modules/dccparty/dccparty.c
diff -u eggdrop1.9/modules/dccparty/dccparty.c:1.16 eggdrop1.9/modules/dccparty/dccparty.c:1.17
--- eggdrop1.9/modules/dccparty/dccparty.c:1.16	Thu Sep 13 17:20:56 2007
+++ eggdrop1.9/modules/dccparty/dccparty.c	Mon Nov  5 18:05:40 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dccparty.c,v 1.16 2007-09-13 22:20:56 sven Exp $";
+static const char rcsid[] = "$Id: dccparty.c,v 1.17 2007-11-06 00:05:40 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -114,6 +114,7 @@
 
 	sockbuf_set_handler(idx, &dcc_handler, session, &dcc_sock_owner);
 	linemode_on(idx);
+	socktimer_on(idx, 60, 0, NULL, NULL, &dcc_generic_owner);
 	return(0);
 }
 
@@ -219,6 +220,7 @@
 				egg_iprintf(idx, _("\r\nWelcome to the dcc partyline interface!\r\n"));
 				if (session->ident) egg_iprintf(idx, _("Your ident is: %s\r\n"), session->ident);
 				if (session->host) egg_iprintf(idx, _("Your hostname is: %s\r\n"), session->host);
+				socktimer_off(idx);
 				/* Put them on the main channel. */
 				partychan_join_name("*", session->party, 0);
 			}
Index: eggdrop1.9/modules/ircparty/ircparty.c
diff -u eggdrop1.9/modules/ircparty/ircparty.c:1.20 eggdrop1.9/modules/ircparty/ircparty.c:1.21
--- eggdrop1.9/modules/ircparty/ircparty.c:1.20	Thu Sep 13 17:20:56 2007
+++ eggdrop1.9/modules/ircparty/ircparty.c	Mon Nov  5 18:05:40 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ircparty.c,v 1.20 2007-09-13 22:20:56 sven Exp $";
+static const char rcsid[] = "$Id: ircparty.c,v 1.21 2007-11-06 00:05:40 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -135,6 +135,7 @@
 	session->idx = newidx;
 
 	sockbuf_set_handler(newidx, &client_handler, session, &irc_sock_owner);
+	socktimer_on(newidx, 60, 0, NULL, NULL, &irc_generic_owner);
 	linemode_on(newidx);
 
 	/* Stealth logins are where we don't say anything until we know they
@@ -323,6 +324,7 @@
 				session->party = partymember_new(-1, session->user, NULL, session->nick, session->ident ? session->ident : "~ircparty", session->host ? session->host : session->ip, &irc_party_handler, session, &irc_pm_owner);
 				session->state = STATE_PARTYLINE;
 				irc_greet(session);
+				socktimer_off(idx);
 				partychan_join_name("*", session->party, 0);
 			}
 			break;
Index: eggdrop1.9/modules/oldbotnet/events.c
diff -u eggdrop1.9/modules/oldbotnet/events.c:1.13 eggdrop1.9/modules/oldbotnet/events.c:1.14
--- eggdrop1.9/modules/oldbotnet/events.c:1.13	Sat Aug 18 17:32:24 2007
+++ eggdrop1.9/modules/oldbotnet/events.c	Mon Nov  5 18:05:40 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: events.c,v 1.13 2007-08-18 22:32:24 sven Exp $";
+static const char rcsid[] = "$Id: events.c,v 1.14 2007-11-06 00:05:40 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -237,15 +237,6 @@
 	} else if (!strcmp(cmd, "away") && src->what == ENTITY_PARTYMEMBER) {
 		if (*text) egg_iprintf(obot->idx, "aw %s %s %s\n", src->user->bot ? src->user->bot->name : botnet_get_name(), b64enc_int(src->user->id), text);
 		else egg_iprintf(obot->idx, "aw %s %s\n", src->user->bot ? src->user->bot->name : botnet_get_name(), b64enc_int(src->user->id));
-	} else if (!strcmp(cmd, "ping")) {
-		if (obot->idle == -1) {
-			botnet_delete(obot->bot, _("Ping timeout"));
-		} else if (obot->idle == 0) {
-			obot->idle = 1;
-		} else {
-			obot->idle = -1;
-			egg_iprintf(obot->idx, "pi\n");
-		}
 	}
 
 	return 0;
Index: eggdrop1.9/modules/oldbotnet/oldbotnet.c
diff -u eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.24 eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.25
--- eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.24	Thu Sep 13 17:20:56 2007
+++ eggdrop1.9/modules/oldbotnet/oldbotnet.c	Mon Nov  5 18:05:40 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: oldbotnet.c,v 1.24 2007-09-13 22:20:56 sven Exp $";
+static const char rcsid[] = "$Id: oldbotnet.c,v 1.25 2007-11-06 00:05:40 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -374,11 +374,26 @@
 
 	sockbuf_set_handler(data->idx, &oldbotnet_handler, data, &sock_owner);
 	linemode_on(data->idx);
+	socktimer_on(data->idx, 30, 0, NULL, NULL, &generic_owner);
 
 	putlog(LOG_MISC, "*", _("Linking to %s (%s %d) on idx %d as %s."), user->handle, host, port, data->idx, data->name);
 	return BIND_RET_BREAK;
 }
 
+static void do_ping(int idx, void *client_data)
+{
+	oldbotnet_t *obot = client_data;
+
+	if (obot->idle == -1) {
+		botnet_delete(obot->bot, _("Ping timeout"));
+	} else if (obot->idle == 0) {
+		obot->idle = 1;
+	} else {
+		obot->idle = -1;
+		egg_iprintf(obot->idx, "pi\n");
+	}
+}
+
 /*!
  * \brief Send a password for login.
  *
@@ -480,6 +495,7 @@
 		xml_node_delete(info);
 		return;
 	}
+	socktimer_on(bot->idx, 90, TIMER_REPEAT, do_ping, bot, &generic_owner);
 	botnet_replay_net(bot->bot);
 	egg_iprintf(bot->idx, "el\n");
 }
Index: eggdrop1.9/modules/telnetparty/telnetparty.c
diff -u eggdrop1.9/modules/telnetparty/telnetparty.c:1.26 eggdrop1.9/modules/telnetparty/telnetparty.c:1.27
--- eggdrop1.9/modules/telnetparty/telnetparty.c:1.26	Thu Sep 13 17:20:58 2007
+++ eggdrop1.9/modules/telnetparty/telnetparty.c	Mon Nov  5 18:05:40 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: telnetparty.c,v 1.26 2007-09-13 22:20:58 sven Exp $";
+static const char rcsid[] = "$Id: telnetparty.c,v 1.27 2007-11-06 00:05:40 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -324,6 +324,7 @@
 
 	sockbuf_set_handler(newidx, &client_handler, session, &telnet_sockbuf_owner);
 	sockbuf_attach_filter(newidx, &telnet_filter, session);
+	socktimer_on(newidx, 60, 0, NULL, NULL, &telnet_generic_owner);
 	linemode_on(newidx);
 
 	/* Stealth logins are where we don't say anything until we know they
@@ -431,6 +432,7 @@
 				session->state = STATE_NICKNAME;
 			}
 			else {
+				socktimer_off(idx);
 				session->party = partymember_new(-1, session->user, NULL, session->nick, session->ident ? session->ident : "~telnet", session->host ? session->host : session->ip, &telnet_party_handler, session, &telnet_partymember_owner);
 				session->state = STATE_PARTYLINE;
 				egg_iprintf(idx, "\r\nWelcome to the telnet partyline interface!\r\n");
Index: eggdrop1.9/src/main.c
diff -u eggdrop1.9/src/main.c:1.190 eggdrop1.9/src/main.c:1.191
--- eggdrop1.9/src/main.c:1.190	Tue May  8 20:32:32 2007
+++ eggdrop1.9/src/main.c	Mon Nov  5 18:05:40 2007
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: main.c,v 1.190 2007-05-09 01:32:32 sven Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.191 2007-11-06 00:05:40 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -236,9 +236,7 @@
 
 		miltime = (nowtm.tm_hour * 100) + (nowtm.tm_min);
 		if (nowtm.tm_min % 5 == 0) {
-			botnet_entity_t me = bot_entity((botnet_bot_t *) 0);
 			eggdrop_event("5minutely");
-			botnet_extension(EXTENSION_NEIGHBOURS, &me, NULL, NULL, "ping", "", 0);
 			botnet_autolink();
 		}
 		if (nowtm.tm_min == 0) eggdrop_event("hourly");
----------------------- End of diff -----------------------



More information about the Changes mailing list