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

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

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


Revision 1.4 - (show annotations) (download) (as text)
Sat Oct 27 19:55:51 2007 UTC (11 years, 5 months ago) by sven
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +5 -5 lines
File MIME type: text/x-chdr
Full botnet support.
The login needs some work, the netburst handling sucks and nobody pings
anyone but it works.

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.3 2007-09-13 22:20:56 sven Exp $";
22 #endif
23
24 #include <eggdrop/eggdrop.h>
25
26 #include "botnet.h"
27
28 /* botnet callbacks */
29 static int on_login(void *client_data, partymember_t *src);
30 static int on_bcast(void *client_data, botnet_entity_t *src, const char *text, int len);
31 static int on_privmsg(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len);
32 static int on_nick(void *client_data, partymember_t *src, const char *oldnick);
33 static int on_quit(void *client_data, partymember_t *src, const char *text, int len);
34 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len);
35 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking);
36 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *reason, int len);
37 static int on_new_bot(void *client_data, botnet_bot_t *bot, int linking);
38 static int on_lost_bot(void *client_data, botnet_bot_t *bot, const char *reason);
39 static int on_link(void *client_data, botnet_entity_t *from, botnet_bot_t *dst, const char *target);
40 static int on_unlink(void *client_data, botnet_entity_t *from, botnet_bot_t *bot, const char *reason);
41 static int on_botmsg(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len);
42 static int on_botbroadcast(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len);
43 static int on_extension(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len);
44
45 botnet_handler_t bothandler = {
46 on_login, on_bcast, on_privmsg, on_nick, on_quit,
47 on_chanmsg, on_join, on_part,
48 on_new_bot, on_lost_bot, on_link, on_unlink, on_botmsg, on_botbroadcast, on_extension
49 };
50
51 static int on_login(void *client_data, partymember_t *src)
52 {
53 bot_t *b = client_data;
54
55 if (src->bot) egg_iprintf(b->idx, ":%s login %s %s %s %s", src->bot->name, src->nick, src->ident, src->host, b64enc_int(src->id));
56 else egg_iprintf(b->idx, "login %s %s %s %s", src->nick, src->ident, src->host, b64enc_int(src->id));
57
58 return 0;
59 }
60
61 /*!
62 * \brief Send a broadcast event out.
63 *
64 * Send a broadcast (ct) out. eggdrop1.6 expects broadcasts to originate from
65 * a bot. If the source is a person, change it to the bot the person is on.
66 *
67 * \param client_data The ::oldbotnet_t struct of the bot.
68 * \param src The source of the broadcast.
69 * \param text The string to broadcast.
70 * \param len The string length.
71 *
72 * \return Always 0.
73 */
74
75 static int on_bcast(void *client_data, botnet_entity_t *src, const char *text, int len)
76 {
77 bot_t *b = client_data;
78
79 egg_iprintf(b->idx, ":%s broadcast :%s", entity_net_name(src), text ? text : "");
80
81 return 0;
82 }
83
84 static int on_privmsg(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len)
85 {
86 bot_t *b = client_data;
87
88 egg_iprintf(b->idx, ":%s privmsg %s :%s", entity_net_name(src), dst->net_name, text);
89
90 return 0;
91 }
92
93 static int on_quit(void *client_data, partymember_t *src, const char *text, int len)
94 {
95 bot_t *b = client_data;
96
97 egg_iprintf(b->idx, ":%s quit :%s", src->net_name, text ? text : "");
98
99 return 0;
100 }
101
102 static int on_nick(void *client_data, partymember_t *src, const char *oldnick)
103 {
104 bot_t *b = client_data;
105
106 egg_iprintf(b->idx, ":%s nick %s", src->net_name, src->nick);
107
108 return 0;
109 }
110
111 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len)
112 {
113 bot_t *b = client_data;
114
115 egg_iprintf(b->idx, ":%s chanmsg %s :%s", entity_net_name(src), chan->name, text ? text : "");
116
117 return 0;
118 }
119
120 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking)
121 {
122 bot_t *b = client_data;
123
124 egg_iprintf(b->idx, ":%s join %s%s", src->net_name, chan->name, linking ? " B" : "");
125
126 return 0;
127 }
128
129 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *reason, int len)
130 {
131 bot_t *b = client_data;
132
133 egg_iprintf(b->idx, ":%s part %s :%s", src->net_name, chan->name, reason ? reason : "");
134
135 return 0;
136 }
137
138 static int on_new_bot(void *client_data, botnet_bot_t *bot, int linking)
139 {
140 int version = 1090000;
141 const char *ver, *type, *fullversion;
142 bot_t *b = client_data;
143
144 type = botnet_get_info(bot, "type");
145 ver = botnet_get_info(bot, "numversion");
146 fullversion = botnet_get_info(bot, "numversion");
147 if (!type) type = "unknown";
148 if (ver) version = atoi(ver);
149 if (!fullversion) fullversion = "unknown";
150 if (bot->uplink) egg_iprintf(b->idx, ":%s newbot %s %s %s %s %s", bot->uplink->name, bot->name, type, b64enc_int(version), fullversion, linking ? "B" : "A");
151 else egg_iprintf(b->idx, "newbot %s %s %s %s%s", bot->name, type, b64enc_int(version), fullversion, linking ? " B" : "");
152
153 return 0;
154 }
155
156 static int on_lost_bot(void *client_data, botnet_bot_t *bot, const char *reason)
157 {
158 bot_t *b = client_data;
159
160 egg_iprintf(b->idx, ":%s bquit :%s", bot->name, reason ? reason : "No reason");
161
162 return 0;
163 }
164
165 static int on_link(void *client_data, botnet_entity_t *from, struct botnet_bot *dst, const char *target)
166 {
167 bot_t *b = client_data;
168
169 egg_iprintf(b->idx, ":%s link %s %s", entity_net_name(from), dst->name, target);
170
171 return 0;
172 }
173
174 static int on_unlink(void *client_data, botnet_entity_t *from, struct botnet_bot *bot, const char *reason)
175 {
176 bot_t *b = client_data;
177
178 egg_iprintf(b->idx, ":%s unlink %s :%s", entity_net_name(from), bot->name, reason);
179
180 return 0;
181 }
182
183 static int on_botbroadcast(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len)
184 {
185 int printlen, totallen;
186 char sbuf[512], *obuf;
187 bot_t *b = client_data;
188
189 if (src) totallen = 1 + strlen(src->name) + 12 + strlen(command) + 2 + len;
190 else totallen = 11 + strlen(command) + 2 + len;
191 if (totallen < 512) obuf = sbuf;
192 else obuf = malloc(totallen + 1);
193
194 if (src) printlen = sprintf(obuf, ":%s bbroadcast %s :", src->name, command);
195 else printlen = sprintf(obuf, "bbroadcast %s :", command);
196 memcpy(obuf + printlen, text, len);
197 sockbuf_write(b->idx, obuf, totallen);
198 if (obuf != sbuf) free(obuf);
199
200 return 0;
201 }
202
203 static int on_botmsg(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len)
204 {
205 int printlen, totallen;
206 char sbuf[512], *obuf;
207 bot_t *b = client_data;
208
209 if (src) totallen = 1 + strlen(src->name) + 8 + strlen(dst->name) + 1 + strlen(command) + 2 + len;
210 else totallen = 7 + strlen(dst->name) + 1 + strlen(command) + 2 + len;
211 if (totallen < 512) obuf = sbuf;
212 else obuf = malloc(totallen + 1);
213
214 if (src) printlen = sprintf(obuf, ":%s botmsg %s %s :", src->name, dst->name, command);
215 else printlen = sprintf(obuf, "botmsg %s %s :", dst->name, command);
216 memcpy(obuf + printlen, text, len);
217 sockbuf_write(b->idx, obuf, totallen);
218 if (obuf != sbuf) free(obuf);
219
220 return 0;
221 }
222
223 static int on_extension(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len)
224 {
225 char sbuf[512], *obuf;
226 int printlen, totallen = 1 + strlen(entity_net_name(src)) + 11 + strlen(dst->name) + 1 + strlen(cmd) + 2 + len;
227 bot_t *b = client_data;
228
229 if (totallen < 512) obuf = sbuf;
230 else obuf = malloc(totallen + 1);
231
232 printlen = sprintf(obuf, ":%s extension %s %s :", entity_net_name(src), dst->name, cmd);
233 memcpy(obuf + printlen, text, len);
234 sockbuf_write(b->idx, obuf, totallen);
235 if (obuf != sbuf) free(obuf);
236
237 return 0;
238 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23