From 8e1b720733250be7c4981d32f148b61139afbd3b Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Wed, 10 Apr 2019 23:40:21 +0800 Subject: uncomment the input_min_value in script.conf for safety reason --- conf/map/script.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/map/script.conf b/conf/map/script.conf index f18e9d6e2..e14fa4bd5 100644 --- a/conf/map/script.conf +++ b/conf/map/script.conf @@ -52,7 +52,7 @@ script_configuration: { // Default value of the 'min' argument of the script command 'input'. // When the 'min' argument isn't provided, this value is used instead. // Defaults to 0. - //input_min_value: 0 + input_min_value: 0 // Default value of the 'max' argument of the script command 'input'. // When the 'max' argument isn't provided, this value is used instead. -- cgit v1.2.3-60-g2f50 From 55567b93ee5b287c632ff18327df6408f0cf4692 Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Thu, 11 Apr 2019 00:12:18 +0800 Subject: Modernize coding style --- src/map/script.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/map/script.c b/src/map/script.c index fe8638ac3..2a4cbd4f2 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -6947,54 +6947,52 @@ static BUILDIN(jobname) return true; } -/// Get input from the player. -/// For numeric inputs the value is capped to the range [min,max]. Returns 1 if -/// the value was higher than 'max', -1 if lower than 'min' and 0 otherwise. -/// For string inputs it returns 1 if the string was longer than 'max', -1 is -/// shorter than 'min' and 0 otherwise. -/// -/// input({,{,}}) -> +/* + * Get input from the player. + * For numeric inputs the value is capped to the range [min,max]. Returns 1 if + * the value was higher than 'max', -1 if lower than 'min' and 0 otherwise. + * For string inputs it returns 1 if the string was longer than 'max', -1 is + * shorter than 'min' and 0 otherwise. + * + * input({,{,}}) -> + */ static BUILDIN(input) { - struct script_data* data; - int64 uid; - const char* name; - int min; - int max; struct map_session_data *sd = script->rid2sd(st); if (sd == NULL) return true; - data = script_getdata(st,2); - if( !data_isreference(data) ) { + struct script_data *data = script_getdata(st, 2); + if (!data_isreference(data)) { ShowError("script:input: not a variable\n"); script->reportdata(data); st->state = END; return false; } - uid = reference_getuid(data); - name = reference_getname(data); - min = (script_hasdata(st,3) ? script_getnum(st,3) : script->config.input_min_value); - max = (script_hasdata(st,4) ? script_getnum(st,4) : script->config.input_max_value); + + int64 uid = reference_getuid(data); + const char *name = reference_getname(data); + int min = (script_hasdata(st, 3) ? script_getnum(st, 3) : script->config.input_min_value); + int max = (script_hasdata(st, 4) ? script_getnum(st, 4) : script->config.input_max_value); #ifdef SECURE_NPCTIMEOUT sd->npc_idle_type = NPCT_WAIT; #endif - if( !sd->state.menu_or_input ) { + if (!sd->state.menu_or_input) { // first invocation, display npc input box sd->state.menu_or_input = 1; st->state = RERUNLINE; - if( is_string_variable(name) ) - clif->scriptinputstr(sd,st->oid); + if (is_string_variable(name)) + clif->scriptinputstr(sd, st->oid); else - clif->scriptinput(sd,st->oid); + clif->scriptinput(sd, st->oid); } else { // take received text/value and store it in the designated variable sd->state.menu_or_input = 0; if (is_string_variable(name)) { int len = (int)strlen(sd->npc_str); - script->set_reg(st, sd, uid, name, sd->npc_str, script_getref(st,2)); + script->set_reg(st, sd, uid, name, sd->npc_str, script_getref(st, 2)); script_pushint(st, (len > max ? 1 : len < min ? -1 : 0)); } else { int amount = sd->npc_amount; -- cgit v1.2.3-60-g2f50 From 797464b89910c4a04d0381a831001f4a7591ad28 Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Thu, 11 Apr 2019 00:50:28 +0800 Subject: Add 3 pc variables just for the input limit ... sd->npc_amount_min and sd->npc_amount_max to limit input range and sd->npc_input_capped_range because the documentation ask for it --- src/map/clif.c | 15 ++++++++++++--- src/map/pc.h | 3 +++ src/map/script.c | 9 ++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index cd3131181..037e168d0 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -12587,10 +12587,19 @@ static void clif_parse_NpcAmountInput(int fd, struct map_session_data *sd) int npcid = RFIFOL(fd,2); int amount = RFIFOL(fd,6); - if (amount >= 0) + if (amount < sd->npc_amount_min) { + sd->npc_amount = sd->npc_amount_min; + sd->npc_input_capped_range = -1; + } + else if (amount > sd->npc_amount_max) { + sd->npc_amount = sd->npc_amount_max; + sd->npc_input_capped_range = 1; + } + else { sd->npc_amount = amount; - else - sd->npc_amount = 0; + sd->npc_input_capped_range = 0; + } + npc->scriptcont(sd, npcid, false); } diff --git a/src/map/pc.h b/src/map/pc.h index b2069d4df..41384b484 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -273,6 +273,9 @@ struct map_session_data { int npc_item_flag; //Marks the npc_id with which you can change equipments during interactions with said npc (see script command enable_itemuse) int npc_menu; // internal variable, used in npc menu handling int npc_amount; + int npc_amount_min; + int npc_amount_max; + int npc_input_capped_range; struct script_state *st; char npc_str[CHATBOX_SIZE]; // for passing npc input box text to script engine int npc_timer_id; //For player attached npc timers. [Skotlex] diff --git a/src/map/script.c b/src/map/script.c index 2a4cbd4f2..391fb34c4 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -6983,10 +6983,13 @@ static BUILDIN(input) // first invocation, display npc input box sd->state.menu_or_input = 1; st->state = RERUNLINE; - if (is_string_variable(name)) + if (is_string_variable(name)) { clif->scriptinputstr(sd, st->oid); - else + } else { + sd->npc_amount_min = min; + sd->npc_amount_max = max; clif->scriptinput(sd, st->oid); + } } else { // take received text/value and store it in the designated variable sd->state.menu_or_input = 0; @@ -6997,7 +7000,7 @@ static BUILDIN(input) } else { int amount = sd->npc_amount; script->set_reg(st, sd, uid, name, (const void *)h64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2)); - script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0)); + script_pushint(st, sd->npc_input_capped_range); } st->state = RUN; } -- cgit v1.2.3-60-g2f50