summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c4
-rw-r--r--src/char/int_storage.c92
-rw-r--r--src/char/int_storage.h8
-rw-r--r--src/map/storage.c4
-rw-r--r--src/plugins/HPMHooking/HPMHooking.Defs.inc8
-rw-r--r--src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc8
-rw-r--r--src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc2
-rw-r--r--src/plugins/HPMHooking/HPMHooking_char.Hooks.inc78
8 files changed, 39 insertions, 165 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 487bec763..f6556073e 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -288,16 +288,12 @@ void char_set_char_offline(int char_id, int account_id)
else
{
struct mmo_charstatus* cp = (struct mmo_charstatus*) idb_get(chr->char_db_,char_id);
- struct storage_data *stor = (struct storage_data *) idb_get(inter_storage->account_storage, account_id);
inter_guild->CharOffline(char_id, cp?cp->guild_id:-1);
if (cp)
idb_remove(chr->char_db_,char_id);
- if (stor) /* Remove inter-storage data. */
- idb_remove(inter_storage->account_storage, account_id);
-
if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `online`='0' WHERE `char_id`='%d' LIMIT 1", char_db, char_id) )
Sql_ShowDebug(inter->sql_handle);
}
diff --git a/src/char/int_storage.c b/src/char/int_storage.c
index 5f005005e..65301127f 100644
--- a/src/char/int_storage.c
+++ b/src/char/int_storage.c
@@ -41,31 +41,33 @@ struct inter_storage_interface inter_storage_s;
struct inter_storage_interface *inter_storage;
/// Save storage data to sql
-int inter_storage_tosql(int account_id, struct storage_data *cp, const struct storage_data *p)
+int inter_storage_tosql(int account_id, const struct storage_data *p)
{
int i = 0, j = 0;
- bool updated_p[MAX_STORAGE] = { false };
+ bool matched_p[MAX_STORAGE] = { false };
int delete[MAX_STORAGE] = { 0 };
int total_deletes = 0, total_updates = 0, total_inserts = 0;
int total_changes = 0;
+ struct storage_data cp = { 0 };
StringBuf buf;
- nullpo_ret(cp);
nullpo_ret(p);
+ VECTOR_INIT(cp.item);
+ inter_storage->fromsql(account_id, &cp);
+
StrBuf->Init(&buf);
-
- if (VECTOR_LENGTH(cp->item) > 0) {
+ if (VECTOR_LENGTH(cp.item) > 0) {
/**
* Compare and update items, if any.
*/
- for (i = 0; i < VECTOR_LENGTH(cp->item); i++) {
- struct item *cp_it = &VECTOR_INDEX(cp->item, i);
+ for (i = 0; i < VECTOR_LENGTH(cp.item); i++) {
+ struct item *cp_it = &VECTOR_INDEX(cp.item, i);
struct item *p_it = NULL;
ARR_FIND(0, VECTOR_LENGTH(p->item), j,
- updated_p[j] != true
+ matched_p[j] != true
&& (p_it = &VECTOR_INDEX(p->item, j)) != NULL
&& cp_it->nameid == p_it->nameid
&& cp_it->unique_id == p_it->unique_id
@@ -84,17 +86,17 @@ int inter_storage_tosql(int account_id, struct storage_data *cp, const struct st
StrBuf->AppendStr(&buf, ", `expire_time`, `bound`, `unique_id`) VALUES");
}
- StrBuf->Printf(&buf, "('%d', '%d', '%d', '%d', '%u', '%d', '%d', '%d'",
- cp_it->id, account_id, p_it->nameid, p_it->amount, p_it->equip, p_it->identify, p_it->refine, p_it->attribute);
+ StrBuf->Printf(&buf, "%s('%d', '%d', '%d', '%d', '%u', '%d', '%d', '%d'",
+ total_updates > 0 ? ", " : "", cp_it->id, account_id, p_it->nameid, p_it->amount, p_it->equip, p_it->identify, p_it->refine, p_it->attribute);
for (k = 0; k < MAX_SLOTS; k++)
StrBuf->Printf(&buf, ", '%d'", p_it->card[k]);
for (k = 0; k < MAX_ITEM_OPTIONS; ++k)
StrBuf->Printf(&buf, ", '%d', '%d'", p_it->option[k].index, p_it->option[k].value);
- StrBuf->Printf(&buf, ", '%u', '%d', '%"PRIu64"')%s", p_it->expire_time, p_it->bound, p_it->unique_id, total_updates > 0 ? ", " : "");
+ StrBuf->Printf(&buf, ", '%u', '%d', '%"PRIu64"')", p_it->expire_time, p_it->bound, p_it->unique_id);
total_updates++;
- updated_p[j] = true;
}
+ matched_p[j] = true;
} else { // Does not exist, so set for deletion.
delete[total_deletes++] = cp_it->id;
}
@@ -125,7 +127,7 @@ int inter_storage_tosql(int account_id, struct storage_data *cp, const struct st
for (i = 0; i < VECTOR_LENGTH(p->item); i++) {
struct item *p_it = &VECTOR_INDEX(p->item, i);
- if (p_it->id != 0)
+ if (matched_p[i])
continue; // Item is not a new entry, so lets continue.
// Store the remaining items.
@@ -140,8 +142,8 @@ int inter_storage_tosql(int account_id, struct storage_data *cp, const struct st
}
StrBuf->Printf(&buf, "%s('%d', '%d', '%d', '%u', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'",
- total_inserts > 0 ? ", " : "", account_id, p_it->nameid, p_it->amount, p_it->equip, p_it->identify, p_it->refine,
- p_it->attribute, p_it->expire_time, p_it->bound, p_it->unique_id);
+ total_inserts > 0 ? ", " : "", account_id, p_it->nameid, p_it->amount, p_it->equip, p_it->identify, p_it->refine,
+ p_it->attribute, p_it->expire_time, p_it->bound, p_it->unique_id);
for (j = 0; j < MAX_SLOTS; ++j)
StrBuf->Printf(&buf, ", '%d'", p_it->card[j]);
for (j = 0; j < MAX_ITEM_OPTIONS; ++j)
@@ -155,15 +157,10 @@ int inter_storage_tosql(int account_id, struct storage_data *cp, const struct st
Sql_ShowDebug(inter->sql_handle);
StrBuf->Destroy(&buf);
-
- /* re-sync loaded data with current table data. */
- VECTOR_CLEAR(cp->item);
- inter_storage->fromsql(account_id, cp);
+ VECTOR_CLEAR(cp.item);
total_changes = total_inserts + total_updates + total_deletes;
-
ShowInfo("storage save complete - id: %d (total: %d)\n", account_id, total_changes);
-
return total_changes;
}
@@ -305,49 +302,15 @@ int inter_storage_guild_storage_fromsql(int guild_id, struct guild_storage* p)
return 0;
}
-/**
- * Ensures storage data entity for a character.
- * @see DBCreateData
- */
-static struct DBData inter_storage_ensure_account_storage(union DBKey key, va_list args)
-{
- struct storage_data *stor = NULL;
-
- CREATE(stor, struct storage_data, 1);
-
- stor->save = false;
- stor->aggregate = 0;
-
- VECTOR_INIT(stor->item);
-
- return DB->ptr2data(stor);
-}
-
-/**
- * Cleaning function called through db_destroy() for vectors in storage_data.
- */
-int inter_storage_clear_account_storage(union DBKey key, struct DBData *data, va_list args)
-{
- struct storage_data *stor = DB->data2ptr(data);
-
- VECTOR_CLEAR(stor->item);
-
- return 0;
-}
-
//---------------------------------------------------------
// storage data initialize
int inter_storage_sql_init(void)
{
- inter_storage->account_storage = idb_alloc(DB_OPT_RELEASE_DATA);
-
return 1;
}
// storage data finalize
void inter_storage_sql_final(void)
{
- inter_storage->account_storage->destroy(inter_storage->account_storage, inter_storage->clear_account_storage);
-
return;
}
@@ -435,14 +398,13 @@ int mapif_parse_AccountStorageLoad(int fd)
*/
int mapif_account_storage_load(int fd, int account_id)
{
- struct storage_data *stor = NULL;
+ struct storage_data stor = { 0 };
int count = 0, i = 0, len = 0;
Assert_ret(account_id > 0);
- stor = (struct storage_data *) idb_ensure(inter_storage->account_storage, account_id, inter_storage->ensure_account_storage);
-
- count = inter_storage->fromsql(account_id, stor);
+ VECTOR_INIT(stor.item);
+ count = inter_storage->fromsql(account_id, &stor);
len = 8 + count * sizeof(struct item);
@@ -451,9 +413,11 @@ int mapif_account_storage_load(int fd, int account_id)
WFIFOW(fd, 2) = (uint16) len;
WFIFOL(fd, 4) = account_id;
for (i = 0; i < count; i++)
- memcpy(WFIFOP(fd, 8 + i * sizeof(struct item)), &VECTOR_INDEX(stor->item, i), sizeof(struct item));
+ memcpy(WFIFOP(fd, 8 + i * sizeof(struct item)), &VECTOR_INDEX(stor.item, i), sizeof(struct item));
WFIFOSET(fd, len);
+ VECTOR_CLEAR(stor.item);
+
return 1;
}
@@ -467,13 +431,11 @@ int mapif_parse_AccountStorageSave(int fd)
{
int payload_size = RFIFOW(fd, 2) - 8, account_id = RFIFOL(fd, 4);
int i = 0, count = 0;
- struct storage_data *cp_stor = NULL, p_stor = { 0 };
+ struct storage_data p_stor = { 0 };
Assert_ret(fd > 0);
Assert_ret(account_id > 0);
- cp_stor = (struct storage_data *) idb_ensure(inter_storage->account_storage, account_id, inter_storage->ensure_account_storage);
-
count = payload_size/sizeof(struct item);
VECTOR_INIT(p_stor.item);
@@ -490,7 +452,7 @@ int mapif_parse_AccountStorageSave(int fd)
p_stor.aggregate = count;
}
- inter_storage->tosql(account_id, cp_stor, &p_stor);
+ inter_storage->tosql(account_id, &p_stor);
VECTOR_CLEAR(p_stor.item);
@@ -783,8 +745,6 @@ void inter_storage_defaults(void)
{
inter_storage = &inter_storage_s;
- inter_storage->ensure_account_storage = inter_storage_ensure_account_storage;
- inter_storage->clear_account_storage = inter_storage_clear_account_storage;
inter_storage->tosql = inter_storage_tosql;
inter_storage->fromsql = inter_storage_fromsql;
inter_storage->guild_storage_tosql = inter_storage_guild_storage_tosql;
diff --git a/src/char/int_storage.h b/src/char/int_storage.h
index 1f6c03f13..46bb6910f 100644
--- a/src/char/int_storage.h
+++ b/src/char/int_storage.h
@@ -31,13 +31,7 @@ struct guild_storage;
* inter_storage interface
**/
struct inter_storage_interface {
- /* */
- struct DBMap *account_storage;
- /* */
- /* */
- struct DBData (*ensure_account_storage) (union DBKey key, va_list args);
- int (*clear_account_storage) (union DBKey key, struct DBData *data, va_list args);
- int (*tosql) (int account_id, struct storage_data *cp, const struct storage_data *p);
+ int (*tosql) (int account_id, const struct storage_data *p);
int (*fromsql) (int account_id, struct storage_data *p);
int (*guild_storage_tosql) (int guild_id, const struct guild_storage *p);
int (*guild_storage_fromsql) (int guild_id, struct guild_storage* p);
diff --git a/src/map/storage.c b/src/map/storage.c
index 4aefaae96..01e7c7c27 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -200,6 +200,8 @@ int storage_additem(struct map_session_data* sd, struct item* item_data, int amo
clif->storageitemadded(sd, it, i, amount);
+ sd->storage.save = true; // set a save flag.
+
return 0;
}
}
@@ -220,6 +222,8 @@ int storage_additem(struct map_session_data* sd, struct item* item_data, int amo
*it = *item_data;
}
+ it->amount = amount;
+
sd->storage.aggregate++;
clif->storageitemadded(sd, it, i, amount);
diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc
index 65c7f23b1..1a2e7a2d5 100644
--- a/src/plugins/HPMHooking/HPMHooking.Defs.inc
+++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc
@@ -2962,12 +2962,8 @@ typedef int (*HPMHOOK_pre_inter_quest_parse_frommap) (int *fd);
typedef int (*HPMHOOK_post_inter_quest_parse_frommap) (int retVal___, int fd);
#endif // CHAR_INT_QUEST_H
#ifdef CHAR_INT_STORAGE_H /* inter_storage */
-typedef struct DBData (*HPMHOOK_pre_inter_storage_ensure_account_storage) (union DBKey *key, va_list args);
-typedef struct DBData (*HPMHOOK_post_inter_storage_ensure_account_storage) (struct DBData retVal___, union DBKey key, va_list args);
-typedef int (*HPMHOOK_pre_inter_storage_clear_account_storage) (union DBKey *key, struct DBData **data, va_list args);
-typedef int (*HPMHOOK_post_inter_storage_clear_account_storage) (int retVal___, union DBKey key, struct DBData *data, va_list args);
-typedef int (*HPMHOOK_pre_inter_storage_tosql) (int *account_id, struct storage_data **cp, const struct storage_data **p);
-typedef int (*HPMHOOK_post_inter_storage_tosql) (int retVal___, int account_id, struct storage_data *cp, const struct storage_data *p);
+typedef int (*HPMHOOK_pre_inter_storage_tosql) (int *account_id, const struct storage_data **p);
+typedef int (*HPMHOOK_post_inter_storage_tosql) (int retVal___, int account_id, const struct storage_data *p);
typedef int (*HPMHOOK_pre_inter_storage_fromsql) (int *account_id, struct storage_data **p);
typedef int (*HPMHOOK_post_inter_storage_fromsql) (int retVal___, int account_id, struct storage_data *p);
typedef int (*HPMHOOK_pre_inter_storage_guild_storage_tosql) (int *guild_id, const struct guild_storage **p);
diff --git a/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc
index 5e449a4d1..21e136c2f 100644
--- a/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc
+++ b/src/plugins/HPMHooking/HPMHooking_char.HPMHooksCore.inc
@@ -624,10 +624,6 @@ struct {
struct HPMHookPoint *HP_inter_pet_parse_frommap_post;
struct HPMHookPoint *HP_inter_quest_parse_frommap_pre;
struct HPMHookPoint *HP_inter_quest_parse_frommap_post;
- struct HPMHookPoint *HP_inter_storage_ensure_account_storage_pre;
- struct HPMHookPoint *HP_inter_storage_ensure_account_storage_post;
- struct HPMHookPoint *HP_inter_storage_clear_account_storage_pre;
- struct HPMHookPoint *HP_inter_storage_clear_account_storage_post;
struct HPMHookPoint *HP_inter_storage_tosql_pre;
struct HPMHookPoint *HP_inter_storage_tosql_post;
struct HPMHookPoint *HP_inter_storage_fromsql_pre;
@@ -2113,10 +2109,6 @@ struct {
int HP_inter_pet_parse_frommap_post;
int HP_inter_quest_parse_frommap_pre;
int HP_inter_quest_parse_frommap_post;
- int HP_inter_storage_ensure_account_storage_pre;
- int HP_inter_storage_ensure_account_storage_post;
- int HP_inter_storage_clear_account_storage_pre;
- int HP_inter_storage_clear_account_storage_post;
int HP_inter_storage_tosql_pre;
int HP_inter_storage_tosql_post;
int HP_inter_storage_fromsql_pre;
diff --git a/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc
index 9b07bdccd..639cdbdd2 100644
--- a/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc
+++ b/src/plugins/HPMHooking/HPMHooking_char.HookingPoints.inc
@@ -344,8 +344,6 @@ struct HookingPointData HookingPoints[] = {
/* inter_quest_interface */
{ HP_POP(inter_quest->parse_frommap, HP_inter_quest_parse_frommap) },
/* inter_storage_interface */
- { HP_POP(inter_storage->ensure_account_storage, HP_inter_storage_ensure_account_storage) },
- { HP_POP(inter_storage->clear_account_storage, HP_inter_storage_clear_account_storage) },
{ HP_POP(inter_storage->tosql, HP_inter_storage_tosql) },
{ HP_POP(inter_storage->fromsql, HP_inter_storage_fromsql) },
{ HP_POP(inter_storage->guild_storage_tosql, HP_inter_storage_guild_storage_tosql) },
diff --git a/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc
index 656fd8e07..96e068903 100644
--- a/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_char.Hooks.inc
@@ -8032,81 +8032,15 @@ int HP_inter_quest_parse_frommap(int fd) {
return retVal___;
}
/* inter_storage_interface */
-struct DBData HP_inter_storage_ensure_account_storage(union DBKey key, va_list args) {
- int hIndex = 0;
- struct DBData retVal___ = { 0 };
- if (HPMHooks.count.HP_inter_storage_ensure_account_storage_pre > 0) {
- struct DBData (*preHookFunc) (union DBKey *key, va_list args);
- *HPMforce_return = false;
- for (hIndex = 0; hIndex < HPMHooks.count.HP_inter_storage_ensure_account_storage_pre; hIndex++) {
- va_list args___copy; va_copy(args___copy, args);
- preHookFunc = HPMHooks.list.HP_inter_storage_ensure_account_storage_pre[hIndex].func;
- retVal___ = preHookFunc(&key, args___copy);
- va_end(args___copy);
- }
- if (*HPMforce_return) {
- *HPMforce_return = false;
- return retVal___;
- }
- }
- {
- va_list args___copy; va_copy(args___copy, args);
- retVal___ = HPMHooks.source.inter_storage.ensure_account_storage(key, args___copy);
- va_end(args___copy);
- }
- if (HPMHooks.count.HP_inter_storage_ensure_account_storage_post > 0) {
- struct DBData (*postHookFunc) (struct DBData retVal___, union DBKey key, va_list args);
- for (hIndex = 0; hIndex < HPMHooks.count.HP_inter_storage_ensure_account_storage_post; hIndex++) {
- va_list args___copy; va_copy(args___copy, args);
- postHookFunc = HPMHooks.list.HP_inter_storage_ensure_account_storage_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, key, args___copy);
- va_end(args___copy);
- }
- }
- return retVal___;
-}
-int HP_inter_storage_clear_account_storage(union DBKey key, struct DBData *data, va_list args) {
- int hIndex = 0;
- int retVal___ = 0;
- if (HPMHooks.count.HP_inter_storage_clear_account_storage_pre > 0) {
- int (*preHookFunc) (union DBKey *key, struct DBData **data, va_list args);
- *HPMforce_return = false;
- for (hIndex = 0; hIndex < HPMHooks.count.HP_inter_storage_clear_account_storage_pre; hIndex++) {
- va_list args___copy; va_copy(args___copy, args);
- preHookFunc = HPMHooks.list.HP_inter_storage_clear_account_storage_pre[hIndex].func;
- retVal___ = preHookFunc(&key, &data, args___copy);
- va_end(args___copy);
- }
- if (*HPMforce_return) {
- *HPMforce_return = false;
- return retVal___;
- }
- }
- {
- va_list args___copy; va_copy(args___copy, args);
- retVal___ = HPMHooks.source.inter_storage.clear_account_storage(key, data, args___copy);
- va_end(args___copy);
- }
- if (HPMHooks.count.HP_inter_storage_clear_account_storage_post > 0) {
- int (*postHookFunc) (int retVal___, union DBKey key, struct DBData *data, va_list args);
- for (hIndex = 0; hIndex < HPMHooks.count.HP_inter_storage_clear_account_storage_post; hIndex++) {
- va_list args___copy; va_copy(args___copy, args);
- postHookFunc = HPMHooks.list.HP_inter_storage_clear_account_storage_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, key, data, args___copy);
- va_end(args___copy);
- }
- }
- return retVal___;
-}
-int HP_inter_storage_tosql(int account_id, struct storage_data *cp, const struct storage_data *p) {
+int HP_inter_storage_tosql(int account_id, const struct storage_data *p) {
int hIndex = 0;
int retVal___ = 0;
if (HPMHooks.count.HP_inter_storage_tosql_pre > 0) {
- int (*preHookFunc) (int *account_id, struct storage_data **cp, const struct storage_data **p);
+ int (*preHookFunc) (int *account_id, const struct storage_data **p);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_inter_storage_tosql_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_inter_storage_tosql_pre[hIndex].func;
- retVal___ = preHookFunc(&account_id, &cp, &p);
+ retVal___ = preHookFunc(&account_id, &p);
}
if (*HPMforce_return) {
*HPMforce_return = false;
@@ -8114,13 +8048,13 @@ int HP_inter_storage_tosql(int account_id, struct storage_data *cp, const struct
}
}
{
- retVal___ = HPMHooks.source.inter_storage.tosql(account_id, cp, p);
+ retVal___ = HPMHooks.source.inter_storage.tosql(account_id, p);
}
if (HPMHooks.count.HP_inter_storage_tosql_post > 0) {
- int (*postHookFunc) (int retVal___, int account_id, struct storage_data *cp, const struct storage_data *p);
+ int (*postHookFunc) (int retVal___, int account_id, const struct storage_data *p);
for (hIndex = 0; hIndex < HPMHooks.count.HP_inter_storage_tosql_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_inter_storage_tosql_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, account_id, cp, p);
+ retVal___ = postHookFunc(retVal___, account_id, p);
}
}
return retVal___;