degesch: add a /connect command
This commit is contained in:
parent
689a337651
commit
56a67d56e0
75
degesch.c
75
degesch.c
|
@ -1983,6 +1983,10 @@ irc_remove_user_from_channel (struct user *user, struct channel *channel)
|
||||||
|
|
||||||
// --- Supporting code ---------------------------------------------------------
|
// --- 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 *
|
static char *
|
||||||
irc_cut_nickname (const char *prefix)
|
irc_cut_nickname (const char *prefix)
|
||||||
{
|
{
|
||||||
|
@ -4236,6 +4240,22 @@ handle_command_part (struct app_context *ctx, char *arguments)
|
||||||
return true;
|
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
|
static bool
|
||||||
handle_command_list (struct app_context *ctx, char *arguments)
|
handle_command_list (struct app_context *ctx, char *arguments)
|
||||||
{
|
{
|
||||||
|
@ -4283,31 +4303,31 @@ static struct command_handler
|
||||||
}
|
}
|
||||||
g_command_handlers[] =
|
g_command_handlers[] =
|
||||||
{
|
{
|
||||||
{ "help", handle_command_help, "Show help",
|
{ "help", handle_command_help, "Show help",
|
||||||
"[<command> | <option>]" },
|
"[<command> | <option>]" },
|
||||||
{ "quit", handle_command_quit, "Quit the program",
|
{ "quit", handle_command_quit, "Quit the program",
|
||||||
"[<message>]" },
|
"[<message>]" },
|
||||||
{ "buffer", handle_command_buffer, "Manage buffers",
|
{ "buffer", handle_command_buffer, "Manage buffers",
|
||||||
"list | clear | move | { close [<number> | <name>] } | <number>" },
|
"list | clear | move | { close [<number> | <name>] } | <number>" },
|
||||||
{ "set", handle_command_set, "Manage configuration",
|
{ "set", handle_command_set, "Manage configuration",
|
||||||
"[<option>]" },
|
"[<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>" },
|
"<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>" },
|
"<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>" },
|
"<target> <message>" },
|
||||||
{ "ctcp", handle_command_ctcp, "Send a CTCP query",
|
{ "ctcp", handle_command_ctcp, "Send a CTCP query",
|
||||||
"<target> <tag>" },
|
"<target> <tag>" },
|
||||||
{ "me", handle_command_me, "Send a CTCP action",
|
{ "me", handle_command_me, "Send a CTCP action",
|
||||||
"<message>" },
|
"<message>" },
|
||||||
|
|
||||||
{ "join", handle_command_join, "Join channels",
|
{ "join", handle_command_join, "Join channels",
|
||||||
"[<channel>[,<channel>...]]" },
|
"[<channel>[,<channel>...]]" },
|
||||||
{ "part", handle_command_part, "Leave channels",
|
{ "part", handle_command_part, "Leave channels",
|
||||||
"[<channel>[,<channel>...]]" },
|
"[<channel>[,<channel>...]]" },
|
||||||
#if 0
|
#if 0
|
||||||
{ "cycle", NULL, "", "" },
|
{ "cycle", NULL, "", "" },
|
||||||
|
@ -4320,7 +4340,9 @@ g_command_handlers[] =
|
||||||
{ "invite", NULL, "", "" },
|
{ "invite", NULL, "", "" },
|
||||||
#endif
|
#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]" },
|
"[<channel>[,<channel>...]] [server]" },
|
||||||
#if 0
|
#if 0
|
||||||
{ "names", NULL, "", "" },
|
{ "names", NULL, "", "" },
|
||||||
|
@ -4330,9 +4352,9 @@ g_command_handlers[] =
|
||||||
{ "motd", NULL, "", "" },
|
{ "motd", NULL, "", "" },
|
||||||
{ "away", NULL, "", "" },
|
{ "away", NULL, "", "" },
|
||||||
#endif
|
#endif
|
||||||
{ "nick", handle_command_nick, "Change current nick",
|
{ "nick", handle_command_nick, "Change current nick",
|
||||||
"<nickname>" },
|
"<nickname>" },
|
||||||
{ "quote", handle_command_quote, "Send a raw command to the server",
|
{ "quote", handle_command_quote, "Send a raw command to the server",
|
||||||
"<command>" },
|
"<command>" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4590,9 +4612,6 @@ start:
|
||||||
return IRC_READ_ERROR;
|
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
|
static void
|
||||||
irc_cancel_timers (struct server *s)
|
irc_cancel_timers (struct server *s)
|
||||||
{
|
{
|
||||||
|
@ -4601,6 +4620,16 @@ irc_cancel_timers (struct server *s)
|
||||||
poller_timer_reset (&s->reconnect_tmr);
|
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
|
static void
|
||||||
on_irc_reconnect_timeout (void *user_data)
|
on_irc_reconnect_timeout (void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -4618,16 +4647,6 @@ on_irc_reconnect_timeout (void *user_data)
|
||||||
irc_queue_reconnect (s);
|
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
|
static void
|
||||||
on_irc_disconnected (struct server *s)
|
on_irc_disconnected (struct server *s)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue