diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-05-03 20:03:21 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-05-03 20:03:21 +0200 |
commit | 56a67d56e0ac5da860756418014f7f1ba2586a33 (patch) | |
tree | 4e7fdca839585354a1ee5ff5e620fb8e9f69d0f9 | |
parent | 689a33765188555365216e2179de489309e22aaf (diff) | |
download | xK-56a67d56e0ac5da860756418014f7f1ba2586a33.tar.gz xK-56a67d56e0ac5da860756418014f7f1ba2586a33.tar.xz xK-56a67d56e0ac5da860756418014f7f1ba2586a33.zip |
degesch: add a /connect command
-rw-r--r-- | degesch.c | 75 |
1 files changed, 47 insertions, 28 deletions
@@ -1983,6 +1983,10 @@ irc_remove_user_from_channel (struct user *user, struct channel *channel) // --- Supporting code --------------------------------------------------------- +static bool irc_connect (struct server *s, bool *should_retry, struct error **); +static void irc_cancel_timers (struct server *s); +static void on_irc_reconnect_timeout (void *user_data); + static char * irc_cut_nickname (const char *prefix) { @@ -4237,6 +4241,22 @@ handle_command_part (struct app_context *ctx, char *arguments) } static bool +handle_command_connect (struct app_context *ctx, char *arguments) +{ + // TODO: multiserver + struct server *s = &ctx->server; + if (s->irc_fd != -1) + { + buffer_send_error (ctx, s->buffer, "Already connected"); + return true; + } + + irc_cancel_timers (s); + on_irc_reconnect_timeout (s); + return true; +} + +static bool handle_command_list (struct app_context *ctx, char *arguments) { if (!server_command_check (ctx, "list channels")) @@ -4283,31 +4303,31 @@ static struct command_handler } g_command_handlers[] = { - { "help", handle_command_help, "Show help", + { "help", handle_command_help, "Show help", "[<command> | <option>]" }, - { "quit", handle_command_quit, "Quit the program", + { "quit", handle_command_quit, "Quit the program", "[<message>]" }, - { "buffer", handle_command_buffer, "Manage buffers", + { "buffer", handle_command_buffer, "Manage buffers", "list | clear | move | { close [<number> | <name>] } | <number>" }, - { "set", handle_command_set, "Manage configuration", + { "set", handle_command_set, "Manage configuration", "[<option>]" }, - { "save", handle_command_save, "Save configuration", + { "save", handle_command_save, "Save configuration", "" }, - { "msg", handle_command_msg, "Send message to a nick or channel", + { "msg", handle_command_msg, "Send message to a nick or channel", "<target> <message>" }, - { "query", handle_command_query, "Send a private message to a nick", + { "query", handle_command_query, "Send a private message to a nick", "<nick> <message>" }, - { "notice", handle_command_notice, "Send notice to a nick or channel", + { "notice", handle_command_notice, "Send notice to a nick or channel", "<target> <message>" }, - { "ctcp", handle_command_ctcp, "Send a CTCP query", + { "ctcp", handle_command_ctcp, "Send a CTCP query", "<target> <tag>" }, - { "me", handle_command_me, "Send a CTCP action", + { "me", handle_command_me, "Send a CTCP action", "<message>" }, - { "join", handle_command_join, "Join channels", + { "join", handle_command_join, "Join channels", "[<channel>[,<channel>...]]" }, - { "part", handle_command_part, "Leave channels", + { "part", handle_command_part, "Leave channels", "[<channel>[,<channel>...]]" }, #if 0 { "cycle", NULL, "", "" }, @@ -4320,7 +4340,9 @@ g_command_handlers[] = { "invite", NULL, "", "" }, #endif - { "list", handle_command_list, "List channels and their topic", + { "connect", handle_command_connect, "Connect to the server", + "" }, + { "list", handle_command_list, "List channels and their topic", "[<channel>[,<channel>...]] [server]" }, #if 0 { "names", NULL, "", "" }, @@ -4330,9 +4352,9 @@ g_command_handlers[] = { "motd", NULL, "", "" }, { "away", NULL, "", "" }, #endif - { "nick", handle_command_nick, "Change current nick", + { "nick", handle_command_nick, "Change current nick", "<nickname>" }, - { "quote", handle_command_quote, "Send a raw command to the server", + { "quote", handle_command_quote, "Send a raw command to the server", "<command>" }, }; @@ -4590,9 +4612,6 @@ start: return IRC_READ_ERROR; } -static bool irc_connect (struct server *s, bool *should_retry, struct error **); -static void irc_queue_reconnect (struct server *s); - static void irc_cancel_timers (struct server *s) { @@ -4602,6 +4621,16 @@ irc_cancel_timers (struct server *s) } static void +irc_queue_reconnect (struct server *s) +{ + // TODO: exponentional backoff + hard_assert (s->irc_fd == -1); + buffer_send_status (s->ctx, s->buffer, + "Trying to reconnect in %ld seconds...", s->ctx->reconnect_delay); + poller_timer_set (&s->reconnect_tmr, s->ctx->reconnect_delay * 1000); +} + +static void on_irc_reconnect_timeout (void *user_data) { struct server *s = user_data; @@ -4619,16 +4648,6 @@ on_irc_reconnect_timeout (void *user_data) } static void -irc_queue_reconnect (struct server *s) -{ - // TODO: exponentional backoff - hard_assert (s->irc_fd == -1); - buffer_send_status (s->ctx, s->buffer, - "Trying to reconnect in %ld seconds...", s->ctx->reconnect_delay); - poller_timer_set (&s->reconnect_tmr, s->ctx->reconnect_delay * 1000); -} - -static void on_irc_disconnected (struct server *s) { // Get rid of the dead socket and related things |