aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c75
1 files changed, 47 insertions, 28 deletions
diff --git a/degesch.c b/degesch.c
index 6a7e0db..2118a4d 100644
--- a/degesch.c
+++ b/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)
{
@@ -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