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.
This commit is contained in:
Lemongrass3110 2016-03-31 22:47:20 +02:00
parent cb87186578
commit b53e00bcc2
9 changed files with 65 additions and 74 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1343,7 +1343,7 @@
1373: %s ÁÕ¤èÒ: %d 1373: %s ÁÕ¤èÒ: %d
1374: %s ÁÕ¤èÒ: %s 1374: %s ÁÕ¤èÒ: %s
1375: %s äÁèÁÕ¤èÒã´æ. 1375: %s äÁèÁÕ¤èÒã´æ.
1376: %s »<><C2BB>א<EFBFBD>·¢י<C2A2><D799><EFBFBD><EFBFBD>ה<EFBFBD>טה´י<C2B4><D799>÷<EFBFBD><C3B7><EFBFBD><EFBFBD>¹<EFBFBD>÷<EFBFBD>¹<EFBFBD>¹: %u //1376: free
// @reloadquestdb // @reloadquestdb
1377: °Ò¹¢éÍÁÙÅ Quest ä´é·Ó¡ÒÃâËÅ´ãËÁèàÃÕºÃéÍÂ. 1377: °Ò¹¢éÍÁÙÅ Quest ä´é·Ó¡ÒÃâËÅ´ãËÁèàÃÕºÃéÍÂ.

View File

@ -9001,14 +9001,23 @@ ACMD_FUNC(accinfo) {
return 0; 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) { ACMD_FUNC(set) {
char reg[32], val[128]; char reg[46], val[128], name[32];
struct script_data* data; int toset = 0, len, index;
int toset = 0, len;
bool is_str = false; 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,1367)); // Usage: @set <variable name> <value>
clif_displaymessage(fd, msg_txt(sd,1368)); // Usage: ex. "@set PoringCharVar 50" 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" clif_displaymessage(fd, msg_txt(sd,1369)); // Usage: ex. "@set PoringCharVarSTR$ Super Duper String"
@ -9025,7 +9034,13 @@ ACMD_FUNC(set) {
return -1; 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( ( len = strlen(val) ) > 1 ) {
if( val[0] == '"' && val[len-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 */ // Only set the variable if there is a value for it
if( is_str ) if( toset >= 2 ){
set_var(sd, reg, (void*) val); setd_sub( NULL, sd, name, index, is_str ? (void*)val : (void*)__64BPRTSIZE((atoi(val))), NULL );
else
set_var(sd, reg, (void*)__64BPRTSIZE((atoi(val))));
} }
CREATE(data, struct script_data,1); uid = reference_uid( add_str( name ), index );
if( is_str ) {// string variable if( is_str ) {// string variable
char* value;
switch( reg[0] ) { switch( reg[0] ) {
case '@': case '@':
data->u.str = pc_readregstr(sd, add_str(reg)); value = pc_readregstr(sd, uid);
break; break;
case '$': case '$':
data->u.str = mapreg_readregstr(add_str(reg)); value = mapreg_readregstr(uid);
break; break;
case '#': case '#':
if( reg[1] == '#' ) if( reg[1] == '#' )
data->u.str = pc_readaccountreg2str(sd, add_str(reg));// global value = pc_readaccountreg2str(sd, uid);// global
else else
data->u.str = pc_readaccountregstr(sd, add_str(reg));// local value = pc_readaccountregstr(sd, uid);// local
break; break;
default: default:
data->u.str = pc_readglobalreg_str(sd, add_str(reg)); value = pc_readglobalreg_str(sd, uid);
break; break;
} }
if( data->u.str == NULL || data->u.str[0] == '\0' ) {// empty string if( value == NULL || value == '\0' ){// empty string
data->type = C_CONSTSTR;
data->u.str = "";
} else {// duplicate string
data->type = C_STR;
data->u.str = aStrdup(data->u.str);
}
} else {// integer variable
data->type = C_INT;
switch( reg[0] ) {
case '@':
data->u.num = pc_readreg(sd, add_str(reg));
break;
case '$':
data->u.num = mapreg_readreg(add_str(reg));
break;
case '#':
if( reg[1] == '#' )
data->u.num = pc_readaccountreg2(sd, add_str(reg));// global
else
data->u.num = pc_readaccountreg(sd, add_str(reg));// local
break;
default:
data->u.num = pc_readglobalreg(sd, add_str(reg));
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 sprintf(atcmd_output,msg_txt(sd,1375),reg); // %s is empty
break; }else{
default: sprintf(atcmd_output,msg_txt(sd,1374),reg,value); // %s value is now :%s
sprintf(atcmd_output,msg_txt(sd,1376),reg,data->type); // %s data type is not supported :%u }
break; } else {// integer variable
int value;
switch( reg[0] ) {
case '@':
value = pc_readreg(sd, uid);
break;
case '$':
value = mapreg_readreg(uid);
break;
case '#':
if( reg[1] == '#' )
value = pc_readaccountreg2(sd, uid);// global
else
value = pc_readaccountreg(sd, uid);// local
break;
default:
value = pc_readglobalreg(sd, uid);
break;
}
sprintf(atcmd_output,msg_txt(sd,1373),reg,value); // %s value is now :%d
} }
clif_displaymessage(fd, atcmd_output); clif_displaymessage(fd, atcmd_output);
if (is_str && data->u.str)
aFree(data->u.str);
aFree(data);
return 0; return 0;
} }
ACMD_FUNC(addperm) { ACMD_FUNC(addperm) {