/[cvs]/eggdrop1.9/modules/oldbotnet/events.c
ViewVC logotype

Contents of /eggdrop1.9/modules/oldbotnet/events.c

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


Revision 1.14 - (show annotations) (download) (as text)
Tue Nov 6 00:05:40 2007 UTC (11 years, 11 months ago) by sven
Branch: MAIN
CVS Tags: HEAD
Changes since 1.13: +1 -10 lines
File MIME type: text/x-chdr
 * Added a new socketfilter that provides a per socket timer for easy
   implementation of various timeouts.
 * All sockets that expect user logins now have a 60 second timeout for
   the user to supply a valid login.
 * All botnet sockets now have a 30 second timeout for the bot to do a
   successful login. After that it has a 90 second timeout after which
   a ping will be sent. After another 90 seconds the socket is closed.

1 /* events.c: oldbotnet events
2 *
3 * Copyright (C) 2003, 2004 Eggheads Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #ifndef lint
21 static const char rcsid[] = "$Id: events.c,v 1.13 2007-08-18 22:32:24 sven Exp $";
22 #endif
23
24 #include <eggdrop/eggdrop.h>
25
26 #include "oldbotnet.h"
27
28 /* botnet callbacks */
29 static int on_bcast(void *client_data, botnet_entity_t *src, const char *text, int len);
30 static int on_privmsg(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len);
31 static int on_nick(void *client_data, partymember_t *src, const char *oldnick);
32 static int on_quit(void *client_data, partymember_t *src, const char *text, int len);
33 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len);
34 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking);
35 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *reason, int len);
36 static int on_new_bot(void *client_data, botnet_bot_t *bot, int linking);
37 static int on_lost_bot(void *client_data, botnet_bot_t *bot, const char *reason);
38 static int on_link(void *client_data, botnet_entity_t *from, botnet_bot_t *dst, const char *target);
39 static int on_unlink(void *client_data, botnet_entity_t *from, botnet_bot_t *bot, const char *reason);
40 static int on_botmsg(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len);
41 static int on_botbroadcast(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len);
42 static int on_extension(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len);
43
44 botnet_handler_t bothandler = {
45 NULL, on_bcast, on_privmsg, on_nick, on_quit,
46 on_chanmsg, on_join, on_part,
47 on_new_bot, on_lost_bot, on_link, on_unlink, on_botmsg, on_botbroadcast, on_extension
48 };
49
50 static const char *filter(const char *text)
51 {
52 char *p;
53 static char buf[512] = {0};
54
55 if (!strchr(text, '\n')) return text;
56
57 strncpy(buf, text, 511);
58 p = strchr(buf, '\n');
59 if (p) *p = 0;
60 return buf;
61 }
62
63 /*!
64 * \brief Send a broadcast event out.
65 *
66 * Send a broadcast (ct) out. eggdrop1.6 expects broadcasts to originate from
67 * a bot. If the source is a person, change it to the bot the person is on.
68 *
69 * \param client_data The ::oldbotnet_t struct of the bot.
70 * \param src The source of the broadcast.
71 * \param text The string to broadcast.
72 * \param len The string length.
73 *
74 * \return Always 0.
75 */
76
77 static int on_bcast(void *client_data, botnet_entity_t *src, const char *text, int len)
78 {
79 const char *name;
80 oldbotnet_t *obot = client_data;
81
82 if (src->what == ENTITY_BOT) name = entity_full_name(src);
83 else if (src->user->bot) name = src->user->bot->name;
84 else name = botnet_get_name();
85
86 egg_iprintf(obot->idx, "ct %s %s\n", name, filter(text));
87
88 return 0;
89 }
90
91 static int on_privmsg(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len)
92 {
93 oldbotnet_t *obot = client_data;
94
95 egg_iprintf(obot->idx, "p %s %s %s\n", entity_full_id_name(src), dst->full_id_name, filter(text));
96
97 return 0;
98 }
99
100 static int on_quit(void *client_data, partymember_t *src, const char *text, int len)
101 {
102 oldbotnet_t *obot = client_data;
103
104 egg_iprintf(obot->idx, "pt %s %s %s\n", src->bot ? src->bot->name : botnet_get_name(), src->nick, b64enc_int(src->id));
105
106 return 0;
107 }
108
109 static int on_nick(void *client_data, partymember_t *src, const char *oldnick)
110 {
111 oldbotnet_t *obot = client_data;
112
113 egg_iprintf(obot->idx, "nc %s %s %s\n", src->bot ? src->bot->name : botnet_get_name(), b64enc_int(src->id), src->nick);
114
115 return 0;
116 }
117
118 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *t, int len)
119 {
120 const char *text = filter(t);
121 oldbotnet_t *obot = client_data;
122
123 if (len >= 9 && !strncasecmp(text, "\1ACTION ", 8) && text[len - 1] == 1) {
124 egg_iprintf(obot->idx, "a %s %s %.*s\n", entity_full_name(src), b64enc_int(assoc_get_id(chan->name)), len - 9, text + 8);
125 } else {
126 egg_iprintf(obot->idx, "c %s %s %s\n", entity_full_name(src), b64enc_int(assoc_get_id(chan->name)), text);
127 }
128 return 0;
129 }
130
131 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking)
132 {
133 char *cid;
134 oldbotnet_t *obot = client_data;
135
136 cid = strdup(b64enc_int(assoc_get_id(chan->name)));
137 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, '*', b64enc_int(src->id), src->ident, src->host);
138 free(cid);
139
140 return 0;
141 }
142
143 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *reason, int len)
144 {
145 oldbotnet_t *obot = client_data;
146
147 if (!src->nchannels) {
148 if (reason && *reason) egg_iprintf(obot->idx, "pt %s %s %s %s\n", src->bot ? src->bot->name : botnet_get_name(), src->nick, b64enc_int(src->id), filter(reason));
149 else egg_iprintf(obot->idx, "pt %s %s %s\n", src->bot ? src->bot->name : botnet_get_name(), src->nick, b64enc_int(src->id));
150 } else {
151 char *cid;
152
153 cid = strdup(b64enc_int(assoc_get_id(src->channels[src->nchannels - 1]->name)));
154 egg_iprintf(obot->idx, "j %s %s %s %c%s %s@%s\n", src->bot ? src->bot->name : botnet_get_name(), src->nick, cid, '*', b64enc_int(src->id), src->ident, src->host);
155 free(cid);
156 }
157
158 return 0;
159 }
160
161 static int on_new_bot(void *client_data, botnet_bot_t *bot, int linking)
162 {
163 int version = 1090000;
164 const char *verstr;
165 oldbotnet_t *obot = client_data;
166
167 verstr = botnet_get_info(bot, "numversion");
168 if (verstr) version = atoi(verstr);
169 egg_iprintf(obot->idx, "n %s %s %c%s\n", bot->name, bot->uplink ? bot->uplink->name : botnet_get_name(), linking ? '-' : '!', b64enc_int(version));
170
171 return 0;
172 }
173
174 static int on_lost_bot(void *client_data, botnet_bot_t *bot, const char *reason)
175 {
176 oldbotnet_t *obot = client_data;
177
178 if (bot == obot->bot) egg_iprintf(obot->idx, "bye %s\n", filter(reason));
179 else egg_iprintf(obot->idx, "un %s %s\n", bot->name, filter(reason));
180
181 return 0;
182 }
183
184 static int on_link(void *client_data, botnet_entity_t *from, struct botnet_bot *dst, const char *target)
185 {
186 oldbotnet_t *obot = client_data;
187
188 egg_iprintf(obot->idx, "l %s %s %s\n", entity_full_id_name(from), dst->name, target);
189
190 return 0;
191 }
192
193 static int on_unlink(void *client_data, botnet_entity_t *from, struct botnet_bot *bot, const char *reason)
194 {
195 oldbotnet_t *obot = client_data;
196
197 egg_iprintf(obot->idx, "ul %s %s %s %s\n", entity_full_id_name(from), bot->uplink->name, bot->name, filter(reason));
198
199 return 0;
200 }
201
202 static int on_botbroadcast(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len)
203 {
204 const char *srcname = src ? src->name : botnet_get_name();
205 oldbotnet_t *obot = client_data;
206
207 if (text && len > 0) egg_iprintf(obot->idx, "z %s %s %s\n", srcname, command, filter(text));
208 else egg_iprintf(obot->idx, "z %s %s\n", srcname, command);
209
210 return 0;
211 }
212
213 static int on_botmsg(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len)
214 {
215 const char *srcname = src ? src->name : botnet_get_name();
216 oldbotnet_t *obot = client_data;
217
218 if (text && len > 0) egg_iprintf(obot->idx, "zb %s %s %s %s\n", srcname, dst->name, command, filter(text));
219 else egg_iprintf(obot->idx, "zb %s %s %s\n", srcname, dst->name, command);
220
221 return 0;
222 }
223
224 static int on_extension(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *t, int len)
225 {
226 const char *text = filter(t);
227 oldbotnet_t *obot = client_data;
228
229 if (!strcmp(cmd, "note")) {
230 egg_iprintf(obot->idx, "p %s %s\n", entity_full_id_name(src), text);
231 } else if (!strcmp(cmd, "who")) {
232 egg_iprintf(obot->idx, "w %s %s %s\n", entity_full_id_name(src), dst->name, text);
233 } else if (!strcmp(cmd, "motd")) {
234 egg_iprintf(obot->idx, "m %s %s\n", entity_full_id_name(src), dst->name);
235 } else if (!strcmp(cmd, "versions") && src->what == ENTITY_PARTYMEMBER) {
236 egg_iprintf(obot->idx, "v %s %s %d:%s\n", src->user->bot->name, dst->name, src->user->id, src->user->nick);
237 } else if (!strcmp(cmd, "away") && src->what == ENTITY_PARTYMEMBER) {
238 if (*text) egg_iprintf(obot->idx, "aw %s %s %s\n", src->user->bot ? src->user->bot->name : botnet_get_name(), b64enc_int(src->user->id), text);
239 else egg_iprintf(obot->idx, "aw %s %s\n", src->user->bot ? src->user->bot->name : botnet_get_name(), b64enc_int(src->user->id));
240 }
241
242 return 0;
243 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23