Add per-server autocommand configuration
This commit is contained in:
parent
1fc6b0ae6c
commit
2dc64f7d1e
3 changed files with 27 additions and 1 deletions
17
irc9.c
17
irc9.c
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue