[cvslog] (2004-10-06 14:59:20 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Wed Oct 6 08:59:20 CST 2004


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2004-10-06 14:59:20 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     lib/eggdrop/timer.c lib/eggdrop/timer.h
     modules/script/scripttimer.c src/core_party.c

Log message:

* added .timers command to view active timers

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/timer.c
diff -u eggdrop1.9/lib/eggdrop/timer.c:1.5 eggdrop1.9/lib/eggdrop/timer.c:1.6
--- eggdrop1.9/lib/eggdrop/timer.c:1.5	Fri Jun 25 12:44:04 2004
+++ eggdrop1.9/lib/eggdrop/timer.c	Wed Oct  6 09:59:09 2004
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: timer.c,v 1.5 2004/06/25 17:44:04 darko Exp $";
+static const char rcsid[] = "$Id: timer.c,v 1.6 2004/10/06 14:59:09 stdarg Exp $";
 #endif
 
 #include <stdio.h>
@@ -32,18 +32,6 @@
 static char *timestamp = NULL;
 static int timestamp_len = 0;
 
-/* Internal use only. */
-typedef struct egg_timer_b {
-	struct egg_timer_b *next;
-	int id;
-	char *name;
-	Function callback;
-	void *client_data;
-	egg_timeval_t howlong;
-	egg_timeval_t trigger_time;
-	int flags;
-} egg_timer_t;
-
 /* We keep a sorted list of active timers. */
 static egg_timer_t *timer_list_head = NULL;
 static int timer_next_id = 1;
@@ -258,36 +246,19 @@
 	return(0);
 }
 
-int timer_list(int **ids)
+egg_timer_t *timer_list()
 {
-	egg_timer_t *timer;
-	int ntimers;
-
-	/* Count timers. */
-	ntimers = 0;
-	for (timer = timer_list_head; timer; timer = timer->next) ntimers++;
-
-	/* Fill in array. */
-	*ids = malloc(sizeof(int) * (ntimers+1));
-	ntimers = 0;
-	for (timer = timer_list_head; timer; timer = timer->next) {
-		(*ids)[ntimers++] = timer->id;
-	}
-	return(ntimers);
+	return(timer_list_head);
 }
 
-int timer_info(int id, char **name, egg_timeval_t *initial_len, egg_timeval_t *trigger_time)
+egg_timer_t *timer_find(int id)
 {
 	egg_timer_t *timer;
 
 	for (timer = timer_list_head; timer; timer = timer->next) {
-		if (timer->id == id) break;
+		if (timer->id == id) return(timer);
 	}
-	if (!timer) return(-1);
-	if (name) *name = timer->name;
-	if (initial_len) memcpy(initial_len, &timer->howlong, sizeof(*initial_len));
-	if (trigger_time) memcpy(trigger_time, &timer->trigger_time, sizeof(*trigger_time));
-	return(0);
+	return(NULL);
 }
 
 int timer_set_timestamp(char *format)
Index: eggdrop1.9/lib/eggdrop/timer.h
diff -u eggdrop1.9/lib/eggdrop/timer.h:1.1 eggdrop1.9/lib/eggdrop/timer.h:1.2
--- eggdrop1.9/lib/eggdrop/timer.h:1.1	Mon Jun 21 15:35:11 2004
+++ eggdrop1.9/lib/eggdrop/timer.h	Wed Oct  6 09:59:09 2004
@@ -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: timer.h,v 1.1 2004/06/21 20:35:11 wingman Exp $
+ * $Id: timer.h,v 1.2 2004/10/06 14:59:09 stdarg Exp $
  */
 
 #ifndef _EGG_TIMER_H_
@@ -27,6 +27,17 @@
 	int usec;
 } egg_timeval_t;
 
+typedef struct egg_timer {
+	struct egg_timer *next;
+	int id;
+	char *name;
+	Function callback;
+	void *client_data;
+	egg_timeval_t howlong;
+	egg_timeval_t trigger_time;
+	int flags;
+} egg_timer_t;
+
 #define TIMER_REPEAT	1
 
 /* Create a simple timer with no client data and no flags. */
@@ -47,8 +58,8 @@
 extern int timer_destroy_all();
 extern int timer_get_shortest(egg_timeval_t *howlong);
 extern int timer_run();
-extern int timer_list(int **ids);
-extern int timer_info(int id, char **name, egg_timeval_t *initial_len, egg_timeval_t *trigger_time);
+extern egg_timer_t *timer_list();
+extern egg_timer_t *timer_find(int id);
 extern char *timer_get_timestamp(void);
 
 #endif /* !_EGG_TIMER_H_ */
Index: eggdrop1.9/modules/script/scripttimer.c
diff -u eggdrop1.9/modules/script/scripttimer.c:1.6 eggdrop1.9/modules/script/scripttimer.c:1.7
--- eggdrop1.9/modules/script/scripttimer.c:1.6	Wed Jun 23 06:19:52 2004
+++ eggdrop1.9/modules/script/scripttimer.c	Wed Oct  6 09:59:09 2004
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: scripttimer.c,v 1.6 2004/06/23 11:19:52 wingman Exp $";
+static const char rcsid[] = "$Id: scripttimer.c,v 1.7 2004/10/06 14:59:09 stdarg Exp $";
 #endif
 
 #include <stdio.h>
@@ -67,9 +67,15 @@
 
 static int script_timers(script_var_t *retval)
 {
-	int *timers, ntimers;
+	egg_timer_t *timer;
+	int ntimers, *timers;
 
-	ntimers = timer_list(&timers);
+	ntimers = 0;
+	for (timer = timer_list(); timer; timer = timer->next) {
+		timers = realloc(timers, sizeof(*timers) * (ntimers+1));
+		timers[ntimers] = timer->id;
+		ntimers++;
+	}
 
 	/* A malloc'd array of ints. */
 	retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_INTEGER;
@@ -81,12 +87,14 @@
 static int script_timer_info(script_var_t *retval, int timer_id)
 {
 	egg_timeval_t howlong, trigger_time, start_time, diff, now;
+	egg_timer_t *timer;
 	char *name;
 
 	retval->type = SCRIPT_VAR | SCRIPT_FREE | SCRIPT_ARRAY;
 	retval->len = 0;
 
-	if (timer_info(timer_id, &name, &howlong, &trigger_time)) return(0);
+	timer = timer_find(timer_id);
+	if (!timer) return(0);
 
 	timer_get_now(&now);
 
@@ -96,7 +104,7 @@
 
 	script_list_append(retval, script_string(name, -1));
 
-	timer_diff(&howlong, &trigger_time, &start_time);
+	timer_diff(&timer->howlong, &timer->trigger_time, &start_time);
 	script_list_append(retval, script_int(start_time.sec));
 	script_list_append(retval, script_int(start_time.usec));
 
@@ -107,7 +115,7 @@
 	script_list_append(retval, script_int(diff.sec));
 	script_list_append(retval, script_int(diff.usec));
 
-	timer_diff(&now, &trigger_time, &diff);
+	timer_diff(&now, &timer->trigger_time, &diff);
 	script_list_append(retval, script_int(diff.sec));
 	script_list_append(retval, script_int(diff.usec));
 
Index: eggdrop1.9/src/core_party.c
diff -u eggdrop1.9/src/core_party.c:1.42 eggdrop1.9/src/core_party.c:1.43
--- eggdrop1.9/src/core_party.c:1.42	Wed Sep 29 13:03:53 2004
+++ eggdrop1.9/src/core_party.c	Wed Oct  6 09:59:09 2004
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: core_party.c,v 1.42 2004/09/29 18:03:53 stdarg Exp $";
+static const char rcsid[] = "$Id: core_party.c,v 1.43 2004/10/06 14:59:09 stdarg Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -616,6 +616,20 @@
 	return BIND_RET_LOG;
 }
 
+static int party_timers(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
+{
+	egg_timer_t *timer;
+	int remain, now;
+
+	now = timer_get_now_sec(NULL);
+	partymember_printf(p, "ID    SEC LEFT    NAME");
+	for (timer = timer_list(); timer; timer = timer->next) {
+		remain = timer->trigger_time.sec - now;
+		partymember_printf(p, "%-5d %-8d    %s", timer->id, remain, timer->name);
+	}
+	return(BIND_RET_LOG);
+}
+
 static int party_restart(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
 {
 	core_restart (nick);
@@ -846,6 +860,7 @@
 	{"n", "loadmod", party_loadmod},	/* DDD	*/ /* n|- */
 	{"n", "unloadmod", party_unloadmod},	/* DDD	*/ /* n|- */
 	{"n", "binds", party_binds},		/* DDD 	*/ /* m|- */
+	{"n", "timers", party_timers},
 	{"m", "+host", party_plus_host},	/* DDC	*/ /* t|m */
 	{"m", "-host", party_minus_host},	/* DDC	*/ /* -|- */
 	{"t", "chhandle", party_chhandle},	/* DDC	*/ /* t|- */
----------------------- End of diff -----------------------



More information about the Changes mailing list