waiting for WHY2_CHAT_CODE_USERNAME

This commit is contained in:
Václav Šmejkal 2025-02-01 20:57:07 +01:00
parent 6c53169f09
commit 4d64d73c07
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -554,12 +554,25 @@ void *why2_communicate_thread(void *arg)
goto deallocation;
}
//KEEP READING UNTIL CODE ARRIVES
char *code = NULL;
why2_bool exiting_read = 0;
do
{
//DEALLOCATE
why2_deallocate(code);
if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ
{
force_exiting = 1; //FAILURE
goto deallocation;
}
//COMPARE CODE
code = get_string_from_json_string(raw, "code");
exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_USERNAME) == 0;
} while (!exiting_read);
decoded_buffer = get_string_from_json_string(raw, "message"); //DECODE
invalid_username = decoded_buffer == NULL || (strlen(decoded_buffer) > (unsigned long) server_config_int("max_username_length")) || (strlen(decoded_buffer) < (unsigned long) server_config_int("min_username_length")) || (!check_username(decoded_buffer)); //CHECK FOR USERNAMES LONGER THAN 20 CHARACTERS