removed goto from username loop & implemented WHY2_MAX_USERNAME_TRIES

This commit is contained in:
Václav Šmejkal 2024-01-27 22:13:02 +01:00
parent 31db7c0622
commit b21d39a35e
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -379,10 +379,11 @@ void *why2_communicate_thread(void *arg)
char *raw;
void *raw_ptr = NULL;
why2_bool force_exiting = 0;
why2_bool invalid_username;
why2_bool invalid_username = 1;
why2_bool exiting = 0;
char *decoded_buffer = NULL;
char *username = node.username;
int usernames_n = 0;
why2_deallocate(string_buffer);
@ -390,9 +391,8 @@ void *why2_communicate_thread(void *arg)
{
if (config_username == NULL) fprintf(stderr, "Your config doesn't contain 'user_pick_username'. Please update your configuration.\n");
repeat_username_get:
invalid_username = 0;
while (invalid_username)
{
why2_send_socket(WHY2_CHAT_CODE_PICK_USERNAME, WHY2_CHAT_SERVER_USERNAME, connection); //ASK USER FOR USERNAME
if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ
@ -415,7 +415,13 @@ void *why2_communicate_thread(void *arg)
if (invalid_username)
{
why2_send_socket(WHY2_CHAT_CODE_INVALID_USERNAME, WHY2_CHAT_SERVER_USERNAME, connection); //TELL THE USER HE IS DUMB AS FUCK
goto repeat_username_get; //REPEAT
}
if (++usernames_n == WHY2_MAX_USERNAME_TRIES) //ASKED CLIENT WAY TOO FUCKING MANY TIMES FOR USERNAME, KICK HIM
{
exiting = 1;
goto deallocation;
}
}
}