From 6f45115b5e21d4806c391673ae9afbf54a6bff48 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 11 Jul 2004 15:42:21 +0000 Subject: [PATCH] Fixed handling WHOIS printing once and for all. Everything unknown between "beginning of whois" and "end of whois" events is now printed as whois_special. Removed whois_registered and whois_help, they're printed with whois_special as well. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3263 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/irc/Makefile.am | 1 + src/fe-common/irc/fe-common-irc.c | 5 + src/fe-common/irc/fe-events-numeric.c | 395 -------------------------- src/fe-common/irc/fe-whois.c | 379 ++++++++++++++++++++++++ src/fe-common/irc/module-formats.c | 2 - src/fe-common/irc/module-formats.h | 2 - src/irc/core/irc-commands.c | 6 +- 7 files changed, 389 insertions(+), 401 deletions(-) create mode 100644 src/fe-common/irc/fe-whois.c diff --git a/src/fe-common/irc/Makefile.am b/src/fe-common/irc/Makefile.am index fa69e940..9ca9ccfa 100644 --- a/src/fe-common/irc/Makefile.am +++ b/src/fe-common/irc/Makefile.am @@ -25,6 +25,7 @@ real_sources = \ fe-netjoin.c \ fe-netsplit.c \ fe-common-irc.c \ + fe-whois.c \ irc-completion.c \ module-formats.c diff --git a/src/fe-common/irc/fe-common-irc.c b/src/fe-common/irc/fe-common-irc.c index 5168481f..fda75ede 100644 --- a/src/fe-common/irc/fe-common-irc.c +++ b/src/fe-common/irc/fe-common-irc.c @@ -68,6 +68,9 @@ void fe_netsplit_deinit(void); void fe_netjoin_init(void); void fe_netjoin_deinit(void); +void fe_whois_init(void); +void fe_whois_deinit(void); + void irc_completion_init(void); void irc_completion_deinit(void); @@ -89,6 +92,7 @@ void fe_common_irc_init(void) fe_modes_init(); fe_netsplit_init(); fe_netjoin_init(); + fe_whois_init(); irc_completion_init(); settings_check(); @@ -113,6 +117,7 @@ void fe_common_irc_deinit(void) fe_modes_deinit(); fe_netsplit_deinit(); fe_netjoin_deinit(); + fe_whois_deinit(); irc_completion_deinit(); theme_unregister(); diff --git a/src/fe-common/irc/fe-events-numeric.c b/src/fe-common/irc/fe-events-numeric.c index 1488a34e..6dcf8eee 100644 --- a/src/fe-common/irc/fe-events-numeric.c +++ b/src/fe-common/irc/fe-events-numeric.c @@ -350,331 +350,6 @@ static void event_sent_invite(IRC_SERVER_REC *server, const char *data) g_free(params); } -static void event_whois(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *user, *host, *realname; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 6, NULL, &nick, &user, - &host, NULL, &realname); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS, nick, user, host, realname); - g_free(params); -} - -static void event_whois_idle(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *secstr, *signonstr, *rest, *timestr; - long days, hours, mins, secs; - time_t signon; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 5 | PARAM_FLAG_GETREST, NULL, - &nick, &secstr, &signonstr, &rest); - - secs = atol(secstr); - signon = strstr(rest, "signon time") == NULL ? 0 : - (time_t) atol(signonstr); - - days = secs/3600/24; - hours = (secs%(3600*24))/3600; - mins = (secs%3600)/60; - secs %= 60; - - if (signon == 0) - printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_IDLE, - nick, days, hours, mins, secs); - else { - timestr = my_asctime(signon); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_IDLE_SIGNON, - nick, days, hours, mins, secs, timestr); - g_free(timestr); - } - g_free(params); -} - -static void event_whois_server(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *whoserver, *desc; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 4, NULL, &nick, &whoserver, &desc); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_SERVER, nick, whoserver, desc); - g_free(params); -} - -static void event_whois_oper(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *type; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 3, NULL, &nick, &type); - /* type = "is an IRC Operator" */ - if (strlen(type) > 5) { - type += 5; - if (*type == ' ') type++; - } - if (*type == '\0') { - /* shouldn't happen */ - type = "IRC Operator"; - } - - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_OPER, nick, type); - g_free(params); -} - -static void event_whois_registered(IRC_SERVER_REC *server, const char *data, - const char *orignick, const char *addr) -{ - char *params, *nick, *txt_identified; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 3, NULL, &nick, &txt_identified); - if (*txt_identified != '\0') { - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_REGISTERED, nick); - } else { - /* or /USERIP reply in undernet.. */ - print_event_received(server, data, orignick, FALSE); - } - g_free(params); -} - -static void event_whois_help(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 2, NULL, &nick); - printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_HELP, nick); - g_free(params); -} - -static void event_whois_modes(IRC_SERVER_REC *server, const char *data, - const char *orignick) -{ - char *params, *nick, *modes; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 6, NULL, &nick, - NULL, NULL, NULL, &modes); - - if (!ischannel(*nick)) { - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_MODES, nick, modes); - } else { - /* OPN's dancer uses for channel forwarding */ - print_event_received(server, data, orignick, FALSE); - } - g_free(params); -} - -static void event_whois_realhost(IRC_SERVER_REC *server, const char *data, - const char *orignick, const char *addr) -{ - char *params, *nick, *txt_real, *txt_hostname, *hostname; - - g_return_if_fail(data != NULL); - - /* real hostname */ - params = event_get_params(data, 5, NULL, &nick, &txt_real, - &txt_hostname, &hostname); - if (strcmp(txt_real, "real") != 0 || - strcmp(txt_hostname, "hostname") != 0) { - /* :... from */ - g_free(params); - params = event_get_params(data, 3, NULL, &nick, &hostname); - - hostname = strstr(hostname, "from "); - if (hostname != NULL) hostname += 5; - } - - if (hostname != NULL) { - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_REALHOST, nick, hostname, ""); - } else { - /* OPN's dancer uses for end of /MAP */ - print_event_received(server, data, orignick, FALSE); - } - g_free(params); -} - -static void event_whois_usermode326(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *usermode; - - g_return_if_fail(data != NULL); - - /* :has oper privs: */ - params = event_get_params(data, 3, NULL, &nick, &usermode); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_USERMODE, nick, usermode); - g_free(params); -} - -static void event_whois_realhost327(IRC_SERVER_REC *server, const char *data, - const char *orignick, const char *addr) -{ - char *params, *nick, *hostname, *ip, *text; - - g_return_if_fail(data != NULL); - - /* :Real hostname/IP */ - params = event_get_params(data, 5, NULL, &nick, &hostname, &ip, &text); - if (*text != '\0') { - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_REALHOST, nick, hostname, ip); - } else { - print_event_received(server, data, orignick, FALSE); - } - g_free(params); -} - -static void event_whois_usermode(IRC_SERVER_REC *server, const char *data, - const char *orignick, const char *addr) -{ - char *params, *txt_usermodes, *nick, *usermode; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 4, NULL, &txt_usermodes, - &nick, &usermode); - - if (strcmp(txt_usermodes, "usermodes") == 0) { - /* usermodes usermode */ - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_USERMODE, nick, usermode); - } else { - /* some servers use this as motd too.. - and OPN's dancer for /MAP */ - print_event_received(server, data, orignick, FALSE); - } - g_free(params); -} - -static void event_whois_special(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *str; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 3, NULL, &nick, &str); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_SPECIAL, nick, str); - g_free(params); -} - -static void event_whowas(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *user, *host, *realname; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 6, NULL, &nick, &user, - &host, NULL, &realname); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOWAS, nick, user, host, realname); - g_free(params); -} - -static void hide_safe_channel_id(IRC_SERVER_REC *server, char *chans) -{ - const char *idchan; - char *p, *dest, *end, id; - int count, length; - - if (!server->isupport_sent) - idchan = "!:5"; - else { - idchan = g_hash_table_lookup(server->isupport, "IDCHAN"); - if (idchan == NULL) - return; - } - - while (*idchan != '\0') { - id = *idchan; - if (idchan[1] != ':') - return; - - length = strtoul(idchan+2, &end, 10); - if (*end == ',') - end++; - else if (*end != '\0') - return; - idchan = end; - - count = 0; - for (dest = p = chans; *p != '\0'; p++) { - if (count > 0) - count--; - else { - if (*p == id) - count = length; - *dest++ = *p; - } - } - *dest = '\0'; - } -} - -static void event_whois_channels(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *chans; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 3, NULL, &nick, &chans); - - /* sure - we COULD print the channel names as-is, but since the - colors, bolds, etc. are mostly just to fool people, I think we - should show the channel names as they REALLY are so they could - even be joined without any extra tricks. */ - chans = show_lowascii(chans); - if (settings_get_bool("whois_hide_safe_channel_id")) - hide_safe_channel_id(server, chans); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_CHANNELS, nick, chans); - g_free(chans); - - g_free(params); -} - -static void event_whois_away(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *awaymsg; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 3, NULL, &nick, &awaymsg); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_AWAY, nick, awaymsg); - g_free(params); -} - -static void event_end_of_whois(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 2, NULL, &nick); - if (server->whois_found) { - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_END_OF_WHOIS, nick); - } - g_free(params); -} - static void event_chanserv_url(IRC_SERVER_REC *server, const char *data) { const char *channel; @@ -689,32 +364,6 @@ static void event_chanserv_url(IRC_SERVER_REC *server, const char *data) g_free(params); } -static void event_whois_auth(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick, *text; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 3, NULL, &nick, &text); - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_WHOIS_EXTRA, nick, text); - g_free(params); -} - -static void event_end_of_whowas(IRC_SERVER_REC *server, const char *data) -{ - char *params, *nick; - - g_return_if_fail(data != NULL); - - params = event_get_params(data, 2, NULL, &nick); - if (server->whowas_found) { - printformat(server, nick, MSGLEVEL_CRAP, - IRCTXT_END_OF_WHOWAS, nick); - } - g_free(params); -} - static void event_target_unavailable(IRC_SERVER_REC *server, const char *data, const char *nick, const char *addr) { @@ -924,8 +573,6 @@ void fe_events_numeric_init(void) last_away_nick = NULL; last_away_msg = NULL; - settings_add_bool("lookandfeel", "whois_hide_safe_channel_id", TRUE); - signal_add("event 221", (SIGNAL_FUNC) event_user_mode); signal_add("event 303", (SIGNAL_FUNC) event_ison); signal_add("event 353", (SIGNAL_FUNC) event_names_list); @@ -945,28 +592,7 @@ void fe_events_numeric_init(void) signal_add("event 306", (SIGNAL_FUNC) event_nowaway); signal_add("event 305", (SIGNAL_FUNC) event_unaway); signal_add("event 301", (SIGNAL_FUNC) event_away); - signal_add("event 311", (SIGNAL_FUNC) event_whois); - signal_add("whois away", (SIGNAL_FUNC) event_whois_away); - signal_add("whowas away", (SIGNAL_FUNC) event_whois_away); - signal_add("event 312", (SIGNAL_FUNC) event_whois_server); - signal_add("event 313", (SIGNAL_FUNC) event_whois_oper); - signal_add("event 307", (SIGNAL_FUNC) event_whois_registered); - signal_add("event 310", (SIGNAL_FUNC) event_whois_help); - signal_add("event 326", (SIGNAL_FUNC) event_whois_usermode326); - signal_add("event 327", (SIGNAL_FUNC) event_whois_realhost327); - signal_add("event 379", (SIGNAL_FUNC) event_whois_modes); - signal_add("event 378", (SIGNAL_FUNC) event_whois_realhost); - signal_add("event 377", (SIGNAL_FUNC) event_whois_usermode); - signal_add("event 320", (SIGNAL_FUNC) event_whois_special); - signal_add("event 308", (SIGNAL_FUNC) event_whois_special); - signal_add("event 275", (SIGNAL_FUNC) event_whois_special); - signal_add("event 314", (SIGNAL_FUNC) event_whowas); - signal_add("event 317", (SIGNAL_FUNC) event_whois_idle); - signal_add("event 318", (SIGNAL_FUNC) event_end_of_whois); signal_add("event 328", (SIGNAL_FUNC) event_chanserv_url); - signal_add("event 330", (SIGNAL_FUNC) event_whois_auth); - signal_add("event 369", (SIGNAL_FUNC) event_end_of_whowas); - signal_add("event 319", (SIGNAL_FUNC) event_whois_channels); signal_add("event 302", (SIGNAL_FUNC) event_userhost); signal_add("event 341", (SIGNAL_FUNC) event_sent_invite); @@ -1034,28 +660,7 @@ void fe_events_numeric_deinit(void) signal_remove("event 306", (SIGNAL_FUNC) event_nowaway); signal_remove("event 305", (SIGNAL_FUNC) event_unaway); signal_remove("event 301", (SIGNAL_FUNC) event_away); - signal_remove("event 311", (SIGNAL_FUNC) event_whois); - signal_remove("whois away", (SIGNAL_FUNC) event_whois_away); - signal_remove("whowas away", (SIGNAL_FUNC) event_whois_away); - signal_remove("event 312", (SIGNAL_FUNC) event_whois_server); - signal_remove("event 313", (SIGNAL_FUNC) event_whois_oper); - signal_remove("event 307", (SIGNAL_FUNC) event_whois_registered); - signal_remove("event 310", (SIGNAL_FUNC) event_whois_help); - signal_remove("event 326", (SIGNAL_FUNC) event_whois_usermode326); - signal_remove("event 327", (SIGNAL_FUNC) event_whois_realhost327); - signal_remove("event 379", (SIGNAL_FUNC) event_whois_modes); - signal_remove("event 378", (SIGNAL_FUNC) event_whois_realhost); - signal_remove("event 377", (SIGNAL_FUNC) event_whois_usermode); - signal_remove("event 320", (SIGNAL_FUNC) event_whois_special); - signal_remove("event 275", (SIGNAL_FUNC) event_whois_special); - signal_remove("event 308", (SIGNAL_FUNC) event_whois_special); - signal_remove("event 314", (SIGNAL_FUNC) event_whowas); - signal_remove("event 317", (SIGNAL_FUNC) event_whois_idle); - signal_remove("event 318", (SIGNAL_FUNC) event_end_of_whois); signal_remove("event 328", (SIGNAL_FUNC) event_chanserv_url); - signal_remove("event 330", (SIGNAL_FUNC) event_whois_auth); - signal_remove("event 369", (SIGNAL_FUNC) event_end_of_whowas); - signal_remove("event 319", (SIGNAL_FUNC) event_whois_channels); signal_remove("event 302", (SIGNAL_FUNC) event_userhost); signal_remove("event 341", (SIGNAL_FUNC) event_sent_invite); diff --git a/src/fe-common/irc/fe-whois.c b/src/fe-common/irc/fe-whois.c new file mode 100644 index 00000000..1e8fd4a6 --- /dev/null +++ b/src/fe-common/irc/fe-whois.c @@ -0,0 +1,379 @@ +/* Copyright (C) 1999-2004 Timo Sirainen */ + +#include "module.h" +#include "module-formats.h" +#include "signals.h" +#include "levels.h" +#include "misc.h" +#include "settings.h" + +#include "irc-servers.h" + +#include "printtext.h" + +static void event_whois(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *user, *host, *realname; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 6, NULL, &nick, &user, + &host, NULL, &realname); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS, nick, user, host, realname); + g_free(params); +} + +static void event_whois_special(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *str; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 3, NULL, &nick, &str); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_SPECIAL, nick, str); + g_free(params); +} + +static void event_whois_idle(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *secstr, *signonstr, *rest, *timestr; + long days, hours, mins, secs; + time_t signon; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 5 | PARAM_FLAG_GETREST, NULL, + &nick, &secstr, &signonstr, &rest); + + secs = atol(secstr); + signon = strstr(rest, "signon time") == NULL ? 0 : + (time_t) atol(signonstr); + + days = secs/3600/24; + hours = (secs%(3600*24))/3600; + mins = (secs%3600)/60; + secs %= 60; + + if (signon == 0) + printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_IDLE, + nick, days, hours, mins, secs); + else { + timestr = my_asctime(signon); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_IDLE_SIGNON, + nick, days, hours, mins, secs, timestr); + g_free(timestr); + } + g_free(params); +} + +static void event_whois_server(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *whoserver, *desc; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 4, NULL, &nick, &whoserver, &desc); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_SERVER, nick, whoserver, desc); + g_free(params); +} + +static void event_whois_oper(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *type; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 3, NULL, &nick, &type); + /* type = "is an IRC Operator" */ + if (strlen(type) > 5) { + type += 5; + if (*type == ' ') type++; + } + if (*type == '\0') { + /* shouldn't happen */ + type = "IRC Operator"; + } + + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_OPER, nick, type); + g_free(params); +} + +static void event_whois_modes(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *modes; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 6, NULL, &nick, + NULL, NULL, NULL, &modes); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_MODES, nick, modes); + g_free(params); +} + +static void event_whois_realhost(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *txt_real, *txt_hostname, *hostname; + + g_return_if_fail(data != NULL); + + /* real hostname */ + params = event_get_params(data, 5, NULL, &nick, &txt_real, + &txt_hostname, &hostname); + if (strcmp(txt_real, "real") != 0 || + strcmp(txt_hostname, "hostname") != 0) { + /* :... from */ + g_free(params); + params = event_get_params(data, 3, NULL, &nick, &hostname); + + hostname = strstr(hostname, "from "); + if (hostname != NULL) hostname += 5; + } + + if (hostname == NULL) { + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_REALHOST, nick, hostname, ""); + } else { + event_whois_special(server, data); + } + g_free(params); +} + +static void event_whois_usermode326(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *usermode; + + g_return_if_fail(data != NULL); + + /* :has oper privs: */ + params = event_get_params(data, 3, NULL, &nick, &usermode); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_USERMODE, nick, usermode); + g_free(params); +} + +static void event_whois_realhost327(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *hostname, *ip, *text; + + g_return_if_fail(data != NULL); + + /* :Real hostname/IP */ + params = event_get_params(data, 5, NULL, &nick, &hostname, &ip, &text); + if (*text != '\0') { + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_REALHOST, nick, hostname, ip); + } else { + event_whois_special(server, data); + } + g_free(params); +} + +static void event_whois_usermode(IRC_SERVER_REC *server, const char *data) +{ + char *params, *txt_usermodes, *nick, *usermode; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 4, NULL, &txt_usermodes, + &nick, &usermode); + + if (strcmp(txt_usermodes, "usermodes") == 0) { + /* usermodes usermode */ + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_USERMODE, nick, usermode); + } else { + event_whois_special(server, data); + } + g_free(params); +} + +static void hide_safe_channel_id(IRC_SERVER_REC *server, char *chans) +{ + const char *idchan; + char *p, *dest, *end, id; + int count, length; + + if (!server->isupport_sent) + idchan = "!:5"; + else { + idchan = g_hash_table_lookup(server->isupport, "IDCHAN"); + if (idchan == NULL) + return; + } + + while (*idchan != '\0') { + id = *idchan; + if (idchan[1] != ':') + return; + + length = strtoul(idchan+2, &end, 10); + if (*end == ',') + end++; + else if (*end != '\0') + return; + idchan = end; + + count = 0; + for (dest = p = chans; *p != '\0'; p++) { + if (count > 0) + count--; + else { + if (*p == id) + count = length; + *dest++ = *p; + } + } + *dest = '\0'; + } +} + +static void event_whois_channels(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *chans; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 3, NULL, &nick, &chans); + + /* sure - we COULD print the channel names as-is, but since the + colors, bolds, etc. are mostly just to fool people, I think we + should show the channel names as they REALLY are so they could + even be joined without any extra tricks. */ + chans = show_lowascii(chans); + if (settings_get_bool("whois_hide_safe_channel_id")) + hide_safe_channel_id(server, chans); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_CHANNELS, nick, chans); + g_free(chans); + + g_free(params); +} + +static void event_whois_away(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *awaymsg; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 3, NULL, &nick, &awaymsg); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_AWAY, nick, awaymsg); + g_free(params); +} + +static void event_end_of_whois(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 2, NULL, &nick); + if (server->whois_found) { + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_END_OF_WHOIS, nick); + } + g_free(params); +} + +static void event_whois_auth(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *text; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 3, NULL, &nick, &text); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOIS_EXTRA, nick, text); + g_free(params); +} + +static void event_whowas(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick, *user, *host, *realname; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 6, NULL, &nick, &user, + &host, NULL, &realname); + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_WHOWAS, nick, user, host, realname); + g_free(params); +} + +static void event_end_of_whowas(IRC_SERVER_REC *server, const char *data) +{ + char *params, *nick; + + g_return_if_fail(data != NULL); + + params = event_get_params(data, 2, NULL, &nick); + if (server->whowas_found) { + printformat(server, nick, MSGLEVEL_CRAP, + IRCTXT_END_OF_WHOWAS, nick); + } + g_free(params); +} + +struct whois_event_table { + int num; + void (*func)(IRC_SERVER_REC *, const char *); +}; + +static struct whois_event_table events[] = { + { 312, event_whois_server }, + { 313, event_whois_oper }, + { 326, event_whois_usermode326 }, + { 327, event_whois_realhost327 }, + { 379, event_whois_modes }, + { 378, event_whois_realhost }, + { 377, event_whois_usermode }, + { 317, event_whois_idle }, + { 330, event_whois_auth }, + { 319, event_whois_channels }, + { 0, NULL } +}; + +static void event_whois_default(IRC_SERVER_REC *server, const char *data) +{ + int i, num; + + num = atoi(current_server_event); + for (i = 0; events[i].num != 0; i++) { + if (events[i].num == num) { + events[i].func(server, data); + return; + } + } + + event_whois_special(server, data); +} + +void fe_whois_init(void) +{ + settings_add_bool("lookandfeel", "whois_hide_safe_channel_id", TRUE); + + signal_add("event 311", (SIGNAL_FUNC) event_whois); + signal_add("whois away", (SIGNAL_FUNC) event_whois_away); + signal_add("whowas away", (SIGNAL_FUNC) event_whois_away); + signal_add("whois default event", (SIGNAL_FUNC) event_whois_default); + signal_add("event 318", (SIGNAL_FUNC) event_end_of_whois); + signal_add("event 314", (SIGNAL_FUNC) event_whowas); + signal_add("event 369", (SIGNAL_FUNC) event_end_of_whowas); +} + +void fe_whois_deinit(void) +{ + signal_remove("event 311", (SIGNAL_FUNC) event_whois); + signal_remove("whois away", (SIGNAL_FUNC) event_whois_away); + signal_remove("whowas away", (SIGNAL_FUNC) event_whois_away); + signal_remove("whois default event", (SIGNAL_FUNC) event_whois_default); + signal_remove("event 318", (SIGNAL_FUNC) event_end_of_whois); + signal_remove("event 314", (SIGNAL_FUNC) event_whowas); + signal_remove("event 369", (SIGNAL_FUNC) event_end_of_whowas); +} diff --git a/src/fe-common/irc/module-formats.c b/src/fe-common/irc/module-formats.c index 3391089e..4b466f1c 100644 --- a/src/fe-common/irc/module-formats.c +++ b/src/fe-common/irc/module-formats.c @@ -99,8 +99,6 @@ FORMAT_REC fecommon_irc_formats[] = { { "whois_idle_signon", "{whois idle %|$1 days $2 hours $3 mins $4 secs {comment signon: $5}}", 6, { 0, 1, 1, 1, 1, 0 } }, { "whois_server", "{whois server %|$1 {comment $2}}", 3, { 0, 0, 0 } }, { "whois_oper", "{whois {hilight $1}}", 2, { 0, 0 } }, - { "whois_registered", "{whois has registered this nick}", 1, { 0 } }, - { "whois_help", "{whois is available for help}", 1, { 0 } }, { "whois_modes", " {whois modes $1}", 2, { 0, 0 } }, { "whois_realhost", "{whois hostname $1-}", 3, { 0, 0, 0 } }, { "whois_usermode", "{whois usermode $1}", 2, { 0, 0 } }, diff --git a/src/fe-common/irc/module-formats.h b/src/fe-common/irc/module-formats.h index d8e5a081..78023734 100644 --- a/src/fe-common/irc/module-formats.h +++ b/src/fe-common/irc/module-formats.h @@ -74,8 +74,6 @@ enum { IRCTXT_WHOIS_IDLE_SIGNON, IRCTXT_WHOIS_SERVER, IRCTXT_WHOIS_OPER, - IRCTXT_WHOIS_REGISTERED, - IRCTXT_WHOIS_HELP, IRCTXT_WHOIS_MODES, IRCTXT_WHOIS_REALHOST, IRCTXT_WHOIS_USERMODE, diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c index d6bc2723..d398a4e7 100644 --- a/src/irc/core/irc-commands.c +++ b/src/irc/core/irc-commands.c @@ -405,13 +405,15 @@ static void cmd_whois(const char *data, IRC_SERVER_REC *server, "event 402", event_402, "event 301", "whois away", /* 301 can come as a reply to /MSG, /WHOIS or /WHOWAS */ "event 401", "whois not found", - "event 311", "whois event", NULL); + "event 311", "whois event", + "", "whois default event", NULL); } else { server_redirect_event(server, "whois", 1, str, TRUE, NULL, "event 318", "whois end", "event 301", "whois away", /* 301 can come as a reply to /MSG, /WHOIS or /WHOWAS */ - "event 311", "whois event", NULL); + "event 311", "whois event", + "", "whois default event", NULL); } g_free(str);