1
0
Fork 0
forked from murx/irc9

Add per-server autocommand configuration

This commit is contained in:
Johannes Findeisen 2026-11-27 18:31:56 +01:00
commit 2dc64f7d1e
3 changed files with 27 additions and 1 deletions

17
irc9.c
View file

@ -106,6 +106,7 @@ typedef struct Server {
int sasl;
char sasl_user[NICKLEN];
char sasl_pass[128];
char *autocommand;
int cap_state;
char caps[512]; /* accumulated multi-line CAP LS reply */
char umode[32];
@ -567,6 +568,18 @@ static void load_config(const char *path)
char *save = NULL;
key = strtok_r(p, " \t", &save);
if (!key) continue;
if (strcasecmp(key, "autocommand") == 0) {
save += strspn(save, " \t");
if (last && *save && strlen(save) <= MAXLINE - 2 &&
!strchr(save, '\r')) {
free(last->autocommand);
last->autocommand = dupstr(save);
} else {
fprintf(stderr, "irc9: autocommand requires a server and an IRC command of at most %d bytes\n",
MAXLINE - 2);
}
continue;
}
a1 = strtok_r(NULL, " \t", &save);
a2 = strtok_r(NULL, " \t", &save);
a3 = strtok_r(NULL, " \t", &save);
@ -1410,7 +1423,10 @@ static void handle_line(Server *s, char *line)
}
if (strcmp(cmd, "001") == 0) {
int first_welcome = !s->connected;
s->connected = 1;
if (first_welcome && s->autocommand)
sendf(s, "%s", s->autocommand);
#ifdef USE_AUTOJOIN
while (s->autojoin) {
AutojoinChannel *channel = s->autojoin;
@ -2598,6 +2614,7 @@ int main(int argc, char **argv)
free(channel);
}
#endif
free(s->autocommand);
free(s);
s = sn;
}