From c52f3538945d16e2cfcabb8d080005867f256ba2 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 9 May 2015 23:30:04 +0200 Subject: degesch: implement /disconnect One bug remaining to make it work. --- degesch.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/degesch.c b/degesch.c index e85f013..0f4cd6e 100644 --- a/degesch.c +++ b/degesch.c @@ -985,8 +985,10 @@ enum server_state struct server { struct app_context *ctx; ///< Application context + bool reconnect; ///< Whether to reconnect on conn. fail. unsigned long reconnect_delay; ///< Reconnect delay in seconds + bool manual_disconnect; ///< Don't reconnect enum server_state state; ///< Connection state struct connector *connector; ///< Connection establisher @@ -2769,10 +2771,24 @@ on_irc_disconnected (struct server *s) if (s->ctx->quitting) try_finish_quit (s->ctx); + else if (s->manual_disconnect) + s->manual_disconnect = false; else irc_queue_reconnect (s); } +static void +irc_initiate_disconnect (struct server *s, const char *reason) +{ + hard_assert (irc_is_connected (s)); + + s->manual_disconnect = true; + if (reason) + irc_send (s, "QUIT :%s", reason); + else + irc_send (s, "QUIT :%s", PROGRAM_NAME " " PROGRAM_VERSION); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static void @@ -4697,12 +4713,7 @@ handle_command_quit (struct app_context *ctx, char *arguments) // TODO: multiserver struct server *s = &ctx->server; if (irc_is_connected (s)) - { - if (*arguments) - irc_send (s, "QUIT :%s", arguments); - else - irc_send (s, "QUIT :%s", PROGRAM_NAME " " PROGRAM_VERSION); - } + irc_initiate_disconnect (s, *arguments ? arguments : NULL); initiate_quit (ctx); return true; } @@ -4781,6 +4792,23 @@ handle_command_connect (struct app_context *ctx, char *arguments) return true; } +static bool +handle_command_disconnect (struct app_context *ctx, char *arguments) +{ + // TODO: multiserver + struct server *s = &ctx->server; + if (s->state == IRC_CONNECTING) + { + buffer_send_status (ctx, s->buffer, "Connecting aborted"); + irc_destroy_connector (s); + } + else if (!irc_is_connected (s)) + buffer_send_error (ctx, s->buffer, "Not connected"); + else + irc_initiate_disconnect (s, *arguments ? arguments : NULL); + return true; +} + static bool handle_command_list (struct app_context *ctx, char *arguments) { @@ -4885,8 +4913,8 @@ g_command_handlers[] = NULL, handle_command_connect }, { "disconnect", "Disconnect from the server", - NULL, - NULL }, + "[reason]", + handle_command_disconnect }, { "list", "List channels and their topic", "[[,...]] [server]", handle_command_list }, -- cgit v1.2.3-70-g09d2