Enable configured channel autojoin by default
This commit is contained in:
parent
df595580c2
commit
1c31e51ef2
4 changed files with 3 additions and 34 deletions
26
irc9.c
26
irc9.c
|
|
@ -99,7 +99,6 @@ typedef struct Window {
|
|||
Member *members;
|
||||
} Window;
|
||||
|
||||
#ifdef USE_AUTOJOIN
|
||||
typedef struct AutojoinChannel {
|
||||
char name[CHANLEN];
|
||||
char *commands;
|
||||
|
|
@ -108,7 +107,6 @@ typedef struct AutojoinChannel {
|
|||
struct timespec due_at;
|
||||
struct AutojoinChannel *next;
|
||||
} AutojoinChannel;
|
||||
#endif
|
||||
|
||||
typedef struct BlacklistedNick {
|
||||
char nick[NICKLEN];
|
||||
|
|
@ -155,11 +153,9 @@ typedef struct Server {
|
|||
#ifdef USE_OPENSSL
|
||||
SSL *ssl;
|
||||
#endif
|
||||
#ifdef USE_AUTOJOIN
|
||||
AutojoinChannel *autojoin;
|
||||
AutojoinChannel *pending_autojoin;
|
||||
struct timespec next_autojoin;
|
||||
#endif
|
||||
struct Server *next;
|
||||
} Server;
|
||||
|
||||
|
|
@ -814,9 +810,7 @@ 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;
|
||||
|
|
@ -860,7 +854,6 @@ static void load_config(const char *path)
|
|||
}
|
||||
a1 = strtok_r(NULL, " \t", &save);
|
||||
if (strcasecmp(key, "channel") == 0) {
|
||||
#ifdef USE_AUTOJOIN
|
||||
if (channel_tail && a1 && strlen(a1) < CHANLEN) {
|
||||
AutojoinChannel *channel = xmalloc(sizeof *channel);
|
||||
*channel = (AutojoinChannel){0};
|
||||
|
|
@ -875,7 +868,6 @@ static void load_config(const char *path)
|
|||
} else if (*command)
|
||||
fprintf(stderr, "irc9: ignoring invalid command for channel %s\n", a1);
|
||||
}
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
a2 = strtok_r(NULL, " \t", &save);
|
||||
|
|
@ -905,9 +897,7 @@ 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);
|
||||
|
|
@ -1188,7 +1178,6 @@ static void handle_connect_results(void)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_AUTOJOIN
|
||||
/* Pace each server's startup JOINs to avoid flooding the connection. */
|
||||
static void send_autojoin(Server *s)
|
||||
{
|
||||
|
|
@ -1222,7 +1211,6 @@ static void free_autojoin(AutojoinChannel **head)
|
|||
free(channel);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void disconnect_server(Server *s)
|
||||
{
|
||||
|
|
@ -1243,10 +1231,8 @@ static void disconnect_server(Server *s)
|
|||
s->cap_state = CAP_NONE;
|
||||
s->caps[0] = 0;
|
||||
s->retry_at = time(NULL) + RETRY;
|
||||
#ifdef USE_AUTOJOIN
|
||||
free_autojoin(&s->pending_autojoin);
|
||||
s->next_autojoin = (struct timespec){0};
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
|
@ -1429,7 +1415,6 @@ static void run_pending_autocommands(Server *s)
|
|||
if (command_due(now, s->autocommand_at)) run_autocommand(s);
|
||||
}
|
||||
|
||||
#ifdef USE_AUTOJOIN
|
||||
static void run_autojoin_command(AutojoinChannel **link, Window *w)
|
||||
{
|
||||
AutojoinChannel *channel = *link;
|
||||
|
|
@ -1495,7 +1480,6 @@ static void run_pending_autojoin_commands(Server *s)
|
|||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void handle_line(Server *s, char *line)
|
||||
{
|
||||
|
|
@ -1597,9 +1581,7 @@ static void handle_line(Server *s, char *line)
|
|||
Window *w = window_get(s, arg[0], W_CHANNEL);
|
||||
member_add(w, nick);
|
||||
if (!silent) append_nickf(w, "* ", hostmask ? hostmask : "someone", " ", "joined %s", arg[0]);
|
||||
#ifdef USE_AUTOJOIN
|
||||
if (strcasecmp(nick, s->nick) == 0) confirm_autojoin(w);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1935,7 +1917,6 @@ static void handle_line(Server *s, char *line)
|
|||
if (narg > 0) appendf(sw, "* %s", arg[narg - 1]);
|
||||
return;
|
||||
}
|
||||
#ifdef USE_AUTOJOIN
|
||||
if (narg >= 2 && (strcmp(cmd, "403") == 0 || strcmp(cmd, "405") == 0 ||
|
||||
strcmp(cmd, "471") == 0 || strcmp(cmd, "473") == 0 ||
|
||||
strcmp(cmd, "474") == 0 || strcmp(cmd, "475") == 0 ||
|
||||
|
|
@ -1943,7 +1924,6 @@ static void handle_line(Server *s, char *line)
|
|||
AutojoinChannel **link = find_pending_join(s, arg[1]);
|
||||
if (*link) remove_pending_autojoin(link);
|
||||
}
|
||||
#endif
|
||||
if (strcmp(cmd, "461") == 0 || strcmp(cmd, "403") == 0 ||
|
||||
strcmp(cmd, "404") == 0 || strcmp(cmd, "405") == 0 ||
|
||||
strcmp(cmd, "482") == 0 ||
|
||||
|
|
@ -2954,11 +2934,9 @@ static int irc_to_ansi_color(int color)
|
|||
|
||||
static long long server_unread_messages(const Server *s)
|
||||
{
|
||||
#ifdef USE_AUTOJOIN
|
||||
if (s->autojoin) return 0;
|
||||
for (const AutojoinChannel *channel = s->pending_autojoin; channel; channel = channel->next)
|
||||
if (!channel->joined) return 0;
|
||||
#endif
|
||||
long long unread = 0;
|
||||
for (const Window *w = s->windows; w; w = w->next)
|
||||
unread += w->unread;
|
||||
|
|
@ -3539,10 +3517,8 @@ int main(int argc, char **argv)
|
|||
connect_server(s);
|
||||
run_pending_autocommands(s);
|
||||
if (quit_flag) break;
|
||||
#ifdef USE_AUTOJOIN
|
||||
send_autojoin(s);
|
||||
run_pending_autojoin_commands(s);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (quit_flag) break;
|
||||
|
|
@ -3598,10 +3574,8 @@ int main(int argc, char **argv)
|
|||
if (s->ssl) SSL_free(s->ssl);
|
||||
#endif
|
||||
if (s->fd >= 0) close(s->fd);
|
||||
#ifdef USE_AUTOJOIN
|
||||
free_autojoin(&s->autojoin);
|
||||
free_autojoin(&s->pending_autojoin);
|
||||
#endif
|
||||
free(s->name);
|
||||
free(s->autocommand);
|
||||
while (s->blacklist) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue