Skip to content

Commit

Permalink
Dismemberment of storage_data from mmo_charstatus.
Browse files Browse the repository at this point in the history
Add `storage_data` reception, parsing and sending from the map-server.
Remove loading and saving of `storage_data` through char.c
Re-declaration of structure storage_data using an item vector.
Re-code of portions in the map-server using `storage_data`.
A new approach is taken by saving the loaded storage data from sql into memory for the duration of the session, thereby removing the need of querying the database to re-load all items everytime a storage save routine is issued from the map-server.
Saving of storage items is done through a new function that significantly reduces the number of queries compared to `char_memitemdata_tosql()`, and therefore run-time speed. This method could potentially reduce the number of delete queries from `MAX_STORAGE` (which could be 600) times to literally `1`.
  • Loading branch information
sagunkho committed Apr 28, 2017
1 parent 109661e commit 2e06aab
Show file tree
Hide file tree
Showing 17 changed files with 638 additions and 156 deletions.
20 changes: 7 additions & 13 deletions src/char/char.c
Expand Up @@ -287,11 +287,17 @@ 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 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);
}
Expand Down Expand Up @@ -442,14 +448,6 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p)
errors++;
}

//map storage data
if( memcmp(p->storage.items, cp->storage.items, sizeof(p->storage.items)) ) {
if (!chr->memitemdata_to_sql(p->storage.items, MAX_STORAGE, p->account_id, TABLE_STORAGE))
strcat(save_status, " storage");
else
errors++;
}

if (
(p->base_exp != cp->base_exp) || (p->base_level != cp->base_level) ||
(p->job_level != cp->job_level) || (p->job_exp != cp->job_exp) ||
Expand Down Expand Up @@ -1284,10 +1282,6 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every

strcat(t_msg, " cart");

//read storage
inter_storage->fromsql(p->account_id, &p->storage);
strcat(t_msg, " storage");

//read skill
//`skill` (`char_id`, `id`, `lv`)
memset(&tmp_skill, 0, sizeof(tmp_skill));
Expand Down

0 comments on commit 2e06aab

Please sign in to comment.