summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2018-10-07 18:16:51 +0200
committerGitHub <noreply@github.com>2018-10-07 18:16:51 +0200
commit7b5270c5bcc152d2f62e4d17faf8d83085a05866 (patch)
treee2c6d94e11c4f19a96b9beee3f9e676ace4c240a
parent09eb7fe1d0ef64f6a9c21d1c834748ead78440a6 (diff)
parent191a266c155085d467e7c73c5553159b5556fdfc (diff)
downloadhercules-7b5270c5bcc152d2f62e4d17faf8d83085a05866.tar.gz
hercules-7b5270c5bcc152d2f62e4d17faf8d83085a05866.tar.bz2
hercules-7b5270c5bcc152d2f62e4d17faf8d83085a05866.tar.xz
hercules-7b5270c5bcc152d2f62e4d17faf8d83085a05866.zip
Merge pull request #2238 from Helianthella/varofpc
fix setting char/account variables of another player
-rw-r--r--src/map/script.c93
1 files changed, 13 insertions, 80 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 7eb713211..be608830f 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -3316,95 +3316,28 @@ static void set_reg_npcscope_str(struct script_state *st, struct reg_db *n, int6
static void set_reg_pc_ref_str(struct script_state *st, struct reg_db *n, int64 num, const char *name, const char *str)
{
- struct script_reg_str *p = NULL;
- unsigned int index = script_getvaridx(num);
-
- nullpo_retv(n);
+ struct DBIterator *iter = db_iterator(map->pc_db);
- if ((p = i64db_get(n->vars, num)) != NULL) {
- if (str[0]) {
- if (p->value) {
- aFree(p->value);
- } else if (index) {
- script->array_update(n, num, false);
- }
- p->value = aStrdup(str);
- } else {
- p->value = NULL;
- if (index) {
- script->array_update(n, num, true);
- }
- }
-
- if (!pc->reg_load) {
- p->flag.update = 1;
- }
- } else if (str[0]) {
- struct DBData prev;
- if (index) {
- script->array_update(n, num, false);
- }
-
- p = ers_alloc(pc->str_reg_ers, struct script_reg_str);
- p->value = aStrdup(str);
-
- if (!pc->reg_load) {
- p->flag.update = 1;
- }
- p->flag.type = 1;
-
- if(n->vars->put(n->vars, DB->i642key(num), DB->ptr2data(p), &prev)) {
- p = DB->data2ptr(&prev);
- if (p->value) {
- aFree(p->value);
- }
- ers_free(pc->str_reg_ers, p);
+ for (struct map_session_data *sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) {
+ if (sd != NULL && n == &sd->regs) {
+ pc->setregistry_str(sd, num, str);
+ break;
}
}
+ dbi_destroy(iter);
}
static void set_reg_pc_ref_num(struct script_state *st, struct reg_db *n, int64 num, const char *name, int val)
{
- struct script_reg_num *p = NULL;
- unsigned int index = script_getvaridx(num);
+ struct DBIterator *iter = db_iterator(map->pc_db);
- nullpo_retv(n);
-
- if ((p = i64db_get(n->vars, num)) != NULL) {
- if (val) {
- if (!p->value && index) {
- script->array_update(n, num, false);
- }
- p->value = val;
- } else {
- p->value = 0;
- if (index) {
- script->array_update(n, num, true);
- }
- }
-
- if (!pc->reg_load) {
- p->flag.update = 1;
- }
- } else if (val) {
- struct DBData prev;
- if (index) {
- script->array_update(n, num, false);
- }
-
- p = ers_alloc(pc->num_reg_ers, struct script_reg_num);
- p->value = val;
-
- if (!pc->reg_load) {
- p->flag.update = 1;
- }
- p->flag.type = 1;
-
- if(n->vars->put(n->vars, DB->i642key(num), DB->ptr2data(p), &prev)) {
- p = DB->data2ptr(&prev);
- ers_free(pc->num_reg_ers, p);
+ for (struct map_session_data *sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) {
+ if (sd != NULL && n == &sd->regs) {
+ pc->setregistry(sd, num, val);
+ break;
}
}
+ dbi_destroy(iter);
}
static void set_reg_npcscope_num(struct script_state *st, struct reg_db *n, int64 num, const char *name, int val)
@@ -20742,7 +20675,7 @@ static BUILDIN(getvariableofpc)
}
if (!sd->regs.vars)
- sd->regs.vars = i64db_alloc(DB_OPT_RELEASE_DATA);
+ sd->regs.vars = i64db_alloc(DB_OPT_BASE);
script->push_val(st->stack, C_NAME, reference_getuid(data), &sd->regs);
return true;