From ab878900afdb9c9caa58b7f84f0a12b6283edf2b Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 11 Mar 2014 04:19:59 +0100 Subject: Added --load-plugin commandline argument Signed-off-by: Haru --- src/map/map.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/map/map.c') diff --git a/src/map/map.c b/src/map/map.c index a7e83cae3..b2d50292e 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5356,6 +5356,7 @@ void map_helpscreen(bool do_exit) ShowInfo(" --inter-config Alternative inter-server configuration.\n"); ShowInfo(" --log-config Alternative logging configuration.\n"); ShowInfo(" --script-check Tests a script for errors, without running the server.\n"); + ShowInfo(" --load-plugin Loads an additional plugin (can be repeated).\n"); HPM->arg_help();/* display help for commands implemented thru HPM */ if( do_exit ) exit(EXIT_SUCCESS); @@ -5566,7 +5567,8 @@ int do_init(int argc, char *argv[]) { bool minimal = false; char *scriptcheck = NULL; - int i; + int i, extra_plugins_count = 0; + const char **extra_plugins = NULL; #ifdef GCOLLECT GC_enable_incremental(); @@ -5579,7 +5581,21 @@ int do_init(int argc, char *argv[]) HPM->load_sub = HPM_map_plugin_load_sub; HPM->symbol_defaults_sub = map_hp_symbols; HPM->grabHPDataSub = HPM_map_grabHPData; - HPM->config_read(); + 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(extra_plugins, const char *, ++extra_plugins_count); + extra_plugins[extra_plugins_count-1] = argv[++i]; + } + } + } + HPM->config_read(extra_plugins, extra_plugins_count); + if (extra_plugins) { + aFree(extra_plugins); + extra_plugins = NULL; + extra_plugins_count = 0; + } HPM->event(HPET_PRE_INIT); @@ -5629,6 +5645,9 @@ int do_init(int argc, char *argv[]) runflag = CORE_ST_STOP; if( map->arg_next_value(arg, i, argc, true) ) scriptcheck = argv[++i]; + } else if( strcmp(arg, "load-plugin") == 0 ) { + if( map->arg_next_value(arg, i, argc, true) ) + i++; } else { ShowError("Unknown option '%s'.\n", argv[i]); exit(EXIT_FAILURE); -- cgit v1.2.3-70-g09d2 From 0e58529609ae84540ca340193abf9ca1e8166b72 Mon Sep 17 00:00:00 2001 From: Haru Date: Tue, 11 Mar 2014 05:06:38 +0100 Subject: Added --load-script commandline argument Signed-off-by: Haru --- script-checker | 19 ++++++++++++----- script-checker.bat | 2 +- src/map/atcommand.c | 2 +- src/map/map.c | 59 ++++++++++++++++++++++++++++++++++++----------------- src/map/map.h | 2 +- 5 files changed, 57 insertions(+), 27 deletions(-) (limited to 'src/map/map.c') diff --git a/script-checker b/script-checker index 521cf9025..f4a277e2d 100755 --- a/script-checker +++ b/script-checker @@ -14,12 +14,21 @@ if [ -z "$1" ]; then echo "Usage: $0 " echo " (you may use a relative or absolute path)" exit -1 -elif [[ "$1" =~ ^\/ ]]; then - FILE="$1" -else - FILE="${ORIG_CWD}/$1" fi if [ ! -x "$EXECUTABLE" ]; then exit -1 fi -"$EXECUTABLE" --script-check "${FILE}" 2>&1 + +while [ -n "$1" ]; do + [ -n "$FILES" ] && FILES="${FILES}!" + if [[ "$1" =~ ^\/ ]]; then + FILES="${FILES}--load-script!$1" + else + FILES="${FILES}--load-script!${ORIG_CWD}/$1" + fi + shift +done + +# We assume that filenames don't contain exclamation marks. +IFS=! +"$EXECUTABLE" --script-check $FILES 2>&1 diff --git a/script-checker.bat b/script-checker.bat index e05eda64e..d81277971 100644 --- a/script-checker.bat +++ b/script-checker.bat @@ -24,6 +24,6 @@ ECHO. :LOOP SET /P SCRIPT="Enter path/to/your/script.txt: " %=% - map-server.exe --script-check %SCRIPT% + map-server.exe --script-check --load-script %SCRIPT% ECHO. GOTO LOOP diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 50ec913c4..4c35999d6 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -3666,7 +3666,7 @@ ACMD(reloadscript) { mapit->free(iter); flush_fifos(); - map->reloadnpc(true); // reload config files seeking for npcs + map->reloadnpc(true, NULL, 0); // reload config files seeking for npcs script->reload(); npc->reload(); diff --git a/src/map/map.c b/src/map/map.c index b2d50292e..9dbe19666 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3559,8 +3559,8 @@ void map_reloadnpc_sub(char *cfgName) fclose(fp); } -void map_reloadnpc(bool clear) -{ +void map_reloadnpc(bool clear, const char * const *extra_scripts, int extra_scripts_count) { + int i; if (clear) npc->addsrcfile("clear"); // this will clear the current script list @@ -3569,6 +3569,11 @@ void map_reloadnpc(bool clear) #else map->reloadnpc_sub("npc/pre-re/scripts_main.conf"); #endif + + // Append extra scripts + for( i = 0; i < extra_scripts_count; i++ ) { + npc->addsrcfile(extra_scripts[i]); + } } int inter_config_read(char *cfgName) { @@ -5355,7 +5360,9 @@ void map_helpscreen(bool do_exit) ShowInfo(" --grf-path Alternative GRF path configuration.\n"); ShowInfo(" --inter-config Alternative inter-server configuration.\n"); ShowInfo(" --log-config Alternative logging configuration.\n"); - ShowInfo(" --script-check Tests a script for errors, without running the server.\n"); + ShowInfo(" --script-check Doesn't run the server, only tests the\n"); + ShowInfo(" scripts passed through --load-script.\n"); + ShowInfo(" --load-script Loads an additional script (can be repeated).\n"); ShowInfo(" --load-plugin Loads an additional plugin (can be repeated).\n"); HPM->arg_help();/* display help for commands implemented thru HPM */ if( do_exit ) @@ -5566,9 +5573,9 @@ void map_load_defaults(void) { int do_init(int argc, char *argv[]) { bool minimal = false; - char *scriptcheck = NULL; - int i, extra_plugins_count = 0; - const char **extra_plugins = NULL; + bool scriptcheck = false; + int i, load_extras_count = 0; + const char **load_extras = NULL; #ifdef GCOLLECT GC_enable_incremental(); @@ -5585,16 +5592,16 @@ int do_init(int argc, char *argv[]) const char* arg = argv[i]; if( strcmp(arg, "--load-plugin") == 0 ) { if( map->arg_next_value(arg, i, argc, true) ) { - RECREATE(extra_plugins, const char *, ++extra_plugins_count); - extra_plugins[extra_plugins_count-1] = argv[++i]; + RECREATE(load_extras, const char *, ++load_extras_count); + load_extras[load_extras_count-1] = argv[++i]; } } } - HPM->config_read(extra_plugins, extra_plugins_count); - if (extra_plugins) { - aFree(extra_plugins); - extra_plugins = NULL; - extra_plugins_count = 0; + HPM->config_read(load_extras, load_extras_count); + if (load_extras) { + aFree(load_extras); + load_extras = NULL; + load_extras_count = 0; } HPM->event(HPET_PRE_INIT); @@ -5643,11 +5650,15 @@ int do_init(int argc, char *argv[]) } else if( strcmp(arg, "script-check") == 0 ) { map->minimal = true; runflag = CORE_ST_STOP; - if( map->arg_next_value(arg, i, argc, true) ) - scriptcheck = argv[++i]; + scriptcheck = true; } else if( strcmp(arg, "load-plugin") == 0 ) { if( map->arg_next_value(arg, i, argc, true) ) i++; + } else if( strcmp(arg, "load-script") == 0 ) { + if( map->arg_next_value(arg, i, argc, true) ) { + RECREATE(load_extras, const char *, ++load_extras_count); + load_extras[load_extras_count-1] = argv[++i]; + } } else { ShowError("Unknown option '%s'.\n", argv[i]); exit(EXIT_FAILURE); @@ -5675,7 +5686,7 @@ int do_init(int argc, char *argv[]) map->config_read_sub(map->MAP_CONF_NAME); // loads npcs - map->reloadnpc(false); + map->reloadnpc(false, load_extras, load_extras_count); chrif->checkdefaultlogin(); @@ -5785,9 +5796,19 @@ int do_init(int argc, char *argv[]) vending->init(minimal); if (scriptcheck) { - if (npc->parsesrcfile(scriptcheck, false) == 0) - exit(EXIT_SUCCESS); - exit(EXIT_FAILURE); + bool failed = load_extras_count > 0 ? false : true; + for (i = 0; i < load_extras_count; i++) { + if (npc->parsesrcfile(load_extras[i], false) != 0) + failed = true; + } + if (failed) + exit(EXIT_FAILURE); + exit(EXIT_SUCCESS); + } + if (load_extras) { + aFree(load_extras); + load_extras = NULL; + load_extras_count = 0; } if( minimal ) { diff --git a/src/map/map.h b/src/map/map.h index 270931689..c1eaeb40d 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -992,7 +992,7 @@ struct map_interface { struct mob_data * (*getmob_boss) (int16 m); struct mob_data * (*id2boss) (int id); // reload config file looking only for npcs - void (*reloadnpc) (bool clear); + void (*reloadnpc) (bool clear, const char * const *extra_scripts, int extra_scripts_count); int (*check_dir) (int s_dir,int t_dir); uint8 (*calc_dir) (struct block_list *src,int16 x,int16 y); -- cgit v1.2.3-70-g09d2 From 1cf8ea92f8e8e992617addc371272c78e60df219 Mon Sep 17 00:00:00 2001 From: Haru Date: Mon, 17 Mar 2014 17:13:11 +0100 Subject: Follow-up to 0e58529 (for MSVC compatibility) - Fixes bugreport:8097, thanks to Frost http://hercules.ws/board/tracker/issue-8097-compile-issue-using-msvc-2010-windows-7-64bit/ Signed-off-by: Haru --- src/map/map.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/map/map.c') diff --git a/src/map/map.c b/src/map/map.c index 9dbe19666..dfcc7f47a 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -5575,7 +5575,7 @@ int do_init(int argc, char *argv[]) bool minimal = false; bool scriptcheck = false; int i, load_extras_count = 0; - const char **load_extras = NULL; + char **load_extras = NULL; #ifdef GCOLLECT GC_enable_incremental(); @@ -5592,12 +5592,12 @@ int do_init(int argc, char *argv[]) const char* arg = argv[i]; if( strcmp(arg, "--load-plugin") == 0 ) { if( map->arg_next_value(arg, i, argc, true) ) { - RECREATE(load_extras, const char *, ++load_extras_count); + RECREATE(load_extras, char *, ++load_extras_count); load_extras[load_extras_count-1] = argv[++i]; } } } - HPM->config_read(load_extras, load_extras_count); + HPM->config_read((const char * const *)load_extras, load_extras_count); if (load_extras) { aFree(load_extras); load_extras = NULL; @@ -5656,7 +5656,7 @@ int do_init(int argc, char *argv[]) i++; } else if( strcmp(arg, "load-script") == 0 ) { if( map->arg_next_value(arg, i, argc, true) ) { - RECREATE(load_extras, const char *, ++load_extras_count); + RECREATE(load_extras, char *, ++load_extras_count); load_extras[load_extras_count-1] = argv[++i]; } } else { @@ -5686,7 +5686,7 @@ int do_init(int argc, char *argv[]) map->config_read_sub(map->MAP_CONF_NAME); // loads npcs - map->reloadnpc(false, load_extras, load_extras_count); + map->reloadnpc(false, (const char * const *)load_extras, load_extras_count); chrif->checkdefaultlogin(); -- cgit v1.2.3-70-g09d2