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...)
This commit is contained in:
Václav Šmejkal 2025-01-31 13:49:55 +01:00
parent 1978ed4cd8
commit e66109c262
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

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