hirc

IRC client
Log | Files | Refs

commit 7eb311c7ced65471fbd33a317b5e2261fe67fe82
parent fbfd084dba542ff9423b54e368fb6bcf59e088d5
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 13 Dec 2021 19:17:15 +0000

s/commands.c s/serv.c: connected to disconnected servers

Diffstat:
Msrc/commands.c | 8+++++++-
Msrc/serv.c | 26++++++++++++++++++++++++--
2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -360,7 +360,13 @@ command_connect(struct Server *server, char *str) { host = strtok(str, " "); port = strtok(NULL, " "); - if (!host) { + if (!host && network && serv_get(&servers, network)) { + serv_connect(serv_get(&servers, network)); + return; + } else if (!host && server) { + serv_connect(server); + return; + } else if (!host) { ui_error("must specify host", NULL); return; } diff --git a/src/serv.c b/src/serv.c @@ -83,8 +83,6 @@ serv_create(char *name, char *host, char *port, char *nick, server->host = estrdup(host); server->port = estrdup(port); server->supports = NULL; - support_set(server, "CHANTYPES", config_gets("def.chantypes")); - support_set(server, "PREFIX", config_gets("def.prefixes")); server->self = nick_create(nick, ' ', NULL); server->self->self = 1; server->history = emalloc(sizeof(struct HistInfo)); @@ -212,10 +210,31 @@ serv_remove(struct Server **head, char *name) { void serv_connect(struct Server *server) { + struct Support *s, *prev; struct addrinfo hints; struct addrinfo *ai; int fd, ret, serrno; + if (!server) + return; + + if (server->status != ConnStatus_notconnected) { + ui_error("server '%s' is already connected", server->name); + return; + } + + for (s = server->supports, prev = NULL; s; s = s->next) { + if (prev) { + free(prev->key); + free(prev->value); + free(prev); + } + prev = s; + } + server->supports = NULL; + support_set(server, "CHANTYPES", config_gets("def.chantypes")); + support_set(server, "PREFIX", config_gets("def.prefixes")); + server->status = ConnStatus_connecting; hist_format(server->history, Activity_status, HIST_SHOW|HIST_MAIN, "SELF_CONNECTING %s %s", server->host, server->port); @@ -294,6 +313,7 @@ serv_poll(struct Server **head, int timeout) { void serv_disconnect(struct Server *server, int reconnect, char *msg) { struct Channel *chan; + struct Support *s, *prev = NULL; if (msg) ircprintf(server, "QUIT %s\r\n", msg); @@ -311,6 +331,8 @@ serv_disconnect(struct Server *server, int reconnect, char *msg) { for (chan = server->channels; chan; chan = chan->next) chan_setold(chan, 1); + server->supports = NULL; + windows[Win_buflist].refresh = 1; }