From 1be53db78a321436d0ebe6093595b769f10874b6 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Sat, 9 Nov 2013 17:06:32 -0200 Subject: HPM Support for plugin-implemented "--args" (options) As a necessary measure for the upcoming bot that will keep .sql files in sync with their .txt counterparts. Special Thanks to Haruna Signed-off-by: shennetsind --- src/map/map.c | 44 +++++++++++++++++++++++++------------------- src/map/map.h | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) (limited to 'src/map') diff --git a/src/map/map.c b/src/map/map.c index cd192b7d4..1d47d196e 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5215,6 +5215,7 @@ void map_helpscreen(bool do_exit) ShowInfo(" --grf-path \t\tAlternative GRF path configuration.\n"); ShowInfo(" --inter-config \t\tAlternative inter-server configuration.\n"); ShowInfo(" --log-config \t\tAlternative logging configuration.\n"); + HPM->arg_help();/* display help for commands implemented thru HPM */ if( do_exit ) exit(EXIT_SUCCESS); } @@ -5257,10 +5258,11 @@ void do_shutdown(void) } } -bool map_arg_next_value(const char* option, int i, int argc) +bool map_arg_next_value(const char* option, int i, int argc, bool must) { if( i >= argc-1 ) { - ShowWarning("Missing value for option '%s'.\n", option); + if( must ) + ShowWarning("Missing value for option '%s'.\n", option); return false; } @@ -5377,6 +5379,8 @@ void map_hp_symbols(void) { } void map_load_defaults(void) { + map_defaults(); + /* */ atcommand_defaults(); battle_defaults(); battleground_defaults(); @@ -5426,17 +5430,23 @@ int do_init(int argc, char *argv[]) #ifdef GCOLLECT GC_enable_incremental(); #endif + + map_load_defaults(); - map_defaults(); - - rnd_init(); - + HPM->load_sub = HPM_map_plugin_load_sub; + HPM->symbol_defaults_sub = map_hp_symbols; + HPM->config_read(); + + HPM->event(HPET_PRE_INIT); + for( i = 1; i < argc ; i++ ) { const char* arg = argv[i]; if( arg[0] != '-' && ( arg[0] != '/' || arg[1] == '-' ) ) {// -, -- and / ShowError("Unknown option '%s'.\n", argv[i]); exit(EXIT_FAILURE); + } else if ( HPM->parse_arg(arg,&i,argv,map->arg_next_value(arg, i, argc, false)) ) { + continue; /* HPM Triggered */ } else if( (++arg)[0] == '-' ) {// long option arg++; @@ -5445,35 +5455,35 @@ int do_init(int argc, char *argv[]) } else if( strcmp(arg, "version") == 0 ) { map->versionscreen(true); } else if( strcmp(arg, "map-config") == 0 ) { - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) map->MAP_CONF_NAME = argv[++i]; } else if( strcmp(arg, "battle-config") == 0 ) { - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) map->BATTLE_CONF_FILENAME = argv[++i]; } else if( strcmp(arg, "atcommand-config") == 0 ) { - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) map->ATCOMMAND_CONF_FILENAME = argv[++i]; } else if( strcmp(arg, "script-config") == 0 ) { - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) map->SCRIPT_CONF_NAME = argv[++i]; } else if( strcmp(arg, "msg-config") == 0 ) { - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) map->MSG_CONF_NAME = argv[++i]; } else if( strcmp(arg, "grf-path-file") == 0 ) { - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) map->GRF_PATH_FILENAME = argv[++i]; } else if( strcmp(arg, "inter-config") == 0 ) { - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) map->INTER_CONF_NAME = argv[++i]; } else if( strcmp(arg, "log-config") == 0 ) { - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) map->LOG_CONF_NAME = argv[++i]; } else if( strcmp(arg, "run-once") == 0 ) { // close the map-server as soon as its done.. for testing [Celest] runflag = CORE_ST_STOP; } else if( strcmp(arg, "script-check") == 0 ) { minimal = true; runflag = CORE_ST_STOP; - if( map->arg_next_value(arg, i, argc) ) + if( map->arg_next_value(arg, i, argc, true) ) scriptcheck = argv[++i]; } else { ShowError("Unknown option '%s'.\n", argv[i]); @@ -5495,7 +5505,6 @@ int do_init(int argc, char *argv[]) } } - map_load_defaults(); if (!minimal) { map->config_read(map->MAP_CONF_NAME); CREATE(map->list,struct map_data,map->count); @@ -5580,9 +5589,6 @@ int do_init(int argc, char *argv[]) timer->add_func_list(map->removemobs_timer, "map_removemobs_timer"); timer->add_interval(timer->gettick()+1000, map->freeblock_timer, 0, 0, 60*1000); - HPM->load_sub = HPM_map_plugin_load_sub; - HPM->symbol_defaults_sub = map_hp_symbols; - HPM->config_read(); HPM->event(HPET_INIT); } diff --git a/src/map/map.h b/src/map/map.h index 20e328c88..4b2671702 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -1047,7 +1047,7 @@ struct map_interface { int (*abort_sub) (struct map_session_data *sd, va_list ap); void (*helpscreen) (bool do_exit); void (*versionscreen) (bool do_exit); - bool (*arg_next_value) (const char *option, int i, int argc); + bool (*arg_next_value) (const char *option, int i, int argc, bool must); void (*addblcell) (struct block_list *bl); void (*delblcell) (struct block_list *bl); int (*get_new_bonus_id) (void); -- cgit v1.2.3-60-g2f50