00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _EGG_BOTNET_H_
00023 #define _EGG_BOTNET_H_
00024
00025 #define BTN_BOTNET_REQUEST_LINK "request-link"
00026 #define BTN_BOTNET_LINK "link"
00027 #define BTN_BOTNET_DISC "disc"
00028 #define BTN_BOTNET_BOT "bot"
00029 #define BTN_BOTNET_EXTENSION "ext"
00030
00031 #define BOT_DELETED 1
00032 #define BOT_LINKING 2
00033
00034 #define EXTENSION_ONE 1
00035 #define EXTENSION_ALL 2
00036 #define EXTENSION_NEIGHBOURS 3
00037
00038 typedef struct {
00039
00040 int (*on_login)(void *client_data, partymember_t *new);
00041 int (*on_bcast)(void *client_data, botnet_entity_t *src, const char *text, int len);
00042 int (*on_privmsg)(void *client_data, botnet_entity_t *src, partymember_t *dst, const char *text, int len);
00043 int (*on_nick)(void *client_data, partymember_t *src, const char *newnick);
00044 int (*on_quit)(void *client_data, partymember_t *src, const char *text, int len);
00045
00046
00047 int (*on_chanmsg)(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len);
00048 int (*on_join)(void *client_data, partychan_t *chan, partymember_t *src, int netburst);
00049 int (*on_part)(void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len);
00050
00051
00052 int (*on_new_bot)(void *client_data, botnet_bot_t *bot, int netburst);
00053 int (*on_lost_bot)(void *client_data, botnet_bot_t *bot_t, const char *reason);
00054 int (*on_link)(void *client_data, botnet_entity_t *from, botnet_bot_t *dst, const char *target);
00055 int (*on_unlink)(void *client_data, botnet_entity_t *from, botnet_bot_t *bot, const char *reason);
00056 int (*on_botmsg)(void *client_data, botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len);
00057 int (*on_botbroadcast)(void *client_data, botnet_bot_t *src, const char *command, const char *text, int len);
00058 int (*on_extension)(void *client_data, botnet_entity_t *src, botnet_bot_t *dst, const char *cmd, const char *text, int len);
00059
00060
00061 } botnet_handler_t;
00062
00071 struct botnet_bot {
00072 char *name;
00073 unsigned flags;
00074 user_t *user;
00075 struct botnet_bot *uplink;
00076 struct botnet_bot *direction;
00077 botnet_handler_t *handler;
00078 void *client_data;
00079 event_owner_t *owner;
00080 partymember_t *partys;
00081 xml_node_t *info;
00082 struct botnet_bot *prev;
00083 struct botnet_bot *next;
00084 struct botnet_bot *prev_local;
00085 struct botnet_bot *next_local;
00086 };
00087
00088 #define ENTITY_PARTYMEMBER 1
00089 #define ENTITY_BOT 2
00090
00103 #define user_entity(user) {ENTITY_PARTYMEMBER, (user), 0}
00104
00118 #define bot_entity(bot) {ENTITY_BOT, 0, (bot)}
00119
00120 #define set_user_entity(e, u) do {\
00121 (e)->what = ENTITY_PARTYMEMBER;\
00122 (e)->user = (u);\
00123 } while (0)
00124
00125 #define set_bot_entity(e, b) do {\
00126 (e)->what = ENTITY_BOT;\
00127 (e)->bot = (b);\
00128 } while (0)
00129
00130 struct botnet_entity {
00131 int what;
00132 partymember_t *user;
00133 botnet_bot_t *bot;
00134 };
00135
00136 #define entity_full_id_name(e) ((e)->what == ENTITY_BOT ? (e)->bot ? (e)->bot->name : botnet_get_name() : (e)->user->full_id_name)
00137 #define entity_full_name(e) ((e)->what == ENTITY_BOT ? (e)->bot ? (e)->bot->name : botnet_get_name() : (e)->user->full_name)
00138 #define entity_common_name(e) ((e)->what == ENTITY_BOT ? (e)->bot ? (e)->bot->name : botnet_get_name() : (e)->user->bot ? (e)->user->full_name : (e)->user->nick)
00139 #define entity_net_name(e) ((e)->what == ENTITY_BOT ? (e)->bot ? (e)->bot->name : botnet_get_name() : (e)->user->net_name)
00140
00141 int botnet_init(void);
00142 int botnet_shutdown(void);
00143
00144 void botnet_autolink(void);
00145 int botnet_set_name(const char *name);
00146 const char *botnet_get_name(void);
00147 const botnet_bot_t *botnet_get_head(void);
00148
00149 botnet_bot_t *botnet_lookup(const char *name);
00150 botnet_bot_t *botnet_new(const char *name, user_t *user, botnet_bot_t *uplink, botnet_bot_t *direction, xml_node_t *info, botnet_handler_t *handler, void *client_data, event_owner_t *owner, int netburst);
00151 void botnet_count_subtree(botnet_bot_t *bot, int *bots, int *members);
00152 void botnet_link_failed(user_t *user, const char *reason);
00153 void botnet_link_success(botnet_bot_t *bot);
00154 int botnet_delete_by_owner(struct egg_module *module, void *script);
00155 int botnet_delete(botnet_bot_t *bot, const char *reason);
00156 int botnet_unlink(botnet_entity_t *from, botnet_bot_t *bot, const char *reason);
00157 int botnet_link(botnet_entity_t *src, botnet_bot_t *dst, const char *target);
00158
00159 const char *botnet_get_info(botnet_bot_t *bot, const char *name);
00160 void botnet_set_info(botnet_bot_t *bot, const char *name, const char *value);
00161 void botnet_set_info_int(botnet_bot_t *bot, const char *name, int value);
00162
00163 void botnet_replay_net(botnet_bot_t *bot);
00164 int botnet_check_direction(botnet_bot_t *direction, botnet_bot_t *src);
00165
00166 void botnet_broadcast(botnet_entity_t *src, const char *text, int len);
00167 void botnet_announce_login(partymember_t *p);
00168 void botnet_member_join(partychan_t *chan, partymember_t *p, int linking);
00169 void botnet_member_part(partychan_t *chan, partymember_t *p, const char *reason, int len);
00170 void botnet_chanmsg(partychan_t *chan, botnet_entity_t *src, const char *reason, int len);
00171 void botnet_member_quit(partymember_t *p, const char *reason, int len);
00172 void botnet_set_nick(partymember_t *p, const char *oldnick);
00173 void botnet_botmsg(botnet_bot_t *src, botnet_bot_t *dst, const char *command, const char *text, int len);
00174 void botnet_botbroadcast(botnet_bot_t *src, const char *command, const char *text, int len);
00175 void botnet_extension(int mode, botnet_entity_t *src, botnet_bot_t *dst, egg_module_t *mod, const char *cmd, const char *text, int len);
00176
00177 #endif