[cvslog] (2003-06-11 08:37:49 UTC) Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Wed Jun 11 02:37:49 CST 2003


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2003-06-11 08:37:49 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     lib/eggdrop/Makefile.am lib/eggdrop/eggdrop.c
     lib/eggdrop/eggdrop.h lib/eggdrop/garbage.h
     lib/eggdrop/partychan.c lib/eggdrop/partyline.h
     lib/eggdrop/partymember.c lib/eggdrop/users.c lib/eggdrop/users.h
     modules/server/Makefile.am modules/server/dcc.c
     modules/server/input.c modules/server/output.c
     modules/server/output.h modules/tclscript/tclscript.c
     modules/telnetparty/events.c src/core_config.c src/core_party.c
     src/logfile.c src/main.c

Added files:
     lib/eggdrop/ircparse.c lib/eggdrop/ircparse.h

Removed files:
     modules/server/parse.c modules/server/parse.h

Log message:

* guppy needed something to read on the bathroom
* new approach to create the initial user -- we prompt for the owner's handle
  when the bot starts with -m, and then generate a random password and print
  it out.

---------------------- diff included ----------------------
Index: eggdrop1.7/lib/eggdrop/Makefile.am
diff -u eggdrop1.7/lib/eggdrop/Makefile.am:1.21 eggdrop1.7/lib/eggdrop/Makefile.am:1.22
--- eggdrop1.7/lib/eggdrop/Makefile.am:1.21	Sat Jun  7 22:21:23 2003
+++ eggdrop1.7/lib/eggdrop/Makefile.am	Wed Jun 11 03:37:38 2003
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.21 2003/06/08 03:21:23 stdarg Exp $
+# $Id: Makefile.am,v 1.22 2003/06/11 08:37:38 stdarg Exp $
 
 MAINTAINERCLEANFILES	= Makefile.in
 
@@ -23,12 +23,12 @@
 			hash_table.c hash_table.h \
 			irccmp.c irccmp.h \
 			ircmasks.c ircmasks.h \
+			ircparse.c ircparse.h \
 			linemode.c linemode.h \
 			egglog.c egglog.h \
 			match.c match.h \
 			md5.c md5.h \
-			memutil.c \
-			memutil.h \
+			memutil.c memutil.h \
 			my_socket.c my_socket.h \
 			partyline.c partyline.h \
 			partychan.c partymember.c \
Index: eggdrop1.7/lib/eggdrop/eggdrop.c
diff -u eggdrop1.7/lib/eggdrop/eggdrop.c:1.5 eggdrop1.7/lib/eggdrop/eggdrop.c:1.6
--- eggdrop1.7/lib/eggdrop/eggdrop.c:1.5	Tue Apr 15 03:18:03 2003
+++ eggdrop1.7/lib/eggdrop/eggdrop.c	Wed Jun 11 03:37:38 2003
@@ -22,12 +22,24 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: eggdrop.c,v 1.5 2003/04/15 08:18:03 stdarg Exp $";
+static const char rcsid[] = "$Id: eggdrop.c,v 1.6 2003/06/11 08:37:38 stdarg Exp $";
 #endif
 
 #include <stdlib.h>
 #include <string.h>
 #include "eggdrop.h"
+
+int eggdrop_init()
+{
+	config_init();
+	egg_net_init();
+	egglog_init();
+	user_init();
+	script_init();
+	partyline_init();
+	module_init();
+	return(0);
+}
 
 eggdrop_t *eggdrop_new(void)
 {
Index: eggdrop1.7/lib/eggdrop/eggdrop.h
diff -u eggdrop1.7/lib/eggdrop/eggdrop.h:1.20 eggdrop1.7/lib/eggdrop/eggdrop.h:1.21
--- eggdrop1.7/lib/eggdrop/eggdrop.h:1.20	Sat Jun  7 22:21:23 2003
+++ eggdrop1.7/lib/eggdrop/eggdrop.h	Wed Jun 11 03:37:38 2003
@@ -7,34 +7,36 @@
 
 #include "../egglib/egglib.h"
 #include <eggdrop/common.h>
-#include <eggdrop/eggconfig.h>
-#include <eggdrop/md5.h>
+#include <eggdrop/flags.h>
+#include <eggdrop/ircmasks.h>
+#include <eggdrop/users.h>
+
 #include <eggdrop/base64.h>
-#include <eggdrop/match.h>
 #include <eggdrop/binds.h>
 #include <eggdrop/botnetutil.h>
-#include <eggdrop/memutil.h>
-#include <eggdrop/fileutil.h>
-#include <eggdrop/script.h>
-#include <eggdrop/my_socket.h>
-#include <eggdrop/sockbuf.h>
+#include <eggdrop/eggconfig.h>
+#include <eggdrop/eggdns.h>
+#include <eggdrop/eggident.h>
+#include <eggdrop/egglog.h>
 #include <eggdrop/eggmod.h>
 #include <eggdrop/eggnet.h>
 #include <eggdrop/eggowner.h>
-#include <eggdrop/eggdns.h>
-#include <eggdrop/eggident.h>
-#include <eggdrop/linemode.h>
 #include <eggdrop/eggtimer.h>
-#include <eggdrop/throttle.h>
+#include <eggdrop/fileutil.h>
+#include <eggdrop/garbage.h>
 #include <eggdrop/hash_table.h>
-#include <eggdrop/xml.h>
-#include <eggdrop/flags.h>
-#include <eggdrop/ircmasks.h>
-#include <eggdrop/users.h>
-#include <eggdrop/partyline.h>
-#include <eggdrop/egglog.h>
 #include <eggdrop/irccmp.h>
-#include <eggdrop/garbage.h>
+#include <eggdrop/ircparse.h>
+#include <eggdrop/linemode.h>
+#include <eggdrop/match.h>
+#include <eggdrop/md5.h>
+#include <eggdrop/memutil.h>
+#include <eggdrop/my_socket.h>
+#include <eggdrop/partyline.h>
+#include <eggdrop/sockbuf.h>
+#include <eggdrop/script.h>
+#include <eggdrop/throttle.h>
+#include <eggdrop/xml.h>
 
 /* Gettext macros */
 #ifdef ENABLE_NLS
@@ -55,6 +57,7 @@
 				   global_funcs mess is cleaned up */
 } eggdrop_t;
 
+extern int eggdrop_init();
 extern eggdrop_t *eggdrop_new(void);
 extern eggdrop_t *eggdrop_delete(eggdrop_t *);
 
Index: eggdrop1.7/lib/eggdrop/garbage.h
diff -u eggdrop1.7/lib/eggdrop/garbage.h:1.1 eggdrop1.7/lib/eggdrop/garbage.h:1.2
--- eggdrop1.7/lib/eggdrop/garbage.h:1.1	Sat Jun  7 22:23:27 2003
+++ eggdrop1.7/lib/eggdrop/garbage.h	Wed Jun 11 03:37:38 2003
@@ -5,5 +5,6 @@
 
 typedef int (*garbage_proc_t)(void *client_data);
 int garbage_add(garbage_proc_t garbage_proc, void *client_data, int flags);
+int garbage_run();
 
 #endif
Index: eggdrop1.7/lib/eggdrop/ircparse.c
diff -u /dev/null eggdrop1.7/lib/eggdrop/ircparse.c:1.1
--- /dev/null	Wed Jun 11 03:37:49 2003
+++ eggdrop1.7/lib/eggdrop/ircparse.c	Wed Jun 11 03:37:38 2003
@@ -0,0 +1,74 @@
+#include <stdlib.h>
+#include <string.h>
+
+#include "ircparse.h"
+
+/* Take care of array manipulation in adding an argument. */
+static void add_arg(irc_msg_t *msg, char *text)
+{
+	if (msg->nargs >= IRC_MSG_NSTATIC_ARGS) {
+		if (msg->nargs > IRC_MSG_NSTATIC_ARGS) {
+			msg->args = (char **)realloc(msg->args, sizeof(char *) * (msg->nargs+1));
+		}
+		else {
+			msg->args = (char **)malloc(sizeof(char *) * (IRC_MSG_NSTATIC_ARGS+1));
+			memcpy(msg->args, msg->static_args, sizeof(char *) * IRC_MSG_NSTATIC_ARGS);
+		}
+	}
+	msg->args[msg->nargs] = text;
+	msg->nargs++;
+}
+
+/* Parses an irc message into standard parts. Be sure to call irc_msg_cleanup()
+ * when you are done using it, so that it can free the argument array if
+ * necessary. */
+void irc_msg_parse(char *text, irc_msg_t *msg)
+{
+	char *space;
+
+	memset(msg, 0, sizeof(*msg));
+	msg->args = msg->static_args;
+	if (*text == ':') {
+		msg->prefix = text+1;
+		space = strchr(msg->prefix, ' ');
+		if (!space) return;
+		*space = 0;
+		text = space+1;
+	}
+	msg->cmd = text;
+	space = strchr(text, ' ');
+	if (!space) return;
+	*space = 0;
+	text = space+1;
+
+	while (*text && (*text != ':')) {
+	       	space = strchr(text, ' ');
+		add_arg(msg, text);
+		if (space) {
+			*space = 0;
+			text = space+1;
+		}
+		else break;
+	}
+	if (*text == ':') add_arg(msg, text+1);
+	add_arg(msg, NULL);
+	msg->nargs--;
+}
+
+/* Replace nulls with spaces again, in case you want to re-use the text. */
+void irc_msg_restore(irc_msg_t *msg)
+{
+	int i;
+	for (i = 0; i < msg->nargs; i++) {
+		if (msg->args[i][-1] == ':') msg->args[i][-2] = ' ';
+		else msg->args[i][-1] = ' ';
+	}
+}
+
+/* Reset the argument array, freeing any dynamic memory. */
+void irc_msg_cleanup(irc_msg_t *msg)
+{
+	if (msg->args && msg->args != msg->static_args) free(msg->args);
+	msg->args = msg->static_args;
+	msg->nargs = 0;
+}
Index: eggdrop1.7/lib/eggdrop/ircparse.h
diff -u /dev/null eggdrop1.7/lib/eggdrop/ircparse.h:1.1
--- /dev/null	Wed Jun 11 03:37:49 2003
+++ eggdrop1.7/lib/eggdrop/ircparse.h	Wed Jun 11 03:37:38 2003
@@ -0,0 +1,18 @@
+#ifndef _IRCPARSE_H_
+#define _IRCPARSE_H_
+
+/* Structure to hold the parts of an irc message. NSTATIC_ARGS is how much
+ * space we allocate statically for arguments. If we run out, more is
+ * allocated dynamically. */
+#define IRC_MSG_NSTATIC_ARGS	10
+typedef struct irc_msg {
+	char *prefix, *cmd, **args;
+	char *static_args[IRC_MSG_NSTATIC_ARGS];
+	int nargs;
+} irc_msg_t;
+
+void irc_msg_parse(char *text, irc_msg_t *msg);
+void irc_msg_restore(irc_msg_t *msg);
+void irc_msg_cleanup(irc_msg_t *msg);
+
+#endif /* _IRCPARSE_H_ */
Index: eggdrop1.7/lib/eggdrop/partychan.c
diff -u eggdrop1.7/lib/eggdrop/partychan.c:1.2 eggdrop1.7/lib/eggdrop/partychan.c:1.3
--- eggdrop1.7/lib/eggdrop/partychan.c:1.2	Sun Jun  8 21:21:53 2003
+++ eggdrop1.7/lib/eggdrop/partychan.c	Wed Jun 11 03:37:38 2003
@@ -64,17 +64,6 @@
 	}
 	if (dirty) chan->members = realloc(chan->members, sizeof(*chan->members) * chan->nmembers);
 
-	dirty = 0;
-	for (i = 0; i < chan->nhandlers; i++) {
-		if (chan->handlers[i].flags & PARTY_DELETED) {
-			memcpy(chan->handlers+i, chan->handlers+i+1, sizeof(*chan->handlers) * (chan->nhandlers-i-1));
-			chan->nhandlers--;
-			dirty++;
-			i--;
-		}
-	}
-	if (dirty) chan->handlers = realloc(chan->handlers, sizeof(*chan->handlers) * chan->nhandlers);
-
 	return(0);
 }
 
@@ -124,6 +113,7 @@
 
 int partychan_join(partychan_t *chan, partymember_t *p)
 {
+	partychan_member_t *mem;
 	int i;
 
 	if (!chan || !p) return(-1);
@@ -141,15 +131,11 @@
 
 	/* Send out the join event to the members. */
 	for (i = 0; i < chan->nmembers; i++) {
-		if (chan->members[i].flags & PARTY_DELETED) continue;
-		(chan->members[i].p->handler->on_join)(chan->members[i].p->client_data, chan, p);
+		mem = chan->members+i;
+		if (mem->flags & PARTY_DELETED || mem->p->flags & PARTY_DELETED) continue;
+		if (mem->p->handler->on_join) (mem->p->handler->on_join)(mem->p->client_data, chan, p);
 	}
 
-	/* Send out the join event to the listeners. */
-	for (i = 0; i < chan->nhandlers; i++) {
-		if (chan->handlers[i].flags & PARTY_DELETED) continue;
-		(chan->handlers[i].handler->on_join)(chan->handlers[i].client_data, chan, p);
-	}
 	return(0);
 }
 
@@ -173,11 +159,12 @@
 int partychan_part(partychan_t *chan, partymember_t *p, const char *text)
 {
 	int i, len;
+	partychan_member_t *mem;
 
 	if (!chan || !p) return(-1);
 
 	/* Remove the channel entry from the member. */
-	for (i = 0; i < p->nchannels; i++) {
+	if (!(p->flags & PARTY_DELETED)) for (i = 0; i < p->nchannels; i++) {
 		if (p->channels[i] == chan) {
 			memcpy(p->channels+i, p->channels+i+1, sizeof(chan) * (p->nchannels-i-1));
 			p->nchannels--;
@@ -195,47 +182,19 @@
 		}
 	}
 
+	/* If the member is already deleted, then the quit event has been
+	 * fired already. */
+	if (p->flags & PARTY_DELETED) return(0);
+
 	len = strlen(text);
 
 	/* Send out the part event to the members. */
 	for (i = 0; i < chan->nmembers; i++) {
-		if (chan->members[i].flags & PARTY_DELETED) continue;
-		(chan->members[i].p->handler->on_part)(chan->members[i].p->client_data, chan, p, text, len);
-	}
-
-	/* Send out the part event to the listeners. */
-	len = strlen(text);
-	for (i = 0; i < chan->nhandlers; i++) {
-		if (chan->handlers[i].flags & PARTY_DELETED) continue;
-		(chan->handlers[i].handler->on_part)(chan->handlers[i].client_data, chan, p, text, len);
+		mem = chan->members+i;
+		if (mem->flags & PARTY_DELETED || mem->p->flags & PARTY_DELETED) continue;
+		if (mem->p->handler->on_part) (mem->p->handler->on_part)(mem->p->client_data, chan, p, text, len);
 	}
-	return(0);
-}
-
-int partychan_join_handler(partychan_t *chan, partyline_event_t *handler, void *client_data)
-{
-	/* Add the handler (if there is one). */
-	chan->handlers = realloc(chan->handlers, sizeof(*chan->handlers) * (chan->nhandlers+1));
-	chan->handlers[chan->nhandlers].handler = handler;
-	chan->handlers[chan->nhandlers].client_data = client_data;
-	chan->handlers[chan->nhandlers].flags = 0;
-	chan->nhandlers++;
-	return(0);
-}
-
-int partychan_part_handler(partychan_t *chan, partyline_event_t *handler, void *client_data)
-{
-	int i;
 
-	if (!chan) return(-1);
-
-	/* Mark the handler for later deletion. */
-	for (i = 0; i < chan->nhandlers; i++) {
-		if (chan->handlers[i].handler == handler && chan->handlers[i].client_data == client_data) {
-			chan->handlers[i].flags |= PARTY_DELETED;
-			break;
-		}
-	}
 	return(0);
 }
 
@@ -257,6 +216,7 @@
 
 int partychan_msg(partychan_t *chan, partymember_t *src, const char *text, int len)
 {
+	partychan_member_t *mem;
 	int i;
 
 	if (!chan || chan->flags & PARTY_DELETED) return(-1);
@@ -264,13 +224,55 @@
 	if (len < 0) len = strlen(text);
 
 	for (i = 0; i < chan->nmembers; i++) {
-		if (chan->members[i].flags & PARTY_DELETED) continue;
-		(chan->members[i].p->handler->on_chanmsg)(chan->members[i].p->client_data, chan, src, text, len);
+		mem = chan->members+i;
+		if (mem->flags & PARTY_DELETED || mem->p->flags & PARTY_DELETED) continue;
+		if (mem->p->handler->on_chanmsg) (mem->p->handler->on_chanmsg)(mem->p->client_data, chan, src, text, len);
+	}
+	return(0);
+}
+
+static partymember_common_t *common_list_head = NULL;
+
+/* Build a list of members on the same channels as p. */
+partymember_common_t *partychan_get_common(partymember_t *p)
+{
+	partymember_common_t *common;
+	partychan_t *chan;
+	partymember_t *mem;
+	int i, j;
+
+	if (common_list_head) {
+		common = common_list_head;
+		common_list_head = common_list_head->next;
+	}
+	else {
+		common = calloc(1, sizeof(*common));
 	}
 
-	for (i = 0; i < chan->nhandlers; i++) {
-		if (chan->handlers[i].flags & PARTY_DELETED) continue;
-		(chan->handlers[i].handler->on_chanmsg)(chan->handlers[i].client_data, chan, src, text, len);
+	common->len = 0;
+	for (i = 0; i < p->nchannels; i++) {
+		chan = p->channels[i];
+		for (j = 0; j < chan->nmembers; j++) {
+			if (chan->members[j].flags & PARTY_DELETED) continue;
+			mem = chan->members[j].p;
+			if (mem->flags & (PARTY_DELETED | PARTY_SELECTED)) continue;
+			mem->flags |= PARTY_SELECTED;
+			if (common->len >= common->max) {
+				common->max = common->len + 10;
+				common->members = realloc(common->members, sizeof(*common->members) * common->max);
+			}
+			common->members[common->len] = mem;
+			common->len++;
+		}
 	}
+	for (i = 0; i < common->len; i++) common->members[i]->flags &= ~PARTY_SELECTED;
+	return(common);
+}
+
+int partychan_free_common(partymember_common_t *common)
+{
+	common->len = 0;
+	common->next = common_list_head;
+	common_list_head = common;
 	return(0);
 }
Index: eggdrop1.7/lib/eggdrop/partyline.h
diff -u eggdrop1.7/lib/eggdrop/partyline.h:1.5 eggdrop1.7/lib/eggdrop/partyline.h:1.6
--- eggdrop1.7/lib/eggdrop/partyline.h:1.5	Mon Jun  9 23:43:18 2003
+++ eggdrop1.7/lib/eggdrop/partyline.h	Wed Jun 11 03:37:38 2003
@@ -3,6 +3,7 @@
 
 /* Flags for partyline. */
 #define PARTY_DELETED	1
+#define PARTY_SELECTED	2
 
 struct partyline_event;
 struct partychan;
@@ -26,12 +27,6 @@
 	int flags;
 } partychan_member_t;
 
-typedef struct partychan_handler {
-	struct partyline_event *handler;
-	void *client_data;
-	int flags;
-} partychan_handler_t;
-
 typedef struct partychan {
 	struct partychan *next, *prev;
 	int cid;
@@ -40,17 +35,25 @@
 
 	partychan_member_t *members;
 	int nmembers;
-	partychan_handler_t *handlers;
-	int nhandlers;
 } partychan_t;
 
+typedef struct partymember_common {
+	struct partymember_common *next;
+	partymember_t **members;
+	int len;
+	int max;
+} partymember_common_t;
+
 typedef struct partyline_event {
+	/* Events that don't depend on a single chan. */
 	int (*on_privmsg)(void *client_data, partymember_t *dest, partymember_t *src, 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);
+
+	/* Channel events. */
 	int (*on_chanmsg)(void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len);
 	int (*on_join)(void *client_data, partychan_t *chan, partymember_t *src);
 	int (*on_part)(void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len);
-
-	int (*on_delete)(void *client_data);
 } partyline_event_t;
 
 int partyline_init();
@@ -75,6 +78,8 @@
 int partychan_msg_name(const char *name, partymember_t *src, const char *text, int len);
 int partychan_msg_cid(int cid, partymember_t *src, const char *text, int len);
 int partychan_msg(partychan_t *chan, partymember_t *src, const char *text, int len);
+partymember_common_t *partychan_get_common(partymember_t *p);
+int partychan_free_common(partymember_common_t *common);
 
 
 partymember_t *partymember_lookup_pid(int pid);
Index: eggdrop1.7/lib/eggdrop/partymember.c
diff -u eggdrop1.7/lib/eggdrop/partymember.c:1.2 eggdrop1.7/lib/eggdrop/partymember.c:1.3
--- eggdrop1.7/lib/eggdrop/partymember.c:1.2	Mon Jun  9 23:43:18 2003
+++ eggdrop1.7/lib/eggdrop/partymember.c	Wed Jun 11 03:37:38 2003
@@ -25,9 +25,14 @@
 	hash_table_delete(pid_ht, (void *)p->pid, NULL);
 
 	/* Free! */
-	free(p->nick);
-	free(p->ident);
-	free(p->host);
+	if (p->nick) free(p->nick);
+	if (p->ident) free(p->ident);
+	if (p->host) free(p->host);
+	if (p->channels) free(p->channels);
+
+	/* Zero it out in case anybody has kept a reference (bad!). */
+	memset(p, 0, sizeof(*p));
+
 	free(p);
 }
 
@@ -85,7 +90,9 @@
 
 int partymember_delete(partymember_t *p, const char *text)
 {
-	int i;
+	int i, len;
+	partymember_common_t *common;
+	partymember_t *mem;
 
 	if (p->flags & PARTY_DELETED) return(-1);
 
@@ -93,14 +100,23 @@
 	p->flags |= PARTY_DELETED;
 	garbage_add(partymember_cleanup, NULL, GARBAGE_ONCE);
 
+	len = strlen(text);
+
+	common = partychan_get_common(p);
+	if (common) for (i = 0; i < common->len; i++) {
+		mem = common->members[i];
+		if (mem->flags & PARTY_DELETED) continue;
+		if (mem->handler->on_quit) (mem->handler->on_quit)(mem->client_data, p, text, len);
+	}
+
 	/* Remove from any stray channels. */
-	for (i = p->nchannels-1; i >= 0; i--) {
+	for (i = 0; i < p->nchannels; i++) {
 		partychan_part(p->channels[i], p, text);
 	}
 	p->nchannels = 0;
 
-	if (p->handler->on_delete) {
-		(p->handler->on_delete)(p->client_data);
+	if (p->handler->on_quit) {
+		(p->handler->on_quit)(p->client_data, p, text, strlen(text));
 	}
 	return(0);
 }
Index: eggdrop1.7/lib/eggdrop/users.c
diff -u eggdrop1.7/lib/eggdrop/users.c:1.13 eggdrop1.7/lib/eggdrop/users.c:1.14
--- eggdrop1.7/lib/eggdrop/users.c:1.13	Mon May 12 09:11:42 2003
+++ eggdrop1.7/lib/eggdrop/users.c	Wed Jun 11 03:37:38 2003
@@ -17,6 +17,9 @@
  * around (probably won't happen), so that we know when we can trust g_uid. */
 static int g_uid = 1, uid_wraparound = 0;
 
+/* The number of users we have. */
+static int nusers = 0;
+
 /* Hash table to associate irchosts (nick!user at host) with users. */
 static hash_table_t *irchost_cache_ht = NULL;
 
@@ -214,6 +217,7 @@
 	hash_table_insert(uid_ht, (void *)u->uid, u);
 	hash_table_check_resize(&handle_ht);
 	hash_table_check_resize(&uid_ht);
+	nusers++;
 	return(u);
 }
 
@@ -238,6 +242,7 @@
 	int i, j;
 	user_setting_t *setting;
 
+	nusers--;
 	hash_table_delete(handle_ht, u->handle, NULL);
 	hash_table_delete(uid_ht, (void *)u->uid, NULL);
 
@@ -613,5 +618,28 @@
 	MD5_Final(hash, &ctx);
 	MD5_Hex(hash, hashhex);
 	user_set_setting(u, NULL, "pass", hashhex);
+	return(0);
+}
+
+int user_count()
+{
+	return(nusers);
+}
+
+/* Generate a password out of digits, uppercase, and lowercase letters. */
+int user_rand_pass(char *buf, int bufsize)
+{
+	int i, c;
+
+	bufsize--;
+	if (!buf || bufsize < 0) return(-1);
+	for (i = 0; i < bufsize; i++) {
+		c = (random() + (random() >> 16) + (random() >> 24)) % 62;
+		if (c < 10) c += 48;	/* Digits. */
+		else if (c < 36) c += 55;	/* Uppercase. */
+		else c += 61;	/* Lowercase. */
+		buf[i] = c;
+	}
+	buf[i] = 0;
 	return(0);
 }
Index: eggdrop1.7/lib/eggdrop/users.h
diff -u eggdrop1.7/lib/eggdrop/users.h:1.4 eggdrop1.7/lib/eggdrop/users.h:1.5
--- eggdrop1.7/lib/eggdrop/users.h:1.4	Sun Feb  2 19:01:07 2003
+++ eggdrop1.7/lib/eggdrop/users.h	Wed Jun 11 03:37:38 2003
@@ -57,5 +57,7 @@
 int user_has_pass(user_t *u);
 int user_check_pass(user_t *u, const char *pass);
 int user_set_pass(user_t *u, const char *pass);
+int user_count();
+int user_rand_pass(char *buf, int bufsize);
 
 #endif
Index: eggdrop1.7/modules/server/Makefile.am
diff -u eggdrop1.7/modules/server/Makefile.am:1.8 eggdrop1.7/modules/server/Makefile.am:1.9
--- eggdrop1.7/modules/server/Makefile.am:1.8	Sat May 10 21:30:54 2003
+++ eggdrop1.7/modules/server/Makefile.am	Wed Jun 11 03:37:38 2003
@@ -1,10 +1,10 @@
-# $Id: Makefile.am,v 1.8 2003/05/11 02:30:54 stdarg Exp $
+# $Id: Makefile.am,v 1.9 2003/06/11 08:37:38 stdarg Exp $
 
 # FIXME: optionally allow a system wide install by ignoring the line below.
 pkglibdir		= $(exec_prefix)/modules
 
 pkglib_LTLIBRARIES	= server.la
-server_la_SOURCES	= server.c binds.c input.c output.c parse.c serverlist.c channels.c nicklist.c scriptcmds.c servsock.c dcc_commands.c dcc.c
+server_la_SOURCES	= server.c binds.c input.c output.c serverlist.c channels.c nicklist.c scriptcmds.c servsock.c dcc_commands.c dcc.c
 server_la_LDFLAGS	= -module -avoid-version -no-undefined
 server_la_LIBADD	= @LIBS@ $(top_builddir)/lib/eggdrop/libeggdrop.la
 
Index: eggdrop1.7/modules/server/dcc.c
diff -u eggdrop1.7/modules/server/dcc.c:1.12 eggdrop1.7/modules/server/dcc.c:1.13
--- eggdrop1.7/modules/server/dcc.c:1.12	Tue Apr 15 03:18:03 2003
+++ eggdrop1.7/modules/server/dcc.c	Wed Jun 11 03:37:38 2003
@@ -7,7 +7,6 @@
 #include <eggdrop/eggdrop.h>
 #include "server.h"
 #include "output.h"
-#include "parse.h"
 #include "binds.h"
 #include <netinet/in.h>
 #include <fcntl.h>
Index: eggdrop1.7/modules/server/input.c
diff -u eggdrop1.7/modules/server/input.c:1.19 eggdrop1.7/modules/server/input.c:1.20
--- eggdrop1.7/modules/server/input.c:1.19	Tue Apr 15 03:18:03 2003
+++ eggdrop1.7/modules/server/input.c	Wed Jun 11 03:37:38 2003
@@ -1,12 +1,6 @@
-/*
- * servmsg.c --
- */
-
 #include <eggdrop/eggdrop.h>
 #include "server.h"
-#include "parse.h"
 #include "channels.h"
-#include "parse.h"
 #include "output.h"
 #include "binds.h"
 #include "servsock.h"
Index: eggdrop1.7/modules/server/output.c
diff -u eggdrop1.7/modules/server/output.c:1.6 eggdrop1.7/modules/server/output.c:1.7
--- eggdrop1.7/modules/server/output.c:1.6	Mon Mar 31 23:56:02 2003
+++ eggdrop1.7/modules/server/output.c	Wed Jun 11 03:37:38 2003
@@ -1,12 +1,5 @@
-#if 0
-#define MAKING_SERVER
-#include "lib/eggdrop/module.h"
-#include "server.h"
-#include "output.h"
-#endif
 #include <eggdrop/eggdrop.h>
 #include "server.h"
-#include "parse.h"
 #include "output.h"
 #include "binds.h"
 
Index: eggdrop1.7/modules/server/output.h
diff -u eggdrop1.7/modules/server/output.h:1.3 eggdrop1.7/modules/server/output.h:1.4
--- eggdrop1.7/modules/server/output.h:1.3	Mon Mar 31 23:56:02 2003
+++ eggdrop1.7/modules/server/output.h	Wed Jun 11 03:37:38 2003
@@ -1,8 +1,6 @@
 #ifndef _OUTPUT_H_
 #define _OUTPUT_H_
 
-#include "parse.h"
-
 /* Server output priorities. */
 #define SERVER_NOQUEUE	1
 #define SERVER_QUICK	2
Index: eggdrop1.7/modules/server/parse.c
diff -u eggdrop1.7/modules/server/parse.c:1.2 eggdrop1.7/modules/server/parse.c:removed
--- eggdrop1.7/modules/server/parse.c:1.2	Tue Feb 18 04:13:17 2003
+++ eggdrop1.7/modules/server/parse.c	Wed Jun 11 03:37:49 2003
@@ -1,74 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-
-#include "parse.h"
-
-/* Take care of array manipulation in adding an argument. */
-static void add_arg(irc_msg_t *msg, char *text)
-{
-	if (msg->nargs >= IRC_MSG_NSTATIC_ARGS) {
-		if (msg->nargs > IRC_MSG_NSTATIC_ARGS) {
-			msg->args = (char **)realloc(msg->args, sizeof(char *) * (msg->nargs+1));
-		}
-		else {
-			msg->args = (char **)malloc(sizeof(char *) * (IRC_MSG_NSTATIC_ARGS+1));
-			memcpy(msg->args, msg->static_args, sizeof(char *) * IRC_MSG_NSTATIC_ARGS);
-		}
-	}
-	msg->args[msg->nargs] = text;
-	msg->nargs++;
-}
-
-/* Parses an irc message into standard parts. Be sure to call irc_msg_cleanup()
- * when you are done using it, so that it can free the argument array if
- * necessary. */
-void irc_msg_parse(char *text, irc_msg_t *msg)
-{
-	char *space;
-
-	memset(msg, 0, sizeof(*msg));
-	msg->args = msg->static_args;
-	if (*text == ':') {
-		msg->prefix = text+1;
-		space = strchr(msg->prefix, ' ');
-		if (!space) return;
-		*space = 0;
-		text = space+1;
-	}
-	msg->cmd = text;
-	space = strchr(text, ' ');
-	if (!space) return;
-	*space = 0;
-	text = space+1;
-
-	while (*text && (*text != ':')) {
-	       	space = strchr(text, ' ');
-		add_arg(msg, text);
-		if (space) {
-			*space = 0;
-			text = space+1;
-		}
-		else break;
-	}
-	if (*text == ':') add_arg(msg, text+1);
-	add_arg(msg, NULL);
-	msg->nargs--;
-}
-
-/* Replace nulls with spaces again, in case you want to re-use the text. */
-void irc_msg_restore(irc_msg_t *msg)
-{
-	int i;
-	for (i = 0; i < msg->nargs; i++) {
-		if (msg->args[i][-1] == ':') msg->args[i][-2] = ' ';
-		else msg->args[i][-1] = ' ';
-	}
-}
-
-/* Reset the argument array, freeing any dynamic memory. */
-void irc_msg_cleanup(irc_msg_t *msg)
-{
-	if (msg->args && msg->args != msg->static_args) free(msg->args);
-	msg->args = msg->static_args;
-	msg->nargs = 0;
-}
Index: eggdrop1.7/modules/server/parse.h
diff -u eggdrop1.7/modules/server/parse.h:1.2 eggdrop1.7/modules/server/parse.h:removed
--- eggdrop1.7/modules/server/parse.h:1.2	Mon Mar 10 03:11:50 2003
+++ eggdrop1.7/modules/server/parse.h	Wed Jun 11 03:37:49 2003
@@ -1,19 +0,0 @@
-#ifndef _PARSE_H_
-#define _PARSE_H_
-
-/* Structure to hold the parts of an irc message. NSTATIC_ARGS is how much
- * space we allocate statically for arguments. If we run out, more is
- * allocated dynamically. */
-#define IRC_MSG_NSTATIC_ARGS	10
-typedef struct irc_msg {
-	struct irc_msg *next;
-	char *prefix, *cmd, **args;
-	char *static_args[IRC_MSG_NSTATIC_ARGS];
-	int nargs;
-} irc_msg_t;
-
-void irc_msg_parse(char *text, irc_msg_t *msg);
-void irc_msg_restore(irc_msg_t *msg);
-void irc_msg_cleanup(irc_msg_t *msg);
-
-#endif /* _PARSE_H_ */
Index: eggdrop1.7/modules/tclscript/tclscript.c
diff -u eggdrop1.7/modules/tclscript/tclscript.c:1.35 eggdrop1.7/modules/tclscript/tclscript.c:1.36
--- eggdrop1.7/modules/tclscript/tclscript.c:1.35	Sat Jun  7 22:21:23 2003
+++ eggdrop1.7/modules/tclscript/tclscript.c	Wed Jun 11 03:37:38 2003
@@ -719,7 +719,9 @@
 	modinfo->description = "provides tcl scripting support";
 	modinfo->close_func = tclscript_close;
 
+	/* Create the interpreter and let tcl load its init.tcl */
 	ginterp = Tcl_CreateInterp();
+	Tcl_Init(ginterp);
 
 	error_logfile = strdup("logs/tcl_errors.log");
 	Tcl_LinkVar(ginterp, "error_logfile", (char *)&error_logfile, TCL_LINK_STRING);
Index: eggdrop1.7/modules/telnetparty/events.c
diff -u eggdrop1.7/modules/telnetparty/events.c:1.2 eggdrop1.7/modules/telnetparty/events.c:1.3
--- eggdrop1.7/modules/telnetparty/events.c:1.2	Mon Jun  9 23:43:18 2003
+++ eggdrop1.7/modules/telnetparty/events.c	Wed Jun 11 03:37:38 2003
@@ -2,16 +2,19 @@
 #include "telnetparty.h"
 
 static int on_privmsg(void *client_data, partymember_t *dest, partymember_t *src, const char *text, int len);
+static int on_nick(void *client_data, partymember_t *src, const char *oldnick, const char *newnick);
+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, partymember_t *src, const char *text, int len);
 static int on_join(void *client_data, partychan_t *chan, partymember_t *src);
 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len);
-static int on_delete(void *client_data);
 
 partyline_event_t telnet_party_handler = {
 	on_privmsg,
+	on_nick,
+	on_quit,
 	on_chanmsg,
-	on_join, on_part,
-	on_delete
+	on_join,
+	on_part
 };
 
 static int on_privmsg(void *client_data, partymember_t *dest, partymember_t *src, const char *text, int len)
@@ -23,6 +26,27 @@
 	return(0);
 }
 
+static int on_nick(void *client_data, partymember_t *src, const char *oldnick, const char *newnick)
+{
+	telnet_session_t *session = client_data;
+
+	egg_iprintf(session->idx, "%s is now known as %s\n", oldnick, newnick);
+	return(0);
+}
+
+static int on_quit(void *client_data, partymember_t *src, const char *text, int len)
+{
+	telnet_session_t *session = client_data;
+
+	if (src == session->party) {
+		sockbuf_delete(session->idx);
+	}
+	else {
+		egg_iprintf(session->idx, "%s (%s@%s) has quit: %s\n", src->nick, src->ident, src->host, text);
+	}
+	return(0);
+}
+
 static int on_chanmsg(void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len)
 {
 	telnet_session_t *session = client_data;
@@ -45,13 +69,5 @@
 	telnet_session_t *session = client_data;
 
 	egg_iprintf(session->idx, "%s %s (%s@%s) has left the channel: %s\r\n", chan->name, src->nick, src->ident, src->host, text);
-	return(0);
-}
-
-static int on_delete(void *client_data)
-{
-	telnet_session_t *session = client_data;
-
-	sockbuf_delete(session->idx);
 	return(0);
 }
Index: eggdrop1.7/src/core_config.c
diff -u eggdrop1.7/src/core_config.c:1.7 eggdrop1.7/src/core_config.c:1.8
--- eggdrop1.7/src/core_config.c:1.7	Sun Jun  8 21:21:53 2003
+++ eggdrop1.7/src/core_config.c	Wed Jun 11 03:37:39 2003
@@ -1,6 +1,7 @@
 #include <eggdrop/eggdrop.h>
 #include "core_config.h"
 
+extern char configfile[];
 core_config_t core_config = {0};
 void *config_root = NULL;
 
@@ -50,5 +51,5 @@
 void core_config_save()
 {
 	config_update_table(core_config_vars, config_root, "eggdrop", 0, NULL);
-	config_save(config_root, "_config.xml");
+	config_save(config_root, configfile);
 }
Index: eggdrop1.7/src/core_party.c
diff -u eggdrop1.7/src/core_party.c:1.4 eggdrop1.7/src/core_party.c:1.5
--- eggdrop1.7/src/core_party.c:1.4	Sun Jun  8 21:21:53 2003
+++ eggdrop1.7/src/core_party.c	Wed Jun 11 03:37:39 2003
@@ -1,4 +1,5 @@
 #include <eggdrop/eggdrop.h>
+#include "core_config.h"
 
 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
 {
@@ -40,15 +41,28 @@
 
 static int party_save(int pid, const char *nick, user_t *u, const char *cmd, const char *text)
 {
+	user_save(core_config.userfile);
 	core_config_save();
 	return(1);
 }
 
+static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
+{
+	if (!text || strlen(text) < 6) {
+		partymember_write(p, "Please use at least 6 characters.", -1);
+		return(0);
+	}
+	user_set_pass(p->user, text);
+	partymember_printf(p, "Changed password to '%s'", text);
+	return(0);
+}
+
 static bind_list_t core_party_binds[] = {
 	{"join", party_join},
+	{"msg", party_msg},
+	{"newpass", party_newpass},
 	{"part", party_part},
 	{"quit", party_quit},
-	{"msg", party_msg},
 	{"set", party_set},
 	{"save", party_save},
 	{0}
Index: eggdrop1.7/src/logfile.c
diff -u eggdrop1.7/src/logfile.c:1.31 eggdrop1.7/src/logfile.c:1.32
--- eggdrop1.7/src/logfile.c:1.31	Tue Apr 15 03:18:03 2003
+++ eggdrop1.7/src/logfile.c	Wed Jun 11 03:37:39 2003
@@ -21,10 +21,7 @@
 	FILE *fp;
 } log_t;
 
-extern int use_stderr; /* From main.c, while we're starting eggdrop. */
-extern int term_z;
-extern int backgrd;
-extern int con_chan;
+extern int backgrd, use_stderr;
 extern time_t now;
 
 static log_t *log_list_head = NULL; /* Linked list of logfiles. */
@@ -215,13 +212,8 @@
 		fprintf(log->fp, "%s%s\n", timestamp, text);
 	}
 
-  if ((!backgrd) && (!con_chan) && (!term_z))
-    printf("%s%s\n", timestamp, text);
-  else if (use_stderr) {
-    fprintf(stderr, "%s%s\n", timestamp, text);
-  }
-
-  return(0);
+	if (!backgrd || use_stderr) printf("%s%s\n", timestamp, text);
+	return(0);
 }
 
 static void check_logsizes()
Index: eggdrop1.7/src/main.c
diff -u eggdrop1.7/src/main.c:1.150 eggdrop1.7/src/main.c:1.151
--- eggdrop1.7/src/main.c:1.150	Sat Jun  7 22:21:23 2003
+++ eggdrop1.7/src/main.c	Wed Jun 11 03:37:39 2003
@@ -30,9 +30,10 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: main.c,v 1.150 2003/06/08 03:21:23 stdarg Exp $";
+static const char rcsid[] = "$Id: main.c,v 1.151 2003/06/11 08:37:39 stdarg Exp $";
 #endif
 
+#include <ctype.h>
 #include <unistd.h>
 #include <eggdrop/eggdrop.h>
 #include "main.h"
@@ -335,7 +336,6 @@
 
 void core_party_init();
 void core_config_init();
-//void telnet_init();
 
 int file_check(const char *filename)
 {
@@ -452,20 +452,51 @@
 		exit(-1);
 	}
 
-  egg = eggdrop_new();
-  config_init();
-  core_config_init(configfile);
-  egglog_init();
-  logfile_init();
-  script_init();
-  user_init();
-  if (core_config.userfile) user_load(core_config.userfile);
-  partyline_init();
-  core_party_init();
-  //telnet_init();
-  module_init();
-  egg_net_init();
-  core_binds_init();
+	egg = eggdrop_new();
+	eggdrop_init();
+	core_config_init(configfile);
+	logfile_init();
+	if (core_config.userfile) user_load(core_config.userfile);
+	core_party_init();
+	core_binds_init();
+
+	if (make_userfile) {
+		user_t *owner;
+		char handle[512], password[12];
+		int len;
+
+		if (user_count() != 0) {
+			printf("\n\n\nYou are trying to create a new userfile, but the old one still exists (%s)!\n\nPlease remove the userfile, or do not pass the -m option.\n\n", core_config.userfile);
+			exit(1);
+		}
+
+		printf("\n\n\nHello! I see you are creating a new userfile.\n\n");
+		printf("Let's create the owner account.\n\n");
+		do {
+			printf("Enter the owner handle: ");
+			fflush(stdout);
+			fgets(handle, sizeof(handle), stdin);
+			for (len = 0; handle[len]; len++) {
+				if (!ispunct(handle[len]) && !isalnum(handle[len])) break;
+			}
+			if (len == 0) {
+				printf("Come on, enter a real handle.\n\n");
+			}
+		} while (len <= 0);
+		handle[len] = 0;
+		owner = user_new(handle);
+		if (!owner) {
+			printf("Failed to create user record! Out of memory?\n\n");
+			exit(1);
+		}
+		user_rand_pass(password, sizeof(password));
+		user_set_pass(owner, password);
+		printf("Your owner handle is '%s' and your password is '%s' (without the quotes).\n\n", handle, password);
+		memset(password, 0, sizeof(password));
+		str_redup(&core_config.owner, handle);
+		core_config_save();
+		user_save(core_config.userfile);
+	}
 
   if (backgrd)
     bg_prepare_split();
@@ -474,24 +505,6 @@
   strcpy(&s[11], &s[20]);
   putlog(LOG_ALL, "*", "--- Loading %s (%s)", ver, s);
 
-	/* Put the module directory in the ltdl search path. */
-	if (core_config.module_path) module_add_dir(core_config.module_path);
-
-	/* Scan the autoload section of config. */
-	config_root = config_get_root("eggdrop");
-	for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "module", i, NULL)); i++) {
-		modname = NULL;
-		config_get_str(&modname, entry, NULL);
-		module_load(modname);
-	}
-	for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "script", i, NULL)); i++) {
-		scriptname = NULL;
-		config_get_str(&scriptname, entry, NULL);
-		script_load(scriptname);
-	}
-
-
-
   if (!pid_file[0])
     snprintf(pid_file, sizeof pid_file, "pid.%s", core_config.botname);
 
@@ -510,6 +523,22 @@
     }
   }
 
+	/* Put the module directory in the ltdl search path. */
+	if (core_config.module_path) module_add_dir(core_config.module_path);
+
+	/* Scan the autoload section of config. */
+	config_root = config_get_root("eggdrop");
+	for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "module", i, NULL)); i++) {
+		modname = NULL;
+		config_get_str(&modname, entry, NULL);
+		module_load(modname);
+	}
+	for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "script", i, NULL)); i++) {
+		scriptname = NULL;
+		config_get_str(&scriptname, entry, NULL);
+		script_load(scriptname);
+	}
+
   /* Move into background? */
   if (backgrd) {
 #ifndef CYGWIN_HACKS
@@ -539,6 +568,7 @@
 #endif
     }
   }
+
 
   use_stderr = 0;		/* Stop writing to stderr now */
   if (backgrd) {
----------------------- End of diff -----------------------


More information about the Changes mailing list