Browse Source

vccd: now we'll not send messages to who sent this message

intirain 4 years ago
parent
commit
df72fb6e20
3 changed files with 12 additions and 8 deletions
  1. 1 1
      Makefile
  2. 1 1
      include/vcc/version.h
  3. 10 6
      vcc.c

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 VCCD_MAJOR 		= 0
 VCCD_MINOR 		= 3
-VCCD_PATCH 		= 1
+VCCD_PATCH 		= 2
 VCCD_COMPILE_TIME 	= $(shell date)
 VCCD_COMPILE_BY 	= $(shell whoami)
 

+ 1 - 1
include/vcc/version.h

@@ -1 +1 @@
-#define VCCD_VERSION "vccd 0.3.1 Sun Mar  6 14:51:32 CST 2022 root"
+#define VCCD_VERSION "vccd 0.3.2 Fri Mar 11 19:07:59 CST 2022 root"

+ 10 - 6
vcc.c

@@ -40,7 +40,7 @@
 
 
 struct klist_node connections = KLIST_NODE_INIT(&connections);
-int vcc_message_broadcast(char *msg, char *usrname);
+int vcc_message_broadcast(char *msg, char *usrname, int except_fd);
 int nusers = 0;
 
 int vcc_new_connection(int fd, struct in_addr *addr) {
@@ -76,7 +76,7 @@ int vcc_new_connection(int fd, struct in_addr *addr) {
 	}
 
 	sprintf(new_msg, join_msg, inet_ntoa(*addr), ++nusers);
-	vcc_message_broadcast(new_msg, "system");
+	vcc_message_broadcast(new_msg, "system", 0);
 
 	free(new_msg);
 
@@ -109,7 +109,7 @@ int vcc_close_connection(int fd) {
 
 	vcc_log("Client closed. \n");
 
-	vcc_message_broadcast(new_msg, "system");
+	vcc_message_broadcast(new_msg, "system", 0);
 	free(new_msg);
 
 	return 0;
@@ -175,12 +175,15 @@ int vcc_send_req(struct klist_node *node, void *p) {
 
 /* send to each user include who sends this message */
 
-int vcc_message_broadcast(char *msg, char *usrname) {
+int vcc_message_broadcast(char *msg, char *usrname, int except_fd) {
 	struct vcc_request *req;
 	struct klist_node *n;
 	int i;
 
-	for (n = connections.next, i = 0; n != &connections; n = n->next, i++) {
+	for (n = connections.next, i = 0; n != &connections; n = n->next) {
+		if (n->value == except_fd) 
+			continue;
+
 		if (unlikely(!(req = malloc(sizeof(struct vcc_request))))) {
 			vcc_log("*** malloc() failed\n");
 
@@ -195,6 +198,7 @@ int vcc_message_broadcast(char *msg, char *usrname) {
 		strcpy(req->usrname, usrname);
 
 		vcc_send_req(n, req);
+		i++;
 	}
 
 	vcc_log("Message sent to %d users. \n", i);
@@ -271,7 +275,7 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 		vcc_update_usrname(fd, req->usrname);
 
 		vcc_log("New message: %s\n", msg);
-		vcc_message_broadcast(msg, req->usrname);
+		vcc_message_broadcast(msg, req->usrname, fd);
 
 		break;