From 885aba79ab0b2ff0e837b8b8f20c6c1709d7cb17 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 27 Jan 2024 15:36:09 +0100 Subject: [PATCH] fixed formatting on invalid command --- include/chat/config.h | 1 + src/chat/misc.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/chat/config.h b/include/chat/config.h index 7bbe825..fa417b8 100644 --- a/include/chat/config.h +++ b/include/chat/config.h @@ -27,6 +27,7 @@ extern "C" { #define WHY2_CHAT_CODE_ACCEPT_MESSAGES "code_000" #define WHY2_CHAT_CODE_PICK_USERNAME "code_001" #define WHY2_CHAT_CODE_SERVER_SIDE_QUIT_COMMUNICATION "code_002" +#define WHY2_CHAT_CODE_INVALID_COMMAND "code_003" //SHORTCUTS CAUSE I'M LAZY BITCH #define WHY2_CHAT_CODE_SSQC WHY2_CHAT_CODE_SERVER_SIDE_QUIT_COMMUNICATION diff --git a/src/chat/misc.c b/src/chat/misc.c index 59a621b..b8f369d 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -390,7 +390,13 @@ void *why2_communicate_thread(void *arg) if (decoded_buffer[0] == '!') //COMMANDS { - if (strcmp(decoded_buffer, "!exit") == 0) exiting = 1; //USER REQUESTED EXIT + if (strcmp(decoded_buffer, "!exit") == 0) //USER REQUESTED EXIT + { + exiting = 1; + } else + { + why2_send_socket(WHY2_CHAT_CODE_INVALID_COMMAND, WHY2_CHAT_SERVER_USERNAME, connection); + } goto deallocation; //IGNORE MESSAGES BEGINNING WITH '!' } @@ -524,11 +530,20 @@ void *why2_listen_server(void *socket) } else if (strcmp(read + 8, WHY2_CHAT_CODE_PICK_USERNAME) == 0) //PICK USERNAME { //TODO: Check username + } else if (strcmp(read + 8, WHY2_CHAT_CODE_INVALID_COMMAND) == 0) //PICK USERNAME + { + printf("\nInvalid command!\n\n"); + fflush(stdout); + + goto continue_input; } } else { - printf(WHY2_CLEAR_AND_GO_UP); - printf("%s\n\n>>> ", read); + printf("%s%s\n\n", WHY2_CLEAR_AND_GO_UP, read); + + continue_input: + + printf(">>> "); fflush(stdout); }