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.11 2007-04-14 15:21:12 sven Exp $";
00022 #endif
00023
00024 #include <eggdrop/eggdrop.h>
00025
00026 #include "ircparty.h"
00027
00028 static int on_privmsg(void *client_data, partymember_t *dest, botnet_entity_t *src, const char *text, int len);
00029 static int on_nick(void *client_data, partymember_t *src, const char *oldnick, const char *newnick);
00030 static int on_quit(void *client_data, partymember_t *src, const botnet_bot_t *lostbot, const char *text, int len);
00031 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len);
00032 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking);
00033 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len);
00034
00035 partyline_event_t irc_party_handler = {
00036 on_privmsg,
00037 on_nick,
00038 on_quit,
00039 on_chanmsg,
00040 on_join,
00041 on_part
00042 };
00043
00044 static int on_privmsg(void *client_data, partymember_t *dest, botnet_entity_t *src, const char *text, int len)
00045 {
00046 irc_session_t *session = client_data;
00047
00048 if (src && src->what == ENTITY_PARTYMEMBER && src->user->bot) egg_iprintf(session->idx, ":%s*%s:%d!%s@%s PRIVMSG %s :%s\r\n", src->user->nick, src->user->bot->name, src->user->id, src->user->ident, src->user->host, dest->nick, text);
00049 else if (src && src->what == ENTITY_PARTYMEMBER) egg_iprintf(session->idx, ":%s:%d!%s@%s PRIVMSG %s :%s\r\n", src->user->nick, src->user->id, src->user->ident, src->user->host, dest->nick, text);
00050 else if (src && src->bot) egg_iprintf(session->idx, ":%s!%s@%s PRIVMSG %s :%s\r\n", src->bot->name, src->bot->name, src->bot->name, dest->nick, text);
00051 else if (src) egg_iprintf(session->idx, ":%s!%s@%s PRIVMSG %s :%s\r\n", botnet_get_name(), botnet_get_name(), botnet_get_name(), dest->nick, text);
00052 else egg_iprintf(session->idx, ":* NOTICE * :%s\r\n", text);
00053 return(0);
00054 }
00055
00056 static int on_nick(void *client_data, partymember_t *src, const char *oldnick, const char *newnick)
00057 {
00058 irc_session_t *session = client_data;
00059
00060 if (src != session->party && src->bot) egg_iprintf(session->idx, ":%s*%s:%d!%s@%s NICK %s*%s:%d\r\n", oldnick, src->bot->name, src->id, src->ident, src->host, newnick, src->bot->name, src->id);
00061 else if (src != session->party) egg_iprintf(session->idx, ":%s:%d!%s@%s NICK %s:%d\r\n", oldnick, src->id, src->ident, src->host, newnick, src->bot->name, src->id);
00062 else egg_iprintf(session->idx, ":%s!%s@%s NICK %s\r\n", oldnick, src->ident, src->host, newnick);
00063 return(0);
00064 }
00065
00066 static int on_quit(void *client_data, partymember_t *src, const botnet_bot_t *lostbot, const char *text, int len)
00067 {
00068 irc_session_t *session = client_data;
00069
00070 if (src != session->party && src->bot) egg_iprintf(session->idx, ":%s*%s:%d!%s@%s QUIT :%s\r\n", src->nick, src->bot->name, src->id, src->ident, src->host, text);
00071 else if (src != session->party) egg_iprintf(session->idx, ":%s:%d!%s@%s QUIT :%s\r\n", src->nick, src->id, src->ident, src->host, text);
00072 else egg_iprintf(session->idx, "ERROR :%s\r\n", text);
00073
00074 return(0);
00075 }
00076
00077 static int on_chanmsg(void *client_data, partychan_t *chan, botnet_entity_t *src, const char *text, int len)
00078 {
00079 irc_session_t *session = client_data;
00080
00081 if (src->what == ENTITY_PARTYMEMBER && src->user == session->party) return 0;
00082 if (src && src->what == ENTITY_PARTYMEMBER && src->user->bot) egg_iprintf(session->idx, ":%s*%s:%d!%s@%s PRIVMSG #%s :%s\r\n", src->user->nick, src->user->bot->name, src->user->id, src->user->ident, src->user->host, chan->name, text);
00083 else if (src && src->what == ENTITY_PARTYMEMBER) egg_iprintf(session->idx, ":%s:%d!%s@%s PRIVMSG #%s :%s\r\n", src->user->nick, src->user->id, src->user->ident, src->user->host, chan->name, text);
00084 else if (src && src->bot) egg_iprintf(session->idx, ":%s!%s@%s PRIVMSG #%s :%s\r\n", src->user->bot->name, src->user->bot->name, src->user->bot->name, chan->name, text);
00085 else if (src) egg_iprintf(session->idx, ":%s!%s@%s PRIVMSG #%s :%s\r\n", botnet_get_name(), botnet_get_name(), botnet_get_name(), chan->name, text);
00086 else egg_iprintf(session->idx, ":* PRIVMSG #%s :%s\r\n", chan->name, text);
00087 return 0;
00088 }
00089
00090 static int on_join(void *client_data, partychan_t *chan, partymember_t *src, int linking)
00091 {
00092 irc_session_t *session = client_data;
00093 partychan_member_t *m;
00094 partymember_t *p;
00095 int i, cur, len;
00096 char buf[510], nick[128];
00097
00098 if (session->party != src) {
00099 if (src->bot) egg_iprintf(session->idx, ":%s*%s:%d!%s@%s JOIN #%s\r\n", src->nick, src->bot->name, src->id, src->ident, src->host, chan->name);
00100 else egg_iprintf(session->idx, ":%s:%d!%s@%s JOIN #%s\r\n", src->nick, src->id, src->ident, src->host, chan->name);
00101 return(0);
00102 }
00103
00104 egg_iprintf(session->idx, ":%s!%s@%s JOIN #%s\r\n", src->nick, src->ident, src->host, chan->name);
00105
00106 sprintf(buf, ":eggdrop.bot 353 %s @ #%s :", session->nick, chan->name);
00107 cur = strlen(buf);
00108
00109 for (i = 0; i < chan->nmembers; i++) {
00110 m = chan->members+i;
00111 if (chan->members[i].flags & PARTY_DELETED) continue;
00112 p = m->p;
00113 if (session->party == p) snprintf(nick, sizeof(nick), "%s", p->nick);
00114 else if (p->bot) snprintf(nick, sizeof(nick), "%s*%s:%d", p->nick, p->bot->name, p->id);
00115 else snprintf(nick, sizeof(nick), "%s:%d", p->nick, p->id);
00116 len = strlen(nick);
00117 if (cur + len > 500) {
00118 cur--;
00119 buf[cur] = 0;
00120 egg_iprintf(session->idx, "%s\r\n", buf);
00121 sprintf(buf, ":eggdrop.bot 353 %s @ #%s :", session->nick, chan->name);
00122 cur = strlen(buf);
00123 }
00124 strcpy(buf+cur, nick);
00125 cur += len;
00126 buf[cur++] = ' ';
00127 }
00128
00129 if (cur > 0) {
00130 cur--;
00131 buf[cur] = 0;
00132 egg_iprintf(session->idx, "%s\r\n", buf);
00133 }
00134 egg_iprintf(session->idx, ":eggdrop.bot 366 %s #%s :End of /NAMES list.\r\n", session->nick, chan->name);
00135 return(0);
00136 }
00137
00138 static int on_part(void *client_data, partychan_t *chan, partymember_t *src, const char *text, int len)
00139 {
00140 irc_session_t *session = client_data;
00141
00142 if (session->party == src) egg_iprintf(session->idx, ":%s!%s@%s PART #%s :%s\r\n", src->nick, src->ident, src->host, chan->name, text);
00143 else if (src->bot) egg_iprintf(session->idx, ":%s*%s:%d!%s@%s PART #%s :%s\r\n", src->nick, src->bot->name, src->id, src->ident, src->host, chan->name, text);
00144 else egg_iprintf(session->idx, ":%s:%d!%s@%s PART #%s :%s\r\n", src->nick, src->id, src->ident, src->host, chan->name, text);
00145 return(0);
00146 }