summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2014-11-09 02:07:09 +0100
committerHaru <haru@dotalux.com>2015-01-18 21:35:36 +0100
commitce08d6238d902590dbfb650f889a8ab8887356bf (patch)
tree218266957f961e71a51a307b432b02ed9647243a /src/login
parent0285ddf7cee2f6569a513fe6118c43f99fd71279 (diff)
downloadhercules-ce08d6238d902590dbfb650f889a8ab8887356bf.tar.gz
hercules-ce08d6238d902590dbfb650f889a8ab8887356bf.tar.bz2
hercules-ce08d6238d902590dbfb650f889a8ab8887356bf.tar.xz
hercules-ce08d6238d902590dbfb650f889a8ab8887356bf.zip
Command line arguments handling overhaul
- login_server, char_server, map_server as well as the tools (mapcache) now have a common command line arguments handling mechanism. - All of them now accept `--help` (`-h`), `--version` (`-v`) and `--load-plugin`. - login_server now accepts `--login-config` and `--lan-config` instead of relying on positional arguments to override those files. The old syntax will no longer work, please update your custom startup scripts. - char_server now accepts `--char-config`, `--inter-config`, `--lan-config` instead of relying on positional arguments. The old syntax will no longer work, please update your custom startup scripts. - mapcache now accepts `--grf-list`, `--map-list`, `--map-cache`, `--rebuild` in place of, respectively, `-grf`, `-list`, `-cache`, `-rebuild`. - A new macro `CMDLINEARG()` is provided, to help defining new command line argument handlers (i.e. in plugins). the `addArg()` call is still required, but its syntax has changed. The `help` argument is now of type `const char *` rather than a function pointer, and it is supposed to contain the message to show in the `--help` screen. Pass `NULL` if no help message is desired. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/login')
-rw-r--r--src/login/login.c68
-rw-r--r--src/login/login.h5
2 files changed, 49 insertions, 24 deletions
diff --git a/src/login/login.c b/src/login/login.c
index ec5b2bb7c..036456a85 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -1899,6 +1899,9 @@ int do_final(void) {
HPM_login_do_final();
+ aFree(login->LOGIN_CONF_NAME);
+ aFree(login->LAN_CONF_NAME);
+
HPM->event(HPET_POST_FINAL);
ShowStatus("Finished.\n");
@@ -1939,6 +1942,39 @@ void login_hp_symbols(void) {
HPM->share(login,"login");
}
+/**
+ * --login-config handler
+ *
+ * Overrides the default login configuration file.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(loginconfig)
+{
+ aFree(login->LOGIN_CONF_NAME);
+ login->LOGIN_CONF_NAME = aStrdup(params);
+ return true;
+}
+/**
+ * --lan-config handler
+ *
+ * Overrides the default subnet configuration file.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(lanconfig)
+{
+ aFree(login->LAN_CONF_NAME);
+ login->LAN_CONF_NAME = aStrdup(params);
+ return true;
+}
+/**
+ * Defines the local command line arguments
+ */
+void cmdline_args_init_local(void)
+{
+ CMDLINEARG_DEF2(login-config, loginconfig, "Alternative login-server configuration.", CMDLINE_OPT_PARAM);
+ CMDLINEARG_DEF2(lan-config, lanconfig, "Alternative subnet configuration.", CMDLINE_OPT_PARAM);
+}
+
//------------------------------
// Login server initialization
//------------------------------
@@ -1959,31 +1995,18 @@ int do_init(int argc, char** argv)
// read login-server configuration
login_set_defaults();
+ login->LOGIN_CONF_NAME = aStrdup("conf/login-server.conf");
+ login->LAN_CONF_NAME = aStrdup("conf/subnet.conf");
+
HPM_login_do_init();
HPM->symbol_defaults_sub = login_hp_symbols;
- HPM->config_read(NULL, 0);
-#if 0
- /* TODO: Move to common code */
- for( i = 1; i < argc; i++ ) {
- const char* arg = argv[i];
- if( strcmp(arg, "--load-plugin") == 0 ) {
- if( map->arg_next_value(arg, i, argc, true) ) {
- RECREATE(load_extras, char *, ++load_extras_count);
- load_extras[load_extras_count-1] = argv[++i];
- }
- }
- }
- HPM->config_read((const char * const *)load_extras, load_extras_count);
- if (load_extras) {
- aFree(load_extras);
- load_extras = NULL;
- load_extras_count = 0;
- }
-#endif
+ cmdline->exec(argc, argv, CMDLINE_OPT_PREINIT);
+ HPM->config_read();
HPM->event(HPET_PRE_INIT);
- login_config_read((argc > 1) ? argv[1] : LOGIN_CONF_NAME);
- login->lan_config_read((argc > 2) ? argv[2] : LAN_CONF_NAME);
+ cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL);
+ login_config_read(login->LOGIN_CONF_NAME);
+ login->lan_config_read(login->LAN_CONF_NAME);
for( i = 0; i < ARRAYLENGTH(server); ++i )
chrif_server_init(i);
@@ -2105,4 +2128,7 @@ void login_defaults(void) {
login->kick = login_kick;
login->login_error = login_login_error;
login->send_coding_key = login_send_coding_key;
+
+ login->LOGIN_CONF_NAME = NULL;
+ login->LAN_CONF_NAME = NULL;
}
diff --git a/src/login/login.h b/src/login/login.h
index 8a377927b..7254b5db2 100644
--- a/src/login/login.h
+++ b/src/login/login.h
@@ -18,9 +18,6 @@ enum E_LOGINSERVER_ST
LOGINSERVER_ST_LAST
};
-#define LOGIN_CONF_NAME "conf/login-server.conf"
-#define LAN_CONF_NAME "conf/subnet.conf"
-
// supported encryption types: 1- passwordencrypt, 2- passwordencrypt2, 3- both
#define PASSWORDENC 3
#define PASSWD_LEN (32+1) // 23+1 for plaintext, 32+1 for md5-ed passwords
@@ -200,6 +197,8 @@ struct login_interface {
void (*char_server_connection_status) (int fd, struct login_session_data* sd, uint8 status);
void (*parse_request_connection) (int fd, struct login_session_data* sd, const char *ip);
int (*parse_login) (int fd);
+ char *LOGIN_CONF_NAME;
+ char *LAN_CONF_NAME;
};
struct login_interface *login;