sending server exit_cmd with the initial welcome message

This commit is contained in:
Václav Šmejkal 2024-04-17 18:04:45 +02:00
parent c98184f1f5
commit 1fc78a2a30
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 12 additions and 5 deletions

View File

@ -108,15 +108,19 @@ int main(void)
//TODO: Remove accents
why2_send_socket(line, NULL, listen_socket); //NULL IS SENT BECAUSE IT IS USELESS TO SEND USER FROM CLIENT - SERVER WON'T USE IT
if (strcmp(line, WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT "\n") == 0) //USER REQUESTED PROGRAM EXIT
{
printf("Exiting...\n");
break;
}
free(return_line);
char *exit_cmd = why2_chat_client_get_server_exit_cmd();
why2_send_socket(exit_cmd, NULL, listen_socket);
why2_deallocate(exit_cmd);
} else
{
why2_send_socket(line, NULL, listen_socket); //NULL IS SENT BECAUSE IT IS USELESS TO SEND USER FROM CLIENT - SERVER WON'T USE IT
free(return_line);
}
}
//DEALLOCATION

View File

@ -382,6 +382,8 @@ void send_socket(char *text, char *username, int socket, why2_bool welcome)
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));
json_object_object_add(json, "exit_cmd", json_object_new_string(WHY2_CHAT_COMMAND_PREFIX WHY2_CHAT_COMMAND_EXIT));
//DEALLOCATION
why2_toml_read_free(max_uname);
why2_toml_read_free(min_uname);
@ -802,6 +804,7 @@ void *why2_listen_server(void *socket)
max_uname = get_int_from_json_string(read, "max_uname");
min_uname = get_int_from_json_string(read, "min_uname");
max_tries = get_int_from_json_string(read, "max_tries");
why2_chat_client_set_server_exit_cmd(get_string_from_json_string(read, "exit_cmd"));
continuing = 1;
}