commit fbfd084dba542ff9423b54e368fb6bcf59e088d5
parent b68c3f2f1850b4339e9d166f5c8458a558f0e4aa
Author: hhvn <dev@hhvn.uk>
Date: Mon, 13 Dec 2021 17:26:58 +0000
s/commands.c s/serv.c: /disconnect
Diffstat:
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/src/commands.c b/src/commands.c
@@ -34,6 +34,7 @@ static void command_kick(struct Server *server, char *str);
static void command_ping(struct Server *server, char *str);
static void command_quote(struct Server *server, char *str);
static void command_connect(struct Server *server, char *str);
+static void command_disconnect(struct Server *server, char *str);
static void command_select(struct Server *server, char *str);
static void command_set(struct Server *server, char *str);
static void command_format(struct Server *server, char *str);
@@ -83,6 +84,9 @@ struct Command commands[] = {
"usage: /connect [-network <name>] [-nick <nick>] [-user <user>]",
" [-real <comment>] [-tls] [-verify] <host> [port]",
"Connect to a network/server", NULL}},
+ {"disconnect", command_disconnect, 0, {
+ "usage: /disconnect [network]",
+ "Disconnect from a network/server", NULL}},
{"select", command_select, 0, {
"usage: /select [-network <name>] [-channel <name>] [buffer id]",
"Select a buffer", NULL}},
@@ -378,6 +382,36 @@ command_connect(struct Server *server, char *str) {
}
static void
+command_disconnect(struct Server *server, char *str) {
+ struct Server *sp;
+ int len;
+ char *msg;
+
+ if (str) {
+ len = strcspn(str, " ");
+ for (sp = servers; sp; sp = sp->next) {
+ if (strlen(sp->name) == len && strncmp(sp->name, str, len) == 0) {
+ msg = strchr(str, ' ');
+ if (msg && *msg)
+ msg++;
+ break;
+ }
+ }
+
+ if (sp == NULL) {
+ sp = server;
+ msg = str;
+ return;
+ }
+ } else sp = server;
+
+ if (!msg || !*msg)
+ msg = config_gets("def.quitmessage");
+
+ serv_disconnect(sp, 0, msg);
+}
+
+static void
command_select(struct Server *server, char *str) {
struct Server *sp;
struct Channel *chp;
diff --git a/src/serv.c b/src/serv.c
@@ -293,6 +293,8 @@ serv_poll(struct Server **head, int timeout) {
void
serv_disconnect(struct Server *server, int reconnect, char *msg) {
+ struct Channel *chan;
+
if (msg)
ircprintf(server, "QUIT %s\r\n", msg);
shutdown(server->rfd, SHUT_RDWR);
@@ -305,6 +307,11 @@ serv_disconnect(struct Server *server, int reconnect, char *msg) {
server->lastrecv = server->pingsent = 0;
server->lastconnected = time(NULL);
server->reconnect = reconnect;
+
+ for (chan = server->channels; chan; chan = chan->next)
+ chan_setold(chan, 1);
+
+ windows[Win_buflist].refresh = 1;
}
int