added /WHO for user list and other fixes
This commit is contained in:
parent
6db8e620b1
commit
2ee7d7d1fb
@ -17,12 +17,16 @@
|
||||
#define CHAN_PRIV_OWNER "~"
|
||||
#define CHAN_PRIV_ADMIN "&"
|
||||
|
||||
// debug 352: chan: #bbsn, user: ~shadow, host: services.ephasic.org, server: memphis.ephasic.org, nick: Shadow, flags: H*, realname: shadow
|
||||
|
||||
struct user
|
||||
{
|
||||
char nick[50];
|
||||
char user[50];
|
||||
char host[256];
|
||||
char real_name[512];
|
||||
|
||||
char server[256];
|
||||
|
||||
#ifdef _WIN32
|
||||
BOOL is_op;
|
||||
BOOL is_halfop;
|
||||
@ -52,6 +56,9 @@ void add_user_to_channel(char *user, char *host, char *chan);
|
||||
void remove_user_from_channel(char *user, char *chan);
|
||||
void update_nick(char *old_nick, char *new_nick);
|
||||
void update_host(char *nick, char *host);
|
||||
void update_user(char *nick, char *user);
|
||||
void update_server(char *nick, char *server);
|
||||
void update_realname(char *nick, char *real_name);
|
||||
void user_quit(char *nick);
|
||||
void set_realname(char *nick, char *real_name);
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define IRC_MOTD "372"
|
||||
#define IRC_END_MOTD "376"
|
||||
#define IRC_NAMREPLY "353"
|
||||
#define IRC_WHOREPLY "352"
|
||||
|
||||
struct ev_handler
|
||||
{
|
||||
|
@ -71,9 +71,6 @@ void add_user_to_channel(char *user, char *host, char *chan)
|
||||
return;
|
||||
}
|
||||
|
||||
if (user_exists(chan, user) == 1)
|
||||
return;
|
||||
|
||||
// parse mode prefix symbols and remove them
|
||||
if (user[0] == '@')
|
||||
{
|
||||
@ -101,6 +98,9 @@ void add_user_to_channel(char *user, char *host, char *chan)
|
||||
user++;
|
||||
}
|
||||
|
||||
if (user_exists(chan, user) == 1)
|
||||
return;
|
||||
|
||||
printf("Adding user %s!%s to channel %s\n", user, host, chan);
|
||||
|
||||
for (i = 0; i < chan_count; i++)
|
||||
@ -180,6 +180,53 @@ void update_host(char *nick, char *host)
|
||||
}
|
||||
}
|
||||
|
||||
void update_user(char *nick, char *user)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < chan_count; i++)
|
||||
{
|
||||
for (j = 0; j < channels[i]->user_count; j++)
|
||||
{
|
||||
if (!strcmp(channels[i]->users[j].nick, nick))
|
||||
{
|
||||
strlcpy(channels[i]->users[j].user, user, 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_server(char *nick, char *server)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < chan_count; i++)
|
||||
{
|
||||
for (j = 0; j < channels[i]->user_count; j++)
|
||||
{
|
||||
if (!strcmp(channels[i]->users[j].nick, nick))
|
||||
{
|
||||
strlcpy(channels[i]->users[j].server, server, 256);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_realname(char *nick, char *real_name)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < chan_count; i++)
|
||||
{
|
||||
for (j = 0; j < channels[i]->user_count; j++)
|
||||
{
|
||||
if (!strcmp(channels[i]->users[j].nick, nick))
|
||||
{
|
||||
strlcpy(channels[i]->users[j].real_name, real_name, 256);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void user_quit(char *nick)
|
||||
{
|
||||
|
@ -44,6 +44,7 @@ void init_events()
|
||||
init_event_type(NICK_INUSE);
|
||||
init_event_type(CTCP);
|
||||
init_event_type(IRC_NAMREPLY);
|
||||
init_event_type(IRC_WHOREPLY);
|
||||
}
|
||||
|
||||
MY_API int add_handler(char *type, void *handler)
|
||||
|
46
src/irc.c
46
src/irc.c
@ -147,6 +147,8 @@ void irc_raw(struct irc_conn *bot, char *fmt, ...)
|
||||
vsnprintf(bot->out, sizeof bot->out, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
sprintf(outbuf, "%s\r\n", bot->out);
|
||||
printf("<< %s\n", outbuf);
|
||||
#ifdef _WIN32
|
||||
sprintf(outbuf, "%s\r\n", bot->out);
|
||||
send(bot->srv_fd, outbuf, strlen(outbuf), 0);
|
||||
@ -187,13 +189,11 @@ void irc_ctcp(struct irc_conn *bot, char *to, char *fmt, ...)
|
||||
|
||||
void irc_parse_raw(struct irc_conn *bot, char *raw)
|
||||
{
|
||||
char *user, *host, *par, *text, *chan, *nick, *nicks;
|
||||
char *user, *host, *par, *text, *chan, *nick, *nicks, *tmp;
|
||||
user = bot->host;
|
||||
|
||||
text = calloc(1, strlen(raw) + 1);
|
||||
|
||||
printf("raw: %s", raw);
|
||||
|
||||
if (!raw || !*raw)
|
||||
{
|
||||
return;
|
||||
@ -218,7 +218,7 @@ void irc_parse_raw(struct irc_conn *bot, char *raw)
|
||||
|
||||
trim(par);
|
||||
|
||||
printf("dbug raw: %s\n", raw);
|
||||
printf("dbug raw: %s\r\n", raw);
|
||||
|
||||
if (!strcmp("PONG", raw))
|
||||
{
|
||||
@ -319,18 +319,12 @@ void irc_parse_raw(struct irc_conn *bot, char *raw)
|
||||
#endif
|
||||
irc_raw(bot, "NICK %s", bot->nick);
|
||||
}
|
||||
else if (strstr("353", raw) != NULL)
|
||||
else if (!strcmp("353", raw))
|
||||
{
|
||||
printf("debug raw: %s\n", raw);
|
||||
printf("debug par: %s, text: %s\n", par, text);
|
||||
// par: BotName = #channel
|
||||
// extract channel name
|
||||
|
||||
chan = skip(par, ' ');
|
||||
chan = skip(chan, '=');
|
||||
chan = skip(chan, ' ');
|
||||
|
||||
// text is a list of nicks separated by spaces
|
||||
#ifdef _WIN32
|
||||
nicks = _strdup(text);
|
||||
#else
|
||||
@ -338,17 +332,41 @@ void irc_parse_raw(struct irc_conn *bot, char *raw)
|
||||
#endif
|
||||
nick = strtok(nicks, " ");
|
||||
|
||||
|
||||
printf("debug: chan: %s, nicks: %s\n", chan, nicks);
|
||||
|
||||
while (nick)
|
||||
{
|
||||
add_user_to_channel(nick, "", chan);
|
||||
|
||||
tmp = nick;
|
||||
if (nick[0] == '@' || nick[0] == '+' || nick[0] == '%' || nick[0] == '~' || nick[0] == '&')
|
||||
{
|
||||
tmp++;
|
||||
}
|
||||
|
||||
irc_raw(bot, "WHO %s", tmp);
|
||||
nick = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
fire_handler(bot, IRC_NAMREPLY, chan, text);
|
||||
}
|
||||
else if (!strcmp(raw, "352"))
|
||||
{
|
||||
char *chan, *user, *host, *server, *nick, *flags, *realname;
|
||||
|
||||
chan = skip(par, ' ');
|
||||
user = skip(chan, ' ');
|
||||
host = skip(user, ' ');
|
||||
server = skip(host, ' ');
|
||||
nick = skip(server, ' ');
|
||||
flags = skip(nick, ' ');
|
||||
realname = skip(text, ' ');
|
||||
|
||||
update_user(nick, user);
|
||||
update_host(nick, host);
|
||||
update_server(nick, server);
|
||||
update_realname(nick, realname);
|
||||
|
||||
fire_handler(bot, IRC_WHOREPLY, chan, user, host, server, nick, flags, realname);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!strcmp("NICK", raw) && !strcmp(user, bot->nick))
|
||||
|
Loading…
Reference in New Issue
Block a user