From ebfcf94471a78dd48d6a5a63c0d40da3a67c2486 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Wed, 1 May 2013 19:13:57 -0400 Subject: Sends status broadcast after changing chat flag --- chat_acceptor.h | 16 ++++++++++++++-- chat_request.h | 1 + localchat.c | 4 ++-- user_command.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/chat_acceptor.h b/chat_acceptor.h index 7c57c43..cb42d75 100644 --- a/chat_acceptor.h +++ b/chat_acceptor.h @@ -22,7 +22,7 @@ void *receive_chat_messages(void *arg) { char *message; message = strtok(in_buf, separators); if (strcmp(message, "SESMSG") == 0) { - printf("\n > %s", strtok(NULL, separators)); + printf("\n----> %s", strtok(NULL, separators)); printf("%s ", prompt); fflush(stdout); } @@ -36,10 +36,15 @@ void *receive_chat_messages(void *arg) { printf("\n*** Peer closed the session. *** \n"); + // close the socket close(client_s); + + // update chat flag and broadcast strcpy(in_chat, "N"); - strcpy(prompt, ">"); + status_broadcast_once(); + // reset the prompt + strcpy(prompt, ">"); printf("%s ", prompt); fflush(stdout); @@ -85,8 +90,15 @@ void accept_callback_accept() { char inp[256]; + // update the prompt strcpy(prompt, "chat>"); + + // update chat flag and broadcast strcpy(in_chat, "Y"); + status_broadcast_once(); + + // print info message + printf("Entering chat mode. Type /q to exit. \n"); pthread_t recv_thread; pthread_create(&recv_thread, NULL, receive_chat_messages, NULL); diff --git a/chat_request.h b/chat_request.h index 38a3d7c..353fbf4 100644 --- a/chat_request.h +++ b/chat_request.h @@ -69,6 +69,7 @@ void send_chat_request(char * username) { // set my in_chat flag strcpy(in_chat, "Y"); + status_broadcast_once(); pthread_t recv_thread; pthread_create(&recv_thread, NULL, receive_chat_messages, NULL); diff --git a/localchat.c b/localchat.c index ad0ba17..be6b57a 100644 --- a/localchat.c +++ b/localchat.c @@ -22,8 +22,8 @@ // define constants #define DEBUG 0 #define MAX_NUM_PEERS 100 -#define CMD_PORT 6062 -#define CHAT_PORT 6063 +#define CMD_PORT 6063 +#define CHAT_PORT 6064 #define BROADCAST_IP "192.168.130.255" #define GLOBAL_MSG_LENGTH 1024 #define REQUEST_TIMEOUT 10 diff --git a/user_command.h b/user_command.h index 803fada..24c2f3e 100644 --- a/user_command.h +++ b/user_command.h @@ -38,6 +38,7 @@ void process_user_command() { // set my flag strcpy(in_chat, "N"); + status_broadcast_once(); // reset prompt strcpy(prompt, ">"); -- cgit v1.2.3