implemented max_username_tries from server config
This commit is contained in:
parent
968498cf4e
commit
965395e9d4
@ -34,7 +34,6 @@ extern "C" {
|
|||||||
|
|
||||||
#define WHY2_MAX_USERNAME_LENGTH 20 //MAXIMAL USERNAME LENGTH
|
#define WHY2_MAX_USERNAME_LENGTH 20 //MAXIMAL USERNAME LENGTH
|
||||||
#define WHY2_MIN_USERNAME_LENGTH 4 //MINIMAL USERNAME LENGTH
|
#define WHY2_MIN_USERNAME_LENGTH 4 //MINIMAL USERNAME LENGTH
|
||||||
#define WHY2_MAX_USERNAME_TRIES 3 //MAXIMAL USERNAME ASK COUNT
|
|
||||||
|
|
||||||
//CODES
|
//CODES
|
||||||
#define WHY2_CHAT_CODE_ACCEPT_MESSAGES "code_000"
|
#define WHY2_CHAT_CODE_ACCEPT_MESSAGES "code_000"
|
||||||
|
@ -426,10 +426,14 @@ void *why2_communicate_thread(void *arg)
|
|||||||
|
|
||||||
send_socket_deallocate(WHY2_CHAT_CODE_PICK_USERNAME, why2_chat_server_config("server_username"), connection); //ASK USER FOR USERNAME
|
send_socket_deallocate(WHY2_CHAT_CODE_PICK_USERNAME, why2_chat_server_config("server_username"), connection); //ASK USER FOR USERNAME
|
||||||
|
|
||||||
|
char *max_tries_str = why2_chat_server_config("max_username_tries");
|
||||||
|
int max_tries = atoi(max_tries_str);
|
||||||
|
why2_toml_read_free(max_tries_str);
|
||||||
|
|
||||||
while (invalid_username)
|
while (invalid_username)
|
||||||
{
|
{
|
||||||
why2_deallocate(username);
|
why2_deallocate(username);
|
||||||
if (usernames_n++ == WHY2_MAX_USERNAME_TRIES) //ASKED CLIENT WAY TOO FUCKING MANY TIMES FOR USERNAME, KICK HIM
|
if (usernames_n++ == max_tries) //ASKED CLIENT WAY TOO FUCKING MANY TIMES FOR USERNAME, KICK HIM
|
||||||
{
|
{
|
||||||
exiting = 1;
|
exiting = 1;
|
||||||
goto deallocation;
|
goto deallocation;
|
||||||
@ -706,7 +710,7 @@ void *why2_listen_server(void *socket)
|
|||||||
{
|
{
|
||||||
if (strcmp(read + strlen(server_uname) + 2, WHY2_CHAT_CODE_SSQC) == 0) //SERVER BROKE UP WITH YOU
|
if (strcmp(read + strlen(server_uname) + 2, WHY2_CHAT_CODE_SSQC) == 0) //SERVER BROKE UP WITH YOU
|
||||||
{
|
{
|
||||||
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 != 0 ? WHY2_CLEAR_AND_GO_UP : "", WHY2_CLEAR_AND_GO_UP WHY2_CLEAR_AND_GO_UP, (asking_username == 0 ? "\n": ""));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
pthread_cancel(getline_thread); //CANCEL CLIENT getline
|
pthread_cancel(getline_thread); //CANCEL CLIENT getline
|
||||||
|
Loading…
x
Reference in New Issue
Block a user