Browse Source

* Expanded the script command 'input': (bugreport:811)
- two new optional arguments 'min' and 'max'
- return value indicating if it's in the correct range
- config variables for the default value of the arguments: 'input_min_value' and 'input_max_value' in script_athena.conf

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@12192 54d463be-8e91-2dee-dedb-b68131a5f0ec

FlavioJS 17 years ago
parent
commit
549684872d
6 changed files with 75 additions and 20 deletions
  1. 6 0
      Changelog-Trunk.txt
  2. 2 0
      conf/Changelog.txt
  3. 11 0
      conf/script_athena.conf
  4. 15 6
      doc/script_commands.txt
  5. 39 14
      src/map/script.c
  6. 2 0
      src/map/script.h

+ 6 - 0
Changelog-Trunk.txt

@@ -3,6 +3,12 @@ Date	Added
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 
+2008/02/11
+	* Expanded the script command 'input': (bugreport:811) [FlavioJS]
+	- two new optional arguments 'min' and 'max'
+	- return value indicating if it's in the correct range
+	- config variables for the default value of the arguments:
+	  'input_min_value' and 'input_max_value' in script_athena.conf
 2008/02/10
 2008/02/10
 	* Added two missing opt2 values, for Angelus and Bleeding status
 	* Added two missing opt2 values, for Angelus and Bleeding status
 	* Fixed Warp Portal code sometimes producing errors/crashes in the case
 	* Fixed Warp Portal code sometimes producing errors/crashes in the case

+ 2 - 0
conf/Changelog.txt

@@ -1,5 +1,7 @@
 Date	Added
 Date	Added
 
 
+2008/02/11
+	* Added 'input_min_value' and 'input_max_value' to script_athena.conf. [FlavioJS]
 2008/01/22
 2008/01/22
 	* Removed hom_setting&02 (ignore skill range) as this was fixed by Gravity
 	* Removed hom_setting&02 (ignore skill range) as this was fixed by Gravity
 	  some time ago. [Skotlex]
 	  some time ago. [Skotlex]

+ 11 - 0
conf/script_athena.conf

@@ -21,4 +21,15 @@ check_cmdcount: 655360
 
 
 check_gotocount: 2048
 check_gotocount: 2048
 
 
+// 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
+
+// Default value of the 'max' argument of the script command 'input'.
+// When the 'max' argument isn't provided, this value is used instead.
+// Defaults to INT_MAX.
+//input_max_value: 2147483647
+input_max_value: 10000000
+
 import: conf/import/script_conf.txt
 import: conf/import/script_conf.txt

+ 15 - 6
doc/script_commands.txt

@@ -4,7 +4,7 @@
 //= A reference manual for the eAthena scripting language.
 //= A reference manual for the eAthena scripting language.
 //= Commands are sorted depending on their functionality.
 //= Commands are sorted depending on their functionality.
 //===== Version ===========================================
 //===== Version ===========================================
-//= 3.12.20071227
+//= 3.14.20080211
 //=========================================================
 //=========================================================
 //= 1.0 - First release, filled will as much info as I could
 //= 1.0 - First release, filled will as much info as I could
 //=       remember or figure out, most likely there are errors,
 //=       remember or figure out, most likely there are errors,
@@ -97,6 +97,8 @@
 //=       Corrected description of scope and npc variables. [FlavioJS]
 //=       Corrected description of scope and npc variables. [FlavioJS]
 //= 3.13.20080104
 //= 3.13.20080104
 //=       Updated 'setcell' desc to match latest code changes [ultramage]
 //=       Updated 'setcell' desc to match latest code changes [ultramage]
+//= 3.14.20080211
+//=       Updated 'input' (new arguments and return value). [FlavioJS]
 //=========================================================
 //=========================================================
 
 
 This document is a reference manual for all the scripting commands and functions 
 This document is a reference manual for all the scripting commands and functions 
@@ -1303,7 +1305,7 @@ the Cancel button, this function will return 255 instead.
 
 
 ---------------------------------------
 ---------------------------------------
 
 
-*input <variable>;
+*input(<variable>{,<min>{,<max>}})
 
 
 This command will make an input box pop up on the client connected to the 
 This command will make an input box pop up on the client connected to the 
 invoking character, to allow entering of a number or a string. This has many 
 invoking character, to allow entering of a number or a string. This has many 
@@ -1349,11 +1351,18 @@ allow the player to enter text. Otherwise, only numbers will be allowed.
 		close;
 		close;
 	}
 	}
 
 
-Notice that in current SVN, you may not input a negative number with this 
-command. This was done to prevent exploits in badly written scripts, which would 
+Normally you may not input a negative number with this command.
+This is done to prevent exploits in badly written scripts, which would 
 let people, for example, put negative amounts of zeny into a bank script and 
 let people, for example, put negative amounts of zeny into a bank script and 
-receive free zeny as a result. Unfortunately it limits the uses of the 'input' 
-command quite a bit.
+receive free zeny as a result.
+
+Since trunk r12192 the command has two optional arguments and a return value.
+The default value of 'min' and 'max' can be set with 'input_min_value' and 
+'input_max_value' in script_athena.conf.
+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.
 
 
 ---------------------------------------
 ---------------------------------------
 
 

+ 39 - 14
src/map/script.c

@@ -189,6 +189,7 @@ DBMap* script_get_userfunc_db(){ return userfunc_db; }
 
 
 struct Script_Config script_config = {
 struct Script_Config script_config = {
 	1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount
 	1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount
+	0, INT_MAX, // input_min_value/input_max_value
 	"OnPCDieEvent", //die_event_name
 	"OnPCDieEvent", //die_event_name
 	"OnPCKillEvent", //kill_pc_event_name
 	"OnPCKillEvent", //kill_pc_event_name
 	"OnNPCKillEvent", //kill_mob_event_name
 	"OnNPCKillEvent", //kill_mob_event_name
@@ -3502,6 +3503,12 @@ int script_config_read(char *cfgName)
 		else if(strcmpi(w1,"check_gotocount")==0) {
 		else if(strcmpi(w1,"check_gotocount")==0) {
 			script_config.check_gotocount = config_switch(w2);
 			script_config.check_gotocount = config_switch(w2);
 		}
 		}
+		else if(strcmpi(w1,"input_min_value")==0) {
+			script_config.input_min_value = config_switch(w2);
+		}
+		else if(strcmpi(w1,"input_max_value")==0) {
+			script_config.input_max_value = config_switch(w2);
+		}
 		else if(strcmpi(w1,"import")==0){
 		else if(strcmpi(w1,"import")==0){
 			script_config_read(w2);
 			script_config_read(w2);
 		}
 		}
@@ -4635,30 +4642,43 @@ BUILDIN_FUNC(jobname)
 	return 0;
 	return 0;
 }
 }
 
 
-/*==========================================
- *
- *------------------------------------------*/
+/// 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(<var>{,<min>{,<max>}}) -> <int>
 BUILDIN_FUNC(input)
 BUILDIN_FUNC(input)
 {
 {
-	TBL_PC *sd = script_rid2sd(st);
-	struct script_data *data = script_getdata(st,2);
-	int num = data->u.num;
-	char *name=str_buf+str_data[num&0x00ffffff].str;
-	char postfix = name[strlen(name)-1];
+	TBL_PC* sd;
+	struct script_data* data;
+	int uid;
+	char* name;
+	int min;
+	int max;
 
 
-	if (!sd) return 0;
+	sd = script_rid2sd(st);
+	if( sd == NULL )
+		return 0;
 
 
+	data = script_getdata(st,2);
 	if( !data_isreference(data) ){
 	if( !data_isreference(data) ){
 		ShowError("script:input: not a variable\n");
 		ShowError("script:input: not a variable\n");
 		script_reportdata(data);
 		script_reportdata(data);
+		st->state = END;
 		return 1;
 		return 1;
 	}
 	}
+	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);
 
 
 	if( !sd->state.menu_or_input )
 	if( !sd->state.menu_or_input )
 	{	// first invocation, display npc input box
 	{	// first invocation, display npc input box
 		sd->state.menu_or_input = 1;
 		sd->state.menu_or_input = 1;
 		st->state = RERUNLINE;
 		st->state = RERUNLINE;
-		if( postfix == '$' )
+		if( is_string_variable(name) )
 			clif_scriptinputstr(sd,st->oid);
 			clif_scriptinputstr(sd,st->oid);
 		else	
 		else	
 			clif_scriptinput(sd,st->oid);
 			clif_scriptinput(sd,st->oid);
@@ -4666,12 +4686,17 @@ BUILDIN_FUNC(input)
 	else
 	else
 	{	// take received text/value and store it in the designated variable
 	{	// take received text/value and store it in the designated variable
 		sd->state.menu_or_input = 0;
 		sd->state.menu_or_input = 0;
-		if( postfix == '$' )
-			set_reg(st,sd,num,name,(void*)sd->npc_str,script_getref(st,2));
+		if( is_string_variable(name) )
+		{
+			size_t len = strlen(sd->npc_str);
+			set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2));
+			script_pushint(st, (len > max ? 1 : len < min ? -1 : 0));
+		}
 		else
 		else
 		{
 		{
-			sd->npc_amount = cap_value(sd->npc_amount, 0, INT_MAX);
-			set_reg(st,sd,num,name,(void*)sd->npc_amount,script_getref(st,2));
+			int amount = sd->npc_amount;
+			set_reg(st, sd, uid, name, (void*)cap_value(amount,min,max), script_getref(st,2));
+			script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0));
 		}
 		}
 	}
 	}
 	return 0;
 	return 0;

+ 2 - 0
src/map/script.h

@@ -12,6 +12,8 @@ extern struct Script_Config {
 	unsigned warn_func_mismatch_paramnum : 1;
 	unsigned warn_func_mismatch_paramnum : 1;
 	int check_cmdcount;
 	int check_cmdcount;
 	int check_gotocount;
 	int check_gotocount;
+	int input_min_value;
+	int input_max_value;
 
 
 	const char *die_event_name;
 	const char *die_event_name;
 	const char *kill_pc_event_name;
 	const char *kill_pc_event_name;