From 1ccd082cd20289c389bc8cb74f1f053c2900c0e5 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Sun, 16 Apr 2017 16:19:55 +1000 Subject: [PATCH] Cleanup remove_channel() remove_channel() is only called in direct response to a message from a server, so it always acts on from_server - remove the unnecessary server argument. The channel argument is always non-NULL - remove the dead code that removed all channels if a NULL channel was passed. --- include/modval.h | 2 +- include/names.h | 2 +- source/names.c | 52 ++++++++++++++++-------------------------------- source/numbers.c | 4 ++-- source/parse.c | 4 ++-- 5 files changed, 23 insertions(+), 41 deletions(-) diff --git a/include/modval.h b/include/modval.h index 04d50fb..e9dc02a 100644 --- a/include/modval.h +++ b/include/modval.h @@ -427,7 +427,7 @@ extern Function_ptr *global; #define get_channel_bans (*(char *(*)(char *, int , int ))global[GET_CHANNEL_BANS]) #define get_channel_mode (*(char *(*)(char *, int ))global[GET_CHANNEL_MODE]) #define clear_bans (*(void (*)(ChannelList *))global[CLEAR_BANS]) -#define remove_channel (*(void (*)(char *, int ))global[REMOVE_CHANNEL]) +#define remove_channel (*(void (*)(const char *))global[REMOVE_CHANNEL]) #define remove_from_channel (*(void (*)(char *, char *, int , int , char *))global[REMOVE_FROM_CHANNEL]) #define rename_nick (*(void (*)(char *, char *, int ))global[RENAME_NICK]) #define get_channel_oper (*(int (*)(char *, int ))global[GET_CHANNEL_OPER]) diff --git a/include/names.h b/include/names.h index a41366b..a47133e 100644 --- a/include/names.h +++ b/include/names.h @@ -61,7 +61,7 @@ void set_channel_mode (char *, int, char *); #endif /* INCLUDE_UNUSED_FUNCTIONS */ ChannelList * BX_add_channel (char *, int, int); ChannelList * BX_add_to_channel (char *, char *, int, int, int, char *, char *, char *, int, int); -void BX_remove_channel (char *, int); +void BX_remove_channel (const char *); void BX_remove_from_channel (char *, char *, int, int, char *); int BX_is_on_channel (char *, int, char *); void list_channels (void); diff --git a/source/names.c b/source/names.c index cf8efee..7477eb9 100644 --- a/source/names.c +++ b/source/names.c @@ -1207,48 +1207,30 @@ void BX_clear_bans(ChannelList *channel) channel->exemptbans = NULL; } -/* - * remove_channel: removes the named channel from the - * server_list[server].chan_list. If the channel is not on the - * server_list[server].chan_list, nothing happens. If the channel was - * the current channel, this will select the top of the - * server_list[server].chan_list to be the current_channel, or 0 if the - * list is empty. +/* remove_channel() + * + * Removes the named channel from the channel list for the current context + * server. If the channel was the current channel for a window, this will + * select a new current channel if possible. + * + * Should be called in direct response to a message from the server indicating + * that we are no longer on the channel. */ - -void BX_remove_channel (char *channel, int server) +void BX_remove_channel(const char *channel) { ChannelList *tmp; - int old_from_server = from_server; - if (channel) + if (*channel == '*') + return; + if ((tmp = lookup_channel(channel, from_server, CHAN_UNLINK))) { - if (*channel == '*') - return; - from_server = server; - from_server = old_from_server; - if ((tmp = lookup_channel(channel, server, CHAN_UNLINK))) - { - clear_bans(tmp); - clear_channel(tmp); - add_to_whowas_chan_buffer(tmp); - } - if (is_current_channel(channel, server, 1)) - switch_channels(0, NULL); + clear_bans(tmp); + clear_channel(tmp); + add_to_whowas_chan_buffer(tmp); } - else - { - ChannelList *next; + if (is_current_channel(channel, from_server, 1)) + switch_channels(0, NULL); - for (tmp = get_server_channels(server); tmp; tmp = next) - { - next = tmp->next; - clear_channel(tmp); - clear_bans(tmp); - add_to_whowas_chan_buffer(tmp); - } - set_server_channels(server, NULL); - } xterm_settitle(); update_all_windows(); } diff --git a/source/numbers.c b/source/numbers.c index 5f09110..4d5bef2 100644 --- a/source/numbers.c +++ b/source/numbers.c @@ -316,7 +316,7 @@ static void not_valid_channel(char *from, char **ArgList) if (!my_stricmp(from, get_server_itsname(from_server))) { if (strcmp(channel, "*")) - remove_channel(channel, from_server); + remove_channel(channel); put_it("%s", convert_output_format(fget_string_var(FORMAT_SERVER_MSG2_FSET), "%s %s %s", update_clock(GET_TIME), channel, ArgList[1])); } } @@ -343,7 +343,7 @@ static void cannot_join_channel(char *from, char **ArgList) remove_from_join_list(chan, from_server); if (!is_on_channel(chan, from_server, get_server_nickname(from_server))) - remove_channel(chan, from_server); + remove_channel(chan); else return; diff --git a/source/parse.c b/source/parse.c index 5d5a48f..7eb339a 100644 --- a/source/parse.c +++ b/source/parse.c @@ -1719,7 +1719,7 @@ static void p_kick(char *from, char **ArgList) new_free(&chankey); if (do_hook(KICK_LIST, "%s %s %s %s", who, from, channel, comment?comment:empty_string)) put_it("%s",convert_output_format(fget_string_var(FORMAT_KICK_USER_FSET),"%s %s %s %s %s",update_clock(GET_TIME),from, channel, who, comment)); - remove_channel(channel, from_server); + remove_channel(channel); update_all_status(window ? window : current_window, NULL, 0); update_input(UPDATE_ALL); logmsg(LOG_KICK_USER, from, 0, "%s %s %s %s", FromUserHost, who, channel, comment); @@ -1784,7 +1784,7 @@ static void p_part(char *from, char **ArgList) put_it("%s",convert_output_format(fget_string_var(FORMAT_LEAVE_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from, FromUserHost, channel, ArgList[1]?ArgList[1]:empty_string)); if (!my_stricmp(from, get_server_nickname(from_server))) { - remove_channel(channel, from_server); + remove_channel(channel); remove_from_mode_list(channel, from_server); remove_from_join_list(channel, from_server); set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0);