Channel autoconnect, installable using make and some fixes.

This commit is contained in:
Johannes Findeisen 2026-11-27 02:17:35 +01:00
commit 3cae7a8242
4 changed files with 66 additions and 8 deletions

41
irc9.c
View file

@ -71,6 +71,13 @@ typedef struct Window {
Member *members;
} Window;
#ifdef USE_AUTOJOIN
typedef struct AutojoinChannel {
char name[CHANLEN];
struct AutojoinChannel *next;
} AutojoinChannel;
#endif
typedef struct Server {
char host[HOSTLEN];
int port;
@ -95,6 +102,9 @@ typedef struct Server {
char umode[32];
#ifdef USE_OPENSSL
SSL *ssl;
#endif
#ifdef USE_AUTOJOIN
AutojoinChannel *autojoin;
#endif
struct Server *next;
} Server;
@ -484,6 +494,9 @@ static void load_config(const char *path)
char line[1024];
Server *last = NULL;
#ifdef USE_AUTOJOIN
AutojoinChannel **channel_tail = NULL;
#endif
while (fgets(line, sizeof line, f)) {
size_t n = strlen(line);
while (n && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = 0;
@ -520,6 +533,9 @@ static void load_config(const char *path)
s->retry_at = 0;
if (!servers) servers = s; else last->next = s;
last = s;
#ifdef USE_AUTOJOIN
channel_tail = &s->autojoin;
#endif
window_new(s, s->host, W_SERVER);
} else if (strcasecmp(key, "sasl") == 0 && a1 && a2 && last) {
snprintf(last->sasl_user, sizeof last->sasl_user, "%s", a1);
@ -530,7 +546,15 @@ static void load_config(const char *path)
strip_formatting = !strcasecmp(a1, "on") || !strcasecmp(a1, "true") ||
!strcasecmp(a1, "yes") || strcmp(a1, "1") == 0;
} else if (strcasecmp(key, "channel") == 0) {
/* Accepted for compatibility; join channels manually with /join. */
#ifdef USE_AUTOJOIN
if (channel_tail && a1 && strlen(a1) < CHANLEN) {
AutojoinChannel *channel = xmalloc(sizeof *channel);
strcpy(channel->name, a1);
channel->next = NULL;
*channel_tail = channel;
channel_tail = &channel->next;
}
#endif
} else {
fprintf(stderr, "irc9: ignoring config line: %s\n", line);
}
@ -1298,6 +1322,14 @@ static void handle_line(Server *s, char *line)
if (strcmp(cmd, "001") == 0) {
s->connected = 1;
#ifdef USE_AUTOJOIN
while (s->autojoin) {
AutojoinChannel *channel = s->autojoin;
sendf(s, "JOIN %s", channel->name);
s->autojoin = channel->next;
free(channel);
}
#endif
appendf(sw, "%s", narg > 0 ? arg[narg - 1] : cmd);
return;
}
@ -2340,6 +2372,13 @@ int main(int argc, char **argv)
if (s->ssl) SSL_free(s->ssl);
#endif
if (s->fd >= 0) close(s->fd);
#ifdef USE_AUTOJOIN
while (s->autojoin) {
AutojoinChannel *channel = s->autojoin;
s->autojoin = channel->next;
free(channel);
}
#endif
free(s);
s = sn;
}