summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-07-13 16:14:32 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-07-13 16:14:32 +0000
commitfb45ace1b19f98add7e1d0a0fc6fe45bc1ebac63 (patch)
tree52b66f102c20e6b47e060efe0e7ceabd36d5aa29 /src/map
parent2e7ba13554118cdc78c9bfa5a6f0e5e8e58baf7b (diff)
downloadhercules-fb45ace1b19f98add7e1d0a0fc6fe45bc1ebac63.tar.gz
hercules-fb45ace1b19f98add7e1d0a0fc6fe45bc1ebac63.tar.bz2
hercules-fb45ace1b19f98add7e1d0a0fc6fe45bc1ebac63.tar.xz
hercules-fb45ace1b19f98add7e1d0a0fc6fe45bc1ebac63.zip
Modified storage data loading
* storage is now loaded/saved along with character status * as a consequence, a lot of storage handling code was removed * there is no more locking done within storage data * mapservers no longer cache the data (solves muiltimapserver exploit) * loading storage on char select may decrease charserver performance git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12950 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r--src/map/atcommand.c17
-rw-r--r--src/map/charcommand.c110
-rw-r--r--src/map/chrif.c8
-rw-r--r--src/map/clif.c7
-rw-r--r--src/map/intif.c77
-rw-r--r--src/map/intif.h2
-rw-r--r--src/map/storage.c240
-rw-r--r--src/map/storage.h9
8 files changed, 114 insertions, 356 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index b47665bf5..3db3bb9f8 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -1155,7 +1155,6 @@ int atcommand_storage(const int fd, struct map_session_data* sd, const char* com
*------------------------------------------*/
int atcommand_guildstorage(const int fd, struct map_session_data* sd, const char* command, const char* message)
{
- struct storage_data *stor; //changes from Freya/Yor
nullpo_retr(-1, sd);
if (!sd->status.guild_id) {
@@ -1163,18 +1162,19 @@ int atcommand_guildstorage(const int fd, struct map_session_data* sd, const char
return -1;
}
- if (sd->npc_id || sd->vender_id || sd->state.trading || sd->state.storage_flag)
+ if (sd->npc_id || sd->vender_id || sd->state.trading)
return -1;
- if (sd->state.storage_flag) {
- clif_displaymessage(fd, msg_txt(251));
+ if (sd->state.storage_flag == 1) {
+ clif_displaymessage(fd, msg_txt(250));
return -1;
}
- if ((stor = account2storage2(sd->status.account_id)) != NULL && stor->storage_status == 1) {
+ if (sd->state.storage_flag == 2) {
clif_displaymessage(fd, msg_txt(251));
return -1;
}
+
storage_guild_storageopen(sd);
clif_displaymessage(fd, "Guild storage opened.");
return 0;
@@ -5547,15 +5547,12 @@ int atcommand_storeall(const int fd, struct map_session_data* sd, const char* co
if (sd->state.storage_flag != 1)
{ //Open storage.
- switch (storage_storageopen(sd)) {
- case 2: //Try again
- clif_displaymessage(fd, "run this command again..");
- return 0;
- case 1: //Failure
+ if( storage_storageopen(sd) == 1 ) {
clif_displaymessage(fd, "You can't open the storage currently.");
return -1;
}
}
+
for (i = 0; i < MAX_INVENTORY; i++) {
if (sd->status.inventory[i].amount) {
if(sd->status.inventory[i].equip != 0)
diff --git a/src/map/charcommand.c b/src/map/charcommand.c
index 7afcabc15..ccbf0cadc 100644
--- a/src/map/charcommand.c
+++ b/src/map/charcommand.c
@@ -606,10 +606,9 @@ int charcommand_effect(const int fd, struct map_session_data* sd, const char* co
*------------------------------------------*/
int charcommand_storagelist(const int fd, struct map_session_data* sd, const char* command, const char* message)
{
- struct storage_data *stor;
struct map_session_data *pl_sd;
struct item_data *item_data, *item_temp;
- int i, j, count, counter, counter2;
+ int i, j, count = 0, counter = 0, counter2 = 0;
char character[NAME_LENGTH], output[200], outputtmp[200];
nullpo_retr(-1, sd);
@@ -634,51 +633,49 @@ int charcommand_storagelist(const int fd, struct map_session_data* sd, const cha
return -1;
}
- if((stor = account2storage2(pl_sd->status.account_id)) != NULL) {
- counter = 0;
- count = 0;
- for (i = 0; i < MAX_STORAGE; i++) {
- if (stor->items[i].nameid > 0 && (item_data = itemdb_search(stor->items[i].nameid)) != NULL) {
- counter = counter + stor->items[i].amount;
- count++;
- if (count == 1) {
- sprintf(output, "------ Storage items list of '%s' ------", pl_sd->status.name);
- clif_displaymessage(fd, output);
- }
- if (stor->items[i].refine)
- sprintf(output, "%d %s %+d (%s %+d, id: %d)", stor->items[i].amount, item_data->name, stor->items[i].refine, item_data->jname, stor->items[i].refine, stor->items[i].nameid);
- else
- sprintf(output, "%d %s (%s, id: %d)", stor->items[i].amount, item_data->name, item_data->jname, stor->items[i].nameid);
+ for (i = 0; i < MAX_STORAGE; i++)
+ {
+ struct item* it = &sd->status.storage.items[i];
+ if( it->nameid > 0 && (item_data = itemdb_search(it->nameid)) != NULL )
+ {
+ counter = counter + it->amount;
+ count++;
+ if (count == 1) {
+ sprintf(output, "------ Storage items list of '%s' ------", pl_sd->status.name);
clif_displaymessage(fd, output);
- memset(output, '\0', sizeof(output));
- counter2 = 0;
- for (j = 0; j < item_data->slot; j++) {
- if (stor->items[i].card[j]) {
- if ((item_temp = itemdb_search(stor->items[i].card[j])) != NULL) {
- if (output[0] == '\0')
- sprintf(outputtmp, " -> (card(s): #%d %s (%s), ", ++counter2, item_temp->name, item_temp->jname);
- else
- sprintf(outputtmp, "#%d %s (%s), ", ++counter2, item_temp->name, item_temp->jname);
- strcat(output, outputtmp);
- }
+ }
+ if (it->refine)
+ sprintf(output, "%d %s %+d (%s %+d, id: %d)", it->amount, item_data->name, it->refine, item_data->jname, it->refine, it->nameid);
+ else
+ sprintf(output, "%d %s (%s, id: %d)", it->amount, item_data->name, item_data->jname, it->nameid);
+ clif_displaymessage(fd, output);
+
+ memset(output, '\0', sizeof(output));
+ counter2 = 0;
+ for (j = 0; j < item_data->slot; j++) {
+ if (it->card[j]) {
+ if ((item_temp = itemdb_search(it->card[j])) != NULL) {
+ if (output[0] == '\0')
+ sprintf(outputtmp, " -> (card(s): #%d %s (%s), ", ++counter2, item_temp->name, item_temp->jname);
+ else
+ sprintf(outputtmp, "#%d %s (%s), ", ++counter2, item_temp->name, item_temp->jname);
+ strcat(output, outputtmp);
}
}
- if (output[0] != '\0') {
- output[strlen(output) - 2] = ')';
- output[strlen(output) - 1] = '\0';
- clif_displaymessage(fd, output);
- }
+ }
+ if (output[0] != '\0') {
+ output[strlen(output) - 2] = ')';
+ output[strlen(output) - 1] = '\0';
+ clif_displaymessage(fd, output);
}
}
- if (count == 0)
- clif_displaymessage(fd, "No item found in the storage of this player.");
- else {
- sprintf(output, "%d item(s) found in %d kind(s) of items.", counter, count);
- clif_displaymessage(fd, output);
- }
- } else {
- clif_displaymessage(fd, "This player has no storage.");
- return 0;
+ }
+
+ if (count == 0)
+ clif_displaymessage(fd, "No item found in the storage of this player.");
+ else {
+ sprintf(output, "%d item(s) found in %d kind(s) of items.", counter, count);
+ clif_displaymessage(fd, output);
}
return 0;
@@ -1643,7 +1640,6 @@ int charcommand_storage(const int fd, struct map_session_data* sd, const char* c
*------------------------------------------*/
int charcommand_guildstorage(const int fd, struct map_session_data* sd, const char* command, const char* message)
{
- struct storage_data *stor; //changes from Freya/Yor
char character[NAME_LENGTH];
struct map_session_data *pl_sd;
@@ -1665,24 +1661,21 @@ int charcommand_guildstorage(const int fd, struct map_session_data* sd, const ch
return -1;
}
- if (pl_sd->npc_id || pl_sd->vender_id || pl_sd->state.trading || pl_sd->state.storage_flag)
+ if (pl_sd->npc_id || pl_sd->vender_id || pl_sd->state.trading)
return -1;
- if (pl_sd->status.guild_id > 0) {
- if (pl_sd->state.storage_flag) {
- clif_displaymessage(fd, "Guild storage is currently in use.");
- return -1;
- }
- if ((stor = account2storage2(pl_sd->status.account_id)) != NULL && stor->storage_status == 1) {
- clif_displaymessage(fd, "Guild storage is currently in use.");
- return -1;
- }
- storage_guild_storageopen(pl_sd);
- } else {
+ if (pl_sd->status.guild_id == 0) {
clif_displaymessage(fd, "Target player is not in a guild.");
return -1;
}
+ if (pl_sd->state.storage_flag) {
+ clif_displaymessage(fd, "Guild storage is currently in use.");
+ return -1;
+ }
+
+ storage_guild_storageopen(pl_sd);
+
clif_displaymessage(pl_sd->fd, "Guild storage opened.");
if (pl_sd->fd != fd)
clif_displaymessage(fd, "Player's guild storage opened.");
@@ -3190,12 +3183,7 @@ int charcommand_storeall(const int fd, struct map_session_data* sd, const char*
if (pl_sd->state.storage_flag != 1)
{ //Open storage.
- switch (storage_storageopen(pl_sd)) {
- case 2: //Try again
- clif_displaymessage(fd, "Had to open the characters storage window...");
- clif_displaymessage(fd, "run this command again..");
- return 0;
- case 1: //Failure
+ if( storage_storageopen(pl_sd) == 1 ) {
clif_displaymessage(fd, "The character currently can't use the storage.");
return 1;
}
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 57fef3863..725fbcc07 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -257,11 +257,11 @@ int chrif_save(struct map_session_data *sd, int flag)
return -1; //Character is saved on reconnect.
//For data sync
- if (sd->state.storage_flag == 1)
- storage_storage_save(sd->status.account_id, flag);
- else if (sd->state.storage_flag == 2)
+ if (sd->state.storage_flag == 2)
storage_guild_storagesave(sd->status.account_id, sd->status.guild_id, flag);
- if (flag) sd->state.storage_flag = 0; //Force close it.
+
+ if (flag)
+ sd->state.storage_flag = 0; //Force close it.
//Saving of registry values.
if (sd->state.reg_dirty&4)
diff --git a/src/map/clif.c b/src/map/clif.c
index 21cf8d208..bf9655aff 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -1867,8 +1867,7 @@ void clif_equiplist(struct map_session_data *sd)
}
}
-//Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
-void clif_storagelist(struct map_session_data *sd,struct storage_data *stor)
+void clif_storagelist(struct map_session_data* sd, struct storage_data* stor)
{
struct item_data *id;
int i,n,ne,fd=sd->fd;
@@ -9736,10 +9735,10 @@ void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
*------------------------------------------*/
void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
{
- if (sd->state.storage_flag == 1)
+ if( sd->state.storage_flag == 1 )
storage_storageclose(sd);
else
- if (sd->state.storage_flag == 2)
+ if( sd->state.storage_flag == 2 )
storage_guild_storageclose(sd);
}
diff --git a/src/map/intif.c b/src/map/intif.c
index 705171f7f..7b79fe452 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -32,7 +32,7 @@
static const int packet_len_table[]={
-1,-1,27,-1, -1, 0,37, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3800-0x380f
- -1, 7, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
+ 0, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
39,-1,15,15, 14,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840
@@ -326,32 +326,6 @@ int intif_request_registry(struct map_session_data *sd, int flag)
return 0;
}
-// 倉庫データ要求
-int intif_request_storage(int account_id)
-{
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3010;
- WFIFOL(inter_fd,2) = account_id;
- WFIFOSET(inter_fd,6);
- return 0;
-}
-// 倉庫データ送信
-int intif_send_storage(struct storage_data *stor)
-{
- if (CheckForCharServer())
- return 0;
- nullpo_retr(0, stor);
- WFIFOHEAD(inter_fd,sizeof(struct storage_data)+8);
- WFIFOW(inter_fd,0) = 0x3011;
- WFIFOW(inter_fd,2) = sizeof(struct storage_data)+8;
- WFIFOL(inter_fd,4) = stor->account_id;
- memcpy( WFIFOP(inter_fd,8),stor, sizeof(struct storage_data) );
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 0;
-}
-
int intif_request_guild_storage(int account_id,int guild_id)
{
if (CheckForCharServer())
@@ -968,53 +942,6 @@ int intif_parse_Registers(int fd)
return 1;
}
-// 倉庫データ受信
-int intif_parse_LoadStorage(int fd)
-{
- struct storage_data *stor;
- struct map_session_data *sd;
-
- sd=map_id2sd( RFIFOL(fd,4) );
- if(sd==NULL){
- ShowError("intif_parse_LoadStorage: user not found %d\n",RFIFOL(fd,4));
- return 1;
- }
-
- stor = account2storage( RFIFOL(fd,4));
-
- if (stor->storage_status == 1) { // Already open.. lets ignore this update
- ShowWarning("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
- return 1;
- }
- if (stor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
- ShowWarning("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
- return 1;
- }
- if (RFIFOW(fd,2)-8 != sizeof(struct storage_data)) {
- ShowError("intif_parse_LoadStorage: data size error %d %d\n", RFIFOW(fd,2)-8, sizeof(struct storage_data));
- return 1;
- }
- if(battle_config.save_log)
- ShowInfo("intif_openstorage: %d\n",RFIFOL(fd,4) );
- memcpy(stor,RFIFOP(fd,8),sizeof(struct storage_data));
- stor->dirty=0;
- stor->storage_status=1;
- sd->state.storage_flag = 1;
- clif_storagelist(sd,stor);
- clif_updatestorageamount(sd,stor->storage_amount);
-
- return 0;
-}
-
-// 倉庫データ送信成功
-int intif_parse_SaveStorage(int fd)
-{
- if(battle_config.save_log)
- ShowInfo("intif_savestorage: done %d %d\n",RFIFOL(fd,2),RFIFOB(fd,6) );
- storage_storage_saved(RFIFOL(fd,2));
- return 0;
-}
-
int intif_parse_LoadGuildStorage(int fd)
{
struct guild_storage *gstor;
@@ -1988,8 +1915,6 @@ int intif_parse(int fd)
case 0x3803: mapif_parse_WisToGM(fd); break;
case 0x3804: intif_parse_Registers(fd); break;
case 0x3806: intif_parse_ChangeNameOk(fd); break;
- case 0x3810: intif_parse_LoadStorage(fd); break;
- case 0x3811: intif_parse_SaveStorage(fd); break;
case 0x3818: intif_parse_LoadGuildStorage(fd); break;
case 0x3819: intif_parse_SaveGuildStorage(fd); break;
case 0x3820: intif_parse_PartyCreated(fd); break;
diff --git a/src/map/intif.h b/src/map/intif.h
index be0bc8d72..b4cc6792f 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -24,8 +24,6 @@ int intif_wis_message_to_gm(char *Wisp_name, int min_gm_level, char *mes);
int intif_saveregistry(struct map_session_data *sd, int type);
int intif_request_registry(struct map_session_data *sd, int flag);
-int intif_request_storage(int account_id);
-int intif_send_storage(struct storage_data *stor);
int intif_request_guild_storage(int account_id, int guild_id);
int intif_send_guild_storage(int account_id, struct guild_storage *gstor);
diff --git a/src/map/storage.c b/src/map/storage.c
index 964d3008c..e4bdfe414 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -24,7 +24,6 @@
#include <string.h>
-static DBMap* storage_db; // int account_id -> struct storage*
static DBMap* guild_storage_db; // int guild_id -> struct guild_storage*
/*==========================================
@@ -44,13 +43,13 @@ static int storage_comp_item(const void *_i1, const void *_i2)
return i1->nameid - i2->nameid;
}
-static void storage_sortitem (struct storage_data *stor)
+static void storage_sortitem(struct storage_data* stor)
{
nullpo_retv(stor);
qsort(stor->items, MAX_STORAGE, sizeof(struct item), storage_comp_item);
}
-static void storage_gsortitem (struct guild_storage* gstor)
+static void storage_gsortitem(struct guild_storage* gstor)
{
nullpo_retv(gstor);
qsort(gstor->storage_, MAX_GUILD_STORAGE, sizeof(struct item), storage_comp_item);
@@ -61,75 +60,38 @@ static void storage_gsortitem (struct guild_storage* gstor)
*------------------------------------------*/
int do_init_storage(void) // map.c::do_init()から呼ばれる
{
- storage_db=idb_alloc(DB_OPT_RELEASE_DATA);
guild_storage_db=idb_alloc(DB_OPT_RELEASE_DATA);
return 1;
}
void do_final_storage(void) // by [MC Cameri]
{
- storage_db->destroy(storage_db,NULL);
guild_storage_db->destroy(guild_storage_db,NULL);
}
static int storage_reconnect_sub(DBKey key,void *data,va_list ap)
{ //Parses storage and saves 'dirty' ones upon reconnect. [Skotlex]
- int type = va_arg(ap, int);
- if (type)
- { //Guild Storage
- struct guild_storage* stor = (struct guild_storage*) data;
- if (stor->dirty && stor->storage_status == 0) //Save closed storages.
- storage_guild_storagesave(0, stor->guild_id,0);
- }
- else
- { //Account Storage
- struct storage_data* stor = (struct storage_data*) data;
- if (stor->dirty && stor->storage_status == 0) //Save closed storages.
- storage_storage_save(stor->account_id, stor->dirty==2?1:0);
- }
+
+ struct guild_storage* stor = (struct guild_storage*) data;
+ if (stor->dirty && stor->storage_status == 0) //Save closed storages.
+ storage_guild_storagesave(0, stor->guild_id,0);
+
return 0;
}
//Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex]
void do_reconnect_storage(void)
{
- storage_db->foreach(storage_db, storage_reconnect_sub, 0);
- guild_storage_db->foreach(guild_storage_db, storage_reconnect_sub, 1);
-}
-
-static void* create_storage(DBKey key, va_list args)
-{
- struct storage_data *stor;
- stor = (struct storage_data *) aCallocA (sizeof(struct storage_data), 1);
- stor->account_id = key.i;
- return stor;
-}
-struct storage_data *account2storage(int account_id)
-{
- return (struct storage_data*)idb_ensure(storage_db,account_id,create_storage);
-}
-
-// Just to ask storage, without creation
-struct storage_data *account2storage2(int account_id)
-{
- return (struct storage_data*)idb_get(storage_db, account_id);
-}
-
-int storage_delete(int account_id)
-{
- idb_remove(storage_db,account_id);
- return 0;
+ guild_storage_db->foreach(guild_storage_db, storage_reconnect_sub);
}
/*==========================================
* Opens a storage. Returns:
* 0 - success
* 1 - fail
- * 2 - Storage requested from char-server (will open automatically later)
*------------------------------------------*/
int storage_storageopen(struct map_session_data *sd)
{
- struct storage_data *stor;
nullpo_retr(0, sd);
if(sd->state.storage_flag)
@@ -141,19 +103,9 @@ int storage_storageopen(struct map_session_data *sd)
return 1;
}
- if((stor = (struct storage_data*)idb_get(storage_db,sd->status.account_id)) == NULL)
- { //Request storage.
- intif_request_storage(sd->status.account_id);
- return 2;
- }
-
- if (stor->storage_status)
- return 1; //Already open/player already has it open...
-
- stor->storage_status = 1;
sd->state.storage_flag = 1;
- clif_storagelist(sd,stor);
- clif_updatestorageamount(sd,stor->storage_amount);
+ clif_storagelist(sd,&sd->status.storage);
+ clif_updatestorageamount(sd,sd->status.storage.storage_amount);
return 0;
}
@@ -175,8 +127,9 @@ int compare_item(struct item *a, struct item *b)
/*==========================================
* Internal add-item function.
*------------------------------------------*/
-static int storage_additem(struct map_session_data* sd, struct storage_data* stor,struct item *item_data,int amount)
+static int storage_additem(struct map_session_data* sd, struct item* item_data, int amount)
{
+ struct storage_data* stor = &sd->status.storage;
struct item_data *data;
int i;
@@ -195,13 +148,12 @@ static int storage_additem(struct map_session_data* sd, struct storage_data* sto
{//Stackable
for( i = 0; i < MAX_STORAGE; i++ )
{
- if( compare_item (&stor->items[i], item_data))
+ if( compare_item(&stor->items[i], item_data) )
{// existing items found, stack them
if( amount > MAX_AMOUNT - stor->items[i].amount )
return 1;
- stor->items[i].amount+=amount;
+ stor->items[i].amount += amount;
clif_storageitemadded(sd,&stor->items[i],i,amount);
- stor->dirty = 1;
if(log_config.enable_logs&0x800)
log_pick_pc(sd, "R", item_data->nameid, -amount, item_data);
return 0;
@@ -216,11 +168,10 @@ static int storage_additem(struct map_session_data* sd, struct storage_data* sto
// add item to slot
memcpy(&stor->items[i],item_data,sizeof(stor->items[0]));
- stor->items[i].amount=amount;
stor->storage_amount++;
+ stor->items[i].amount = amount;
clif_storageitemadded(sd,&stor->items[i],i,amount);
clif_updatestorageamount(sd,stor->storage_amount);
- stor->dirty = 1;
if(log_config.enable_logs&0x800)
log_pick_pc(sd, "R", item_data->nameid, -amount, item_data);
@@ -230,25 +181,23 @@ static int storage_additem(struct map_session_data* sd, struct storage_data* sto
/*==========================================
* Internal del-item function
*------------------------------------------*/
-static int storage_delitem(struct map_session_data* sd, struct storage_data* stor, int n, int amount)
+static int storage_delitem(struct map_session_data* sd, int n, int amount)
{
- if( stor->items[n].nameid == 0 || stor->items[n].amount < amount )
+ if( sd->status.storage.items[n].nameid == 0 || sd->status.storage.items[n].amount < amount )
return 1;
- stor->items[n].amount -= amount;
+ sd->status.storage.items[n].amount -= amount;
- if( log_config.enable_logs&0x800 )
- log_pick_pc(sd, "R", stor->items[n].nameid, amount, &stor->items[n]);
+ if(log_config.enable_logs&0x800)
+ log_pick_pc(sd, "R", sd->status.storage.items[n].nameid, amount, &sd->status.storage.items[n]);
- if( stor->items[n].amount == 0 )
+ if( sd->status.storage.items[n].amount == 0 )
{
- memset(&stor->items[n],0,sizeof(stor->items[0]));
- stor->storage_amount--;
- clif_updatestorageamount(sd,stor->storage_amount);
+ memset(&sd->status.storage.items[n],0,sizeof(sd->status.storage.items[0]));
+ sd->status.storage.storage_amount--;
+ clif_updatestorageamount(sd,sd->status.storage.storage_amount);
}
clif_storageitemremoved(sd,n,amount);
-
- stor->dirty = 1;
return 0;
}
@@ -257,13 +206,10 @@ static int storage_delitem(struct map_session_data* sd, struct storage_data* sto
*------------------------------------------*/
int storage_storageadd(struct map_session_data* sd, int index, int amount)
{
- struct storage_data *stor;
-
nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage2(sd->status.account_id));
- if( stor->storage_amount > MAX_STORAGE || !stor->storage_status )
- return 0; // storage full / storage closed
+ if( sd->status.storage.storage_amount > MAX_STORAGE )
+ return 0; // storage full
if( index < 0 || index >= MAX_INVENTORY )
return 0;
@@ -274,7 +220,7 @@ int storage_storageadd(struct map_session_data* sd, int index, int amount)
if( amount < 1 || amount > sd->status.inventory[index].amount )
return 0;
- if( storage_additem(sd,stor,&sd->status.inventory[index],amount) == 0 )
+ if( storage_additem(sd,&sd->status.inventory[index],amount) == 0 )
pc_delitem(sd,index,amount,0);
return 1;
@@ -285,24 +231,19 @@ int storage_storageadd(struct map_session_data* sd, int index, int amount)
*------------------------------------------*/
int storage_storageget(struct map_session_data* sd, int index, int amount)
{
- struct storage_data *stor;
int flag;
- nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage2(sd->status.account_id));
-
-
if( index < 0 || index >= MAX_STORAGE )
return 0;
- if( stor->items[index].nameid <= 0 )
+ if( sd->status.storage.items[index].nameid <= 0 )
return 0; //Nothing there
- if( amount < 1 || amount > stor->items[index].amount )
+ if( amount < 1 || amount > sd->status.storage.items[index].amount )
return 0;
- if( (flag = pc_additem(sd,&stor->items[index],amount)) == 0 )
- storage_delitem(sd,stor,index,amount);
+ if( (flag = pc_additem(sd,&sd->status.storage.items[index],amount)) == 0 )
+ storage_delitem(sd,index,amount);
else
clif_additem(sd,0,0,flag);
@@ -314,12 +255,9 @@ int storage_storageget(struct map_session_data* sd, int index, int amount)
*------------------------------------------*/
int storage_storageaddfromcart(struct map_session_data* sd, int index, int amount)
{
- struct storage_data *stor;
-
nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage2(sd->status.account_id));
- if( stor->storage_amount > MAX_STORAGE || !stor->storage_status )
+ if( sd->status.storage.storage_amount > MAX_STORAGE )
return 0; // storage full / storage closed
if( index < 0 || index >= MAX_CART )
@@ -331,7 +269,7 @@ int storage_storageaddfromcart(struct map_session_data* sd, int index, int amoun
if( amount < 1 || amount > sd->status.cart[index].amount )
return 0;
- if( storage_additem(sd,stor,&sd->status.cart[index],amount) == 0 )
+ if( storage_additem(sd,&sd->status.cart[index],amount) == 0 )
pc_cart_delitem(sd,index,amount,0);
return 1;
@@ -342,25 +280,19 @@ int storage_storageaddfromcart(struct map_session_data* sd, int index, int amoun
*------------------------------------------*/
int storage_storagegettocart(struct map_session_data* sd, int index, int amount)
{
- struct storage_data *stor;
-
nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage2(sd->status.account_id));
- if( !stor->storage_status )
- return 0;
-
if( index < 0 || index >= MAX_STORAGE )
return 0;
- if( stor->items[index].nameid <= 0 )
+ if( sd->status.storage.items[index].nameid <= 0 )
return 0; //Nothing there.
- if( amount < 1 || amount > stor->items[index].amount )
+ if( amount < 1 || amount > sd->status.storage.items[index].amount )
return 0;
- if( pc_cart_additem(sd,&stor->items[index],amount) == 0 )
- storage_delitem(sd,stor,index,amount);
+ if( pc_cart_additem(sd,&sd->status.storage.items[index],amount) == 0 )
+ storage_delitem(sd,index,amount);
return 1;
}
@@ -369,107 +301,31 @@ int storage_storagegettocart(struct map_session_data* sd, int index, int amount)
/*==========================================
* Modified By Valaris to save upon closing [massdriller]
*------------------------------------------*/
-int storage_storageclose(struct map_session_data* sd)
+void storage_storageclose(struct map_session_data* sd)
{
- struct storage_data *stor;
-
- nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage2(sd->status.account_id));
+ nullpo_retv(sd);
clif_storageclose(sd);
- if (stor->storage_status)
- {
- if (save_settings&4)
- chrif_save(sd,0); //Invokes the storage saving as well.
- else
- storage_storage_save(sd->status.account_id, 0);
- }
- stor->storage_status = 0;
- sd->state.storage_flag = 0;
- return 0;
+ if( save_settings&4 )
+ chrif_save(sd,0); //Invokes the storage saving as well.
+
+ sd->state.storage_flag = 0;
}
/*==========================================
* When quitting the game.
*------------------------------------------*/
-int storage_storage_quit(struct map_session_data* sd, int flag)
+void storage_storage_quit(struct map_session_data* sd, int flag)
{
- struct storage_data *stor;
-
- nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage2(sd->status.account_id));
+ nullpo_retv(sd);
- if( stor->storage_status )
- {
- if (save_settings&4)
- chrif_save(sd, flag); //Invokes the storage saving as well.
- else
- storage_storage_save(sd->status.account_id, flag);
- }
- stor->storage_status = 0;
- sd->state.storage_flag = 0;
-
- return 0;
-}
-
-void storage_storage_dirty(struct map_session_data* sd)
-{
- struct storage_data *stor;
-
- stor=account2storage2(sd->status.account_id);
-
- if(stor)
- stor->dirty = 1;
-}
-
-int storage_storage_save(int account_id, int final)
-{
- struct storage_data *stor;
+ if (save_settings&4)
+ chrif_save(sd, flag); //Invokes the storage saving as well.
- stor=account2storage2(account_id);
- if(!stor) return 0;
-
- if(stor->dirty)
- {
- if (final) {
- stor->dirty = 2;
- stor->storage_status = 0; //To prevent further manipulation of it.
- }
- intif_send_storage(stor);
- return 1;
- }
- if (final)
- { //Clear storage from memory. Nothing to save.
- storage_delete(account_id);
- return 1;
- }
-
- return 0;
+ sd->state.storage_flag = 0;
}
-//Ack from Char-server indicating the storage was saved. [Skotlex]
-int storage_storage_saved(int account_id)
-{
- struct storage_data *stor;
-
- if((stor=account2storage2(account_id)) == NULL)
- return 0;
-
- if (stor->dirty == 2)
- { //Final save of storage. Remove from memory.
- storage_delete(account_id);
- return 1;
- }
-
- if (stor->dirty && stor->storage_status == 0)
- { //Only mark it clean if it's not in use. [Skotlex]
- stor->dirty = 0;
- storage_sortitem(stor);
- return 1;
- }
- return 0;
-}
static void* create_guildstorage(DBKey key, va_list args)
{
diff --git a/src/map/storage.h b/src/map/storage.h
index 221bc109d..25848d0db 100644
--- a/src/map/storage.h
+++ b/src/map/storage.h
@@ -16,16 +16,11 @@ int storage_storageadd(struct map_session_data *sd,int index,int amount);
int storage_storageget(struct map_session_data *sd,int index,int amount);
int storage_storageaddfromcart(struct map_session_data *sd,int index,int amount);
int storage_storagegettocart(struct map_session_data *sd,int index,int amount);
-int storage_storageclose(struct map_session_data *sd);
+void storage_storageclose(struct map_session_data *sd);
int do_init_storage(void);
void do_final_storage(void);
void do_reconnect_storage(void);
-struct storage_data* account2storage(int account_id);
-struct storage_data* account2storage2(int account_id);
-int storage_storage_quit(struct map_session_data *sd, int flag);
-int storage_storage_save(int account_id, int final);
-int storage_storage_saved(int account_id); //Ack from char server that guild store was saved.
-void storage_storage_dirty(struct map_session_data *sd);
+void storage_storage_quit(struct map_session_data *sd, int flag);
struct guild_storage* guild2storage(int guild_id);
int guild_storage_delete(int guild_id);