diff options
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/src/map/script.c b/src/map/script.c index bf9348645..0fd8bda2a 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3539,6 +3539,32 @@ static void set_reg_instance_num(struct script_state *st, int64 num, const char } /** + * Validates if a variable is permanent (stored in database) by passed variable name. + * + * @param name The variable name to validate. + * @return True if variable is permanent, otherwise false. + * + **/ +static bool script_is_permanent_variable(const char *name) +{ + nullpo_retr(false, name); + + if (strlen(name) == 0) + return false; + + if (ISALNUM(name[0]) != 0) + return true; // Permanent characater variable. + + if (name[0] == '#') + return true; // Permanent (global) account variable. + + if (strlen(name) > 1 && name[0] == '$' && ISALNUM(name[1]) != 0) + return true; // Permanent server variable. + + return false; +} + +/** * Stores the value of a script variable * * @param st current script state. @@ -3583,6 +3609,18 @@ static int set_reg(struct script_state *st, struct map_session_data *sd, int64 n if (is_string_variable(name)) {// string variable const char *str = (const char*)value; + if (script->is_permanent_variable(name) && strlen(str) > SCRIPT_STRING_VAR_LENGTH) { + ShowError("script:set_reg: Value of variable %s is too long: %lu! Maximum is %d. Skipping...\n", + name, strlen(str), SCRIPT_STRING_VAR_LENGTH); + + if (st != NULL) { + script->reportsrc(st); + st->state = END; + } + + return 0; + } + switch (prefix) { case '@': if (ref) { @@ -16362,7 +16400,6 @@ static BUILDIN(atcommand) struct map_session_data *sd, *dummy_sd = NULL; int fd; const char* cmd; - bool ret = true; cmd = script_getstr(st,2); @@ -16385,11 +16422,12 @@ static BUILDIN(atcommand) if (!atcommand->exec(fd, sd, cmd, false)) { ShowWarning("script: buildin_atcommand: failed to execute command '%s'\n", cmd); - script->reportsrc(st); - ret = false; + if (dummy_sd != NULL) + aFree(dummy_sd); + return false; } if (dummy_sd) aFree(dummy_sd); - return ret; + return true; } /** @@ -28101,6 +28139,11 @@ static void script_hardcoded_constants(void) script->set_constant("MST_AROUND4", MST_AROUND4, false, false); script->set_constant("MST_AROUND", MST_AROUND , false, false); + script->constdb_comment("Monster group constants"); + script->set_constant("ALL_MOBS_NONBOSS", ALL_MOBS_NONBOSS, false, false); + script->set_constant("ALL_MOBS_BOSS", ALL_MOBS_BOSS, false, false); + script->set_constant("ALL_MOBS", ALL_MOBS, false, false); + script->constdb_comment("pc block constants, use with *setpcblock* and *checkpcblock*"); script->set_constant("PCBLOCK_NONE", PCBLOCK_NONE, false, false); script->set_constant("PCBLOCK_MOVE", PCBLOCK_MOVE, false, false); @@ -28505,6 +28548,7 @@ void script_defaults(void) script->load_parameters = script_load_parameters; script->print_line = script_print_line; script->errorwarning_sub = script_errorwarning_sub; + script->is_permanent_variable = script_is_permanent_variable; script->set_reg = set_reg; script->set_reg_ref_str = set_reg_npcscope_str; script->set_reg_pc_ref_str = set_reg_pc_ref_str; |