/[cvs]/eggdrop1.9/src/egg_timer.c
ViewVC logotype

Contents of /eggdrop1.9/src/egg_timer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (show annotations) (download) (as text)
Sun Nov 3 23:16:09 2002 UTC (16 years, 10 months ago) by stdarg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.14: +1 -1 lines
File MIME type: text/x-chdr
FILE REMOVED
* Moved md5 code to lib/eggdrop so I can use it for password hashing
* Passwords are stored as standard hex encoding of md5(salt + password)
* Started moving script interface functions to modules/script

1 /*
2 * egg_timer.c --
3 *
4 */
5 /*
6 * Copyright (C) 2002 Eggheads Development Team
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 #ifndef lint
24 static const char rcsid[] = "$Id: egg_timer.c,v 1.14 2002/09/20 02:06:25 stdarg Exp $";
25 #endif
26
27 #include <stdio.h> /* NULL */
28 #include <eggdrop/eggdrop.h>
29
30 /* From main.c */
31 extern egg_timeval_t egg_timeval_now;
32
33 static int script_single_timer(int nargs, int sec, int usec, script_callback_t *callback);
34 static int script_repeat_timer(int nargs, int sec, int usec, script_callback_t *callback);
35 static int script_timers(script_var_t *retval);
36 static int script_timer_info(script_var_t *retval, int timer_id);
37
38 static script_command_t script_cmds[] = {
39 {"", "timer", script_single_timer, NULL, 2, "iic", "seconds ?microseconds? callback", SCRIPT_INTEGER, SCRIPT_VAR_ARGS | SCRIPT_VAR_FRONT | SCRIPT_PASS_COUNT},
40 {"", "rtimer", script_repeat_timer, NULL, 2, "iic", "seconds ?microseconds? callback", SCRIPT_INTEGER, SCRIPT_VAR_ARGS | SCRIPT_VAR_FRONT | SCRIPT_PASS_COUNT},
41 {"", "killtimer", timer_destroy, NULL, 1, "i", "timer-id", SCRIPT_INTEGER, 0},
42 {"", "timers", script_timers, NULL, 0, "", "", 0, SCRIPT_PASS_RETVAL},
43 {"", "timer_info", script_timer_info, NULL, 1, "i", "timer-id", 0, SCRIPT_PASS_RETVAL},
44 {0}
45 };
46
47 void timer_init()
48 {
49 script_create_commands(script_cmds);
50 }
51
52 static int script_timer(int sec, int usec, script_callback_t *callback, int flags)
53 {
54 egg_timeval_t howlong;
55 int id;
56
57 howlong.sec = sec;
58 howlong.usec = usec;
59 callback->syntax = (char *)malloc(1);
60 callback->syntax[0] = 0;
61 id = timer_create_complex(&howlong, callback->callback, callback, flags);
62 return(id);
63 }
64
65 static int script_single_timer(int nargs, int sec, int usec, script_callback_t *callback)
66 {
67 if (nargs < 3) {
68 sec = usec;
69 usec = 0;
70 }
71
72 callback->flags |= SCRIPT_CALLBACK_ONCE;
73 return script_timer(sec, usec, callback, 0);
74 }
75
76 static int script_repeat_timer(int nargs, int sec, int usec, script_callback_t *callback)
77 {
78 if (nargs < 3) {
79 sec = usec;
80 usec = 0;
81 }
82
83 return script_timer(sec, usec, callback, TIMER_REPEAT);
84 }
85
86 static int script_timers(script_var_t *retval)
87 {
88 int *timers, ntimers;
89
90 ntimers = timer_list(&timers);
91
92 /* A malloc'd array of ints. */
93 retval->type = SCRIPT_ARRAY | SCRIPT_FREE | SCRIPT_INTEGER;
94 retval->value = timers;
95 retval->len = ntimers;
96 return(0);
97 }
98
99 static int script_timer_info(script_var_t *retval, int timer_id)
100 {
101 int *info;
102 egg_timeval_t howlong, trigger_time, start_time, diff;
103
104 if (timer_info(timer_id, &howlong, &trigger_time)) {
105 retval->type = SCRIPT_STRING | SCRIPT_ERROR;
106 retval->value = "Timer not found";
107 return(0);
108 }
109
110 /* We have 11 fields. */
111 info = (int *)malloc(sizeof(int) * 11);
112
113 /* Timer id, when it started, initial timer length,
114 how long it's run already, how long until it triggers,
115 absolute time when it triggers. */
116 info[0] = timer_id;
117
118 timer_diff(&howlong, &trigger_time, &start_time);
119 info[1] = start_time.sec;
120 info[2] = start_time.usec;
121
122 info[3] = howlong.sec;
123 info[4] = howlong.usec;
124
125 timer_diff(&start_time, &egg_timeval_now, &diff);
126 info[5] = diff.sec;
127 info[6] = diff.usec;
128
129 timer_diff(&egg_timeval_now, &trigger_time, &diff);
130 info[7] = diff.sec;
131 info[8] = diff.usec;
132
133 info[9] = trigger_time.sec;
134 info[10] = trigger_time.usec;
135
136 /* A malloc'd array of ints. */
137 retval->type = SCRIPT_FREE | SCRIPT_ARRAY | SCRIPT_INTEGER;
138 retval->value = info;
139 retval->len = 11;
140
141 return(0);
142 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23