From 8a81c515dfa040520eac45821a65b08798cb3984 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 21 Feb 2024 20:50:45 +0100 Subject: [PATCH] added welcome parameter to packet sending --- src/chat/misc.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index b811b57..08681a0 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -335,8 +335,7 @@ int find_colon(char *text) return -1; } -//GLOBAL -void why2_send_socket(char *text, char *username, int socket) +void send_socket(char *text, char *username, int socket, why2_bool welcome) { char *output = why2_strdup(""); size_t length_buffer = strlen(text); @@ -363,6 +362,24 @@ void why2_send_socket(char *text, char *username, int socket) json_object_object_add(json, "message", json_object_new_string(text_copy)); if (username != NULL) json_object_object_add(json, "username", json_object_new_string(username)); //WAS SENT FROM SERVER + if (welcome) //SENDING WELCOME MESSAGE TO USER + { + //GET FROM CONFIG + char *max_uname = why2_chat_server_config("max_username_length"); + char *min_uname = why2_chat_server_config("min_username_length"); + char *max_tries = why2_chat_server_config("max_username_tries"); + + //ADD THE INFO OBJS + json_object_object_add(json, "max_uname", json_object_new_string(max_uname)); + json_object_object_add(json, "min_uname", json_object_new_string(min_uname)); + json_object_object_add(json, "max_tries", json_object_new_string(max_tries)); + + //DEALLOCATION + why2_toml_read_free(max_uname); + why2_toml_read_free(min_uname); + why2_toml_read_free(max_tries); + } + //GENERATE JSON STRING json_object_object_foreach(json, key, value) { @@ -393,6 +410,12 @@ void why2_send_socket(char *text, char *username, int socket) why2_deallocate(output); } +//GLOBAL +void why2_send_socket(char *text, char *username, int socket) +{ + send_socket(text, username, socket, 0); +} + void *why2_communicate_thread(void *arg) { int connection = *(int*) arg;