From e66109c2627d0d4d942c99a503e4f5ab8de46ca0 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 31 Jan 2025 13:49:55 +0100 Subject: [PATCH] sending WHY2_CHAT_CODE_LIST_SERVER as a code not sure if it will work (there's no way for me to test it rn...) --- src/chat/misc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index 6ea4c46..f7009b7 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -720,7 +720,7 @@ void *why2_communicate_thread(void *arg) why2_node_t *buffer = head; connection_node_t value_buffer; unsigned long alloc_size = 0; - char *append_buffer; + size_t last_size = 0; //COUNT REQUIRED MESSAGE ALLOCATION SIZE do @@ -731,29 +731,23 @@ void *why2_communicate_thread(void *arg) buffer = buffer -> next; //ITER } while (buffer != NULL); - char *message = why2_calloc(strlen(WHY2_CHAT_CODE_LIST_SERVER) + alloc_size + 2, sizeof(char)); + char *message = why2_calloc(alloc_size + 1, sizeof(char)); buffer = head; //RESET - sprintf(message, WHY2_CHAT_CODE_LIST_SERVER); //SET CODE - //FILL THE message do { value_buffer = *(connection_node_t*) buffer -> value; - append_buffer = why2_malloc(strlen(value_buffer.username) + why2_count_int_length(value_buffer.id) + 3); //ALLOCATE THE BUFFER - sprintf(append_buffer, ";%s;%ld", value_buffer.username, value_buffer.id); //FILL THE BUFFER + sprintf(message + last_size, "%s;%ld;", value_buffer.username, value_buffer.id); //APPEND - strcat(message, append_buffer); //JOIN THE BUFFER TO OUTPUT message + last_size = strlen(message); - why2_deallocate(append_buffer); //DEALLOCATION buffer = buffer -> next; //ITER } while (buffer != NULL); - strcat(message, ";"); - //SEND - send_socket_deallocate(message, why2_chat_server_config("server_username"), connection); + send_socket_code_deallocate(message, why2_chat_server_config("server_username"), connection, WHY2_CHAT_CODE_LIST_SERVER); //DEALLOCATION why2_deallocate(message);