]> PatchyGit - patchyircd.git/commitdiff
add autojoin channels
authorEgor <egor@patchysicp.xyz>
Fri, 27 May 2022 17:31:52 +0000 (20:31 +0300)
committerEgor <egor@patchysicp.xyz>
Fri, 27 May 2022 17:31:52 +0000 (20:31 +0300)
common.h
irc.c
main.c

index 449d17e..2d4acd6 100644 (file)
--- 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 (file)
--- 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 (file)
--- 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;
 }