diff options
author | Timo Sirainen <cras@irssi.org> | 2000-12-01 01:00:28 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-12-01 01:00:28 +0000 |
commit | bb53065babd413b05d6f3afa97e1537cd9aa8069 (patch) | |
tree | f028a227a878b742a55d338a7ff8633b68b7e925 /src | |
parent | 12ec2b86b8eeca24e01f648a5a75f0e942da61a0 (diff) | |
download | irssi-bb53065babd413b05d6f3afa97e1537cd9aa8069.zip |
Netsplit printing fixes.
Print multiple identical mode changes in one line
(mode +o nick by nick1, nick2, nick3)
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@906 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r-- | src/fe-common/irc/Makefile.am | 1 | ||||
-rw-r--r-- | src/fe-common/irc/fe-common-irc.c | 5 | ||||
-rw-r--r-- | src/fe-common/irc/fe-events.c | 26 | ||||
-rw-r--r-- | src/fe-common/irc/fe-modes.c | 228 | ||||
-rw-r--r-- | src/fe-common/irc/fe-netjoin.c | 13 | ||||
-rw-r--r-- | src/fe-common/irc/fe-netsplit.c | 11 |
6 files changed, 255 insertions, 29 deletions
diff --git a/src/fe-common/irc/Makefile.am b/src/fe-common/irc/Makefile.am index 1bac01fa..8fca5bd5 100644 --- a/src/fe-common/irc/Makefile.am +++ b/src/fe-common/irc/Makefile.am @@ -19,6 +19,7 @@ libfe_common_irc_a_SOURCES = \ fe-ctcp.c \ fe-events.c \ fe-events-numeric.c \ + fe-modes.c \ fe-netjoin.c \ fe-netsplit.c \ fe-common-irc.c \ diff --git a/src/fe-common/irc/fe-common-irc.c b/src/fe-common/irc/fe-common-irc.c index 8899c7a6..3dccd6a4 100644 --- a/src/fe-common/irc/fe-common-irc.c +++ b/src/fe-common/irc/fe-common-irc.c @@ -54,6 +54,9 @@ void fe_events_deinit(void); void fe_events_numeric_init(void); void fe_events_numeric_deinit(void); +void fe_modes_init(void); +void fe_modes_deinit(void); + void fe_netsplit_init(void); void fe_netsplit_deinit(void); @@ -98,6 +101,7 @@ void fe_common_irc_init(void) fe_ctcp_init(); fe_events_init(); fe_events_numeric_init(); + fe_modes_init(); fe_netsplit_init(); fe_netjoin_init(); @@ -115,6 +119,7 @@ void fe_common_irc_deinit(void) fe_ctcp_deinit(); fe_events_deinit(); fe_events_numeric_deinit(); + fe_modes_deinit(); fe_netsplit_deinit(); fe_netjoin_deinit(); diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index feeef679..b978a501 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -254,30 +254,6 @@ static void event_mode(const char *data, IRC_SERVER_REC *server, g_free(params); } -/* FIXME: should be moved to fe-common/core/fe-messages.c.. */ -static void sig_message_mode(IRC_SERVER_REC *server, const char *channel, - const char *nick, const char *addr, - const char *mode) -{ - if (nick == NULL) nick = server->real_address; - - if (ignore_check(SERVER(server), nick, addr, channel, mode, MSGLEVEL_MODES)) - return; - - if (!ischannel(*channel)) { - /* user mode change */ - printformat(server, NULL, MSGLEVEL_MODES, IRCTXT_USERMODE_CHANGE, mode, channel); - } else if (addr == NULL) { - /* channel mode changed by server */ - printformat(server, channel, MSGLEVEL_MODES, - IRCTXT_SERVER_CHANMODE_CHANGE, channel, mode, nick); - } else { - /* channel mode changed by normal user */ - printformat(server, channel, MSGLEVEL_MODES, - IRCTXT_CHANMODE_CHANGE, channel, mode, nick); - } -} - static void event_pong(const char *data, IRC_SERVER_REC *server, const char *nick) { char *params, *host, *reply; @@ -496,7 +472,6 @@ void fe_events_init(void) signal_add("event kill", (SIGNAL_FUNC) event_kill); signal_add("event nick", (SIGNAL_FUNC) event_nick); signal_add("event mode", (SIGNAL_FUNC) event_mode); - signal_add("message mode", (SIGNAL_FUNC) sig_message_mode); signal_add("event pong", (SIGNAL_FUNC) event_pong); signal_add("event invite", (SIGNAL_FUNC) event_invite); signal_add("event topic", (SIGNAL_FUNC) event_topic); @@ -527,7 +502,6 @@ void fe_events_deinit(void) signal_remove("event kill", (SIGNAL_FUNC) event_kill); signal_remove("event nick", (SIGNAL_FUNC) event_nick); signal_remove("event mode", (SIGNAL_FUNC) event_mode); - signal_remove("message mode", (SIGNAL_FUNC) sig_message_mode); signal_remove("event pong", (SIGNAL_FUNC) event_pong); signal_remove("event invite", (SIGNAL_FUNC) event_invite); signal_remove("event topic", (SIGNAL_FUNC) event_topic); diff --git a/src/fe-common/irc/fe-modes.c b/src/fe-common/irc/fe-modes.c new file mode 100644 index 00000000..bfbd86f2 --- /dev/null +++ b/src/fe-common/irc/fe-modes.c @@ -0,0 +1,228 @@ +/* + fe-modes.c : irssi + + Copyright (C) 2000 Timo Sirainen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "module.h" +#include "module-formats.h" +#include "signals.h" +#include "levels.h" +#include "misc.h" +#include "settings.h" + +#include "irc.h" +#include "irc-servers.h" +#include "irc-channels.h" +#include "modes.h" +#include "ignore.h" + +#include "printtext.h" + +#define MODE_WAIT_TIME 3 /* how many seconds to wait for identical modes */ + +typedef struct { + IRC_CHANNEL_REC *channel; + char *mode; + GSList *nicks; + time_t last_mode; +} MODE_REC; + +static int mode_tag, group_multi_mode; +static GSList *modes; + +static MODE_REC *mode_find_channel(IRC_CHANNEL_REC *channel) +{ + GSList *tmp; + + g_return_val_if_fail(channel != NULL, NULL); + + for (tmp = modes; tmp != NULL; tmp = tmp->next) { + MODE_REC *rec = tmp->data; + + if (rec->channel == channel) + return rec; + } + + return NULL; +} + +static void mode_destroy(MODE_REC *mode) +{ + g_return_if_fail(mode != NULL); + + modes = g_slist_remove(modes, mode); + g_slist_foreach(mode->nicks, (GFunc) g_free, NULL); + g_slist_free(mode->nicks); + g_free(mode->mode); + g_free(mode); +} + +static void print_mode(MODE_REC *rec) +{ + GSList *tmp; + char *nicks; + + if (g_slist_find(channels, rec->channel) == NULL) { + /* channel was destroyed while we were waiting.. */ + return; + } + + tmp = modes; modes = NULL; + + nicks = gslist_to_string(rec->nicks, ", "); + printformat(rec->channel->server, rec->channel->name, MSGLEVEL_MODES, + IRCTXT_CHANMODE_CHANGE, + rec->channel->name, rec->mode, nicks); + g_free(nicks); + + modes = tmp; +} + +/* something is going to be printed to screen, print our current netsplit + message before it. */ +static void sig_print_starting(void) +{ + while (modes != NULL) { + print_mode(modes->data); + mode_destroy(modes->data); + } +} + +static int sig_check_modes(void) +{ + GSList *tmp, *next; + + if (modes == NULL) + return 1; + + for (tmp = modes; tmp != NULL; tmp = next) { + MODE_REC *rec = tmp->data; + + next = tmp->next; + if (time(NULL)-rec->last_mode >= MODE_WAIT_TIME) { + print_mode(rec); + mode_destroy(rec); + } + } + + if (modes == NULL) + signal_remove("print starting", (SIGNAL_FUNC) sig_print_starting); + return 1; +} + +static void msg_multi_mode(IRC_CHANNEL_REC *channel, const char *sender, + const char *addr, const char *mode) +{ + MODE_REC *rec; + + if (modes == NULL) + signal_add("print starting", (SIGNAL_FUNC) sig_print_starting); + + rec = mode_find_channel(channel); + if (rec != NULL && strcmp(rec->mode, mode) != 0) { + /* different mode than last time, show and remove the old */ + print_mode(rec); + mode_destroy(rec); + rec = NULL; + } + + if (rec == NULL) { + /* no previous mode, create new */ + rec = g_new0(MODE_REC, 1); + modes = g_slist_append(modes, rec); + + rec->channel = channel; + rec->mode = g_strdup(mode); + } + + rec->nicks = g_slist_append(rec->nicks, g_strdup(sender)); + rec->last_mode = time(NULL); + + signal_stop(); +} + +/* FIXME: should be moved to fe-common/core/fe-messages.c.. */ +static void sig_message_mode(IRC_SERVER_REC *server, const char *channel, + const char *nick, const char *addr, + const char *mode) +{ + if (nick == NULL) nick = server->real_address; + + if (ignore_check(SERVER(server), nick, addr, channel, + mode, MSGLEVEL_MODES)) + return; + + if (!ischannel(*channel)) { + /* user mode change */ + printformat(server, NULL, MSGLEVEL_MODES, + IRCTXT_USERMODE_CHANGE, mode, channel); + } else if (addr == NULL) { + /* channel mode changed by server */ + printformat(server, channel, MSGLEVEL_MODES, + IRCTXT_SERVER_CHANMODE_CHANGE, + channel, mode, nick); + } else { + /* channel mode changed by normal user */ + IRC_CHANNEL_REC *chanrec; + + chanrec = !group_multi_mode ? NULL : + irc_channel_find(server, channel); + + if (chanrec != NULL) + msg_multi_mode(chanrec, nick, addr, mode); + else { + printformat(server, channel, MSGLEVEL_MODES, + IRCTXT_CHANMODE_CHANGE, + channel, mode, nick); + } + } +} + +static void read_settings(void) +{ + int old_group; + + old_group = group_multi_mode; + group_multi_mode = settings_get_bool("group_multi_mode"); + + if (old_group && !group_multi_mode) { + g_source_remove(mode_tag); + mode_tag = -1; + } else if (!old_group && group_multi_mode) { + mode_tag = g_timeout_add(1000, (GSourceFunc) sig_check_modes, NULL); + } +} + +void fe_modes_init(void) +{ + settings_add_bool("misc", "group_multi_mode", TRUE); + mode_tag = -1; + + read_settings(); + signal_add("message mode", (SIGNAL_FUNC) sig_message_mode); + signal_add("setup changed", (SIGNAL_FUNC) read_settings); +} + +void fe_modes_deinit(void) +{ + if (mode_tag != -1) + g_source_remove(mode_tag); + + signal_remove("message mode", (SIGNAL_FUNC) sig_message_mode); + signal_remove("setup changed", (SIGNAL_FUNC) read_settings); +} diff --git a/src/fe-common/irc/fe-netjoin.c b/src/fe-common/irc/fe-netjoin.c index 0473e52c..916a1985 100644 --- a/src/fe-common/irc/fe-netjoin.c +++ b/src/fe-common/irc/fe-netjoin.c @@ -33,7 +33,7 @@ #include "printtext.h" -#define NETJOIN_WAIT_TIME 2 /* how many seconds to wait for the netsplitted JOIN messages to stop */ +#define NETJOIN_WAIT_TIME 5 /* how many seconds to wait for the netsplitted JOIN messages to stop */ #define NETJOIN_MAX_WAIT 30 /* how many seconds to wait for nick to join to the rest of the channels she was before the netsplit */ typedef struct { @@ -56,6 +56,7 @@ typedef struct { static int join_tag; static int netjoin_max_nicks, hide_netsplit_quits; +static int printing_joins; static GSList *joinservers; static NETJOIN_SERVER_REC *netjoin_find_server(IRC_SERVER_REC *server) @@ -172,6 +173,8 @@ static void print_netjoins(NETJOIN_SERVER_REC *server) g_return_if_fail(server != NULL); + printing_joins = TRUE; + /* save nicks to string, clear now_channels and remove the same channels from old_channels list */ channels = g_hash_table_new((GHashFunc) g_istr_hash, @@ -225,7 +228,9 @@ static void print_netjoins(NETJOIN_SERVER_REC *server) g_hash_table_destroy(channels); if (server->netjoins == NULL) - netjoin_server_remove(server); + netjoin_server_remove(server); + + printing_joins = FALSE; } /* something is going to be printed to screen, print our current netsplit @@ -234,6 +239,9 @@ static void sig_print_starting(void) { GSList *tmp, *next; + if (printing_joins) + return; + for (tmp = joinservers; tmp != NULL; tmp = next) { NETJOIN_SERVER_REC *server = tmp->data; @@ -398,6 +406,7 @@ void fe_netjoin_init(void) settings_add_int("misc", "netjoin_max_nicks", 10); join_tag = -1; + printing_joins = FALSE; read_settings(); signal_add("setup changed", (SIGNAL_FUNC) read_settings); diff --git a/src/fe-common/irc/fe-netsplit.c b/src/fe-common/irc/fe-netsplit.c index 9a4b9446..ca1ca76a 100644 --- a/src/fe-common/irc/fe-netsplit.c +++ b/src/fe-common/irc/fe-netsplit.c @@ -32,10 +32,11 @@ #include "printtext.h" -#define SPLIT_WAIT_TIME 2 /* how many seconds to wait for the QUIT split messages to stop */ +#define SPLIT_WAIT_TIME 5 /* how many seconds to wait for the QUIT split messages to stop */ static int split_tag; static int netsplit_max_nicks, netsplit_nicks_hide_threshold; +static int printing_splits; static int get_last_split(IRC_SERVER_REC *server) { @@ -196,6 +197,8 @@ static void print_splits(IRC_SERVER_REC *server) TEMP_SPLIT_REC temp; GSList *servers; + printing_splits = TRUE; + servers = g_slist_copy(server->split_servers); while (servers != NULL) { NETSPLIT_SERVER_REC *sserver = servers->data; @@ -215,6 +218,8 @@ static void print_splits(IRC_SERVER_REC *server) g_slist_free(temp.servers); g_slist_free(temp.channels); } + + printing_splits = FALSE; } static int check_server_splits(IRC_SERVER_REC *server) @@ -237,6 +242,9 @@ static void sig_print_starting(void) { GSList *tmp; + if (printing_splits) + return; + for (tmp = servers; tmp != NULL; tmp = tmp->next) { IRC_SERVER_REC *rec = tmp->data; @@ -320,6 +328,7 @@ void fe_netsplit_init(void) settings_add_int("misc", "netsplit_max_nicks", 10); settings_add_int("misc", "netsplit_nicks_hide_threshold", 15); split_tag = -1; + printing_splits = FALSE; read_settings(); signal_add("netsplit add", (SIGNAL_FUNC) sig_netsplit_servers); |