[cvslog] (2007-04-18 01:46:03 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Tue Apr 17 19:46:03 CST 2007


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2007-04-18 01:46:02 UTC
Commited by: sven

Modified files:
     lib/eggdrop/botnet.c lib/eggdrop/botnet.h lib/eggdrop/partychan.c
     lib/eggdrop/partymember.c modules/oldbotnet/events.c
     modules/oldbotnet/oldbotnet.c

Log message:

More oldbotnet stuff, bugfixes, features.
Nearly complete support, but not yet ...

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/botnet.c
diff -u eggdrop1.9/lib/eggdrop/botnet.c:1.6 eggdrop1.9/lib/eggdrop/botnet.c:1.7
--- eggdrop1.9/lib/eggdrop/botnet.c:1.6	Sat Apr 14 10:21:11 2007
+++ eggdrop1.9/lib/eggdrop/botnet.c	Tue Apr 17 20:45:52 2007
@@ -28,7 +28,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: botnet.c,v 1.6 2007-04-14 15:21:11 sven Exp $";
+static const char rcsid[] = "$Id: botnet.c,v 1.7 2007-04-18 01:45:52 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -122,6 +122,9 @@
 
 static bind_table_t *BT_bot;
 
+/*! \todo Document me */
+
+static bind_table_t *BT_extension;
 /*!
  * \brief Inits the whole botnet stuff
  *
@@ -140,7 +143,8 @@
 	BT_request_link = bind_table_add(BTN_BOTNET_REQUEST_LINK, 2, "Us", 0, BIND_BREAKABLE);
 	BT_link = bind_table_add(BTN_BOTNET_LINK, 1, "B", 0, BIND_STACKABLE);
 	BT_disc = bind_table_add(BTN_BOTNET_DISC, 3, "BBs", 0, BIND_STACKABLE);
-	BT_bot = bind_table_add(BTN_BOTNET_BOT, 2, "Bss", 0, 0);
+	BT_bot = bind_table_add(BTN_BOTNET_BOT, 3, "Bss", 0, 0);
+	BT_extension = bind_table_add(BTN_BOTNET_EXTENSION, 3, "Ess", 0, 0);
 	return 0;
 }
 
@@ -165,6 +169,8 @@
 	bind_table_del(BT_request_link);
 	bind_table_del(BT_link);
 	bind_table_del(BT_disc);
+	bind_table_del(BT_bot);
+	bind_table_del(BT_extension);
 
 	/* force a garbage run since we might have some partymembers 
  	 * marked as deleted and w/o a garbage_run we may not destroy
@@ -715,7 +721,7 @@
 		if (dir->handler && dir->handler->on_botmsg) dir->handler->on_botmsg(dir->client_data, src, dst, command, text, len);
 		return;
 	}
-	bind_check(BT_bot, NULL, command, command, text);
+	bind_check(BT_bot, NULL, command, src, command, text);
 }
 
 void botnet_botbroadcast(botnet_bot_t *src, const char *command, const char *text, int len)
@@ -725,10 +731,31 @@
 	if (!text) len = 0;
 	else if (len < 0) len = strlen(text);
 
-	bind_check(BT_bot, NULL, command, command, text);
+	bind_check(BT_bot, NULL, command, src, command, text);
 
 	for (tmp = localbot_head; tmp; tmp = tmp->next_local) {
 		if (tmp->flags & BOT_DELETED || (src && tmp == src->direction)) continue;
 		if (tmp->handler && tmp->handler->on_botbroadcast) tmp->handler->on_botbroadcast(tmp->client_data, src, command, text, len);
 	}
 }
+
+void botnet_extension(int mode, botnet_entity_t *src, botnet_bot_t *dst, egg_module_t *mod, const char *cmd, const char *text, int len)
+{
+	botnet_bot_t *tmp, *srcbot = src->what == ENTITY_BOT ? src->bot : src->user->bot;
+
+	if (!text) len = 0;
+	else if (len < 0) len = strlen(text);
+
+	if (!dst) bind_check(BT_extension, NULL, cmd, src, cmd, text);
+	if (mode == EXTENSION_ONE) {
+		if (dst && dst->direction->handler && dst->direction->handler->on_extension)
+			dst->direction->handler->on_extension(dst->direction->client_data, src, dst, cmd, text, len);
+		return;
+	}
+
+	for (tmp = localbot_head; tmp; tmp = tmp->next_local) {
+		if (tmp->flags & BOT_DELETED || (srcbot && tmp == srcbot->direction)) continue;
+		if (mod && !(tmp->owner && tmp->owner->module == mod)) continue;
+		dst->direction->handler->on_extension(dst->direction->client_data, src, mode == EXTENSION_ALL ? NULL : tmp, cmd, text, len);
+	}
+}
Index: eggdrop1.9/lib/eggdrop/botnet.h
diff -u eggdrop1.9/lib/eggdrop/botnet.h:1.3 eggdrop1.9/lib/eggdrop/botnet.h:1.4
--- eggdrop1.9/lib/eggdrop/botnet.h:1.3	Sat Apr 14 10:21:11 2007
+++ eggdrop1.9/lib/eggdrop/botnet.h	Tue Apr 17 20:45:52 2007
@@ -16,20 +16,26 @@
  * 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.3 2007-04-14 15:21:11 sven Exp $
+ * $Id: botnet.h,v 1.4 2007-04-18 01:45:52 sven Exp $
  */
 
 #ifndef _EGG_BOTNET_H_
 #define _EGG_BOTNET_H_
 
 #define BTN_BOTNET_REQUEST_LINK "request-link"
-#define BTN_BOTNET_LINK "link"
-#define BTN_BOTNET_DISC "disc"
-#define BTN_BOTNET_BOT  "bot"
+#define BTN_BOTNET_LINK         "link"
+#define BTN_BOTNET_DISC         "disc"
+#define BTN_BOTNET_BOT          "bot"
+#define BTN_BOTNET_EXTENSION    "ext"
+
+#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_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 *oldnick, const char *newnick);
 	int (*on_quit)(void *client_data, partymember_t *src, const char *text, int len);
 
@@ -44,7 +50,7 @@
 	int (*on_unlink)(void *client_data, botnet_entity_t *from, struct botnet_bot *bot, const char *reason);
 	int (*on_botmsg)(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len);
 	int (*on_botbroadcast)(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len);
-	int (*on_extension)(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, egg_module_t *mod, const char *cmd, const char *text, int len);
+	int (*on_extension)(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len);
 
 	/* Module/Script responsible for this bot */
 } botnet_handler_t;
@@ -154,6 +160,6 @@
 void botnet_member_quit(partymember_t *p, const char *reason, int len);
 void botnet_botmsg(botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len);
 void botnet_botbroadcast(botnet_bot_t *src, const char *command, const char *text, int len);
-void botnet_extension(botnet_entity_t *src, botnet_bot_t *dst, egg_module_t *mod, const char *cmd, const char *text, int len);
+void botnet_extension(int mode, botnet_entity_t *src, botnet_bot_t *dst, egg_module_t *mod, const char *cmd, const char *text, int len);
 
 #endif /* !_EGG_BOTNET_H_ */
Index: eggdrop1.9/lib/eggdrop/partychan.c
diff -u eggdrop1.9/lib/eggdrop/partychan.c:1.24 eggdrop1.9/lib/eggdrop/partychan.c:1.25
--- eggdrop1.9/lib/eggdrop/partychan.c:1.24	Sat Apr 14 10:21:11 2007
+++ eggdrop1.9/lib/eggdrop/partychan.c	Tue Apr 17 20:45:52 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: partychan.c,v 1.24 2007-04-14 15:21:11 sven Exp $";
+static const char rcsid[] = "$Id: partychan.c,v 1.25 2007-04-18 01:45:52 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -332,7 +332,7 @@
 	/* Trigger the partyline channel part bind. */
 	bind_check(BT_partypart, NULL, NULL, chan->name, chan->cid, p, text, len);
 
-	if (p->handler->on_part) (p->handler->on_part)(p->client_data, chan, p, text, len);
+	if (p->handler && p->handler->on_part) p->handler->on_part(p->client_data, chan, p, text, len);
 
 	/* Send out the part event to the members. */
 	for (i = 0; i < chan->nmembers; i++) {
Index: eggdrop1.9/lib/eggdrop/partymember.c
diff -u eggdrop1.9/lib/eggdrop/partymember.c:1.25 eggdrop1.9/lib/eggdrop/partymember.c:1.26
--- eggdrop1.9/lib/eggdrop/partymember.c:1.25	Sat Apr 14 10:21:12 2007
+++ eggdrop1.9/lib/eggdrop/partymember.c	Tue Apr 17 20:45:52 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: partymember.c,v 1.25 2007-04-14 15:21:12 sven Exp $";
+static const char rcsid[] = "$Id: partymember.c,v 1.26 2007-04-18 01:45:52 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -118,7 +118,7 @@
 	partymember_t *mem;
 
 	mem = calloc(1, sizeof(*mem));
-	if (id == -1) id = partymember_get_id(NULL);
+	if (id == -1) id = partymember_get_id(bot);
 	mem->id = id;
 	mem->user = user;
 	mem->bot = bot;
@@ -339,7 +339,9 @@
 	if (len < 0) len = strlen(text);
 	if (p->handler && p->handler->on_privmsg)
 		p->handler->on_privmsg(p->client_data, p, src, text, len);
-	return(0);
+	else if (p->bot && p->bot->direction->handler && p->bot->direction->handler->on_privmsg)
+		p->bot->direction->handler->on_privmsg(p->bot->direction->client_data, src, p, text, len);
+	return 0;
 }
 
 int partymember_local_broadcast(botnet_entity_t *src, const char *text, int len)
Index: eggdrop1.9/modules/oldbotnet/events.c
diff -u eggdrop1.9/modules/oldbotnet/events.c:1.9 eggdrop1.9/modules/oldbotnet/events.c:1.10
--- eggdrop1.9/modules/oldbotnet/events.c:1.9	Sat Apr 14 10:21:13 2007
+++ eggdrop1.9/modules/oldbotnet/events.c	Tue Apr 17 20:45:52 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: events.c,v 1.9 2007-04-14 15:21:13 sven Exp $";
+static const char rcsid[] = "$Id: events.c,v 1.10 2007-04-18 01:45:52 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -27,19 +27,22 @@
 
 /* botnet callbacks */
 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_quit(void *client_data, partymember_t *src, const char *text, int len);
 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len);
 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking);
+static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *reason, int len);
 static int on_new_bot(void *client_data, botnet_bot_t *bot, int linking);
 static int on_lost_bot(void *client_data, botnet_bot_t *bot, const char *reason);
 static int on_unlink(void *client_data, botnet_entity_t *from, botnet_bot_t *bot, const char *reason);
 static int on_botmsg(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len);
 static int on_botbroadcast(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len);
+static int on_extension(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len);
 
 botnet_handler_t bothandler = {
-	on_bcast, NULL, on_quit,
-	on_chanmsg, on_join, NULL,
-	on_new_bot, on_lost_bot, on_unlink, on_botmsg, on_botbroadcast, NULL
+	on_bcast, on_privmsg, NULL, on_quit,
+	on_chanmsg, on_join, on_part,
+	on_new_bot, on_lost_bot, on_unlink, on_botmsg, on_botbroadcast, on_extension
 };
 
 static int tobase64[] = {
@@ -108,6 +111,15 @@
 	return 0;
 }
 
+static int on_privmsg(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len)
+{
+	oldbotnet_t *obot = client_data;
+
+	egg_iprintf(obot->idx, "p %s %s %s\n", src->full_id_name, dst->full_id_name, text);
+
+	return 0;
+}
+
 static int on_quit(void *client_data, partymember_t *src, const char *text, int len)
 {
 	oldbotnet_t *obot = client_data;
@@ -136,6 +148,25 @@
 
 	cid = strdup(itob(assoc_get_id(chan->name)));
 	egg_iprintf(obot->idx, "j %s%s %s %s %c%s %s@%s\n", linking ? "!" : "", src->bot ? src->bot->name : botnet_get_name(), src->nick, cid, '*', itob(src->id), src->ident, src->host);
+	free(cid);
+
+	return 0;
+}
+
+static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *reason, int len)
+{
+	oldbotnet_t *obot = client_data;
+
+	if (!src->nchannels) {
+		if (reason && *reason) egg_iprintf(obot->idx, "pt %s %s %s %s\n", src->bot ? src->bot->name : botnet_get_name(), src->nick, itob(src->id), reason);
+		else egg_iprintf(obot->idx, "pt %s %s %d\n", src->bot ? src->bot->name : botnet_get_name(), src->nick, itob(src->id));
+	} else {
+		char *cid;
+
+		cid = strdup(itob(assoc_get_id(src->channels[src->nchannels - 1]->name)));
+		egg_iprintf(obot->idx, "j %s %s %s %c%s %s@%s\n", src->bot ? src->bot->name : botnet_get_name(), src->nick, cid, '*', itob(src->id), src->ident, src->host);
+		free(cid);
+	}
 
 	return 0;
 }
@@ -153,7 +184,7 @@
 {
 	oldbotnet_t *obot = client_data;
 
-	if (bot == obot->bot) egg_iprintf(obot->idx, "bye %s", reason);
+	if (bot == obot->bot) egg_iprintf(obot->idx, "bye %s\n", reason);
 	else egg_iprintf(obot->idx, "un %s %s\n", bot->name, reason);
 
 	return 0;
@@ -173,8 +204,8 @@
 	const char *srcname = src ? src->name : botnet_get_name();
 	oldbotnet_t *obot = client_data;
 
-	if (text && len > 0) egg_iprintf(obot->idx, "z %s %s %s", srcname, command, text);
-	else egg_iprintf(obot->idx, "z %s %s", srcname, command);
+	if (text && len > 0) egg_iprintf(obot->idx, "z %s %s %s\n", srcname, command, text);
+	else egg_iprintf(obot->idx, "z %s %s\n", srcname, command);
 
 	return 0;
 }
@@ -184,8 +215,21 @@
 	const char *srcname = src ? src->name : botnet_get_name();
 	oldbotnet_t *obot = client_data;
 
-	if (text && len > 0) egg_iprintf(obot->idx, "zb %s %s %s %s", srcname, dst->name, command, text);
-	else egg_iprintf(obot->idx, "zb %s %s %s", srcname, dst->name, command);
+	if (text && len > 0) egg_iprintf(obot->idx, "zb %s %s %s %s\n", srcname, dst->name, command, text);
+	else egg_iprintf(obot->idx, "zb %s %s %s\n", srcname, dst->name, command);
+
+	return 0;
+}
+
+static int on_extension(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len)
+{
+	oldbotnet_t *obot = client_data;
+
+	if (!strcmp(cmd, "note")) {
+		egg_iprintf(obot->idx, "p %s %s\n", src->full_id_name, text);
+	} else if (!strcmp(cmd, "who")) {
+		egg_iprintf(obot->idx, "w %s %s %s\n", src->full_id_name, dst->name, text);
+	}
 
 	return 0;
 }
Index: eggdrop1.9/modules/oldbotnet/oldbotnet.c
diff -u eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.16 eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.17
--- eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.16	Sat Apr 14 10:21:13 2007
+++ eggdrop1.9/modules/oldbotnet/oldbotnet.c	Tue Apr 17 20:45:52 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: oldbotnet.c,v 1.16 2007-04-14 15:21:13 sven Exp $";
+static const char rcsid[] = "$Id: oldbotnet.c,v 1.17 2007-04-18 01:45:52 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -45,10 +45,13 @@
 static int got_part(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_chat(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_nlinked(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_unlink(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_unlinked(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_bye(botnet_bot_t *bot, const char *cmd, const char *text);
 static int got_endlink(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_thisbot(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_privmsg(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_who(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_botmsg(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_botbroadcast(botnet_bot_t *bot, const char *cmd, const char *next);
 
@@ -101,40 +104,58 @@
 static bind_list_t obot_binds[] = {
 	{NULL, "a", got_actchan},
 	{NULL, "actchan", got_actchan},
+
 	{NULL, "bye", got_bye},
+
 	{NULL, "c", got_chat},
 	{NULL, "chan", got_chat},
+
 	{NULL, "ct", got_bcast}, 
 	{NULL, "chat", got_bcast},
+
 	{NULL, "el", got_endlink},
+
 	{NULL, "h", got_handshake},
 	{NULL, "handshake", got_handshake},
+
 	{NULL, "i", got_idle},
 	{NULL, "idle", got_idle},
+
 	{NULL, "j", got_join},
 	{NULL, "join", got_join},
+
 	{NULL, "n", got_nlinked},
 	{NULL, "nlinked", got_nlinked},
+
+	{NULL, "p", got_privmsg},
+	{NULL, "priv", got_privmsg},
+
 	{NULL, "pi", got_ping},
 	{NULL, "ping", got_ping},
+
 	{NULL, "pt", got_part},
 	{NULL, "part", got_part},
+
 	{NULL, "tb", got_thisbot},
 	{NULL, "thisbot", got_thisbot},
+
+	{NULL, "ul", got_unlink},
+	{NULL, "unlink", got_unlink},
+
 	{NULL, "un", got_unlinked},
 	{NULL, "unlinked", got_unlinked},
+
+	{NULL, "w", got_who},
+	{NULL, "who", got_who},
+
 	{NULL, "z", got_botmsg},
 	{NULL, "zapf", got_botmsg},
+
 	{NULL, "zb", got_botbroadcast},
 	{NULL, "zapf-broad", got_botbroadcast},
 	{0}
 };
 
-static partyline_event_t oldbotnet_party = {
-	NULL, NULL, NULL,
-	NULL, NULL, NULL
-};
-
 static sockbuf_handler_t oldbotnet_handler = {
 	"oldbotnet",
 	oldbotnet_on_connect, oldbotnet_on_eof, NULL,
@@ -193,15 +214,6 @@
 	return a->id;
 }
 
-static int oldbotnet_init()
-{
-	BT_obot = bind_table_add("obot", 3, "Bss", MATCH_MASK, BIND_STACKABLE);	/* DDD */
-	bind_add_list("obot", obot_binds);
-	bind_add_list("party", party_binds);
-	bind_add_simple(BTN_BOTNET_REQUEST_LINK, NULL, "old-eggdrop", do_link);
-	return(0);
-}
-
 static char base64to[256] = {
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -466,6 +478,7 @@
 	botnet_bot_t *srcbot;
 
 	if (egg_get_word(text, &text, &srcname)) return BIND_RET_BREAK;
+	while (isspace(*text)) text++;
 
 	srcbot = botnet_lookup(srcname);
 	free(srcname);
@@ -557,6 +570,86 @@
 	return BIND_RET_BREAK;
 }
 
+static int get_entity(botnet_bot_t *bot, botnet_entity_t *src, char *word)
+{
+	if (!strchr(word, '@')) {
+		botnet_bot_t *b = botnet_lookup(word);
+		if (botnet_check_direction(bot, b)) return -1;
+		set_bot_entity(src, b);
+		return 0;
+	}
+
+	partymember_t *p = partymember_lookup(word, NULL, -1);
+	if (p) {
+		set_user_entity(src, p);
+		return 0;
+	}
+
+	int id = -1;
+	char *nick = word, *ptr = strchr(word, '@');
+	botnet_bot_t *srcbot = botnet_lookup(ptr + 1);
+
+	if (botnet_check_direction(bot, srcbot)) return -1;
+	*ptr = 0;
+	ptr = strchr(word, ':');
+	if (ptr) {
+		*ptr = 0;
+		id = atoi(word);
+		nick = ptr + 1;
+	}
+	p = partymember_new(id, NULL, srcbot, nick, "temp", "user.on.an.old.bot", NULL, NULL, &generic_owner);
+	set_user_entity(src, p);
+	return 1;
+}
+
+/*!
+ * \brief Remote request to unlink a bot
+ *
+ * Someone on another bot wants us or a bot further downstream to unlink from
+ * a bot. In any case, the details are handled by botnet_unlink(), we just
+ * pass it on.
+ *
+ * \param bot The bot the msg came from.
+ * \param cmd "unlink" or "ul".
+ * \param next The parameters.
+ *
+ * \format \b unlink from at bot dst bot-to-kill [reason]
+ */
+
+static int got_unlink(botnet_bot_t *bot, const char *cmd, const char *text)
+{
+	int n;
+	char *word[3];
+	const char *reason;
+	botnet_bot_t *target;
+	botnet_entity_t src;
+
+	n = egg_get_word_array(text, &text, word, 3);
+	if (n != 3) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+	while (isspace(*text)) text++;
+	if (text && *text) reason = text;
+	else reason = "No reason.";
+
+	target = botnet_lookup(word[2]);
+
+	if (!target) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	n = get_entity(bot, &src, word[0]);
+	if (n < 0) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	botnet_unlink(&src, target, reason);
+	return BIND_RET_BREAK;
+}
+
 static int got_unlinked(botnet_bot_t *bot, const char *cmd, const char *text)
 {
 	char *lostname;
@@ -631,7 +724,7 @@
 		}
 		else host = word[0];
 
-		p = partymember_new(id, NULL, frombot, word[1], ident, host, &oldbotnet_party, NULL, &generic_owner);
+		p = partymember_new(id, NULL, frombot, word[1], ident, host, NULL, NULL, &generic_owner);
 	}
 	partychan_join_name(assoc_get_name(btoi(word[2])), p, linking);
 	egg_free_word_array(word, 5);
@@ -651,6 +744,7 @@
 		egg_free_word_array(word, 3);
 		return BIND_RET_BREAK;
 	}
+	while (isspace(*next)) next++;
 	if (next && *next) reason = next;
 	else reason = "No reason.";
 
@@ -667,6 +761,62 @@
 	return BIND_RET_BREAK;
 }
 
+/*!
+ * \brief Private message for someone.
+ *
+ * A partymember or a bot have a private message for someone, local or remote.
+ * In any case, the details are handled by insert_here(), we just pass it on.
+ *
+ * \param bot The bot the msg came from.
+ * \param cmd "priv" or "p".
+ * \param next The parameters.
+ *
+ * \format \b priv from at bot dst message
+ */
+
+static int got_privmsg(botnet_bot_t *bot, const char *cmd, const char *next)
+{
+	int n;
+	char *word[2];
+	const char *original = next;
+	botnet_entity_t src;
+	partymember_t *dst;
+
+	n = egg_get_word_array(next, &next, word, 2);
+	if (n != 2) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+	while (isspace(*next)) next++;
+	if (!next || !*next) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	n = get_entity(bot, &src, word[0]);
+	if (n < 0) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	dst = partymember_lookup(word[1], NULL, -1);
+
+	if (!dst) {
+		char *p = strchr(word[1], '@');
+		if (p) {
+			botnet_bot_t *dstbot = botnet_lookup(p + 1);
+			if (dstbot || !strcmp(p + 1, botnet_get_name())) {
+				botnet_extension(EXTENSION_ONE, &src, dstbot, NULL, "note", strchr(original, ' ') + 1, -1);
+			}
+		}
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	partymember_msg(dst, &src, next, -1);
+	return BIND_RET_BREAK;
+}
+
 static int got_chat(botnet_bot_t *bot, const char *cmd, const char *next)
 {
 	char *word[2];
@@ -746,6 +896,7 @@
 		return BIND_RET_BREAK;
 	}
 
+	while (isspace(*next)) next++;
 	if (!dst && !strcmp(word[2], "assoc") && next && *next) got_assoc(src, next);
 	botnet_botmsg(src, dst, word[2], next, -1);
 	egg_free_word_array(word, 3);
@@ -785,11 +936,43 @@
 		return BIND_RET_BREAK;
 	}
 
+	while (isspace(*next)) next++;
 	botnet_botbroadcast(src, word[1], next, -1);
 	egg_free_word_array(word, 2);
 	return BIND_RET_BREAK;
 }
 
+static int got_who(botnet_bot_t *bot, const char *cmd, const char *next)
+{
+	int n;
+	char *word[2];
+	botnet_entity_t src;
+	botnet_bot_t *dst;
+
+	n = egg_get_word_array(next, &next, word, 2);
+	if (n != 2) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	dst = botnet_lookup(word[1]);
+	if (!dst && strcmp(word[1], botnet_get_name())) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	n = get_entity(bot, &src, word[0]);
+	if (n < 0 || src.what == ENTITY_BOT || botnet_check_direction(bot, src.user->bot)) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	while (isspace(*next)) next++;
+	botnet_extension(EXTENSION_ONE, &src, dst, NULL, "who", next, -1);
+	egg_free_word_array(word, 2);
+	return BIND_RET_BREAK;
+}
+
 static int oldbotnet_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port)
 {
 	oldbotnet_t *data = client_data;
@@ -810,7 +993,7 @@
 
 	if (next) while (isspace(*next)) next++;
 
-	if (!strcasecmp(cmd, "error") || (!bot->connected && !strcasecmp(cmd, "bye"))) {
+	if (!strcasecmp(cmd, "e") || !strcasecmp(cmd, "error") || (!bot->connected && !strcasecmp(cmd, "bye"))) {
 		putlog(LOG_MISC, "*", _("Botnet error from %s: %s"), bot->user->handle, next);
 		if (bot->connected) botnet_delete(bot->bot, next);
 		else sockbuf_delete(bot->idx);
@@ -872,6 +1055,15 @@
 	return 0;
 }
 
+static int oldbotnet_init()
+{
+	BT_obot = bind_table_add("obot", 3, "Bss", MATCH_MASK, BIND_STACKABLE);
+	bind_add_list("obot", obot_binds);
+	bind_add_list("party", party_binds);
+	bind_add_simple(BTN_BOTNET_REQUEST_LINK, NULL, "old-eggdrop", do_link);
+	return 0;
+}
+
 static int oldbotnet_close(int why)
 {
 	assoc_t *a, *next;
@@ -882,7 +1074,13 @@
 		free(a);
 	} 
 	assocs.next = NULL;
-	return(0);
+
+	bind_table_del(BT_obot);
+	bind_rem_list("obot", obot_binds);
+	bind_rem_list("party", party_binds);
+	bind_rem_simple(BTN_BOTNET_REQUEST_LINK, NULL, "old-eggdrop", do_link);
+
+	return 0;
 }
 
 int oldbotnet_LTX_start(egg_module_t *modinfo)
----------------------- End of diff -----------------------



More information about the Changes mailing list