added welcome parameter to packet sending

This commit is contained in:
Václav Šmejkal 2024-02-21 20:50:45 +01:00
parent 965395e9d4
commit 8a81c515df
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -335,8 +335,7 @@ int find_colon(char *text)
return -1; return -1;
} }
//GLOBAL void send_socket(char *text, char *username, int socket, why2_bool welcome)
void why2_send_socket(char *text, char *username, int socket)
{ {
char *output = why2_strdup(""); char *output = why2_strdup("");
size_t length_buffer = strlen(text); 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)); 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 (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 //GENERATE JSON STRING
json_object_object_foreach(json, key, value) json_object_object_foreach(json, key, value)
{ {
@ -393,6 +410,12 @@ void why2_send_socket(char *text, char *username, int socket)
why2_deallocate(output); 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) void *why2_communicate_thread(void *arg)
{ {
int connection = *(int*) arg; int connection = *(int*) arg;