degesch: add a /connect command

This commit is contained in:
Přemysl Eric Janouch 2015-05-03 20:03:21 +02:00
parent 689a337651
commit 56a67d56e0
1 changed files with 47 additions and 28 deletions

View File

@ -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)
{
@ -4236,6 +4240,22 @@ handle_command_part (struct app_context *ctx, char *arguments)
return true;
}
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)
{
@ -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)
{
@ -4601,6 +4620,16 @@ irc_cancel_timers (struct server *s)
poller_timer_reset (&s->reconnect_tmr);
}
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)
{
@ -4618,16 +4647,6 @@ on_irc_reconnect_timeout (void *user_data)
irc_queue_reconnect (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_disconnected (struct server *s)
{