From 8c742b18848cdb5b782b9b8a8e6dc96ed85a2bb7 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 21 Feb 2024 16:39:44 +0100 Subject: [PATCH] implemented default_username from server config --- include/chat/flags.h | 1 - src/chat/misc.c | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/chat/flags.h b/include/chat/flags.h index 163e706..65069e4 100644 --- a/include/chat/flags.h +++ b/include/chat/flags.h @@ -32,7 +32,6 @@ extern "C" { #define WHY2_CLEAR_AND_GO_UP "\33[2K\r\033[A" //i mean read the name #define WHY2_INVALID_POINTER (void*) 0xffffffffffffffff -#define WHY2_CHAT_DEFAULT_USERNAME "anon" #define WHY2_MAX_USERNAME_LENGTH 20 //MAXIMAL USERNAME LENGTH #define WHY2_MIN_USERNAME_LENGTH 4 //MINIMAL USERNAME LENGTH diff --git a/src/chat/misc.c b/src/chat/misc.c index ed3318e..9383156 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -405,10 +405,15 @@ void *why2_communicate_thread(void *arg) why2_bool invalid_username = 1; why2_bool exiting = 0; char *decoded_buffer = NULL; - char *username = why2_strdup(WHY2_CHAT_DEFAULT_USERNAME); + char *username; int usernames_n = 0; struct json_object *json = json_tokener_parse("{}"); + //GET DEFAULT USERNAME + char *default_username = why2_chat_server_config("default_username"); + username = why2_strdup(default_username); + why2_toml_read_free(default_username); + if (config_username == NULL || strcmp(config_username, "true") == 0) { if (config_username == NULL) fprintf(stderr, "Your config doesn't contain 'user_pick_username'. Please update your configuration.\n");