From ea0a05e7991024a4973f5f459b9e35d3a16331b9 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 27 May 2022 00:41:14 +0300 Subject: [PATCH] fix sending NICK message twice --- irc.c | 18 +++++------------- net.c | 2 -- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/irc.c b/irc.c index a099a7c..5176a98 100644 --- a/irc.c +++ b/irc.c @@ -66,19 +66,12 @@ int get_cookie() { } void sendbuf_visible(struct client_data *client) { int cookie = get_cookie(); - struct trie_find *f1 = NULL, *f2 = NULL; - if (trie_findfirst(&f1, &client->channels) == 1) + struct trie_find *f = NULL; + if (trie_findfirst(&f, &client->channels) == 1) do { - struct channel *chan = f1->n->value; - if (trie_findfirst(&f2, &chan->members) == 1) - do { - struct client_data *cl = f2->n->value; - if (cl->cookie != cookie) { - sendbuf(cl); - cl->cookie = cookie; - } - } while (trie_findnext(&f2) == 1); - } while (trie_findnext(&f1) == 1); + struct channel *chan = f->n->value; + sendbuf_list_sans_self(client, &chan->members, cookie); + } while (trie_findnext(&f) == 1); } const char *format_umodes(struct client_data *cl) { static char umodes[6] = ""; @@ -488,7 +481,6 @@ int processPacket(struct client_data *client, char *source, char *command, int a rpl_away(client, cl), sendbuf(client); } } - // Start GitHub Copilot - this shit actually be copy pasting my code lmao } else if(strcmp(command, "QUIT") == 0) { msg_quit(client, "Quit: ", args[0] ? args[0] : ""); sendbuf_visible(client); diff --git a/net.c b/net.c index 951b46c..56c87f8 100644 --- a/net.c +++ b/net.c @@ -16,7 +16,6 @@ void killConnection(struct client_data *cl, bool byChoice) { clients[i] = 0; if (cl->peername) fprintf(stderr, "Client disconnected from Socket: %"PRISocket", IP: %s PORT: %d\n", cl->FD, cl->peername, cl->peerport); - // Start GitHub Copilot if(!byChoice && cl->nick && cl->username) { msg_quit(cl, "", "Has left the building (Forced)"); sendbuf_visible(cl); @@ -24,7 +23,6 @@ void killConnection(struct client_data *cl, bool byChoice) { // Send error to client informing them that they will be disconnected msg_error("Closing Link"); sendbuf(cl); - // End GitHub Copilot if (cl->FD != INVALID_SOCKET) { #ifdef HAS_TLS if (cl->cctx) { -- 2.56.0