瀏覽代碼

vccd: add users

intirain 4 年之前
父節點
當前提交
d53dbb16da
共有 3 個文件被更改,包括 11 次插入 和 10 次删除
  1. 2 2
      Makefile
  2. 1 1
      include/vcc/version.h
  3. 8 7
      vcc.c

+ 2 - 2
Makefile

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

+ 1 - 1
include/vcc/version.h

@@ -1 +1 @@
-#define VCCD_VERSION "vccd 0.1.5 Sun Mar  6 08:00:25 CST 2022 root"
+#define VCCD_VERSION "vccd 0.2.0 Sun Mar  6 08:14:27 CST 2022 root"

+ 8 - 7
vcc.c

@@ -40,13 +40,13 @@
 
 
 struct klist_node connections = KLIST_NODE_INIT(&connections);
-int vcc_message_broadcast(char *msg);
+int vcc_message_broadcast(char *msg, char *usrname);
 int nusers = 0;
 
 int vcc_new_connection(int fd, struct in_addr *addr) {
 	struct klist_node *n;
 	char *new_msg;
-	const static char join_msg[] = {"system: New user from %s joined. Now there are %d users. \n"};
+	const static char join_msg[] = {"New user from %s joined. Now there are %d users. \n"};
 
 	vcc_log("New connection from %s\n", inet_ntoa(*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);
+	vcc_message_broadcast(new_msg, "system");
 
 	free(new_msg);
 
@@ -86,7 +86,7 @@ int vcc_new_connection(int fd, struct in_addr *addr) {
 
 int vcc_close_connection(int fd) {
 	struct klist_node *n, *t;
-	const static char leave_msg[] = {"system: A user left, now there are only %d users here. \n"};
+	const static char leave_msg[] = {"An user left, now there are only %d users here. \n"};
 	char *new_msg;
 
 	for (n = connections.next; n != &connections 
@@ -109,7 +109,7 @@ int vcc_close_connection(int fd) {
 
 	vcc_log("Client closed. \n");
 
-	vcc_message_broadcast(new_msg);
+	vcc_message_broadcast(new_msg, "system");
 	free(new_msg);
 
 	return 0;
@@ -175,7 +175,7 @@ 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) {
+int vcc_message_broadcast(char *msg, char *usrname) {
 	struct vcc_request *req;
 	struct klist_node *n;
 	int i;
@@ -188,6 +188,7 @@ int vcc_message_broadcast(char *msg) {
 		}
 
 		strcpy(req->msg, msg);
+		strcpy(req->usrname, usrname);
 
 		vcc_send_req(n, req);
 	}
@@ -205,7 +206,7 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 		return 0;
 
 	vcc_log("New message: %s\n", msg);
-	vcc_message_broadcast(msg);
+	vcc_message_broadcast(msg, req->usrname);
 
 	return 0;
 }