summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pamment <apamment@yandex.com>2019-05-11 20:14:37 +1000
committerAndrew Pamment <apamment@yandex.com>2019-05-11 20:14:37 +1000
commitdbccfe1c7efc053585e5151e05eab42fe2fbcefe (patch)
tree4cf37c2ddce8561d72551565c479db40f464c267
parenta8aabc1f7078fe0e0f9920efb287ef83d99ca4dd (diff)
Fix leaking of client leaving messages
-rw-r--r--utils/magichat/main.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/utils/magichat/main.c b/utils/magichat/main.c
index f2d27a8..687f830 100644
--- a/utils/magichat/main.c
+++ b/utils/magichat/main.c
@@ -47,7 +47,7 @@ int main(int argc, char **argv) {
int c;
int new_fd;
struct chat_msg msg;
- int i, j, k;
+ int i, j, k, l;
char buffer[1024];
char buf[1024];
char motd[256];
@@ -227,15 +227,27 @@ int main(int argc, char **argv) {
if (FD_ISSET(j, &master)) {
if (ipv6) {
if (j != server_socket && j != server_socket6 && j != clients[k]->fd) {
- if (send(j, buffer, strlen(buffer), 0) == -1) {
- perror("send");
- }
+ for (l =0 l< client_count; l++) {
+ if (clients[l]->fd == j) {
+ if (strcmp(clients[l]->nick, "UNKNOWN") != 0) {
+ if (send(j, buffer, strlen(buffer), 0) == -1) {
+ perror("send");
+ }
+ }
+ }
+ }
}
} else {
if (j != server_socket && j != clients[k]->fd) {
- if (send(j, buffer, strlen(buffer), 0) == -1) {
- perror("send");
- }
+ for (l =0 l< client_count; l++) {
+ if (clients[l]->fd == j) {
+ if (strcmp(clients[l]->nick, "UNKNOWN") != 0) {
+ if (send(j, buffer, strlen(buffer), 0) == -1) {
+ perror("send");
+ }
+ }
+ }
+ }
}
}
}