From 857a3afe95661061ea1c9a03fd6b940b9d1be09c Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Mon, 19 Feb 2024 12:41:57 +0100 Subject: [PATCH] removed gotos from why2_communicate_thread msg loop --- src/chat/misc.c | 53 +++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index 2fcc862..a780480 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -509,37 +509,42 @@ void *why2_communicate_thread(void *arg) if (decoded_buffer == NULL) //idk sometimes this happen, idk why { - force_exiting = 1; - goto deallocation; - } - - if (decoded_buffer[0] == '!') //COMMANDS + force_exiting = 1; //force exit <3 + } else { - if (strcmp(decoded_buffer, "!exit") == 0) //USER REQUESTED EXIT + if (strlen(decoded_buffer) != 0) { - exiting = 1; - } else - { - why2_send_socket(WHY2_CHAT_CODE_INVALID_COMMAND, WHY2_CHAT_SERVER_USERNAME, connection); + if (decoded_buffer[0] == '!') //COMMANDS + { + 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); //INFORM USER THAT HE'S DUMB + } + + //IGNORE MESSAGES BEGINNING WITH '!' + } else + { + //REBUILD MESSAGE WITH USERNAME + json_object_object_add(json, "message", json_object_new_string(decoded_buffer)); + json_object_object_add(json, "username", json_object_new_string(get_username(connection))); + + json_object_object_foreach(json, key, value) //GENERATE JSON STRING + { + append(&raw_output, key, (char*) json_object_get_string(value)); + } + add_brackets(&raw_output); + + send_to_all(raw_output); //e + } } - - goto deallocation; //IGNORE MESSAGES BEGINNING WITH '!' } - //REBUILD MESSAGE WITH USERNAME - json_object_object_add(json, "message", json_object_new_string(decoded_buffer)); - json_object_object_add(json, "username", json_object_new_string(get_username(connection))); - - json_object_object_foreach(json, key, value) //GENERATE JSON STRING - { - append(&raw_output, key, (char*) json_object_get_string(value)); - } - add_brackets(&raw_output); - - send_to_all(raw_output); //e - deallocation: + //DEALLOCATION why2_deallocate(raw); why2_deallocate(raw_ptr); why2_deallocate(raw_output);