Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First working prototype of server chosing option in login screen #93

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ git_version
map_editor/mapedit.x86.linux.bin
docs/DOXYTAGS
docs/html
.idea/
cmake-build-debug/
pawn_scripts/*.amx
pawn_scripts/features.inc

Expand Down
1 change: 1 addition & 0 deletions elconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -2937,6 +2937,7 @@ static void init_ELC_vars(void)
"Username", "Your user name here", SERVER);
add_var(OPT_PASSWORD, "password", "p", active_password_str, change_string, sizeof(active_password_str),
"Password", "Put your password here", SERVER);
add_var(OPT_STRING,"server","s",active_server_str,change_string,sizeof(active_server_str),"Server","Put your server here",SERVER);
add_var(OPT_BOOL,"passmngr_enabled","pme",&passmngr_enabled,change_var,0,"Enable Password Manager", "If enabled, user names and passwords are saved locally by the built-in password manager. Multiple sets of details can be saved. You can choose which details to use at the login screen.",SERVER);
add_var(OPT_MULTI,"log_chat","log",&log_chat,change_int,LOG_SERVER,"Log Messages","Log messages from the server (chat, harvesting events, GMs, etc)",SERVER,"Do not log chat", "Log chat only", "Log server messages", "Log server to srv_log.txt", NULL);
add_var(OPT_BOOL,"rotate_chat_log","rclog",&rotate_chat_log_config_var,change_rotate_chat_log,0,"Rotate Chat Log File","Tag the chat/server message log files with year and month. You will still need to manage deletion of the old files. Requires a client restart.",SERVER);
Expand Down
2 changes: 1 addition & 1 deletion gamewin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ int keypress_root_common (SDL_Keycode key_code, Uint32 key_unicode, Uint16 key_m
put_string_in_input_field((unsigned char*)line);
}
}
else if(is_disconnected() && !alt_on && !ctrl_on && !locked_to_console)
else if(is_disconnected() && !alt_on && !ctrl_on && !locked_to_console && can_login)
{
connect_to_server();
}
Expand Down
10 changes: 7 additions & 3 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void load_entrable_list(void)
}
#endif // FASTER_MAP_LOAD

static void read_config(void)
void read_config(void)
{
// Set our configdir
const char * tcfg = get_path_config();
Expand Down Expand Up @@ -793,13 +793,14 @@ void init_stuff(void)
init_text_buffers ();

load_server_list("servers.lst");
set_server_details();
set_default_config();

#ifdef NEW_SOUND
initial_sound_init();
#endif

// Read the config file
// TODO: config is stored per server... here we load the default config
read_config();

// Parse command line options
Expand Down Expand Up @@ -1061,6 +1062,7 @@ void init_stuff(void)
safe_snprintf(config_location, sizeof(config_location), datadir_location_str, datadir);
LOG_TO_CONSOLE(c_green4, config_location);
cfgdir = get_path_config();
cfgdir = get_path_default_config();
if (cfgdir != NULL) {
//Realistically, if this failed, then there's not much point in continuing, but oh well...
safe_snprintf(config_location, sizeof(config_location), config_location_str, cfgdir);
Expand Down Expand Up @@ -1097,8 +1099,10 @@ void init_stuff(void)
}
else if (has_accepted)
{
//switch_to_login();
show_window (opening_root_win);
connect_to_server();
//show_window (login_root_win);
//connect_to_server();
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions init.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ typedef struct
extern char configdir[256]; /*!< the default directory where we look for configuration files */
extern char datadir[256]; /*!< the default directory where we look for data files (aka installation dir) */

/*!
* \ingroup readconfig
* \brief Reads the server configuration file.
*
* Reads the server configuration, or the default one if no server selected.
*
* \pre If the config could not be read, the function calls exit.
*/
void read_config(void);

/*!
* \ingroup loadsave
* \brief Stores the window layout in the binary cfg file.
Expand Down
23 changes: 23 additions & 0 deletions io/elpathwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,27 @@ const char * get_path_config_base(void)
}
#endif // platform check

fprintf(stderr,"[DEBUG] get_path_config_base: %s\n", locbuffer);

return locbuffer;
}

const char * get_path_default_config(void)
{
static char locbuffer[MAX_PATH] = {0};

// Check if we have selected a server yet, otherwise return the base config dir
#ifndef MAP_EDITOR
safe_snprintf(locbuffer, sizeof(locbuffer), "%s%s", get_path_config_base(), "");
#else
safe_snprintf(locbuffer, sizeof(locbuffer), "%s/", get_path_config_base());
#endif //!MAP_EDITOR

fprintf(stderr,"[DEBUG] get_path_default_config: %s\n", locbuffer);

return locbuffer;
}

const char * get_path_config(void)
{
static char locbuffer[MAX_PATH] = {0};
Expand Down Expand Up @@ -780,6 +799,10 @@ int copy_file(const char *source, const char *dest)
return 0;
}

int check_default_config(void)
{
return file_exists(get_path_config());
}

int check_configdir(void)
{
Expand Down
15 changes: 15 additions & 0 deletions io/elpathwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ extern "C" {
*/
const char * get_path_config_base(void);

/**
* @brief Gets the directory for the default config files
*
* Get the directory where we should be storing default config files
* @return Returns a string with the path on success, or an empty string (indicating the use of the current directory, usually data_dir) on failure
*/
const char * get_path_default_config(void);

/**
* @brief Gets the directory for config files
*
Expand Down Expand Up @@ -171,6 +179,13 @@ void file_update_clear_old(void);
*/
void remove_file_updates(char * filename, int custom);

/**
* @brief Check for valid default config
*
* Checks if we can stat() default config file
*/
int check_default_config(void);

/**
* @brief Check for valid configdir
*
Expand Down
Loading