summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-command.c34
-rw-r--r--src/plugins/irc/irc-server.c49
-rw-r--r--src/plugins/irc/irc-server.h1
3 files changed, 51 insertions, 33 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index a6453c8eb..f80e2fccf 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -3112,39 +3112,7 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc,
if (weechat_strcasecmp (argv[1], "switch") == 0)
{
if (weechat_config_boolean (irc_config_look_one_server_buffer))
- {
- if (irc_current_server)
- {
- ptr_server2 = irc_current_server->next_server;
- if (!ptr_server2)
- ptr_server2 = irc_servers;
- while (ptr_server2 != irc_current_server)
- {
- if (ptr_server2->buffer)
- {
- irc_current_server = ptr_server2;
- break;
- }
- ptr_server2 = ptr_server2->next_server;
- if (!ptr_server2)
- ptr_server2 = irc_servers;
- }
- }
- else
- {
- for (ptr_server2 = irc_servers; ptr_server2;
- ptr_server2 = ptr_server2->next_server)
- {
- if (ptr_server2->buffer)
- {
- irc_current_server = ptr_server2;
- break;
- }
- }
- }
- if (irc_current_server)
- irc_server_set_current_server (irc_current_server);
- }
+ irc_server_switch_next ();
return WEECHAT_RC_OK;
}
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index ffcfc651c..dc18745dc 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -635,6 +635,48 @@ irc_server_outqueue_free_all (struct t_irc_server *server)
}
/*
+ * irc_server_switch_next: swicth to next server
+ */
+
+void
+irc_server_switch_next ()
+{
+ struct t_irc_server *ptr_server;
+
+ if (irc_current_server)
+ {
+ ptr_server = irc_current_server->next_server;
+ if (!ptr_server)
+ ptr_server = irc_servers;
+ while (ptr_server != irc_current_server)
+ {
+ if (ptr_server->buffer)
+ {
+ irc_current_server = ptr_server;
+ break;
+ }
+ ptr_server = ptr_server->next_server;
+ if (!ptr_server)
+ ptr_server = irc_servers;
+ }
+ }
+ else
+ {
+ for (ptr_server = irc_servers; ptr_server;
+ ptr_server = ptr_server->next_server)
+ {
+ if (ptr_server->buffer)
+ {
+ irc_current_server = ptr_server;
+ break;
+ }
+ }
+ }
+ if (irc_current_server)
+ irc_server_set_current_server (irc_current_server);
+}
+
+/*
* irc_server_free_data: free server data
*/
@@ -692,6 +734,13 @@ irc_server_free (struct t_irc_server *server)
if (!server)
return;
+ if (irc_current_server == server)
+ {
+ irc_server_switch_next ();
+ if (irc_current_server == server)
+ irc_current_server = NULL;
+ }
+
/* close all channels/privates */
irc_channel_free_all (server);
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 2ed059176..49344adc0 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -172,6 +172,7 @@ extern void irc_server_buffer_set_highlight_words (struct t_gui_buffer *buffer);
extern void irc_server_set_nick (struct t_irc_server *server, const char *nick);
extern struct t_irc_server *irc_server_alloc (const char *name);
extern int irc_server_alloc_with_url (const char *irc_url);
+extern void irc_server_switch_next ();
extern void irc_server_free_all ();
extern struct t_irc_server *irc_server_copy (struct t_irc_server *server,
const char *new_name);