sendbuf(cl);
} while (trie_findnext(&f) == 1);
}
+void sendbuf_visible(struct client_data *client) {
+ static int cookie = 0;
+ if (++cookie == 0) {
+ // handle overflow
+ struct trie_find *f = NULL;
+ if (trie_findfirst(&f, &client_map) == 1)
+ do {
+ struct client_data *cl = f->n->value;
+ cl->cookie = 0;
+ } while (trie_findnext(&f) == 1);
+ cookie++;
+ }
+ struct trie_find *f1 = NULL, *f2 = NULL;
+ if (trie_findfirst(&f1, &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);
+}
int parsePacket(struct client_data *client) {
char *source = NULL;
char *command = NULL;
// 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] : "");
- sendall_log(client->FD, databuf.buf, databuf.len, 0); // TODO: limit visibility
+ sendbuf_visible(client);
killConnection(client, true);
return 1;
} else if(strcmp(command, "PONG") == 0) {
if(client->nick) {
copy_strf(&databuf, ":%s!%s@%s NICK %s\n", client->nick, client->username, client->hostname, nickname);
sendbuf(client);
- sendall_log(client->FD, databuf.buf, databuf.len, 0); // TODO: limit visibility
+ sendbuf_visible(client);
trie_set(&client_map, client->key, NULL, NULL);
free(client->nick);
free(client->key);
#include "ircfmt.h"
#include <stdbool.h>
-void sendall_log(SOCKET socket, const char *buffer, size_t length, int flags) {
- int i;
- for(i=0;i<CLIENTS;i++) {
- if(clients[i] == 0) continue;
- if(clients[i]->FD == socket) {
- continue;
- } else {
- send_log(clients[i]->FD, buffer, length, flags);
- }
- }
-}
-
struct client_data *allocClient(){
struct client_data *NewClient = malloc(sizeof(struct client_data));
memset(NewClient, 0, sizeof(struct client_data));
// Start GitHub Copilot
if(!byChoice && cl->nick && cl->username) {
msg_quit(cl, "", "Has left the building (Forced)");
- sendall_log(cl->FD, databuf.buf, databuf.len, 0);
+ sendbuf_visible(cl);
}
// Send error to client informing them that they will be disconnected
msg_error("Closing Link");
#include "common.h"
#include <stdbool.h>
-void sendall_log(SOCKET socket, const char *buffer, size_t length, int flags);
void sendbuf(struct client_data *client);
+void sendbuf_visible(struct client_data *client);
struct client_data *allocClient();
void killConnection(struct client_data *client, bool byChoice);
void recvProc(struct client_data *cl);