implemented config functions
way better now
This commit is contained in:
parent
41a0911a28
commit
f77f3a8c93
@ -84,9 +84,9 @@ void init_config(char *filename)
|
||||
|
||||
char *config(char *key, enum CONFIG_TYPES type)
|
||||
{
|
||||
char *path;
|
||||
char *path = NULL;
|
||||
|
||||
switch (type) //GET PATH
|
||||
switch (type) //GET path
|
||||
{
|
||||
case CLIENT:
|
||||
path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER"));
|
||||
|
@ -52,12 +52,11 @@ int main(void)
|
||||
//GET IP
|
||||
printf("Welcome.\n\n");
|
||||
|
||||
char *path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER"));
|
||||
char *auto_connect = why2_toml_read(path, "auto_connect");
|
||||
char *auto_connect = why2_chat_client_config("auto_connect");
|
||||
|
||||
if (strcmp(auto_connect, "true") == 0) //USER ENABLED AUTOMATIC CONNECTION
|
||||
{
|
||||
char *auto_connect_ip = why2_toml_read(path, "auto_connect_ip"); //GET IP
|
||||
char *auto_connect_ip = why2_chat_client_config("auto_connect_ip"); //GET IP
|
||||
|
||||
line = strdup(auto_connect_ip);
|
||||
printf("%s\n", line);
|
||||
@ -71,7 +70,6 @@ int main(void)
|
||||
line_length = 3; //THIS IS FOR THE UNDERLINE THINGY
|
||||
}
|
||||
|
||||
why2_deallocate(path);
|
||||
why2_toml_read_free(auto_connect);
|
||||
|
||||
server_addr.sin_addr.s_addr = inet_addr(line);
|
||||
|
@ -368,8 +368,7 @@ void *why2_communicate_thread(void *arg)
|
||||
printf("User connected.\t\t%d\n", connection);
|
||||
|
||||
//GET USERNAME
|
||||
char *string_buffer = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{USER}", getenv("USER"));
|
||||
char *config_username = why2_toml_read(string_buffer, "user_pick_username");
|
||||
char *config_username = why2_chat_server_config("user_pick_username");
|
||||
|
||||
char *raw = NULL;
|
||||
void *raw_ptr = NULL;
|
||||
@ -382,8 +381,6 @@ void *why2_communicate_thread(void *arg)
|
||||
int usernames_n = 0;
|
||||
struct json_object *json = json_tokener_parse("{}");
|
||||
|
||||
why2_deallocate(string_buffer);
|
||||
|
||||
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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user