[cvslog] (2007-09-13 22:21:09 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Thu Sep 13 16:21:11 CST 2007


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2007-09-13 22:21:08 UTC
Commited by: sven

Modified files:
     lib/eggdrop/botnet.c lib/eggdrop/botnet.h lib/eggdrop/dns.c
     lib/eggdrop/ident.c lib/eggdrop/module.c lib/eggdrop/module.h
     lib/eggdrop/partymember.c lib/eggdrop/sockbuf.c
     lib/eggdrop/sockbuf.h modules/botnet/botnet.c
     modules/botnet/events.c modules/dccparty/dccparty.c
     modules/ircparty/ircparty.c modules/oldbotnet/oldbotnet.c
     modules/proxy/http.c modules/proxy/proxy.c modules/proxy/proxy.h
     modules/proxy/socks5.c modules/script/egg_script_internal.h
     modules/script/scriptmod.c modules/script/scriptnet.c
     modules/server/dcc.c modules/server/server.c
     modules/server/server.h modules/server/servsock.c
     modules/telnetparty/telnetparty.c src/terminal.c

Log message:

 * Added a owner to sockbufs. Ugly but necessary.
 * Some more botnet stuff. Bots can actually link now.

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/botnet.c
diff -u eggdrop1.9/lib/eggdrop/botnet.c:1.12 eggdrop1.9/lib/eggdrop/botnet.c:1.13
--- eggdrop1.9/lib/eggdrop/botnet.c:1.12	Sun Aug 19 14:49:16 2007
+++ eggdrop1.9/lib/eggdrop/botnet.c	Thu Sep 13 17:20:55 2007
@@ -28,16 +28,13 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: botnet.c,v 1.12 2007-08-19 19:49:16 sven Exp $";
+static const char rcsid[] = "$Id: botnet.c,v 1.13 2007-09-13 22:20:55 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
 
 #define BAD_BOTNAME_CHARS " *?@:"   //!< A string of characters that aren't allowed in a botname.
 
-#define BOT_DELETED 1
-
-
 typedef struct {
 	int priority;
 	int min_prio;
@@ -582,7 +579,7 @@
 	
 	for (p = start ? start->partys : partymember_get_local_head(); p; p = p->next_on_bot) {
 		if (p->flags & PARTY_DELETED) continue;
-		if (dst->handler->on_login) dst->handler->on_login(dst->client_data, p, 1);
+		if (dst->handler->on_login) dst->handler->on_login(dst->client_data, p);
 		for (i = 0; i < p->nchannels; ++i) {
 			if (dst->handler->on_join) dst->handler->on_join(dst->client_data, p->channels[i], p, 1);
 		}
@@ -857,6 +854,29 @@
 	}
 }
 
+/*!
+ * \brief Sends a partyline join out to the botnet
+ *
+ * This function simply calls the on_login callback for all directly linked
+ * bots except the one the event came from. It should only be called by
+ * exactly one function.
+ *
+ * \param p The user that has joined the partyline.
+ *
+ * \warning If this function is referenced by \e any other function
+ *          except partychan_new() it is a bug.
+ */
+
+void botnet_announce_login(partymember_t *p)
+{
+	botnet_bot_t *tmp;
+
+	for (tmp = localbot_head; tmp; tmp = tmp->next_local) {
+		if (tmp->flags & BOT_DELETED || (p->bot && tmp == p->bot->direction)) continue;
+		if (tmp->handler && tmp->handler->on_login) tmp->handler->on_login(tmp->client_data, p);
+	}
+}
+
 void botnet_member_part(partychan_t *chan, partymember_t *p, const char *reason, int len)
 {
 	botnet_bot_t *tmp;
Index: eggdrop1.9/lib/eggdrop/botnet.h
diff -u eggdrop1.9/lib/eggdrop/botnet.h:1.8 eggdrop1.9/lib/eggdrop/botnet.h:1.9
--- eggdrop1.9/lib/eggdrop/botnet.h:1.8	Sun Aug 19 14:49:17 2007
+++ eggdrop1.9/lib/eggdrop/botnet.h	Thu Sep 13 17:20:55 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: botnet.h,v 1.8 2007-08-19 19:49:17 sven Exp $
+ * $Id: botnet.h,v 1.9 2007-09-13 22:20:55 sven Exp $
  */
 
 #ifndef _EGG_BOTNET_H_
@@ -28,13 +28,16 @@
 #define BTN_BOTNET_BOT          "bot"
 #define BTN_BOTNET_EXTENSION    "ext"
 
+#define BOT_DELETED          1
+#define BOT_LINKING          2
+
 #define EXTENSION_ONE        1
 #define EXTENSION_ALL        2
 #define EXTENSION_NEIGHBOURS 3
 
 typedef struct {
 	/* Events that don't depend on a single chan. */
-	int (*on_login)(void *client_data, partymember_t *new, int netburst);
+	int (*on_login)(void *client_data, partymember_t *new);
 	int (*on_bcast)(void *client_data, botnet_entity_t *src, const char *text, int len);
 	int (*on_privmsg)(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len);
 	int (*on_nick)(void *client_data, partymember_t *src, const char *newnick);
@@ -161,6 +164,7 @@
 int botnet_check_direction(botnet_bot_t *direction, botnet_bot_t *src);
 
 void botnet_broadcast(botnet_entity_t *src, const char *text, int len);
+void botnet_announce_login(partymember_t *p);
 void botnet_member_join(partychan_t *chan, partymember_t *p, int linking);
 void botnet_member_part(partychan_t *chan, partymember_t *p, const char *reason, int len);
 void botnet_chanmsg(partychan_t *chan, botnet_entity_t *src, const char *reason, int len);
Index: eggdrop1.9/lib/eggdrop/dns.c
diff -u eggdrop1.9/lib/eggdrop/dns.c:1.20 eggdrop1.9/lib/eggdrop/dns.c:1.21
--- eggdrop1.9/lib/eggdrop/dns.c:1.20	Sat Apr 14 10:21:11 2007
+++ eggdrop1.9/lib/eggdrop/dns.c	Thu Sep 13 17:20:55 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dns.c,v 1.20 2007-04-14 15:21:11 sven Exp $";
+static const char rcsid[] = "$Id: dns.c,v 1.21 2007-09-13 22:20:55 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -154,7 +154,7 @@
 	}
 	if (i == 5) return;
 	dns_idx = sockbuf_new();
-	sockbuf_set_handler(dns_idx, &dns_handler, NULL);
+	sockbuf_set_handler(dns_idx, &dns_handler, NULL, NULL);
 	sockbuf_set_sock(dns_idx, sock, 0);
 }
 
Index: eggdrop1.9/lib/eggdrop/ident.c
diff -u eggdrop1.9/lib/eggdrop/ident.c:1.6 eggdrop1.9/lib/eggdrop/ident.c:1.7
--- eggdrop1.9/lib/eggdrop/ident.c:1.6	Mon Oct  2 23:02:12 2006
+++ eggdrop1.9/lib/eggdrop/ident.c	Thu Sep 13 17:20:55 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ident.c,v 1.6 2006-10-03 04:02:12 sven Exp $";
+static const char rcsid[] = "$Id: ident.c,v 1.7 2007-09-13 22:20:55 sven Exp $";
 #endif
 
 #include <stdio.h>
@@ -47,8 +47,7 @@
 static sockbuf_handler_t ident_handler = {
 	"ident",
 	ident_on_connect, ident_on_eof, NULL,
-	ident_on_read, NULL,
-	NULL
+	ident_on_read, NULL
 };
 
 static ident_info_t *ident_head = NULL;
@@ -79,7 +78,7 @@
 	ident_info->id = ident_id++;
 	ident_info->next = ident_head;
 	ident_head = ident_info;
-	sockbuf_set_handler(idx, &ident_handler, ident_info);
+	sockbuf_set_handler(idx, &ident_handler, ident_info, NULL);
 	return(ident_info->id);
 }
 
Index: eggdrop1.9/lib/eggdrop/module.c
diff -u eggdrop1.9/lib/eggdrop/module.c:1.14 eggdrop1.9/lib/eggdrop/module.c:1.15
--- eggdrop1.9/lib/eggdrop/module.c:1.14	Sun Aug 19 14:49:17 2007
+++ eggdrop1.9/lib/eggdrop/module.c	Thu Sep 13 17:20:55 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: module.c,v 1.14 2007-08-19 19:49:17 sven Exp $";
+static const char rcsid[] = "$Id: module.c,v 1.15 2007-09-13 22:20:55 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -248,6 +248,7 @@
 {
 	int errors;
 	const char *error;
+	module_list_t *m;
 
 	if (entry->prev) entry->prev->next = entry->next;
 	else deleted_head = entry->next;
@@ -257,6 +258,14 @@
 
 	script_remove_events_by_owner(&entry->modinfo, 0);
 
+	for (m = module_list_head; m; m = m->next) {
+		if (m->modinfo.event_cleanup) m->modinfo.event_cleanup(&entry->modinfo);
+	}
+	
+	for (m = deleted_head; m; m = m->next) {
+		if (m->modinfo.event_cleanup) m->modinfo.event_cleanup(&entry->modinfo);
+	}
+	
 	errors = lt_dlclose(entry->hand);
 	if (errors) {
 		putlog(LOG_MISC, "*", "Error unloading %s!", entry->modinfo.name);
Index: eggdrop1.9/lib/eggdrop/module.h
diff -u eggdrop1.9/lib/eggdrop/module.h:1.48 eggdrop1.9/lib/eggdrop/module.h:1.49
--- eggdrop1.9/lib/eggdrop/module.h:1.48	Sat Jan 13 06:23:39 2007
+++ eggdrop1.9/lib/eggdrop/module.h	Thu Sep 13 17:20:55 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: module.h,v 1.48 2007-01-13 12:23:39 sven Exp $
+ * $Id: module.h,v 1.49 2007-09-13 22:20:55 sven Exp $
  */
 
 #ifndef _EGG_MODULE_H_
@@ -37,6 +37,7 @@
 typedef int (*egg_start_func_t)(egg_module_t *modinfo);
 typedef int (*egg_close_func_t)(int why);
 typedef void (*egg_unload_func_t)(void);
+typedef void (*egg_cleanup_hook_t)(egg_module_t *mod);
 
 struct egg_module {
 	const char *name;
@@ -46,6 +47,7 @@
 
 	egg_close_func_t close_func;
 	egg_unload_func_t unload_func;
+	egg_cleanup_hook_t event_cleanup;
 	void *module_data;
 
 	/* API and versioning info. */
Index: eggdrop1.9/lib/eggdrop/partymember.c
diff -u eggdrop1.9/lib/eggdrop/partymember.c:1.30 eggdrop1.9/lib/eggdrop/partymember.c:1.31
--- eggdrop1.9/lib/eggdrop/partymember.c:1.30	Sun Aug 19 14:49:17 2007
+++ eggdrop1.9/lib/eggdrop/partymember.c	Thu Sep 13 17:20:55 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: partymember.c,v 1.30 2007-08-19 19:49:17 sven Exp $";
+static const char rcsid[] = "$Id: partymember.c,v 1.31 2007-09-13 22:20:55 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -156,6 +156,7 @@
 	}
 
 	npartymembers++;
+	botnet_announce_login(mem);
 	bind_check(BT_new, NULL, nick, mem);
 	return(mem);
 }
Index: eggdrop1.9/lib/eggdrop/sockbuf.c
diff -u eggdrop1.9/lib/eggdrop/sockbuf.c:1.22 eggdrop1.9/lib/eggdrop/sockbuf.c:1.23
--- eggdrop1.9/lib/eggdrop/sockbuf.c:1.22	Sat Jan 13 06:23:40 2007
+++ eggdrop1.9/lib/eggdrop/sockbuf.c	Thu Sep 13 17:20:55 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: sockbuf.c,v 1.22 2007-01-13 12:23:40 sven Exp $";
+static const char rcsid[] = "$Id: sockbuf.c,v 1.23 2007-09-13 22:20:55 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -58,6 +58,7 @@
 
 	sockbuf_handler_t *handler;	/* User's event handlers */
 	void *client_data;	/* User's client data */
+	event_owner_t *owner;
 } sockbuf_t;
 
 static sockbuf_t *sockbufs = NULL;
@@ -613,7 +614,7 @@
 		}
 	}
 
-	if (sbuf->handler->on_delete) sbuf->handler->on_delete(sbuf->client_data, idx);
+	if (sbuf->owner && sbuf->owner->on_delete) sbuf->owner->on_delete(sbuf->owner, sbuf->client_data);
 
 	/* Close the file descriptor. */
 	if (sbuf->sock >= 0) socket_close(sbuf->sock);
@@ -669,11 +670,12 @@
 	return(0);
 }
 
-int sockbuf_set_handler(int idx, sockbuf_handler_t *handler, void *client_data)
+int sockbuf_set_handler(int idx, sockbuf_handler_t *handler, void *client_data, event_owner_t *owner)
 {
 	if (!sockbuf_isvalid(idx)) return(-1);
 	sockbufs[idx].handler = handler;
 	sockbufs[idx].client_data = client_data;
+	sockbufs[idx].owner = owner;
 
 	return(0);
 }
Index: eggdrop1.9/lib/eggdrop/sockbuf.h
diff -u eggdrop1.9/lib/eggdrop/sockbuf.h:1.8 eggdrop1.9/lib/eggdrop/sockbuf.h:1.9
--- eggdrop1.9/lib/eggdrop/sockbuf.h:1.8	Sat Oct  9 23:55:11 2004
+++ eggdrop1.9/lib/eggdrop/sockbuf.h	Thu Sep 13 17:20:55 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: sockbuf.h,v 1.8 2004-10-10 04:55:11 stdarg Exp $
+ * $Id: sockbuf.h,v 1.9 2007-09-13 22:20:55 sven Exp $
  */
 
 #ifndef _EGG_SOCKBUF_H_
@@ -95,21 +95,21 @@
 	int (*on_written)(void *client_data, int idx, int len, int remaining);
 
 	/* Command-level events. */
-	int (*on_delete)(void *client_data, int idx);
+//	int (*on_delete)(void *client_data, int idx);
 } sockbuf_handler_t;
 
 int sockbuf_init(void);
 int sockbuf_shutdown(void);
 
 int sockbuf_write(int idx, const char *data, int len);
-int sockbuf_new();
+int sockbuf_new(void);
 int sockbuf_delete(int idx);
 int sockbuf_list(int **idx, int *len, int flags);
 int sockbuf_isvalid(int idx);
 int sockbuf_close(int idx);
 int sockbuf_flush(int idx);
 int sockbuf_get_handler(int idx, sockbuf_handler_t **handler, void *client_data_ptr);
-int sockbuf_set_handler(int idx, sockbuf_handler_t *handler, void *client_data);
+int sockbuf_set_handler(int idx, sockbuf_handler_t *handler, void *client_data, event_owner_t *owner);
 int sockbuf_get_sock(int idx);
 int sockbuf_set_sock(int idx, int sock, int flags);
 int sockbuf_get_peer(int idx, const char **peer_ip, int *peer_port);
Index: eggdrop1.9/modules/botnet/botnet.c
diff -u eggdrop1.9/modules/botnet/botnet.c:1.3 eggdrop1.9/modules/botnet/botnet.c:1.4
--- eggdrop1.9/modules/botnet/botnet.c:1.3	Sun Aug 19 14:49:18 2007
+++ eggdrop1.9/modules/botnet/botnet.c	Thu Sep 13 17:20:56 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: botnet.c,v 1.3 2007-08-19 19:49:18 sven Exp $";
+static const char rcsid[] = "$Id: botnet.c,v 1.4 2007-09-13 22:20:56 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -47,16 +47,21 @@
 static int idx_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
 static int idx_on_read(void *client_data, int idx, char *data, int len);
 static int idx_on_eof(void *client_data, int idx, int err, const char *errmsg);
-static int idx_on_delete(void *client_data, int idx);
+static int idx_on_delete(event_owner_t *owner, void *client_data);
 
+static int got_join(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
+static int got_login(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
 static int got_newbot(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
 
 static struct {
 	char *cmd;
 	int source;
+	int min_argc;
 	int (*function)(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len);
 } cmd_mapping[] = {
-	{"newbot", ENTITY_BOT, got_newbot}
+	{"join", ENTITY_PARTYMEMBER, 1, got_join},
+	{"login", ENTITY_BOT, 4, got_login},
+	{"newbot", ENTITY_BOT, 4, got_newbot}
 };
 
 static int cmd_num = sizeof(cmd_mapping) / sizeof(cmd_mapping[0]);
@@ -83,6 +88,12 @@
 	bot_on_delete
 };
 
+static event_owner_t sock_owner = {
+	"botnet", NULL,
+	NULL, NULL,
+	idx_on_delete
+};
+
 static event_owner_t generic_owner = {
 	"botnet", NULL,
 	NULL, NULL,
@@ -104,8 +115,7 @@
 static sockbuf_handler_t client_handler = {
 	"botnet",
 	idx_on_connect, idx_on_eof, NULL,
-	idx_on_read, NULL,
-	idx_on_delete
+	idx_on_read, NULL
 };
 
 /* +bot <bot> <host> <port> */
@@ -220,29 +230,47 @@
 	data->linking = 1;
 	data->idle = 0;
 
-	sockbuf_set_handler(data->idx, &client_handler, data);
+	sockbuf_set_handler(data->idx, &client_handler, data, &sock_owner);
 	netstring_on(data->idx);
 
 	putlog(LOG_MISC, "*", _("Linking to %s (%s %d) on idx %d."), user->handle, host, port, data->idx);
 	return BIND_RET_BREAK;
 }
 
+/* login channel [netburst] */
+
+static int got_join(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len)
+{
+	int netburst = 0;
+
+	if (argc >= 2) netburst = b64dec_int(argv[1]) & 1;
+	partychan_join_name(argv[0], src->user, netburst);
+
+	return 0;
+}
+
+/* login nick ident host id */
+
+static int got_login(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len)
+{
+	partymember_new(b64dec_int(argv[3]), NULL, src->bot, argv[0], argv[1], argv[2], NULL, NULL, &generic_owner);
+	return 0;
+}
+
 /* newbot uplink name type version fullversion linking */
 
 static int got_newbot(bot_t *bot, botnet_entity_t *src, char *cmd, int argc, char *argv[21], int len)
 {
-	int flags;
+	int flags = 0;
 	xml_node_t *info;
 	botnet_bot_t *new;
 
-	if (argc < 5) return 0;
-	
-	flags = b64dec_int(argv[4]);
+	if (argc >= 5) flags = b64dec_int(argv[4]);
 
 	info = xml_node_new();
 	xml_node_set_str(argv[1], info, "type", 0, (void *) 0);
 	xml_node_set_int(b64dec_int(argv[2]), info, "numversion", 0, (void *) 0);
-	xml_node_set_str(argv[3], info, "version", (void *) 0);
+	xml_node_set_str(argv[3], info, "version", 0, (void *) 0);
 
 	new = botnet_new(argv[0], NULL, src->bot, bot->bot, info, NULL, NULL, &generic_owner, flags & 1);
 	if (!new) {
@@ -268,7 +296,7 @@
 	session->linking = 1;
 	session->idle = 0;
 
-	sockbuf_set_handler(newidx, &client_handler, session);
+	sockbuf_set_handler(newidx, &client_handler, session, &sock_owner);
 	netstring_on(newidx);
 
 	return 0;
@@ -359,11 +387,11 @@
 			return 0;
 		}
 		*bot->pass = 0;
-		egg_iprintf(bot->idx, "thisbot %s eggdrop %s %s :%s", botnet_get_name(), "1090000", "eggdrop1.9.0+cvs", "some informative stuff");
+		egg_iprintf(bot->idx, ":%s thisbot eggdrop %s %s :%s", botnet_get_name(), b64enc_int(1090000), "eggdrop1.9.0+cvs", "some informative stuff");
 	} else if (!strcasecmp(cmd, "THISBOT")) {
 		xml_node_t *info;
 
-		if (!bot->pass || *bot->pass || argc != 5 || strcmp(bot->user->handle, argv[0])) {
+		if (!bot->pass || *bot->pass || argc != 4) {
 			sockbuf_delete(bot->idx);
 			return 0;
 		}
@@ -373,8 +401,8 @@
 		
 		info = xml_node_new();
 		xml_node_set_str(argv[0], info, "type", 0, (void *) 0);
-		xml_node_set_int(b64dec_int(argv[2]), info, "numversion", 0, (void *) 0);
-		xml_node_set_str(argv[3], info, "version", 0, (void *) 0);
+		xml_node_set_int(b64dec_int(argv[1]), info, "numversion", 0, (void *) 0);
+		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);
 		botnet_replay_net(bot->bot);
@@ -421,19 +449,19 @@
 	} else if (!strcasecmp(cmd, "THISBOT")) {
 		xml_node_t *info;
 
-		if (argc != 5 || strcmp(bot->user->handle, argv[0])) {
+		if (argc != 4) {
 			sockbuf_delete(bot->idx);
 			return 0;
 		}
-		egg_iprintf(bot->idx, "thisbot eggdrop %s %s %s :%s", botnet_get_name(), "1090000", "eggdrop1.9.0+cvs", "some informative stuff");
+		egg_iprintf(bot->idx, ":%s thisbot eggdrop %s %s :%s", botnet_get_name(), b64enc_int(1090000), "eggdrop1.9.0+cvs", "some informative stuff");
 		free(bot->pass);
 		bot->pass = NULL;
 		bot->linking = 0;
 
 		info = xml_node_new();
 		xml_node_set_str(argv[0], info, "type", 0, (void *) 0);
-		xml_node_set_int(b64dec_int(argv[2]), info, "numversion", 0, (void *) 0);
-		xml_node_set_str(argv[3], info, "version", 0, (void *) 0);
+		xml_node_set_int(b64dec_int(argv[1]), info, "numversion", 0, (void *) 0);
+		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);
 		botnet_replay_net(bot->bot);
@@ -480,13 +508,20 @@
 	len -= argv[argc - 1] - start;
 	argv[argc] = NULL;
 	if (!bot->bot) {
-		if (bot->incoming) return recving_login(bot, srcstr, argv[0], argc, argv + 1, len);
-		else return sending_login(bot, srcstr, argv[0], argc, argv + 1, len);
+		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);
 	}
 
 	if (srcstr) {
+		char *at;
 		botnet_bot_t *srcbot;
-		get_entity(&src, srcstr);
+
+		at = strchr(srcstr, '@');
+		if (get_entity(&src, srcstr)) {
+			if (at && !*at) putlog(LOG_MISC, "*", _("Botnet: Desync! %s says %s came from %s@%s who doesn't exist!"), bot->bot->name, argv[0], srcstr, at + 1);
+			else putlog(LOG_MISC, "*", _("Botnet: Desync! %s says %s came from %s who doesn't exist!"), bot->bot->name, argv[0], srcstr);
+			return 0;
+		}
 		if (src.what == ENTITY_BOT) srcbot = src.bot;
 		else srcbot = src.user->bot;
 		if (botnet_check_direction(bot->bot, srcbot)) return 0;
@@ -498,13 +533,13 @@
 	while (min <= max) {
 		int ret = strcasecmp(argv[0], cmd_mapping[cur].cmd);
 		if (!ret) {
+			if (argc < cmd_mapping[cur].min_argc) return 0;
 			if (cmd_mapping[cur].source && cmd_mapping[cur].source != src.what) return 0;
-			return cmd_mapping[cur].function(bot, &src, argv[0], argc, argv + 1, len);
+			return cmd_mapping[cur].function(bot, &src, argv[0], argc - 1, argv + 1, len);
 		} else if (ret < 0) {
-			max = cur;
+			max = cur - 1;
 		} else {
-			if (min == cur) ++min;
-			else min = cur;
+			min = cur + 1;
 		}
 		cur = (min + max) / 2;
 	}
@@ -530,7 +565,7 @@
 	return 0;
 }
 
-static int idx_on_delete(void *client_data, int idx)
+static int idx_on_delete(event_owner_t *owner, void *client_data)
 {
 	bot_t *bot = client_data;
 
@@ -578,7 +613,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);
+	sockbuf_set_handler(listen_idx, &server_handler, NULL, &sock_owner);
 
 	bind_add_simple(BTN_BOTNET_REQUEST_LINK, NULL, "eggdrop", do_link);
 }
@@ -599,7 +634,7 @@
 
 int botnet_LTX_start(egg_module_t *modinfo)
 {
-	bot_owner.module = generic_owner.module = modinfo;
+	bot_owner.module = sock_owner.module = generic_owner.module = modinfo;
 	modinfo->name = "botnet";
 	modinfo->author = "eggdev";
 	modinfo->version = "1.0.0";
Index: eggdrop1.9/modules/botnet/events.c
diff -u eggdrop1.9/modules/botnet/events.c:1.2 eggdrop1.9/modules/botnet/events.c:1.3
--- eggdrop1.9/modules/botnet/events.c:1.2	Sat Aug 18 17:32:24 2007
+++ eggdrop1.9/modules/botnet/events.c	Thu Sep 13 17:20:56 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: events.c,v 1.2 2007-08-18 22:32:24 sven Exp $";
+static const char rcsid[] = "$Id: events.c,v 1.3 2007-09-13 22:20:56 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -26,7 +26,7 @@
 #include "botnet.h"
 
 /* botnet callbacks */
-static int on_login(void *client_data, partymember_t *src, int linking);
+static int on_login(void *client_data, partymember_t *src);
 static int on_bcast(void *client_data, botnet_entity_t *src, const char *text, int len);
 static int on_privmsg(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len);
 static int on_nick(void *client_data, partymember_t *src, const char *oldnick);
@@ -48,12 +48,12 @@
 	on_new_bot, on_lost_bot, on_link, on_unlink, on_botmsg, on_botbroadcast, on_extension
 };
 
-static int on_login(void *client_data, partymember_t *src, int linking)
+static int on_login(void *client_data, partymember_t *src)
 {
 	bot_t *b = client_data;
 
-	if (src->bot) egg_iprintf(b->idx, ":%s login %s %s %s %s %d", src->bot->name, src->nick, src->ident, src->host, b64enc_int(src->id), linking);
-	else egg_iprintf(b->idx, "login %s %s %s %s %d", src->nick, src->ident, src->host, b64enc_int(src->id), linking);
+	if (src->bot) egg_iprintf(b->idx, ":%s login %s %s %s %s %d", src->bot->name, src->nick, src->ident, src->host, b64enc_int(src->id));
+	else egg_iprintf(b->idx, "login %s %s %s %s %d", src->nick, src->ident, src->host, b64enc_int(src->id));
 
 	return 0;
 }
@@ -121,7 +121,7 @@
 {
 	bot_t *b = client_data;
 
-	egg_iprintf(b->idx, ":%s join %s %d", src->net_name, chan->name, linking);
+	egg_iprintf(b->idx, ":%s join %s%s", src->net_name, chan->name, linking ? " B" : "");
 
 	return 0;
 }
@@ -147,7 +147,8 @@
 	if (!type) type = "unknown";
 	if (ver) version = atoi(ver);
 	if (!fullversion) fullversion = "unknown";
-	egg_iprintf(b->idx, ":%s newbot %s %s %s %s %s", bot->uplink ? bot->uplink->name : botnet_get_name(), bot->name, type, b64enc_int(version), fullversion, linking ? "B" : "A");
+	if (bot->uplink) egg_iprintf(b->idx, ":%s newbot %s %s %s %s %s", bot->uplink->name, bot->name, type, b64enc_int(version), fullversion, linking ? "B" : "A");
+	else egg_iprintf(b->idx, "newbot %s %s %s %s%s", bot->name, type, b64enc_int(version), fullversion, linking ? " B" : "");
 
 	return 0;
 }
Index: eggdrop1.9/modules/dccparty/dccparty.c
diff -u eggdrop1.9/modules/dccparty/dccparty.c:1.15 eggdrop1.9/modules/dccparty/dccparty.c:1.16
--- eggdrop1.9/modules/dccparty/dccparty.c:1.15	Sat Jan 13 06:23:40 2007
+++ eggdrop1.9/modules/dccparty/dccparty.c	Thu Sep 13 17:20:56 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dccparty.c,v 1.15 2007-01-13 12:23:40 sven Exp $";
+static const char rcsid[] = "$Id: dccparty.c,v 1.16 2007-09-13 22:20:56 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -47,7 +47,7 @@
 static int dcc_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
 static int dcc_on_read(void *client_data, int idx, char *data, int len);
 static int dcc_on_eof(void *client_data, int idx, int err, const char *errmsg);
-static int dcc_on_delete(void *client_data, int idx);
+static int dcc_on_delete(event_owner_t *owner, void *client_data);
 static int dcc_pm_delete(event_owner_t *owner, void *client_data);
 
 static int ident_result(void *client_data, const char *ip, int port, const char *reply);
@@ -66,11 +66,16 @@
 	dcc_pm_delete
 };
 
+static event_owner_t dcc_sock_owner = {
+	"dccparty", 0,
+	0, 0,
+	dcc_on_delete
+};
+
 static sockbuf_handler_t dcc_handler = {
 	"dcc",
 	dcc_on_connect, dcc_on_eof, NULL,
-	dcc_on_read, NULL,
-	dcc_on_delete
+	dcc_on_read, NULL
 };
 
 int dcc_init()
@@ -107,7 +112,7 @@
 	session->nick = strdup(nick);
 	session->idx = idx;
 
-	sockbuf_set_handler(idx, &dcc_handler, session);
+	sockbuf_set_handler(idx, &dcc_handler, session, &dcc_sock_owner);
 	linemode_on(idx);
 	return(0);
 }
@@ -243,15 +248,18 @@
 {
 	dcc_session_t *session = client_data;
 
+	session->party = NULL;
+
 	sockbuf_delete(session->idx);
 
 	return 0;
 }
 
-static int dcc_on_delete(void *client_data, int idx)
+static int dcc_on_delete(event_owner_t *owner, void *client_data)
 {
 	dcc_session_t *session = client_data;
 
+	session->idx = -1;
 	if (session->party) {
 		partymember_delete(session->party, NULL, "Deleted!");
 		session->party = NULL;
@@ -274,7 +282,7 @@
 {
 	void *config_root;
 
-	dcc_generic_owner.module = dcc_pm_owner.module = modinfo;
+	dcc_generic_owner.module = dcc_sock_owner.module = dcc_pm_owner.module = modinfo;
 
 	modinfo->name = "dccparty";
 	modinfo->author = "eggdev";
Index: eggdrop1.9/modules/ircparty/ircparty.c
diff -u eggdrop1.9/modules/ircparty/ircparty.c:1.19 eggdrop1.9/modules/ircparty/ircparty.c:1.20
--- eggdrop1.9/modules/ircparty/ircparty.c:1.19	Sat Apr 14 10:21:13 2007
+++ eggdrop1.9/modules/ircparty/ircparty.c	Thu Sep 13 17:20:56 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ircparty.c,v 1.19 2007-04-14 15:21:13 sven Exp $";
+static const char rcsid[] = "$Id: ircparty.c,v 1.20 2007-09-13 22:20:56 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -56,7 +56,7 @@
 static int irc_on_newclient(void *client_data, int idx, int newidx, const char *peer_ip, int peer_port);
 static int irc_on_read(void *client_data, int idx, char *data, int len);
 static int irc_on_eof(void *client_data, int idx, int err, const char *errmsg);
-static int irc_on_delete(void *client_data, int idx);
+static int irc_on_delete(event_owner_t *owner, void *client_data);
 static int irc_pm_delete(event_owner_t *owner, void *client_data);
 
 static int ident_result(void *client_data, const char *ip, int port, const char *reply);
@@ -79,6 +79,12 @@
 	0
 };
 
+static event_owner_t irc_sock_owner = {
+	"ircparty", 0,
+	0, 0,
+	irc_on_delete
+};
+
 static event_owner_t irc_pm_owner = {
 	"ircparty", 0,
 	0, 0,
@@ -94,8 +100,7 @@
 static sockbuf_handler_t client_handler = {
 	"ircparty",
 	NULL, irc_on_eof, NULL,
-	irc_on_read, NULL,
-	irc_on_delete
+	irc_on_read, NULL
 };
 
 int irc_init()
@@ -104,7 +109,7 @@
 	bind_add_list("ircparty", ircparty_binds);
 	/* Open our listening socket. */
 	irc_idx = egg_server(irc_config.vhost, irc_config.port, &irc_port);
-	sockbuf_set_handler(irc_idx, &server_handler, NULL);
+	sockbuf_set_handler(irc_idx, &server_handler, NULL, NULL);
 	return(0);
 }
 
@@ -129,7 +134,7 @@
 	session->port = peer_port;
 	session->idx = newidx;
 
-	sockbuf_set_handler(newidx, &client_handler, session);
+	sockbuf_set_handler(newidx, &client_handler, session, &irc_sock_owner);
 	linemode_on(newidx);
 
 	/* Stealth logins are where we don't say anything until we know they
@@ -347,12 +352,13 @@
 {
 	irc_session_t *session = client_data;
 
+	session->party = NULL;
 	sockbuf_delete(session->idx);
 
 	return 0;
 }
 
-static int irc_on_delete(void *client_data, int idx)
+static int irc_on_delete(event_owner_t *owner, void *client_data)
 {
 	irc_session_t *session = client_data;
 
@@ -379,7 +385,7 @@
 {
 	void *config_root;
 
-	irc_generic_owner.module = irc_pm_owner.module = modinfo;
+	irc_generic_owner.module = irc_sock_owner.module = irc_pm_owner.module = modinfo;
 
 	modinfo->name = "ircparty";
 	modinfo->author = "eggdev";
Index: eggdrop1.9/modules/oldbotnet/oldbotnet.c
diff -u eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.23 eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.24
--- eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.23	Sun Aug 19 14:49:18 2007
+++ eggdrop1.9/modules/oldbotnet/oldbotnet.c	Thu Sep 13 17:20:56 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: oldbotnet.c,v 1.23 2007-08-19 19:49:18 sven Exp $";
+static const char rcsid[] = "$Id: oldbotnet.c,v 1.24 2007-09-13 22:20:56 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -66,7 +66,7 @@
 static int oldbotnet_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
 static int oldbotnet_on_read(void *client_data, int idx, char *data, int len);
 static int oldbotnet_on_eof(void *client_data, int idx, int err, const char *errmsg);
-static int oldbotnet_on_delete(void *client_data, int idx);
+static int oldbotnet_on_delete(event_owner_t *owner, void *client_data);
 
 static event_owner_t bot_owner = {
 	"oldbotnet", NULL,
@@ -86,11 +86,11 @@
 	NULL
 };
 
-/*static event_owner_t sock_owner = {
+static event_owner_t sock_owner = {
 	"oldbotnet", NULL,
 	NULL, NULL,
-	sock_on_delete
-};*/
+	oldbotnet_on_delete
+};
 
 typedef struct assoc {
 	char *name;
@@ -189,8 +189,7 @@
 static sockbuf_handler_t oldbotnet_handler = {
 	"oldbotnet",
 	oldbotnet_on_connect, oldbotnet_on_eof, NULL,
-	oldbotnet_on_read, NULL,
-	oldbotnet_on_delete
+	oldbotnet_on_read, NULL
 };
 
 static bind_table_t *BT_obot = NULL;
@@ -373,7 +372,7 @@
 	data->idle = 0;
 	data->anonymous = NULL;
 
-	sockbuf_set_handler(data->idx, &oldbotnet_handler, data);
+	sockbuf_set_handler(data->idx, &oldbotnet_handler, data, &sock_owner);
 	linemode_on(data->idx);
 
 	putlog(LOG_MISC, "*", _("Linking to %s (%s %d) on idx %d as %s."), user->handle, host, port, data->idx, data->name);
@@ -1293,7 +1292,7 @@
 	return 0;
 }
 
-static int oldbotnet_on_delete(void *client_data, int idx)
+static int oldbotnet_on_delete(event_owner_t *owner, void *client_data)
 {
 	oldbotnet_t *bot = client_data;
 
@@ -1338,7 +1337,7 @@
 
 int oldbotnet_LTX_start(egg_module_t *modinfo)
 {
-	bot_owner.module = anonymous_owner.module = generic_owner.module = modinfo;
+	sock_owner.module = bot_owner.module = anonymous_owner.module = generic_owner.module = modinfo;
 	modinfo->name = "oldbotnet";
 	modinfo->author = "eggdev";
 	modinfo->version = "1.0.0";
Index: eggdrop1.9/modules/proxy/http.c
diff -u eggdrop1.9/modules/proxy/http.c:1.5 eggdrop1.9/modules/proxy/http.c:1.6
--- eggdrop1.9/modules/proxy/http.c:1.5	Sun Oct 17 00:14:06 2004
+++ eggdrop1.9/modules/proxy/http.c	Thu Sep 13 17:20:57 2007
@@ -16,14 +16,19 @@
 static int http_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
 static int http_on_eof(void *client_data, int idx, int err, const char *errmsg);
 static int http_on_read(void *client_data, int idx, char *data, int len);
-static int http_on_delete(void *client_data, int idx);
+static int http_on_delete(event_owner_t *owner, void *client_data);
 static int http_on_their_delete(void *client_data, int idx);
 
+event_owner_t http_owner = {
+	"proxy", NULL,
+	NULL, NULL,
+	http_on_delete
+};
+
 static sockbuf_handler_t http_events = {
 	"http proxy",
 	http_on_connect, http_on_eof, NULL,
-	http_on_read, NULL,
-	http_on_delete
+	http_on_read, NULL
 };
 
 static sockbuf_filter_t delete_listener = {
@@ -42,7 +47,7 @@
 	sockbuf_on_eof(idx, SOCKBUF_LEVEL_INTERNAL, err, errmsg);
 }
 
-static int http_on_delete(void *client_data, int idx)
+static int http_on_delete(event_owner_t *owner, void *client_data)
 {
 	proxy_info_t *info = client_data;
 	sockbuf_detach_filter(info->their_idx, &delete_listener, info);
@@ -167,7 +172,7 @@
 
 	info->status = 0;
 
-	sockbuf_set_handler(info->our_idx, &http_events, info);
+	sockbuf_set_handler(info->our_idx, &http_events, info, &http_owner);
 	sockbuf_attach_filter(info->their_idx, &delete_listener, info);
 
 	return(info->their_idx);
Index: eggdrop1.9/modules/proxy/proxy.c
diff -u eggdrop1.9/modules/proxy/proxy.c:1.8 eggdrop1.9/modules/proxy/proxy.c:1.9
--- eggdrop1.9/modules/proxy/proxy.c:1.8	Sat Jan 13 06:23:40 2007
+++ eggdrop1.9/modules/proxy/proxy.c	Thu Sep 13 17:20:57 2007
@@ -64,6 +64,7 @@
 
 int proxy_LTX_start(egg_module_t *modinfo)
 {
+	http_owner.module = socks5_owner.module = modinfo;
 	modinfo->name = "proxy";
 	modinfo->author = "eggdev";
 	modinfo->version = "1.0.0";
Index: eggdrop1.9/modules/proxy/proxy.h
diff -u eggdrop1.9/modules/proxy/proxy.h:1.2 eggdrop1.9/modules/proxy/proxy.h:1.3
--- eggdrop1.9/modules/proxy/proxy.h:1.2	Thu Dec 18 18:51:37 2003
+++ eggdrop1.9/modules/proxy/proxy.h	Thu Sep 13 17:20:57 2007
@@ -1,6 +1,9 @@
 #ifndef _PROXY_H_
 #define _PROXY_H_
 
+#define http_owner proxy_LTX_http_owner
+#define socks5_owner proxy_LTX_socks5_owner
+
 typedef struct {
 	char *username;
 	char *password;
@@ -14,7 +17,10 @@
 
 /* From http.c */
 int http_reconnect(int idx, const char *host, int port);
+event_owner_t http_owner;
 
 /* From socks5.c */
 int socks5_reconnect(int idx, const char *host, int port);
+event_owner_t socks5_owner;
+
 #endif
Index: eggdrop1.9/modules/proxy/socks5.c
diff -u eggdrop1.9/modules/proxy/socks5.c:1.6 eggdrop1.9/modules/proxy/socks5.c:1.7
--- eggdrop1.9/modules/proxy/socks5.c:1.6	Fri Dec  9 00:24:50 2005
+++ eggdrop1.9/modules/proxy/socks5.c	Thu Sep 13 17:20:57 2007
@@ -17,16 +17,21 @@
 static int socks5_on_read(void *client_data, int idx, char *data, int len);
 static int socks5_on_eof(void *client_data, int idx, int err, const char *errmsg);
 static int socks5_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
-static int socks5_on_delete(void *client_data, int idx);
+static int socks5_on_delete(event_owner_t *owner, void *client_data);
 
 static int socks5_on_their_eof(void *client_data, int idx, int err, const char *errmsg);
 static int socks5_on_their_delete(void *client_data, int idx);
 
+event_owner_t socks5_owner = {
+	"proxy", NULL,
+	NULL, NULL,
+	socks5_on_delete
+};
+
 static sockbuf_handler_t socks5_events = {
 	"socks5 proxy",
 	socks5_on_connect, socks5_on_eof, NULL,
-	socks5_on_read, NULL,
-	socks5_on_delete
+	socks5_on_read, NULL
 };
 
 static sockbuf_filter_t delete_listener = {
@@ -251,7 +256,7 @@
 
 /* When our idx is deleted, we have to send an error to the original idx and
  * free our stuff. */
-static int socks5_on_delete(void *client_data, int idx)
+static int socks5_on_delete(event_owner_t *owner, void *client_data)
 {
 	proxy_info_t *info = client_data;
 
@@ -328,7 +333,7 @@
 	if (idx >= 0) info->their_idx = idx;
 	else info->their_idx = sockbuf_new();
 
-	sockbuf_set_handler(info->our_idx, &socks5_events, info);
+	sockbuf_set_handler(info->our_idx, &socks5_events, info, &socks5_owner);
 	sockbuf_attach_filter(info->their_idx, &delete_listener, info);
 
 	return(info->their_idx);
Index: eggdrop1.9/modules/script/egg_script_internal.h
diff -u eggdrop1.9/modules/script/egg_script_internal.h:1.2 eggdrop1.9/modules/script/egg_script_internal.h:1.3
--- eggdrop1.9/modules/script/egg_script_internal.h:1.2	Fri Aug 25 12:22:50 2006
+++ eggdrop1.9/modules/script/egg_script_internal.h	Thu Sep 13 17:20:57 2007
@@ -12,5 +12,10 @@
 #define script_new_user_cmds script_LTX_script_new_user_cmds
 #define script_party_cmds script_LTX_script_party_cmds
 #define script_timer_cmds script_LTX_script_timer_cmds
+#define script_event_cleanup script_LTX_script_event_cleanup
+#define socket_owner script_LTX_socket_owner
+
+void script_event_cleanup(egg_module_t *m);
+event_owner_t socket_owner;
 
 #endif
Index: eggdrop1.9/modules/script/scriptmod.c
diff -u eggdrop1.9/modules/script/scriptmod.c:1.14 eggdrop1.9/modules/script/scriptmod.c:1.15
--- eggdrop1.9/modules/script/scriptmod.c:1.14	Fri Aug 25 12:22:51 2006
+++ eggdrop1.9/modules/script/scriptmod.c	Thu Sep 13 17:20:57 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: scriptmod.c,v 1.14 2006-08-25 17:22:51 sven Exp $";
+static const char rcsid[] = "$Id: scriptmod.c,v 1.15 2007-09-13 22:20:57 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -44,10 +44,12 @@
 
 int script_LTX_start(egg_module_t *modinfo)
 {
+	socket_owner.module = modinfo;
 	modinfo->name = "script";
 	modinfo->author = "eggdev";
 	modinfo->version = "1.0.0";
 	modinfo->description = "provides core scripting functions";
+	modinfo->event_cleanup = script_event_cleanup;
 
 	script_create_commands(script_config_cmds);
 	script_create_commands(script_log_cmds);
Index: eggdrop1.9/modules/script/scriptnet.c
diff -u eggdrop1.9/modules/script/scriptnet.c:1.11 eggdrop1.9/modules/script/scriptnet.c:1.12
--- eggdrop1.9/modules/script/scriptnet.c:1.11	Sun Aug 20 10:23:05 2006
+++ eggdrop1.9/modules/script/scriptnet.c	Thu Sep 13 17:20:57 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: scriptnet.c,v 1.11 2006-08-20 15:23:05 sven Exp $";
+static const char rcsid[] = "$Id: scriptnet.c,v 1.12 2007-09-13 22:20:57 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -56,15 +56,53 @@
 static int on_newclient(void *client_data, int idx, int newidx, const char *peer_ip, int peer_port);
 static int on_read(void *client_data, int idx, char *data, int len);
 static int on_written(void *client_data, int idx, int len, int remaining);
-static int on_delete(void *client_data, int idx);
+static int on_delete(event_owner_t *owner, void *client_data);
 
 static sockbuf_handler_t sock_handler = {
 	"script",
 	on_connect, on_eof, on_newclient,
-	on_read, on_written,
+	on_read, on_written
+};
+
+event_owner_t socket_owner = {
+	"script", NULL,
+	NULL, NULL,
 	on_delete
 };
 
+void script_event_cleanup(egg_module_t *module) {
+	script_net_info_t *i, *next;
+
+	for (i = script_net_info_head; i; i = next) {
+		next = i->next;
+		if (i->on_connect && i->on_connect->owner && i->on_connect->owner->module == module) {
+			if (i->on_connect->owner->on_delete) i->on_connect->owner->on_delete(i->on_connect->owner, i->on_connect);
+			i->on_connect = NULL;
+		}
+		if (i->on_eof && i->on_eof->owner && i->on_eof->owner->module == module) {
+			if (i->on_eof->owner->on_delete) i->on_eof->owner->on_delete(i->on_eof->owner, i->on_eof);
+			i->on_eof = NULL;
+		}
+		if (i->on_newclient && i->on_newclient->owner && i->on_newclient->owner->module == module) {
+			if (i->on_newclient->owner->on_delete) i->on_newclient->owner->on_delete(i->on_newclient->owner, i->on_newclient);
+			i->on_newclient = NULL;
+		}
+		if (i->on_read && i->on_read->owner && i->on_read->owner->module == module) {
+			if (i->on_read->owner->on_delete) i->on_read->owner->on_delete(i->on_read->owner, i->on_read);
+			i->on_read = NULL;
+		}
+		if (i->on_written && i->on_written->owner && i->on_written->owner->module == module) {
+			if (i->on_written->owner->on_delete) i->on_written->owner->on_delete(i->on_written->owner, i->on_written);
+			i->on_written = NULL;
+		}
+		if (i->on_delete && i->on_delete->owner && i->on_delete->owner->module == module) {
+			if (i->on_delete->owner->on_delete) i->on_delete->owner->on_delete(i->on_delete->owner, i->on_delete);
+			i->on_delete = NULL;
+		}
+		if (!i->on_connect && !i->on_eof && !i->on_newclient && !i->on_read && !i->on_written && !i->on_delete) sockbuf_delete(i->idx);
+	}
+}
+
 /* Put an idx under script control. */
 static int script_net_takeover(int idx)
 {
@@ -73,7 +111,7 @@
 	info = calloc(1, sizeof(*info));
 	info->idx = idx;
 	script_net_info_add(info);
-	sockbuf_set_handler(info->idx, &sock_handler, info);
+	sockbuf_set_handler(info->idx, &sock_handler, info, &socket_owner);
 	return(0);
 }
 
@@ -288,7 +326,7 @@
 	return(0);
 }
 
-static int on_delete(void *client_data, int idx)
+static int on_delete(event_owner_t *owner, void *client_data)
 {
 	script_net_info_t *info = client_data;
 
@@ -299,7 +337,7 @@
 	if (info->on_written && info->on_written->owner && info->on_written->owner->on_delete) info->on_written->owner->on_delete(info->on_written->owner, info->on_written);
 
 	if (info->on_delete) {
-		info->on_delete->callback(info->on_delete, idx);
+		info->on_delete->callback(info->on_delete, info->idx);
 		if (info->on_delete && info->on_delete->owner && info->on_delete->owner->on_delete) info->on_delete->owner->on_delete(info->on_delete->owner, info->on_delete);
 	}
 	script_net_info_remove(info);
Index: eggdrop1.9/modules/server/dcc.c
diff -u eggdrop1.9/modules/server/dcc.c:1.26 eggdrop1.9/modules/server/dcc.c:1.27
--- eggdrop1.9/modules/server/dcc.c:1.26	Mon Sep 11 20:50:51 2006
+++ eggdrop1.9/modules/server/dcc.c	Thu Sep 13 17:20:57 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dcc.c,v 1.26 2006-09-12 01:50:51 sven Exp $";
+static const char rcsid[] = "$Id: dcc.c,v 1.27 2007-09-13 22:20:57 sven Exp $";
 #endif
 
 #include <unistd.h>
@@ -60,7 +60,7 @@
 static dcc_send_t *dcc_recv_head = NULL;
 
 static int dcc_listen_newclient(void *client_data, int idx, int newidx, const char *peer_ip, int peer_port);
-static int dcc_listen_delete(void *client_data, int idx);
+static int dcc_listen_delete(event_owner_t *owner, void *client_data);
 static int dcc_listen_timeout(void *client_data);
 static int dcc_chat_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
 static int dcc_chat_eof(void *client_data, int idx, int err, const char *errmsg);
@@ -78,11 +78,16 @@
 static int dcc_recv_delete(void *client_data, int idx);
 static void update_snapshot(dcc_send_t *send, int len);
 
+event_owner_t server_dcclistener_owner = {
+	"server", 0,
+	0, 0,
+	dcc_listen_delete
+};
+
 static sockbuf_handler_t dcc_listen_handler = {
 	"DCC listen",
 	NULL, NULL, dcc_listen_newclient,
-	NULL, NULL,
-	dcc_listen_delete
+	NULL, NULL
 };
 
 #define DCC_FILTER_LEVEL (SOCKBUF_LEVEL_TEXT_BUFFER + 100)
@@ -135,7 +140,7 @@
 	listen->serv = idx;
 	listen->port = port;
 
-	sockbuf_set_handler(idx, &dcc_listen_handler, listen);
+	sockbuf_set_handler(idx, &dcc_listen_handler, listen, &server_dcclistener_owner);
 
 	/* See if they want the default timeout. */
 	if (!timeout) timeout = server_config.dcc_timeout;
@@ -195,7 +200,7 @@
 	return(0);
 }
 
-static int dcc_listen_delete(void *client_data, int idx)
+static int dcc_listen_delete(event_owner_t *owner, void *client_data)
 {
 	dcc_listen_t *listen = client_data;
 
Index: eggdrop1.9/modules/server/server.c
diff -u eggdrop1.9/modules/server/server.c:1.67 eggdrop1.9/modules/server/server.c:1.68
--- eggdrop1.9/modules/server/server.c:1.67	Sat Jan 13 06:23:40 2007
+++ eggdrop1.9/modules/server/server.c	Thu Sep 13 17:20:57 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: server.c,v 1.67 2007-01-13 12:23:40 sven Exp $";
+static const char rcsid[] = "$Id: server.c,v 1.68 2007-09-13 22:20:57 sven Exp $";
 #endif
 
 #include "server.h"
@@ -309,7 +309,7 @@
 
 int start(egg_module_t *modinfo)
 {
-	server_owner.module = modinfo;
+	server_owner.module = server_dcclistener_owner.module = modinfo;
 
 	modinfo->name = "server";
 	modinfo->author = "eggdev";
Index: eggdrop1.9/modules/server/server.h
diff -u eggdrop1.9/modules/server/server.h:1.26 eggdrop1.9/modules/server/server.h:1.27
--- eggdrop1.9/modules/server/server.h:1.26	Wed Dec 28 11:27:31 2005
+++ eggdrop1.9/modules/server/server.h	Thu Sep 13 17:20:58 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: server.h,v 1.26 2005-12-28 17:27:31 sven Exp $
+ * $Id: server.h,v 1.27 2007-09-13 22:20:58 sven Exp $
  */
 
 #ifndef _EGG_MOD_SERVER_SERVER_H_
@@ -102,7 +102,7 @@
 
 extern server_config_t server_config;
 extern current_server_t current_server;
-extern event_owner_t server_owner;
+extern event_owner_t server_owner, server_dcclistener_owner;
 
 extern int server_support(const char *name, const char **value);
 extern void *server_get_api();
Index: eggdrop1.9/modules/server/servsock.c
diff -u eggdrop1.9/modules/server/servsock.c:1.25 eggdrop1.9/modules/server/servsock.c:1.26
--- eggdrop1.9/modules/server/servsock.c:1.25	Mon Jun 20 21:55:34 2005
+++ eggdrop1.9/modules/server/servsock.c	Thu Sep 13 17:20:58 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: servsock.c,v 1.25 2005-06-21 02:55:34 stdarg Exp $";
+static const char rcsid[] = "$Id: servsock.c,v 1.26 2007-09-13 22:20:58 sven Exp $";
 #endif
 
 #include "server.h"
@@ -30,13 +30,11 @@
 static int server_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
 static int server_on_eof(void *client_data, int idx, int err, const char *errmsg);
 static int server_on_read(void *client_data, int idx, char *text, int len);
-static int server_on_delete(void *client_data, int idx);
 
 static sockbuf_handler_t server_handler = {
 	"server",
 	server_on_connect, server_on_eof, NULL,
-	server_on_read, NULL,
-	server_on_delete
+	server_on_read, NULL
 };
 
 /**********************************************************************
@@ -66,7 +64,7 @@
 	if (current_server.idx < 0) {
 		putlog(LOG_SERV, "*", _("Error connecting to server."));
 	}
-	sockbuf_set_handler(current_server.idx, &server_handler, NULL);
+	sockbuf_set_handler(current_server.idx, &server_handler, NULL, NULL);
 }
 
 /* Close the current server connection. */
@@ -156,8 +154,3 @@
 	server_parse_input(text);
 	return(0);
 }
-
-static int server_on_delete(void *client_data, int idx)
-{
-	return(0);
-}
Index: eggdrop1.9/modules/telnetparty/telnetparty.c
diff -u eggdrop1.9/modules/telnetparty/telnetparty.c:1.25 eggdrop1.9/modules/telnetparty/telnetparty.c:1.26
--- eggdrop1.9/modules/telnetparty/telnetparty.c:1.25	Sat Apr 14 10:21:13 2007
+++ eggdrop1.9/modules/telnetparty/telnetparty.c	Thu Sep 13 17:20:58 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: telnetparty.c,v 1.25 2007-04-14 15:21:13 sven Exp $";
+static const char rcsid[] = "$Id: telnetparty.c,v 1.26 2007-09-13 22:20:58 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -47,7 +47,7 @@
 static int telnet_on_newclient(void *client_data, int idx, int newidx, const char *peer_ip, int peer_port);
 static int telnet_on_read(void *client_data, int idx, char *data, int len);
 static int telnet_on_eof(void *client_data, int idx, int err, const char *errmsg);
-static int telnet_on_delete(void *client_data, int idx);
+static int telnet_on_delete(event_owner_t *owner, void *client_data);
 static int telnet_filter_read(void *client_data, int idx, char *data, int len);
 static int telnet_filter_write(void *client_data, int idx, const char *data, int len);
 static int telnet_filter_delete(void *client_data, int idx);
@@ -63,6 +63,12 @@
 	0
 };
 
+static event_owner_t telnet_sockbuf_owner = {
+	"telnetparty", 0,
+	0, 0,
+	telnet_on_delete
+};
+
 static event_owner_t telnet_partymember_owner = {
 	"telnetparty", 0,
 	0, 0,
@@ -87,15 +93,14 @@
 static sockbuf_handler_t client_handler = {
 	"telnet",
 	NULL, telnet_on_eof, NULL,
-	telnet_on_read, NULL,
-	telnet_on_delete
+	telnet_on_read, NULL
 };
 
 int telnet_init()
 {	
 	/* Open our listening socket. */
 	telnet_idx = egg_server(telnet_config.vhost, telnet_config.port, &telnet_port);
-	sockbuf_set_handler(telnet_idx, &server_handler, NULL);
+	sockbuf_set_handler(telnet_idx, &server_handler, NULL, NULL);
 	
 	return(0);
 }
@@ -317,7 +322,7 @@
 	session->port = peer_port;
 	session->idx = newidx;
 
-	sockbuf_set_handler(newidx, &client_handler, session);
+	sockbuf_set_handler(newidx, &client_handler, session, &telnet_sockbuf_owner);
 	sockbuf_attach_filter(newidx, &telnet_filter, session);
 	linemode_on(newidx);
 
@@ -456,7 +461,7 @@
 	return(0);
 }
 
-static int telnet_on_delete(void *client_data, int idx)
+static int telnet_on_delete(event_owner_t *owner, void *client_data)
 {
 	telnet_session_t *session = client_data;
 
@@ -643,7 +648,7 @@
 {
 	void *config_root;
 
-	telnet_generic_owner.module = telnet_partymember_owner.module = modinfo;
+	telnet_generic_owner.module = telnet_sockbuf_owner.module = telnet_partymember_owner.module = modinfo;
 	modinfo->name = "telnetparty";
 	modinfo->author = "eggdev";
 	modinfo->version = "1.0.0";
Index: eggdrop1.9/src/terminal.c
diff -u eggdrop1.9/src/terminal.c:1.10 eggdrop1.9/src/terminal.c:1.11
--- eggdrop1.9/src/terminal.c:1.10	Sun Jun  3 18:43:46 2007
+++ eggdrop1.9/src/terminal.c	Thu Sep 13 17:20:58 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: terminal.c,v 1.10 2007-06-03 23:43:46 sven Exp $";
+static const char rcsid[] = "$Id: terminal.c,v 1.11 2007-09-13 22:20:58 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>			/* partyline_*		*/
@@ -41,7 +41,6 @@
 	NULL,
 	NULL,
 	on_read,
-	NULL,
 	NULL
 };
 
@@ -74,7 +73,7 @@
 	/* Connect an idx to stdin. */
 	terminal_session.in_idx = sockbuf_new();
 	sockbuf_set_sock(terminal_session.in_idx, dup(fileno(stdin)), SOCKBUF_CLIENT);
-	sockbuf_set_handler(terminal_session.in_idx, &terminal_sockbuf_handler, NULL);
+	sockbuf_set_handler(terminal_session.in_idx, &terminal_sockbuf_handler, NULL, NULL);
 	linemode_on(terminal_session.in_idx);
 
 	/* And one for stdout. */
----------------------- End of diff -----------------------



More information about the Changes mailing list