summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-09 23:30:04 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-09 23:30:04 +0200
commitc52f3538945d16e2cfcabb8d080005867f256ba2 (patch)
tree30b8f466328a773e77eb30ee2684aa2c795761ec /degesch.c
parente3b14e7d3689c5af25ceaaf186da7e4fb0948844 (diff)
downloadxK-c52f3538945d16e2cfcabb8d080005867f256ba2.tar.gz
xK-c52f3538945d16e2cfcabb8d080005867f256ba2.tar.xz
xK-c52f3538945d16e2cfcabb8d080005867f256ba2.zip
degesch: implement /disconnect
One bug remaining to make it work.
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c44
1 files 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;
}
@@ -4782,6 +4793,23 @@ handle_command_connect (struct app_context *ctx, char *arguments)
}
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)
{
if (!server_command_check (ctx, "list channels"))
@@ -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 },