From 8da0383c82134441d56a7fad7f68b437d6963ce8 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Mon, 19 Feb 2024 11:06:07 +0100 Subject: [PATCH] fixed username formatting & iters --- src/chat/misc.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index 680321b..448152f 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -403,6 +403,12 @@ void *why2_communicate_thread(void *arg) while (invalid_username) { + if (usernames_n++ == WHY2_MAX_USERNAME_TRIES) //ASKED CLIENT WAY TOO FUCKING MANY TIMES FOR USERNAME, KICK HIM + { + exiting = 1; + goto deallocation; + } + if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ { force_exiting = 1; //FAILURE @@ -440,12 +446,6 @@ void *why2_communicate_thread(void *arg) why2_deallocate(raw); why2_deallocate(raw_ptr); - if (++usernames_n == WHY2_MAX_USERNAME_TRIES) //ASKED CLIENT WAY TOO FUCKING MANY TIMES FOR USERNAME, KICK HIM - { - exiting = 1; - goto deallocation; - } - if (invalid_username) { why2_send_socket(WHY2_CHAT_CODE_INVALID_USERNAME, WHY2_CHAT_SERVER_USERNAME, connection); //TELL THE USER HE IS DUMB AS FUCK @@ -664,24 +664,28 @@ void *why2_listen_server(void *socket) { if (strcmp(read + 8, WHY2_CHAT_CODE_SSQC) == 0) { - printf("%s%s%s\nServer closed the connection.\n", asking_username == WHY2_MAX_USERNAME_TRIES ? WHY2_CLEAR_AND_GO_UP : "", WHY2_CLEAR_AND_GO_UP WHY2_CLEAR_AND_GO_UP, (asking_username == 0 ? "\n": "")); + printf("%s%s%s\nServer closed the connection.\n", asking_username > WHY2_MAX_USERNAME_TRIES ? WHY2_CLEAR_AND_GO_UP : "", WHY2_CLEAR_AND_GO_UP WHY2_CLEAR_AND_GO_UP, (asking_username == 0 ? "\n": "")); fflush(stdout); pthread_cancel(getline_thread); //CANCEL CLIENT getline exiting = 1; //EXIT THIS THREAD } else if (strcmp(read + 8, WHY2_CHAT_CODE_ACCEPT_MESSAGES) == 0) //PICK USERNAME { - asking_username = 0; - //goto continue_input; + /*if (asking_username != 0) + { + asking_username = 0; + printf(WHY2_CLEAR_AND_GO_UP); + fflush(stdout); + } + + goto continue_input;*/ } else if (strcmp(read + 8, WHY2_CHAT_CODE_PICK_USERNAME) == 0) //PICK USERNAME { username_pick: - printf("%s%sEnter username (a-Z, 0-9; %d-%d characters):\n", asking_username > 0 ? WHY2_CLEAR_AND_GO_UP : "", WHY2_CLEAR_AND_GO_UP, WHY2_MIN_USERNAME_LENGTH, WHY2_MAX_USERNAME_LENGTH); + printf("%s%sEnter username (a-Z, 0-9; %d-%d characters):\n", asking_username++ > 0 ? WHY2_CLEAR_AND_GO_UP : "", WHY2_CLEAR_AND_GO_UP, WHY2_MIN_USERNAME_LENGTH, WHY2_MAX_USERNAME_LENGTH); fflush(stdout); - asking_username++; - goto continue_input; } else if (strcmp(read + 8, WHY2_CHAT_CODE_INVALID_COMMAND) == 0) //PICK USERNAME { @@ -699,6 +703,13 @@ void *why2_listen_server(void *socket) } else { printf(WHY2_CLEAR_AND_GO_UP WHY2_CLEAR_AND_GO_UP); //do not fucking ask me how the fucking formatting fucking works, i dont fucking know + + if (asking_username > 1) + { + asking_username = 0; + printf(WHY2_CLEAR_AND_GO_UP); + } + printf("\n\n%s%s\n\n", WHY2_CLEAR_AND_GO_UP, read); continue_input: