From d398247f762e111e82f418af142dd7e70d1d167a Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 14 Oct 2000 01:03:11 +0000 Subject: [PATCH] Handle event "407 duplicate channel" correctly - happens when trying to create !channel (/join !!channel) while it already exists. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@741 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/irc/fe-events-numeric.c | 22 +++++++++++++++++++++ src/fe-common/irc/module-formats.c | 1 + src/fe-common/irc/module-formats.h | 1 + src/irc/core/channel-events.c | 28 +++++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/fe-common/irc/fe-events-numeric.c b/src/fe-common/irc/fe-events-numeric.c index 4c365a51..88775eb1 100644 --- a/src/fe-common/irc/fe-events-numeric.c +++ b/src/fe-common/irc/fe-events-numeric.c @@ -587,6 +587,26 @@ static void event_too_many_channels(const char *data, IRC_SERVER_REC *server) cannot_join(data, server, IRCTXT_JOINERROR_TOOMANY); } +static void event_duplicate_channel(const char *data, IRC_SERVER_REC *server) +{ + char *params, *channel, *p; + + g_return_if_fail(data != NULL); + + /* this new addition to ircd breaks completely with older + "standards", "nick Duplicate ::!!channel ...." */ + params = event_get_params(data, 3, NULL, NULL, &channel); + p = strchr(channel, ' '); + if (p != NULL) *p = '\0'; + + if (channel[0] == '!' && channel[1] == '!') { + printformat(server, NULL, MSGLEVEL_CRAP, + IRCTXT_JOINERROR_DUPLICATE, channel+1); + } + + g_free(params); +} + static void event_channel_is_full(const char *data, IRC_SERVER_REC *server) { cannot_join(data, server, IRCTXT_JOINERROR_FULL); @@ -710,6 +730,7 @@ void fe_events_numeric_init(void) signal_add("event 401", (SIGNAL_FUNC) event_no_such_nick); signal_add("event 403", (SIGNAL_FUNC) event_no_such_channel); signal_add("event 405", (SIGNAL_FUNC) event_too_many_channels); + signal_add("event 407", (SIGNAL_FUNC) event_duplicate_channel); signal_add("event 471", (SIGNAL_FUNC) event_channel_is_full); signal_add("event 472", (SIGNAL_FUNC) event_unknown_mode); signal_add("event 473", (SIGNAL_FUNC) event_invite_only); @@ -768,6 +789,7 @@ void fe_events_numeric_deinit(void) signal_remove("event 401", (SIGNAL_FUNC) event_no_such_nick); signal_remove("event 403", (SIGNAL_FUNC) event_no_such_channel); signal_remove("event 405", (SIGNAL_FUNC) event_too_many_channels); + signal_remove("event 407", (SIGNAL_FUNC) event_duplicate_channel); signal_remove("event 471", (SIGNAL_FUNC) event_channel_is_full); signal_remove("event 472", (SIGNAL_FUNC) event_unknown_mode); signal_remove("event 473", (SIGNAL_FUNC) event_invite_only); diff --git a/src/fe-common/irc/module-formats.c b/src/fe-common/irc/module-formats.c index 4b193840..e9d41684 100644 --- a/src/fe-common/irc/module-formats.c +++ b/src/fe-common/irc/module-formats.c @@ -55,6 +55,7 @@ FORMAT_REC fecommon_irc_formats[] = { { "joinerror_bad_key", "Cannot join to channel %_$0%_ %K(%nBad channel key%K)", 1, { 0 } }, { "joinerror_bad_mask", "Cannot join to channel %_$0%_ %K(%nBad channel mask%K)", 1, { 0 } }, { "joinerror_unavail", "Cannot join to channel %_$0%_ %K(%nChannel is temporarily unavailable%K)", 1, { 0 } }, + { "joinerror_duplicate", "Channel %_$0%_ already exists - cannot create it", 1, { 0 } }, { "channel_rejoin", "Channel %_$0%_ is temporarily unavailable, this is normally because of netsplits. Irssi will now automatically try to rejoin to this channel until the join is successfull. Use /RMREJOINS command if you wish to abort this.", 1, { 0 } }, { "inviting", "Inviting $0 to %_$1", 2, { 0, 0 } }, { "not_invited", "You have not been invited to a channel!", 0 }, diff --git a/src/fe-common/irc/module-formats.h b/src/fe-common/irc/module-formats.h index 75e84a4b..88980328 100644 --- a/src/fe-common/irc/module-formats.h +++ b/src/fe-common/irc/module-formats.h @@ -32,6 +32,7 @@ enum { IRCTXT_JOINERROR_BAD_KEY, IRCTXT_JOINERROR_BAD_MASK, IRCTXT_JOINERROR_UNAVAIL, + IRCTXT_JOINERROR_DUPLICATE, IRCTXT_CHANNEL_REJOIN, IRCTXT_INVITING, IRCTXT_NOT_INVITED, diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c index 936ca0e2..0fc43c5b 100644 --- a/src/irc/core/channel-events.c +++ b/src/irc/core/channel-events.c @@ -54,6 +54,30 @@ static void event_cannot_join(const char *data, IRC_SERVER_REC *server) g_free(params); } +static void event_duplicate_channel(const char *data, IRC_SERVER_REC *server) +{ + CHANNEL_REC *chanrec; + char *params, *channel, *p; + + g_return_if_fail(data != NULL); + + /* this new addition to ircd breaks completely with older + "standards", "nick Duplicate ::!!channel ...." */ + params = event_get_params(data, 3, NULL, NULL, &channel); + p = strchr(channel, ' '); + if (p != NULL) *p = '\0'; + + if (channel[0] == '!' && channel[1] == '!') { + chanrec = channel_find(SERVER(server), channel+1); + if (chanrec != NULL && !chanrec->names_got) { + chanrec->left = TRUE; + channel_destroy(chanrec); + } + } + + g_free(params); +} + static void event_target_unavailable(const char *data, IRC_SERVER_REC *server) { char *params, *channel; @@ -246,7 +270,7 @@ void channel_events_init(void) { signal_add_first("event 403", (SIGNAL_FUNC) event_cannot_join); /* no such channel */ signal_add_first("event 405", (SIGNAL_FUNC) event_cannot_join); /* too many channels */ - signal_add_first("event 407", (SIGNAL_FUNC) event_cannot_join); /* duplicate channel */ + signal_add_first("event 407", (SIGNAL_FUNC) event_duplicate_channel); /* duplicate channel */ signal_add_first("event 471", (SIGNAL_FUNC) event_cannot_join); /* channel is full */ signal_add_first("event 473", (SIGNAL_FUNC) event_cannot_join); /* invite only */ signal_add_first("event 474", (SIGNAL_FUNC) event_cannot_join); /* banned */ @@ -266,7 +290,7 @@ void channel_events_deinit(void) { signal_remove("event 403", (SIGNAL_FUNC) event_cannot_join); /* no such channel */ signal_remove("event 405", (SIGNAL_FUNC) event_cannot_join); /* too many channels */ - signal_remove("event 407", (SIGNAL_FUNC) event_cannot_join); /* duplicate channel */ + signal_remove("event 407", (SIGNAL_FUNC) event_duplicate_channel); /* duplicate channel */ signal_remove("event 471", (SIGNAL_FUNC) event_cannot_join); /* channel is full */ signal_remove("event 473", (SIGNAL_FUNC) event_cannot_join); /* invite only */ signal_remove("event 474", (SIGNAL_FUNC) event_cannot_join); /* banned */