degesch: add a /connect command
This commit is contained in:
parent
689a337651
commit
56a67d56e0
45
degesch.c
45
degesch.c
|
@ -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)
|
||||
{
|
||||
|
@ -4320,6 +4340,8 @@ g_command_handlers[] =
|
|||
{ "invite", NULL, "", "" },
|
||||
#endif
|
||||
|
||||
{ "connect", handle_command_connect, "Connect to the server",
|
||||
"" },
|
||||
{ "list", handle_command_list, "List channels and their topic",
|
||||
"[<channel>[,<channel>...]] [server]" },
|
||||
#if 0
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue