summaryrefslogtreecommitdiff
path: root/src/char/char.c
diff options
context:
space:
mode:
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);