[cvslog] (2007-04-22 13:18:42 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Sun Apr 22 07:18:43 CST 2007


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2007-04-22 13:18:42 UTC
Commited by: sven

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

Log message:

 * Complete oldbotnet support expect for (user)file sharing.

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/botnet.c
diff -u eggdrop1.9/lib/eggdrop/botnet.c:1.7 eggdrop1.9/lib/eggdrop/botnet.c:1.8
--- eggdrop1.9/lib/eggdrop/botnet.c:1.7	Tue Apr 17 20:45:52 2007
+++ eggdrop1.9/lib/eggdrop/botnet.c	Sun Apr 22 08:18:31 2007
@@ -28,7 +28,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: botnet.c,v 1.7 2007-04-18 01:45:52 sven Exp $";
+static const char rcsid[] = "$Id: botnet.c,v 1.8 2007-04-22 13:18:31 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -37,6 +37,7 @@
 
 #define BOT_DELETED 1
 
+
 static char *botname;
 static char *default_botname = "eggdrop";
 
@@ -602,7 +603,7 @@
 int botnet_check_direction(botnet_bot_t *direction, botnet_bot_t *src)
 {
 	if (!src || src->direction != direction) {
-		putlog(LOG_MISC, "*", _("Fake message from %s rejected! (direction != %s)."), direction->name, src ? src->name : "non-existant bot");
+		putlog(LOG_MISC, "*", _("Fake message from %s rejected! (direction != %s)."), direction->name, src ? src->name : _("non-existent bot"));
 		return 1;
 	}
 	return 0;
@@ -629,14 +630,32 @@
 	return 0;
 }
 
-int botnet_link(user_t *user)
+int botnet_link(botnet_entity_t *src, botnet_bot_t *dst, const char *target)
 {
 	char *type;
+	user_t *user;
+	botnet_entity_t entity_me = bot_entity((botnet_bot_t *) 0);
+
+	if (dst) {
+		if (dst->direction->handler && dst->direction->handler->on_link)
+			dst->direction->handler->on_link(dst->direction->client_data, src, dst, target);
+		return 0;
+	}
 
-	if (!user_check_flags_str(user, NULL, "b")) return -1;
-	if (user_get_setting(user, NULL, "bot-type", &type)) return -2;
+	user = user_lookup_by_handle(target);
+	if (!user || !user_check_flags_str(user, NULL, "b")) {
+		if (src->what == ENTITY_PARTYMEMBER) partymember_msg(src->user, &entity_me, _("Can't link there: No such bot."), -1);
+		return -1;
+	}
+	if (user_get_setting(user, NULL, "bot-type", &type)) {
+		if (src->what == ENTITY_PARTYMEMBER) partymember_msg(src->user, &entity_me, _("Can't link there: Unknown bot type."), -1);
+		return -2;
+	}
 
-	if (!bind_check(BT_request_link, NULL, type, user, type)) return -3;
+	if (!bind_check(BT_request_link, NULL, type, user, type)) {
+		if (src->what == ENTITY_PARTYMEMBER) partymember_msg(src->user, &entity_me, _("Can't link there: Module not loaded."), -1);
+		return -3;
+	}
 
 	return 0;
 }
@@ -701,6 +720,16 @@
 	partymember_local_broadcast(src, text, len);
 }
 
+void botnet_set_nick(partymember_t *p, const char *oldnick)
+{
+	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_nick) tmp->handler->on_nick(tmp->client_data, p, oldnick);
+	}
+}
+
 void botnet_member_quit(partymember_t *p, const char *reason, int len)
 {
 	botnet_bot_t *tmp;
@@ -756,6 +785,7 @@
 	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);
+		if (tmp->handler && tmp->handler->on_extension)
+			tmp->handler->on_extension(tmp->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.4 eggdrop1.9/lib/eggdrop/botnet.h:1.5
--- eggdrop1.9/lib/eggdrop/botnet.h:1.4	Tue Apr 17 20:45:52 2007
+++ eggdrop1.9/lib/eggdrop/botnet.h	Sun Apr 22 08:18:32 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.4 2007-04-18 01:45:52 sven Exp $
+ * $Id: botnet.h,v 1.5 2007-04-22 13:18:32 sven Exp $
  */
 
 #ifndef _EGG_BOTNET_H_
@@ -36,7 +36,7 @@
 	/* 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_nick)(void *client_data, partymember_t *src, const char *newnick);
 	int (*on_quit)(void *client_data, partymember_t *src, const char *text, int len);
 
 	/* Channel events. */
@@ -45,9 +45,10 @@
 	int (*on_part)(void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len);
 
 	/* Botnet events. */
-	int (*on_new_bot)(void *client_data, struct botnet_bot *bot, int netburst);
-	int (*on_lost_bot)(void *client_data, struct botnet_bot *bot, const char *reason);
-	int (*on_unlink)(void *client_data, botnet_entity_t *from, struct botnet_bot *bot, const char *reason);
+	int (*on_new_bot)(void *client_data, botnet_bot_t *bot, int netburst);
+	int (*on_lost_bot)(void *client_data, botnet_bot_t *bot_t, const char *reason);
+	int (*on_link)(void *client_data, botnet_entity_t *from, botnet_bot_t *dst, const char *target);
+	int (*on_unlink)(void *client_data, botnet_entity_t *from, botnet_bot_t *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, const char *cmd, const char *text, int len);
@@ -148,7 +149,7 @@
 int botnet_delete_by_owner(struct egg_module *module, void *script);
 int botnet_delete(botnet_bot_t *bot, const char *reason);
 int botnet_unlink(botnet_entity_t *from, botnet_bot_t *bot, const char *reason);
-int botnet_link(user_t *user);
+int botnet_link(botnet_entity_t *src, botnet_bot_t *dst, const char *target);
 
 void botnet_replay_net(botnet_bot_t *bot);
 int botnet_check_direction(botnet_bot_t *direction, botnet_bot_t *src);
@@ -158,6 +159,7 @@
 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);
 void botnet_member_quit(partymember_t *p, const char *reason, int len);
+void botnet_set_nick(partymember_t *p, const char *oldnick);
 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(int mode, botnet_entity_t *src, botnet_bot_t *dst, egg_module_t *mod, const char *cmd, const char *text, int len);
Index: eggdrop1.9/lib/eggdrop/partymember.c
diff -u eggdrop1.9/lib/eggdrop/partymember.c:1.26 eggdrop1.9/lib/eggdrop/partymember.c:1.27
--- eggdrop1.9/lib/eggdrop/partymember.c:1.26	Tue Apr 17 20:45:52 2007
+++ eggdrop1.9/lib/eggdrop/partymember.c	Sun Apr 22 08:18:32 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: partymember.c,v 1.26 2007-04-18 01:45:52 sven Exp $";
+static const char rcsid[] = "$Id: partymember.c,v 1.27 2007-04-22 13:18:32 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -232,6 +232,7 @@
 	p->nick = strdup(nick);
 	if (p->handler && p->handler->on_nick)
 		(p->handler->on_nick)(p->client_data, p, oldnick, nick);
+	botnet_set_nick(p, oldnick);
 	p->flags |= PARTY_SELECTED;
 	common = partychan_get_common(p);
 	if (common) {
Index: eggdrop1.9/modules/oldbotnet/events.c
diff -u eggdrop1.9/modules/oldbotnet/events.c:1.10 eggdrop1.9/modules/oldbotnet/events.c:1.11
--- eggdrop1.9/modules/oldbotnet/events.c:1.10	Tue Apr 17 20:45:52 2007
+++ eggdrop1.9/modules/oldbotnet/events.c	Sun Apr 22 08:18:32 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: events.c,v 1.10 2007-04-18 01:45:52 sven Exp $";
+static const char rcsid[] = "$Id: events.c,v 1.11 2007-04-22 13:18:32 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -28,21 +28,23 @@
 /* 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_nick(void *client_data, partymember_t *src, const char *oldnick);
 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_link(void *client_data, botnet_entity_t *from, botnet_bot_t *dst, const char *target);
 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, on_privmsg, NULL, on_quit,
+	on_bcast, on_privmsg, on_nick, on_quit,
 	on_chanmsg, on_join, on_part,
-	on_new_bot, on_lost_bot, on_unlink, on_botmsg, on_botbroadcast, on_extension
+	on_new_bot, on_lost_bot, on_link, on_unlink, on_botmsg, on_botbroadcast, on_extension
 };
 
 static int tobase64[] = {
@@ -129,6 +131,15 @@
 	return 0;
 }
 
+static int on_nick(void *client_data, partymember_t *src, const char *oldnick)
+{
+	oldbotnet_t *obot = client_data;
+
+	egg_iprintf(obot->idx, "nc %s %s %s\n", src->bot ? src->bot->name : botnet_get_name(), itob(src->id), src->nick);
+
+	return 0;
+}
+
 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len)
 {
 	oldbotnet_t *obot = client_data;
@@ -190,11 +201,20 @@
 	return 0;
 }
 
+static int on_link(void *client_data, botnet_entity_t *from, struct botnet_bot *dst, const char *target)
+{
+	oldbotnet_t *obot = client_data;
+
+	egg_iprintf(obot->idx, "l %s %s %s\n", from->full_id_name, dst->name, target);
+
+	return 0;
+}
+
 static int on_unlink(void *client_data, botnet_entity_t *from, struct botnet_bot *bot, const char *reason)
 {
 	oldbotnet_t *obot = client_data;
 
-	egg_iprintf(obot->idx, "ul %s %s %s %s\n", from->full_name, bot->uplink->name, bot->name, reason);
+	egg_iprintf(obot->idx, "ul %s %s %s %s\n", from->full_id_name, bot->uplink->name, bot->name, reason);
 
 	return 0;
 }
@@ -229,6 +249,13 @@
 		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);
+	} else if (!strcmp(cmd, "motd")) {
+		egg_iprintf(obot->idx, "m %s %s\n", src->full_id_name, dst->name);
+	} else if (!strcmp(cmd, "versions")) {
+		egg_iprintf(obot->idx, "v %s %s %d:%s\n", src->user->bot->name, dst->name, src->user->id, src->user->nick);
+	} else if (!strcmp(cmd, "away")) {
+		if (*text) egg_iprintf(obot->idx, "aw %s %s %s\n", src->user->bot ? src->user->bot->name : botnet_get_name(), itob(src->user->id), text);
+		else egg_iprintf(obot->idx, "aw %s %s\n", src->user->bot ? src->user->bot->name : botnet_get_name(), itob(src->user->id));
 	}
 
 	return 0;
Index: eggdrop1.9/modules/oldbotnet/oldbotnet.c
diff -u eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.17 eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.18
--- eggdrop1.9/modules/oldbotnet/oldbotnet.c:1.17	Tue Apr 17 20:45:52 2007
+++ eggdrop1.9/modules/oldbotnet/oldbotnet.c	Sun Apr 22 08:18:32 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: oldbotnet.c,v 1.17 2007-04-18 01:45:52 sven Exp $";
+static const char rcsid[] = "$Id: oldbotnet.c,v 1.18 2007-04-22 13:18:32 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -37,23 +37,29 @@
 
 /* Oldbotnet commands. */
 static int got_actchan(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_away(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_bcast(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);
+static int got_bye(botnet_bot_t *bot, const char *cmd, const char *text);
+static int got_chat(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_endlink(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_handshake(botnet_bot_t *bot, const char *cmd, const char *next);
-static int got_ping(botnet_bot_t *bot, const char *cmd, char *next);
 static int got_idle(botnet_bot_t *bot, const char *cmd, const char *next);
 static int got_join(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_motd(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_nickchange(botnet_bot_t *bot, const char *cmd, const char *next);
 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_ping(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_pong(botnet_bot_t *bot, const char *cmd, const char *next);
+static int got_link(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_versions(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);
 
 /* Sockbuf handler. */
 static int oldbotnet_on_connect(void *client_data, int idx, const char *peer_ip, int peer_port);
@@ -105,6 +111,10 @@
 	{NULL, "a", got_actchan},
 	{NULL, "actchan", got_actchan},
 
+	{NULL, "aw", got_away},
+	{NULL, "away", got_away},
+	{NULL, "unaway", got_away},
+
 	{NULL, "bye", got_bye},
 
 	{NULL, "c", got_chat},
@@ -124,15 +134,26 @@
 	{NULL, "j", got_join},
 	{NULL, "join", got_join},
 
+	{NULL, "l", got_link},
+	{NULL, "link", got_link},
+
+	{NULL, "m", got_motd},
+	{NULL, "motd", got_motd},
+
 	{NULL, "n", got_nlinked},
 	{NULL, "nlinked", got_nlinked},
 
+	{NULL, "nc", got_nickchange},
+
 	{NULL, "p", got_privmsg},
 	{NULL, "priv", got_privmsg},
 
 	{NULL, "pi", got_ping},
 	{NULL, "ping", got_ping},
 
+	{NULL, "po", got_pong},
+	{NULL, "pong", got_pong},
+
 	{NULL, "pt", got_part},
 	{NULL, "part", got_part},
 
@@ -142,6 +163,8 @@
 	{NULL, "ul", got_unlink},
 	{NULL, "unlink", got_unlink},
 
+	{NULL, "v", got_versions},
+
 	{NULL, "un", got_unlinked},
 	{NULL, "unlinked", got_unlinked},
 
@@ -246,6 +269,38 @@
 	return(i);
 }
 
+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;
+}
+
 /* +obot <obot> <host> <port> [username] [password] */
 static int party_plus_obot(partymember_t *p, char *nick, user_t *u, char *cmd, char *text)
 {
@@ -500,7 +555,7 @@
  * \param next Nothing.
  */
 
-static int got_ping(botnet_bot_t *bot, const char *cmd, char *next)
+static int got_ping(botnet_bot_t *bot, const char *cmd, const char *next)
 {
 	oldbotnet_t *obot = bot->client_data;
 
@@ -525,6 +580,106 @@
 	return BIND_RET_BREAK;
 }
 
+static int got_motd(botnet_bot_t *bot, const char *cmd, const char *next)
+{
+	char *word[2];
+	int n;
+	botnet_bot_t *dst;
+	botnet_entity_t src;
+
+	n = egg_get_word_array(next, NULL, 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_PARTYMEMBER || botnet_check_direction(bot, src.user->bot)) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	botnet_extension(EXTENSION_ONE, &src, dst, NULL, "motd", "", 0);
+	return BIND_RET_BREAK;
+}
+
+static int got_versions(botnet_bot_t *bot, const char *cmd, const char *next)
+{
+	char *word[3];
+	int n;
+	botnet_bot_t *dst, *srcbot;
+	partymember_t *src;
+
+	n = egg_get_word_array(next, NULL, word, 3);
+	if (n != 3) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	srcbot = botnet_lookup(word[0]);
+	dst = botnet_lookup(word[1]);
+	if (!srcbot || botnet_check_direction(bot, srcbot) || (!dst && strcmp(word[1], botnet_get_name()))) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	src = partymember_lookup(word[2], srcbot, -1);
+	if (!src) {
+		int id;
+		char *ptr = strchr(word[2], ':');
+
+		if (ptr) {
+			*ptr = 0;
+			id = atoi(word[2]);
+			++ptr;
+		} else {
+			ptr = word[2];
+			src = partymember_new(id, NULL, srcbot, ptr, "temp", "user.on.an.old.bot", NULL, NULL, &generic_owner);
+		}
+	}
+	botnet_entity_t e = user_entity(src);
+
+	botnet_extension(EXTENSION_ONE, &e, dst, NULL, "versions", "", 0);
+	return BIND_RET_BREAK;
+}
+
+static int got_nickchange(botnet_bot_t *bot, const char *cmd, const char *next)
+{
+	char *word[3];
+	int n, id;
+	botnet_bot_t *srcbot;
+	partymember_t *src;
+
+	n = egg_get_word_array(next, NULL, word, 3);
+	if (n != 3) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	srcbot = botnet_lookup(word[0]);
+	if (botnet_check_direction(bot, srcbot)) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	id = btoi(word[1]);
+	src = partymember_lookup(NULL, srcbot, id);
+	if (!src) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	partymember_set_nick(src, word[2]);
+
+	return BIND_RET_BREAK;
+}
+
 static int got_nlinked(botnet_bot_t *bot, const char *cmd, const char *next)
 {
 	char *word[3];
@@ -570,36 +725,9 @@
 	return BIND_RET_BREAK;
 }
 
-static int get_entity(botnet_bot_t *bot, botnet_entity_t *src, char *word)
+static int got_pong(botnet_bot_t *bot, const char *cmd, const char *next)
 {
-	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;
+	return BIND_RET_BREAK;
 }
 
 /*!
@@ -650,6 +778,44 @@
 	return BIND_RET_BREAK;
 }
 
+static int got_away(botnet_bot_t *bot, const char *cmd, const char *next)
+{
+	char *word[2];
+	int n, linking = 0;
+	botnet_bot_t *src;
+	partymember_t *p;
+
+	n = egg_get_word_array(next, &next, word, 2);
+	if (n != 2) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	if (word[0][0] == '!') {
+		linking = 1;
+		src = botnet_lookup(word[0] + 1);
+	} else {
+		src = botnet_lookup(word[0]);
+	}
+	if (botnet_check_direction(bot, src)) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	p = partymember_lookup(NULL, src, btoi(word[1]));
+	if (!p) {
+		egg_free_word_array(word, 2);
+		return BIND_RET_BREAK;
+	}
+
+	while (isspace(*next)) ++next;
+
+	botnet_entity_t s = user_entity(p);
+	botnet_extension(EXTENSION_ALL, &s, NULL, NULL, "away", next, -1);
+
+	return BIND_RET_BREAK;
+}
+
 static int got_unlinked(botnet_bot_t *bot, const char *cmd, const char *text)
 {
 	char *lostname;
@@ -903,6 +1069,31 @@
 	return BIND_RET_BREAK;
 }
 
+static int got_link(botnet_bot_t *bot, const char *cmd, const char *next)
+{
+	int n;
+	char *word[3];
+	botnet_bot_t *dst;
+	botnet_entity_t src;
+
+	n = egg_get_word_array(next, &next, word, 3);
+	if (n != 3) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	n = get_entity(bot, &src, word[0]);
+	dst = botnet_lookup(word[1]);
+	if (n < 0 || botnet_check_direction(bot, src.what == ENTITY_BOT ? src.bot : src.user->bot) || (!dst && strcmp(word[1], botnet_get_name()))) {
+		egg_free_word_array(word, 3);
+		return BIND_RET_BREAK;
+	}
+
+	botnet_link(&src, dst, word[2]);
+
+	return BIND_RET_BREAK;
+}
+
 /*!
  * \brief Handle a message from a bot to the entire net.
  *
Index: eggdrop1.9/src/core_party.c
diff -u eggdrop1.9/src/core_party.c:1.54 eggdrop1.9/src/core_party.c:1.55
--- eggdrop1.9/src/core_party.c:1.54	Sat Apr 14 10:21:13 2007
+++ eggdrop1.9/src/core_party.c	Sun Apr 22 08:18:32 2007
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: core_party.c,v 1.54 2007-04-14 15:21:13 sven Exp $";
+static const char rcsid[] = "$Id: core_party.c,v 1.55 2007-04-22 13:18:32 sven Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -467,28 +467,32 @@
 
 static int party_link(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
 {
-	int error;
-	user_t *who;
+	char *via;
+	const char *target;
+	botnet_bot_t *dst = NULL;
+	botnet_entity_t src = user_entity(p);
 
 	if (!text || !*text) {
-		partymember_printf(p, _("Syntax: link <handle>"));
-		return 0;
-	}
-	who = user_lookup_by_handle(text);
-	if (!who) {
-		partymember_printf(p, _("User '%s' not found."), text);
+		partymember_printf(p, _("Syntax: link <handle> [via-bot]"));
 		return 0;
 	}
-	error = botnet_link(who);
-	if (!error) return 0;
 
-	if (error == -1) {
-		partymember_printf(p, _("Error linking to '%s': User is not a bot."), who->handle);
-	} else if (error == -2) {
-		partymember_printf(p, _("Error linking to '%s': Bot type not set."), who->handle);
-	} else if (error == -3) {
-		partymember_printf(p, _("Error linking to '%s': No module loaded to link to that bot type."), who->handle);
-	}
+	egg_get_arg(text, &target, &via);
+	while (target && isspace(*target)) ++target;
+
+	if (target && *target) {
+		dst = botnet_lookup(via);
+		if (!dst && strcmp(via, botnet_get_name())) {
+			partymember_printf(p, _("No such bot: %s."), via);
+			free(via);
+			return 0;
+		}
+		free(via);
+	} else {
+		target = text;
+		free(via);
+	}	
+	botnet_link(&src, dst, target);
 
 	return 0;
 }
----------------------- End of diff -----------------------



More information about the Changes mailing list