Selaa lähdekoodia

Added support for arrays to atcommand set

Removed allocation and freeing of an unneeded script data structure.
Additionally removed a message that could never be shown.
Lemongrass3110 9 vuotta sitten
vanhempi
commit
b53e00bcc2

+ 1 - 1
conf/msg_conf/map_msg.conf

@@ -1458,7 +1458,7 @@
 1373: %s value is now: %d
 1374: %s value is now: %s
 1375: %s is blank.
-1376: %s data type is not supported: %u
+//1376: free
 
 // @reloadquestdb
 1377: Quest database has been reloaded.

+ 1 - 1
conf/msg_conf/map_msg_chn.conf

@@ -1337,7 +1337,7 @@
 1373: %s value is now :%d
 1374: %s value is now :%s
 1375: %s is empty
-1376: %s data type is not supported :%u
+//1376: free
 
 // @reloadquestdb
 1377: 完成重載任睥數據庫.

+ 1 - 1
conf/msg_conf/map_msg_frn.conf

@@ -1350,7 +1350,7 @@
 1373: %s valeur est maintenant :%d
 1374: %s valeur est maintenant :%s
 1375: %s est vide
-1376: Le type de donnée %s n'est pas supportée :%u
+//1376: free
 
 // @reloadquestdb
 1377: Base de données des Quêtes rechargée.

+ 1 - 1
conf/msg_conf/map_msg_idn.conf

@@ -1438,7 +1438,7 @@
 1373: Nilai %s saat ini: %d
 1374: Nilai %s saat ini: %s
 1375: %s kosong
-1376: Jenis data %s tidak didukung: %u
+//1376: free
 
 // @reloadquestdb
 1377: Database Quest sudah dimuat ulang.

+ 1 - 1
conf/msg_conf/map_msg_por.conf

@@ -1331,7 +1331,7 @@
 1373: %s valor agora é :%d
 1374: %s valor agora é :%s
 1375: %s é vazia
-1376: %s tipo de dado não é suportado :%u
+//1376: free
 
 // @reloadquestdb
 1377: Banco de dados de quest recarregado.

+ 1 - 1
conf/msg_conf/map_msg_rus.conf

@@ -1350,7 +1350,7 @@
 1373: %s значение :%d
 1374: %s значение :%s
 1375: %s пусто
-1376: %s данные не поддерживаются :%u
+//1376: free
 
 // @reloadquestdb
 1377: База данных квестов перезагружена.

+ 1 - 1
conf/msg_conf/map_msg_spn.conf

@@ -1336,7 +1336,7 @@
 1373: El valor %s ahora es:%d
 1374: El valor %s ahora es :%s
 1375: %s está vacío
-1376: %s data type is not supported :%u
+//1376: free
 
 // @reloadquestdb
 1377: Se ha actualizado la base de datos de las quest con éxito.

+ 1 - 1
conf/msg_conf/map_msg_tha.conf

@@ -1343,7 +1343,7 @@
 1373: %s ÁÕ¤èÒ: %d
 1374: %s ÁÕ¤èÒ: %s
 1375: %s äÁèÁÕ¤èÒã´æ.
-1376: %s »ÃÐàÀ·¢éÍÁÙÅäÁèä´éÃѺ¡ÒÃʹѺʹع: %u
+//1376: free
 
 // @reloadquestdb
 1377: °Ò¹¢éÍÁÙÅ Quest ä´é·Ó¡ÒÃâËÅ´ãËÁèàÃÕºÃéÍÂ.

+ 42 - 51
src/map/atcommand.c

@@ -9001,14 +9001,23 @@ ACMD_FUNC(accinfo) {
 	return 0;
 }
 
-/* [Ind] */
+/**
+ * @set <variable name{[index]}>{ <value>}
+ * 
+ * Gets or sets a value of a non server variable.
+ * If a value is specified it is used to set the variable's value,
+ * if not the variable's value is read.
+ * In any case it reads and displays the variable's value.
+ *
+ * Original implementation by Ind
+*/
 ACMD_FUNC(set) {
-	char reg[32], val[128];
-	struct script_data* data;
-	int toset = 0, len;
+	char reg[46], val[128], name[32];
+	int toset = 0, len, index;
 	bool is_str = false;
+	int64 uid;
 
-	if( !message || !*message || (toset = sscanf(message, "%31s %127[^\n]s", reg, val)) < 1  ) {
+	if( !message || !*message || (toset = sscanf(message, "%45s %127[^\n]s", reg, val)) < 1  ) {
 		clif_displaymessage(fd, msg_txt(sd,1367)); // Usage: @set <variable name> <value>
 		clif_displaymessage(fd, msg_txt(sd,1368)); // Usage: ex. "@set PoringCharVar 50"
 		clif_displaymessage(fd, msg_txt(sd,1369)); // Usage: ex. "@set PoringCharVarSTR$ Super Duper String"
@@ -9025,7 +9034,13 @@ ACMD_FUNC(set) {
 		return -1;
 	}
 
-	is_str = ( reg[strlen(reg) - 1] == '$' );
+	// Check if the user wanted to set an array
+	if( sscanf( reg, "%31[^[][%11d]", name, &index ) < 2 ){
+		// The user did not specify array brackets, so we set the index to zero
+		index = 0;
+	}
+
+	is_str = is_string_variable(name);
 
 	if( ( len = strlen(val) ) > 1 ) {
 		if( val[0] == '"' && val[len-1] == '"') {
@@ -9034,89 +9049,65 @@ ACMD_FUNC(set) {
 		}
 	}
 
-	if( toset >= 2 ) {/* we only set the var if there is an val, otherwise we only output the value */
-		if( is_str )
-			set_var(sd, reg, (void*) val);
-		else
-			set_var(sd, reg, (void*)__64BPRTSIZE((atoi(val))));
-
+	// Only set the variable if there is a value for it
+	if( toset >= 2 ){
+		setd_sub( NULL, sd, name, index, is_str ? (void*)val : (void*)__64BPRTSIZE((atoi(val))), NULL );
 	}
 
-	CREATE(data, struct script_data,1);
-
+	uid = reference_uid( add_str( name ), index );
 
 	if( is_str ) {// string variable
+		char* value;
 
 		switch( reg[0] ) {
 			case '@':
-				data->u.str = pc_readregstr(sd, add_str(reg));
+				value = pc_readregstr(sd, uid);
 				break;
 			case '$':
-				data->u.str = mapreg_readregstr(add_str(reg));
+				value = mapreg_readregstr(uid);
 				break;
 			case '#':
 				if( reg[1] == '#' )
-					data->u.str = pc_readaccountreg2str(sd, add_str(reg));// global
+					value = pc_readaccountreg2str(sd, uid);// global
 				else
-					data->u.str = pc_readaccountregstr(sd, add_str(reg));// local
+					value = pc_readaccountregstr(sd, uid);// local
 				break;
 			default:
-				data->u.str = pc_readglobalreg_str(sd, add_str(reg));
+				value = pc_readglobalreg_str(sd, uid);
 				break;
 		}
 
-		if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string
-			data->type = C_CONSTSTR;
-			data->u.str = "";
-		} else {// duplicate string
-			data->type = C_STR;
-			data->u.str = aStrdup(data->u.str);
+		if( value == NULL || value == '\0' ){// empty string
+			sprintf(atcmd_output,msg_txt(sd,1375),reg); // %s is empty
+		}else{
+			sprintf(atcmd_output,msg_txt(sd,1374),reg,value); // %s value is now :%s
 		}
-
 	} else {// integer variable
+		int value;
 
-		data->type = C_INT;
 		switch( reg[0] ) {
 			case '@':
-				data->u.num = pc_readreg(sd, add_str(reg));
+				value = pc_readreg(sd, uid);
 				break;
 			case '$':
-				data->u.num = mapreg_readreg(add_str(reg));
+				value = mapreg_readreg(uid);
 				break;
 			case '#':
 				if( reg[1] == '#' )
-					data->u.num = pc_readaccountreg2(sd, add_str(reg));// global
+					value = pc_readaccountreg2(sd, uid);// global
 				else
-					data->u.num = pc_readaccountreg(sd, add_str(reg));// local
+					value = pc_readaccountreg(sd, uid);// local
 				break;
 			default:
-				data->u.num = pc_readglobalreg(sd, add_str(reg));
+				value = pc_readglobalreg(sd, uid);
 				break;
 		}
 
-	}
-
-	switch( data->type ) {
-		case C_INT:
-			sprintf(atcmd_output,msg_txt(sd,1373),reg,data->u.num); // %s value is now :%d
-			break;
-		case C_STR:
-			sprintf(atcmd_output,msg_txt(sd,1374),reg,data->u.str); // %s value is now :%s
-			break;
-		case C_CONSTSTR:
-			sprintf(atcmd_output,msg_txt(sd,1375),reg); // %s is empty
-			break;
-		default:
-			sprintf(atcmd_output,msg_txt(sd,1376),reg,data->type); // %s data type is not supported :%u
-			break;
+		sprintf(atcmd_output,msg_txt(sd,1373),reg,value); // %s value is now :%d
 	}
 
 	clif_displaymessage(fd, atcmd_output);
 
-	if (is_str && data->u.str)
-		aFree(data->u.str);
-	aFree(data);
-
 	return 0;
 }
 ACMD_FUNC(addperm) {