|
|
@@ -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;
|
|
|
}
|