summaryrefslogtreecommitdiff
path: root/src/char/char.c
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/char/char.c
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/char/char.c')
-rw-r--r--src/char/char.c90
1 files changed, 63 insertions, 27 deletions
diff --git a/src/char/char.c b/src/char/char.c
index f29bf8cff..1301f2cc4 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -50,10 +50,6 @@
#endif
// private declarations
-#define CHAR_CONF_NAME "conf/char-server.conf"
-#define LAN_CONF_NAME "conf/subnet.conf"
-#define SQL_CONF_NAME "conf/inter-server.conf"
-
char char_db[256] = "char";
char scdata_db[256] = "sc_data";
char cart_db[256] = "cart_inventory";
@@ -5707,6 +5703,11 @@ int do_final(void) {
if( chr->server[i].map )
aFree(chr->server[i].map);
+ aFree(chr->CHAR_CONF_NAME);
+ aFree(chr->LAN_CONF_NAME);
+ aFree(chr->SQL_CONF_NAME);
+ aFree(chr->INTER_CONF_NAME);
+
HPM->event(HPET_POST_FINAL);
ShowStatus("Finished.\n");
@@ -5763,45 +5764,80 @@ void char_hp_symbols(void) {
HPM->share(inter->sql_handle, "sql_handle");
}
+/**
+ * --char-config handler
+ *
+ * Overrides the default char configuration file.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(charconfig)
+{
+ aFree(chr->CHAR_CONF_NAME);
+ chr->CHAR_CONF_NAME = aStrdup(params);
+ return true;
+}
+/**
+ * --inter-config handler
+ *
+ * Overrides the default inter-server configuration file.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(interconfig)
+{
+ aFree(chr->INTER_CONF_NAME);
+ chr->INTER_CONF_NAME = aStrdup(params);
+ return true;
+}
+/**
+ * --lan-config handler
+ *
+ * Overrides the default subnet configuration file.
+ * @see cmdline->exec
+ */
+static CMDLINEARG(lanconfig)
+{
+ aFree(chr->LAN_CONF_NAME);
+ chr->LAN_CONF_NAME = aStrdup(params);
+ return true;
+}
+/**
+ * Initializes the command line arguments handlers.
+ */
+void cmdline_args_init_local(void)
+{
+ CMDLINEARG_DEF2(char-config, charconfig, "Alternative char-server configuration.", CMDLINE_OPT_PARAM);
+ CMDLINEARG_DEF2(inter-config, interconfig, "Alternative inter-server configuration.", CMDLINE_OPT_PARAM);
+ CMDLINEARG_DEF2(lan-config, lanconfig, "Alternative subnet configuration.", CMDLINE_OPT_PARAM);
+}
+
int do_init(int argc, char **argv) {
int i;
memset(&skillid2idx, 0, sizeof(skillid2idx));
char_load_defaults();
+ chr->CHAR_CONF_NAME = aStrdup("conf/char-server.conf");
+ chr->LAN_CONF_NAME = aStrdup("conf/subnet.conf");
+ chr->SQL_CONF_NAME = aStrdup("conf/inter-server.conf");
+ chr->INTER_CONF_NAME = aStrdup("conf/inter-server.conf");
+
for(i = 0; i < MAX_MAP_SERVERS; i++ )
chr->server[i].map = NULL;
HPM_char_do_init();
HPM->symbol_defaults_sub = char_hp_symbols;
-#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
- HPM->config_read(NULL, 0);
+ cmdline->exec(argc, argv, CMDLINE_OPT_PREINIT);
+ HPM->config_read();
HPM->event(HPET_PRE_INIT);
//Read map indexes
mapindex->init();
start_point.map = mapindex->name2id("new_zone01");
- chr->config_read((argc < 2) ? CHAR_CONF_NAME : argv[1]);
- chr->lan_config_read((argc > 3) ? argv[3] : LAN_CONF_NAME);
- chr->sql_config_read(SQL_CONF_NAME);
+ cmdline->exec(argc, argv, CMDLINE_OPT_NORMAL);
+ chr->config_read(chr->CHAR_CONF_NAME);
+ chr->lan_config_read(chr->LAN_CONF_NAME);
+ chr->sql_config_read(chr->SQL_CONF_NAME);
if (strcmp(chr->userid, "s1")==0 && strcmp(chr->passwd, "p1")==0) {
ShowWarning("Using the default user/password s1/p1 is NOT RECOMMENDED.\n");
@@ -5809,7 +5845,7 @@ int do_init(int argc, char **argv) {
ShowNotice("And then change the user/password to use in conf/char-server.conf (or conf/import/char_conf.txt)\n");
}
- inter->init_sql((argc > 2) ? argv[2] : inter_cfgName); // inter server configuration
+ inter->init_sql(chr->INTER_CONF_NAME); // inter server configuration
auth_db = idb_alloc(DB_OPT_RELEASE_DATA);
chr->online_char_db = idb_alloc(DB_OPT_RELEASE_DATA);