00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef lint
00021 static const char rcsid[] = "$Id: events.c,v 1.4 2007-10-27 19:55:51 sven Exp $";
00022 #endif
00023
00024 #include <eggdrop/eggdrop.h>
00025
00026 #include "botnet.h"
00027
00028
00029 static int on_login(void *client_data, partymember_t *src);
00030 static int on_bcast(void *client_data, botnet_entity_t *src, const char *text, int len);
00031 static int on_privmsg(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len);
00032 static int on_nick(void *client_data, partymember_t *src, const char *oldnick);
00033 static int on_quit(void *client_data, partymember_t *src, const char *text, int len);
00034 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len);
00035 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking);
00036 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *reason, int len);
00037 static int on_new_bot(void *client_data, botnet_bot_t *bot, int linking);
00038 static int on_lost_bot(void *client_data, botnet_bot_t *bot, const char *reason);
00039 static int on_link(void *client_data, botnet_entity_t *from, botnet_bot_t *dst, const char *target);
00040 static int on_unlink(void *client_data, botnet_entity_t *from, botnet_bot_t *bot, const char *reason);
00041 static int on_botmsg(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len);
00042 static int on_botbroadcast(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len);
00043 static int on_extension(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len);
00044
00045 botnet_handler_t bothandler = {
00046 on_login, on_bcast, on_privmsg, on_nick, on_quit,
00047 on_chanmsg, on_join, on_part,
00048 on_new_bot, on_lost_bot, on_link, on_unlink, on_botmsg, on_botbroadcast, on_extension
00049 };
00050
00051 static int on_login(void *client_data, partymember_t *src)
00052 {
00053 bot_t *b = client_data;
00054
00055 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));
00056 else egg_iprintf(b->idx, "login %s %s %s %s", src->nick, src->ident, src->host, b64enc_int(src->id));
00057
00058 return 0;
00059 }
00060
00075 static int on_bcast(void *client_data, botnet_entity_t *src, const char *text, int len)
00076 {
00077 bot_t *b = client_data;
00078
00079 egg_iprintf(b->idx, ":%s broadcast :%s", entity_net_name(src), text ? text : "");
00080
00081 return 0;
00082 }
00083
00084 static int on_privmsg(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len)
00085 {
00086 bot_t *b = client_data;
00087
00088 egg_iprintf(b->idx, ":%s privmsg %s :%s", entity_net_name(src), dst->net_name, text);
00089
00090 return 0;
00091 }
00092
00093 static int on_quit(void *client_data, partymember_t *src, const char *text, int len)
00094 {
00095 bot_t *b = client_data;
00096
00097 egg_iprintf(b->idx, ":%s quit :%s", src->net_name, text ? text : "");
00098
00099 return 0;
00100 }
00101
00102 static int on_nick(void *client_data, partymember_t *src, const char *oldnick)
00103 {
00104 bot_t *b = client_data;
00105
00106 egg_iprintf(b->idx, ":%s nick %s", src->net_name, src->nick);
00107
00108 return 0;
00109 }
00110
00111 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len)
00112 {
00113 bot_t *b = client_data;
00114
00115 egg_iprintf(b->idx, ":%s chanmsg %s :%s", entity_net_name(src), chan->name, text ? text : "");
00116
00117 return 0;
00118 }
00119
00120 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking)
00121 {
00122 bot_t *b = client_data;
00123
00124 egg_iprintf(b->idx, ":%s join %s%s", src->net_name, chan->name, linking ? " B" : "");
00125
00126 return 0;
00127 }
00128
00129 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *reason, int len)
00130 {
00131 bot_t *b = client_data;
00132
00133 egg_iprintf(b->idx, ":%s part %s :%s", src->net_name, chan->name, reason ? reason : "");
00134
00135 return 0;
00136 }
00137
00138 static int on_new_bot(void *client_data, botnet_bot_t *bot, int linking)
00139 {
00140 int version = 1090000;
00141 const char *ver, *type, *fullversion;
00142 bot_t *b = client_data;
00143
00144 type = botnet_get_info(bot, "type");
00145 ver = botnet_get_info(bot, "numversion");
00146 fullversion = botnet_get_info(bot, "numversion");
00147 if (!type) type = "unknown";
00148 if (ver) version = atoi(ver);
00149 if (!fullversion) fullversion = "unknown";
00150 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");
00151 else egg_iprintf(b->idx, "newbot %s %s %s %s%s", bot->name, type, b64enc_int(version), fullversion, linking ? " B" : "");
00152
00153 return 0;
00154 }
00155
00156 static int on_lost_bot(void *client_data, botnet_bot_t *bot, const char *reason)
00157 {
00158 bot_t *b = client_data;
00159
00160 egg_iprintf(b->idx, ":%s bquit :%s", bot->name, reason ? reason : "No reason");
00161
00162 return 0;
00163 }
00164
00165 static int on_link(void *client_data, botnet_entity_t *from, struct botnet_bot *dst, const char *target)
00166 {
00167 bot_t *b = client_data;
00168
00169 egg_iprintf(b->idx, ":%s link %s %s", entity_net_name(from), dst->name, target);
00170
00171 return 0;
00172 }
00173
00174 static int on_unlink(void *client_data, botnet_entity_t *from, struct botnet_bot *bot, const char *reason)
00175 {
00176 bot_t *b = client_data;
00177
00178 egg_iprintf(b->idx, ":%s unlink %s :%s", entity_net_name(from), bot->name, reason);
00179
00180 return 0;
00181 }
00182
00183 static int on_botbroadcast(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len)
00184 {
00185 int printlen, totallen;
00186 char sbuf[512], *obuf;
00187 bot_t *b = client_data;
00188
00189 if (src) totallen = 1 + strlen(src->name) + 12 + strlen(command) + 2 + len;
00190 else totallen = 11 + strlen(command) + 2 + len;
00191 if (totallen < 512) obuf = sbuf;
00192 else obuf = malloc(totallen + 1);
00193
00194 if (src) printlen = sprintf(obuf, ":%s bbroadcast %s :", src->name, command);
00195 else printlen = sprintf(obuf, "bbroadcast %s :", command);
00196 memcpy(obuf + printlen, text, len);
00197 sockbuf_write(b->idx, obuf, totallen);
00198 if (obuf != sbuf) free(obuf);
00199
00200 return 0;
00201 }
00202
00203 static int on_botmsg(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len)
00204 {
00205 int printlen, totallen;
00206 char sbuf[512], *obuf;
00207 bot_t *b = client_data;
00208
00209 if (src) totallen = 1 + strlen(src->name) + 8 + strlen(dst->name) + 1 + strlen(command) + 2 + len;
00210 else totallen = 7 + strlen(dst->name) + 1 + strlen(command) + 2 + len;
00211 if (totallen < 512) obuf = sbuf;
00212 else obuf = malloc(totallen + 1);
00213
00214 if (src) printlen = sprintf(obuf, ":%s botmsg %s %s :", src->name, dst->name, command);
00215 else printlen = sprintf(obuf, "botmsg %s %s :", dst->name, command);
00216 memcpy(obuf + printlen, text, len);
00217 sockbuf_write(b->idx, obuf, totallen);
00218 if (obuf != sbuf) free(obuf);
00219
00220 return 0;
00221 }
00222
00223 static int on_extension(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len)
00224 {
00225 char sbuf[512], *obuf;
00226 int printlen, totallen = 1 + strlen(entity_net_name(src)) + 11 + strlen(dst->name) + 1 + strlen(cmd) + 2 + len;
00227 bot_t *b = client_data;
00228
00229 if (totallen < 512) obuf = sbuf;
00230 else obuf = malloc(totallen + 1);
00231
00232 printlen = sprintf(obuf, ":%s extension %s %s :", entity_net_name(src), dst->name, cmd);
00233 memcpy(obuf + printlen, text, len);
00234 sockbuf_write(b->idx, obuf, totallen);
00235 if (obuf != sbuf) free(obuf);
00236
00237 return 0;
00238 }