degesch: implement /disconnect

One bug remaining to make it work.
This commit is contained in:
Přemysl Eric Janouch 2015-05-09 23:30:04 +02:00
parent e3b14e7d36
commit c52f353894
1 changed files with 36 additions and 8 deletions

View File

@ -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",
"[<channel>[,<channel>...]] [server]",
handle_command_list },