Skip to content
Permalink
Browse files

Added --load-script commandline argument

Signed-off-by: Haru <haru@dotalux.com>
  • Loading branch information
MishimaHaruna committed Mar 11, 2014
1 parent ab87890 commit 0e58529609ae84540ca340193abf9ca1e8166b72
Showing with 57 additions and 27 deletions.
  1. +14 −5 script-checker
  2. +1 −1 script-checker.bat
  3. +1 −1 src/map/atcommand.c
  4. +40 −19 src/map/map.c
  5. +1 −1 src/map/map.h
@@ -14,12 +14,21 @@ if [ -z "$1" ]; then
echo "Usage: $0 <path to the script>"
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
@@ -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
@@ -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();

@@ -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 <file> Alternative GRF path configuration.\n");
ShowInfo(" --inter-config <file> Alternative inter-server configuration.\n");
ShowInfo(" --log-config <file> Alternative logging configuration.\n");
ShowInfo(" --script-check <file> 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 <file> Loads an additional script (can be repeated).\n");
ShowInfo(" --load-plugin <name> 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 ) {
@@ -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);

0 comments on commit 0e58529

Please sign in to comment.
You can’t perform that action at this time.