From: Egor Date: Fri, 27 May 2022 17:31:52 +0000 (+0300) Subject: add autojoin channels X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=4c56f118f00a147e80d1118b9db292f9bcdf95dc;p=patchyircd.git add autojoin channels --- diff --git a/common.h b/common.h index 449d17e..2d4acd6 100644 --- a/common.h +++ b/common.h @@ -77,6 +77,7 @@ struct channel { #define is_chanvoice(chan, client) (trie_get(&(chan)->v, (client)->key)) extern struct trie_node *client_map; extern struct trie_node *channel_map; +extern struct trie_node *autojoin; extern struct client_data *clients; extern fd_set readfds; extern struct sockaddr_in serverAddrV4; diff --git a/irc.c b/irc.c index 4118b1d..8553465 100644 --- a/irc.c +++ b/irc.c @@ -6,6 +6,7 @@ struct dynarr databuf; struct trie_node *client_map = NULL; struct trie_node *channel_map = NULL; +struct trie_node *autojoin = NULL; const char *hostname = "irc.patchysicp.xyz"; #define is_registered(cl) ((cl)->regstate == REG_REGISTERED) @@ -974,6 +975,11 @@ void newUser(struct client_data *client) { sendLUSERS(client); rpl_umodeis(client), sendbuf(client); sendMOTD(client); + struct trie_find *f = NULL; + if (trie_findfirst(&f, &autojoin) == 1) + do { + channel_join(client, f->key, NULL); + } while (trie_findnext(&f) == 1); } void sendLUSERS(struct client_data *client) { diff --git a/main.c b/main.c index efcd80f..3fcf7dd 100644 --- a/main.c +++ b/main.c @@ -227,6 +227,11 @@ int main(int argc, char *argv[]) listeners[listener_count].ctx = is_tls ? tls_ctx : NULL; listeners[listener_count++].sock = create_listen_sock(argv[i+1], argv[i+2]); i += 2; + } else if(!strcmp(argv[i], "--autojoin")) { + if (i + 1 >= argc) + return fprintf(stderr, "not enough parameters\n"), 1; + trie_set(&autojoin, argv[i+1], (void*)1, NULL); + i += 1; } else { return fprintf(stderr, "unknown flag '%s'\n", argv[i]), 1; } @@ -369,5 +374,6 @@ int main(int argc, char *argv[]) tls_free(tls_ctx); #endif free(databuf.buf); + trie_free(&autojoin); return 0; }