summaryrefslogtreecommitdiff
path: root/src/map/storage.c
diff options
context:
space:
mode:
authorDennis Friis <peavey@inspircd.org>2009-06-23 00:22:39 +0200
committerDennis Friis <peavey@inspircd.org>2009-06-25 01:13:20 +0200
commit4b825f68fa8e8ec86d6aa1694f629ed348fe50f1 (patch)
tree54c4567fb51f8b1edb2cde224ea2ef6e7d994053 /src/map/storage.c
parent353fd0ec49222512a4292fb1452c2c82c8e3a38d (diff)
downloadtmwa-4b825f68fa8e8ec86d6aa1694f629ed348fe50f1.tar.gz
tmwa-4b825f68fa8e8ec86d6aa1694f629ed348fe50f1.tar.bz2
tmwa-4b825f68fa8e8ec86d6aa1694f629ed348fe50f1.tar.xz
tmwa-4b825f68fa8e8ec86d6aa1694f629ed348fe50f1.zip
Redo storage, derived from ea stable.
Diffstat (limited to 'src/map/storage.c')
-rw-r--r--src/map/storage.c362
1 files changed, 235 insertions, 127 deletions
diff --git a/src/map/storage.c b/src/map/storage.c
index 30a8b4c..50f0bef 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -3,18 +3,19 @@
#include <stdlib.h>
#include <string.h>
-#include "db.h"
+#include "../common/db.h"
+#include "../common/nullpo.h"
+#include "../common/malloc.h"
+
+#include "storage.h"
+#include "chrif.h"
#include "itemdb.h"
#include "clif.h"
#include "intif.h"
#include "pc.h"
-#include "storage.h"
#include "guild.h"
-#include "nullpo.h"
-
-#ifdef MEMWATCH
-#include "memwatch.h"
-#endif
+#include "battle.h"
+#include "atcommand.h"
static struct dbt *storage_db;
static struct dbt *guild_storage_db;
@@ -23,32 +24,30 @@ static struct dbt *guild_storage_db;
* 倉庫内アイテムソート
*------------------------------------------
*/
-int storage_comp_item(const void *_i1, const void *_i2){
-struct item *i1=(struct item *)_i1;
-struct item *i2=(struct item *)_i2;
+int storage_comp_item(const void *_i1, const void *_i2)
+{
+ struct item *i1 = (struct item *)_i1;
+ struct item *i2 = (struct item *)_i2;
- if (i1->nameid == i2->nameid) {
+ if (i1->nameid == i2->nameid)
return 0;
- } else if (!(i1->nameid) || !(i1->amount)){
+ else if (!(i1->nameid) || !(i1->amount))
return 1;
- } else if (!(i2->nameid) || !(i2->amount)){
+ else if (!(i2->nameid) || !(i2->amount))
return -1;
- } else {
- return i1->nameid - i2->nameid;
- }
+ return i1->nameid - i2->nameid;
}
-
-void sortage_sortitem(struct storage* stor){
+void sortage_sortitem (struct storage *stor)
+{
nullpo_retv(stor);
-
- qsort(stor->storage, MAX_STORAGE, sizeof(struct item), storage_comp_item);
+ qsort(stor->storage_, MAX_STORAGE, sizeof(struct item), storage_comp_item);
}
-void sortage_gsortitem(struct guild_storage* gstor){
+void sortage_gsortitem (struct guild_storage* gstor)
+{
nullpo_retv(gstor);
-
- qsort(gstor->storage, MAX_GUILD_STORAGE, sizeof(struct item), storage_comp_item);
+ qsort(gstor->storage_, MAX_GUILD_STORAGE, sizeof(struct item), storage_comp_item);
}
/*==========================================
@@ -61,36 +60,72 @@ int do_init_storage(void) // map.c::do_init()から呼ばれる
guild_storage_db=numdb_init();
return 1;
}
+static int guild_storage_db_final(void *key,void *data,va_list ap)
+{
+ struct guild_storage *gstor=(struct guild_storage *) data;
+ free(gstor);
+ return 0;
+}
+static int storage_db_final(void *key,void *data,va_list ap)
+{
+ struct storage *stor=(struct storage *) data;
+ free(stor);
+ return 0;
+}
+void do_final_storage(void) // by [MC Cameri]
+{
+ if (storage_db)
+ numdb_final(storage_db,storage_db_final);
+ if (guild_storage_db)
+ numdb_final(guild_storage_db,guild_storage_db_final);
+}
+
+
+static int storage_reconnect_sub(void *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);
+ }
+ else
+ { //Account Storage
+ struct storage* stor = (struct storage*) data;
+ if (stor->dirty && stor->storage_status == 0) //Save closed storages.
+ storage_storage_save(stor->account_id);
+ }
+ return 0;
+}
-void do_final_storage(void) // map.c::do_final()から呼ばれる
+//Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex
+void do_reconnect_storage(void)
{
+ numdb_foreach(storage_db, storage_reconnect_sub, 0);
+ numdb_foreach(guild_storage_db, storage_reconnect_sub, 1);
}
struct storage *account2storage(int account_id)
{
- struct storage *stor;
- stor=numdb_search(storage_db,account_id);
+ struct storage *stor = (struct storage *) numdb_search (storage_db,account_id);
if(stor == NULL) {
- stor = calloc(sizeof(struct storage), 1);
- if(stor == NULL){
- printf("storage: out of memory!\n");
- exit(0);
- }
- memset(stor,0,sizeof(struct storage));
- stor->account_id=account_id;
- numdb_insert(storage_db,stor->account_id,stor);
+ stor = (struct storage *) aCallocA (sizeof(struct storage), 1);
+ stor->account_id = account_id;
+ numdb_insert(storage_db, stor->account_id, stor);
}
return stor;
}
// Just to ask storage, without creation
-struct storage *account2storage2(int account_id) {
- return numdb_search(storage_db, account_id);
+struct storage *account2storage2(int account_id)
+{
+ return (struct storage *) numdb_search(storage_db, account_id);
}
int storage_delete(int account_id)
{
- struct storage *stor = numdb_search(storage_db,account_id);
+ struct storage *stor = (struct storage *) numdb_search(storage_db,account_id);
if(stor) {
numdb_erase(storage_db,account_id);
free(stor);
@@ -104,18 +139,24 @@ int storage_delete(int account_id)
*/
int storage_storageopen(struct map_session_data *sd)
{
+//#ifdef TXT_ONLY
struct storage *stor;
-
+//#endif
nullpo_retr(0, sd);
- if((stor = numdb_search(storage_db,sd->status.account_id)) != NULL) {
- stor->storage_status = 1;
- sd->state.storage_flag = 0;
- clif_storageitemlist(sd,stor);
- clif_storageequiplist(sd,stor);
- clif_updatestorageamount(sd,stor);
- return 0;
+//Storage loading always from sql idea from Komurka [Skotlex] - removed as it opens exploits when server lags.
+//#ifdef TXT_ONLY
+ if((stor = (struct storage *) numdb_search(storage_db,sd->status.account_id)) != NULL) {
+ if (stor->storage_status == 0) {
+ stor->storage_status = 1;
+ sd->state.storage_flag = 1;
+ clif_storageitemlist(sd,stor);
+ clif_storageequiplist(sd,stor);
+ clif_updatestorageamount(sd,stor);
+ return 0;
+ }
} else
+//#endif
intif_request_storage(sd->status.account_id);
return 1;
@@ -142,12 +183,10 @@ int storage_additem(struct map_session_data *sd,struct storage *stor,struct item
if(!itemdb_isequip2(data)){
// 装備品ではないので、既所有品なら個数のみ変化させる
for(i=0;i<MAX_STORAGE;i++){
- if(stor->storage[i].nameid == item_data->nameid &&
- stor->storage[i].card[0] == item_data->card[0] && stor->storage[i].card[1] == item_data->card[1] &&
- stor->storage[i].card[2] == item_data->card[2] && stor->storage[i].card[3] == item_data->card[3]){
- if(stor->storage[i].amount+amount > MAX_AMOUNT)
+ if( compare_item (&stor->storage_[i], item_data)) {
+ if(stor->storage_[i].amount+amount > MAX_AMOUNT)
return 1;
- stor->storage[i].amount+=amount;
+ stor->storage_[i].amount+=amount;
clif_storageitemadded(sd,stor,i,amount);
break;
}
@@ -156,9 +195,9 @@ int storage_additem(struct map_session_data *sd,struct storage *stor,struct item
if(i>=MAX_STORAGE){
// 装備品か未所有品だったので空き欄へ追加
for(i=0;i<MAX_STORAGE;i++){
- if(stor->storage[i].nameid==0){
- memcpy(&stor->storage[i],item_data,sizeof(stor->storage[0]));
- stor->storage[i].amount=amount;
+ if(stor->storage_[i].nameid==0){
+ memcpy(&stor->storage_[i],item_data,sizeof(stor->storage_[0]));
+ stor->storage_[i].amount=amount;
stor->storage_amount++;
clif_storageitemadded(sd,stor,i,amount);
clif_updatestorageamount(sd,stor);
@@ -168,6 +207,8 @@ int storage_additem(struct map_session_data *sd,struct storage *stor,struct item
if(i>=MAX_STORAGE)
return 1;
}
+
+ stor->dirty = 1;
return 0;
}
/*==========================================
@@ -179,17 +220,18 @@ int storage_delitem(struct map_session_data *sd,struct storage *stor,int n,int a
nullpo_retr(1, sd);
nullpo_retr(1, stor);
- if(stor->storage[n].nameid==0 || stor->storage[n].amount<amount)
+ if(stor->storage_[n].nameid==0 || stor->storage_[n].amount<amount)
return 1;
- stor->storage[n].amount-=amount;
- if(stor->storage[n].amount==0){
- memset(&stor->storage[n],0,sizeof(stor->storage[0]));
+ stor->storage_[n].amount-=amount;
+ if(stor->storage_[n].amount==0){
+ memset(&stor->storage_[n],0,sizeof(stor->storage_[0]));
stor->storage_amount--;
clif_updatestorageamount(sd,stor);
}
clif_storageitemremoved(sd,n,amount);
+ stor->dirty = 1;
return 0;
}
/*==========================================
@@ -201,15 +243,16 @@ int storage_storageadd(struct map_session_data *sd,int index,int amount)
struct storage *stor;
nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage(sd->status.account_id));
+ nullpo_retr(0, stor=account2storage2(sd->status.account_id));
if( (stor->storage_amount <= MAX_STORAGE) && (stor->storage_status == 1) ) { // storage not full & storage open
if(index>=0 && index<MAX_INVENTORY) { // valid index
- if( (amount <= sd->status.inventory[index].amount) && (amount > 0) ) { //valid amount
- if(storage_additem(sd,stor,&sd->status.inventory[index],amount)==0)
- // remove item from inventory
- pc_delitem(sd,index,amount,0);
- } // valid amount
+ if( (amount <= sd->status.inventory[index].amount) && (amount > 0) ) { //valid amount
+// log_tostorage(sd, index, 0);
+ if(storage_additem(sd,stor,&sd->status.inventory[index],amount)==0)
+ // remove item from inventory
+ pc_delitem(sd,index,amount,0);
+ } // valid amount
}// valid index
}// storage not full & storage open
@@ -226,15 +269,16 @@ int storage_storageget(struct map_session_data *sd,int index,int amount)
int flag;
nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage(sd->status.account_id));
+ nullpo_retr(0, stor=account2storage2(sd->status.account_id));
if(stor->storage_status == 1) { // storage open
if(index>=0 && index<MAX_STORAGE) { // valid index
- if( (amount <= stor->storage[index].amount) && (amount > 0) ) { //valid amount
- if((flag = pc_additem(sd,&stor->storage[index],amount)) == 0)
+ if( (amount <= stor->storage_[index].amount) && (amount > 0) ) { //valid amount
+ if((flag = pc_additem(sd,&stor->storage_[index],amount)) == 0)
storage_delitem(sd,stor,index,amount);
- else
- clif_additem(sd,0,0,flag);
+ //else //taken out because it can dupe items if the above fails somehow :) [Kevin]
+ //clif_additem(sd,0,0,flag);
+// log_fromstorage(sd, index, 0);
} // valid amount
}// valid index
}// storage open
@@ -250,7 +294,7 @@ int storage_storageaddfromcart(struct map_session_data *sd,int index,int amount)
struct storage *stor;
nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage(sd->status.account_id));
+ nullpo_retr(0, stor=account2storage2(sd->status.account_id));
if( (stor->storage_amount <= MAX_STORAGE) && (stor->storage_status == 1) ) { // storage not full & storage open
if(index>=0 && index<MAX_INVENTORY) { // valid index
@@ -273,12 +317,12 @@ int storage_storagegettocart(struct map_session_data *sd,int index,int amount)
struct storage *stor;
nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage(sd->status.account_id));
+ nullpo_retr(0, stor=account2storage2(sd->status.account_id));
if(stor->storage_status == 1) { // storage open
if(index>=0 && index<MAX_STORAGE) { // valid index
- if( (amount <= stor->storage[index].amount) && (amount > 0) ) { //valid amount
- if(pc_cart_additem(sd,&stor->storage[index],amount)==0){
+ if( (amount <= stor->storage_[index].amount) && (amount > 0) ) { //valid amount
+ if(pc_cart_additem(sd,&stor->storage_[index],amount)==0){
storage_delitem(sd,stor,index,amount);
}
} // valid amount
@@ -290,24 +334,21 @@ 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)
{
- struct storage *stor=NULL;
+ struct storage *stor;
nullpo_retr(0, sd);
- nullpo_retr(0, stor=account2storage(sd->status.account_id));
+ nullpo_retr(0, stor=account2storage2(sd->status.account_id));
+ clif_storageclose(sd);
+ chrif_save(sd); //This will invoke the storage save function as well. [Skotlex]
+
stor->storage_status=0;
sd->state.storage_flag = 0;
- clif_storageclose(sd);
-
- chrif_save(sd);
- storage_storage_save(sd);
-
- sortage_sortitem(stor);
return 0;
}
@@ -321,31 +362,64 @@ int storage_storage_quit(struct map_session_data *sd)
nullpo_retr(0, sd);
- stor = numdb_search(storage_db,sd->status.account_id);
- if(stor) stor->storage_status = 0;
+ stor = account2storage2(sd->status.account_id);
+ if(stor) {
+ chrif_save(sd); //Invokes the storage saving as well.
+ stor->storage_status = 0;
+ sd->state.storage_flag = 0;
+ }
return 0;
}
-int storage_storage_save(struct map_session_data *sd)
+void storage_storage_dirty(struct map_session_data *sd)
{
struct storage *stor;
- nullpo_retr(0, sd);
+ stor=account2storage2(sd->status.account_id);
- stor=numdb_search(storage_db,sd->status.account_id);
- if(stor) intif_send_storage(stor);
+ if(stor)
+ stor->dirty = 1;
+}
+
+int storage_storage_save(int account_id)
+{
+ struct storage *stor;
+
+ stor=account2storage2(account_id);
+ if(stor && stor->dirty)
+ {
+ intif_send_storage(stor);
+ return 1;
+ }
return 0;
}
+//Ack from Char-server indicating the storage was saved. [Skotlex]
+int storage_storage_saved(int account_id)
+{
+ struct storage *stor;
+
+ if((stor=account2storage2(account_id)) != NULL)
+ { //Only mark it clean if it's not in use. [Skotlex]
+ if (stor->dirty && stor->storage_status == 0)
+ {
+ stor->dirty = 0;
+ sortage_sortitem(stor);
+ }
+ return 1;
+ }
+ return 0;
+}
+
struct guild_storage *guild2storage(int guild_id)
{
struct guild_storage *gs = NULL;
if(guild_search(guild_id) != NULL) {
- gs=numdb_search(guild_storage_db,guild_id);
+ gs=(struct guild_storage *) numdb_search(guild_storage_db,guild_id);
if(gs == NULL) {
- gs = calloc(sizeof(struct guild_storage), 1);
+ gs = (struct guild_storage *) aCallocA(sizeof(struct guild_storage), 1);
if(gs==NULL){
printf("storage: out of memory!\n");
exit(0);
@@ -357,9 +431,14 @@ struct guild_storage *guild2storage(int guild_id)
return gs;
}
-int guild_storage_delete(int guild_id)
+struct guild_storage *guild2storage2(int guild_id)
+{ //For just locating a storage without creating one. [Skotlex]
+ return (struct guild_storage *) numdb_search(guild_storage_db,guild_id);
+}
+
+int guild_storage_delete(int guild_id)
{
- struct guild_storage *gstor = numdb_search(guild_storage_db,guild_id);
+ struct guild_storage *gstor = (struct guild_storage *) numdb_search(guild_storage_db,guild_id);
if(gstor) {
numdb_erase(guild_storage_db,guild_id);
free(gstor);
@@ -375,11 +454,11 @@ int storage_guild_storageopen(struct map_session_data *sd)
if(sd->status.guild_id <= 0)
return 2;
- if((gstor = numdb_search(guild_storage_db,sd->status.guild_id)) != NULL) {
+ if((gstor = guild2storage2(sd->status.guild_id)) != NULL) {
if(gstor->storage_status)
return 1;
gstor->storage_status = 1;
- sd->state.storage_flag = 1;
+ sd->state.storage_flag = 2;
clif_guildstorageitemlist(sd,gstor);
clif_guildstorageequiplist(sd,gstor);
clif_updateguildstorageamount(sd,gstor);
@@ -411,12 +490,10 @@ int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor
if(!itemdb_isequip2(data)){
// 装備品ではないので、既所有品なら個数のみ変化させる
for(i=0;i<MAX_GUILD_STORAGE;i++){
- if(stor->storage[i].nameid == item_data->nameid &&
- stor->storage[i].card[0] == item_data->card[0] && stor->storage[i].card[1] == item_data->card[1] &&
- stor->storage[i].card[2] == item_data->card[2] && stor->storage[i].card[3] == item_data->card[3]){
- if(stor->storage[i].amount+amount > MAX_AMOUNT)
+ if(compare_item(&stor->storage_[i], item_data)) {
+ if(stor->storage_[i].amount+amount > MAX_AMOUNT)
return 1;
- stor->storage[i].amount+=amount;
+ stor->storage_[i].amount+=amount;
clif_guildstorageitemadded(sd,stor,i,amount);
break;
}
@@ -425,9 +502,9 @@ int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor
if(i>=MAX_GUILD_STORAGE){
// 装備品か未所有品だったので空き欄へ追加
for(i=0;i<MAX_GUILD_STORAGE;i++){
- if(stor->storage[i].nameid==0){
- memcpy(&stor->storage[i],item_data,sizeof(stor->storage[0]));
- stor->storage[i].amount=amount;
+ if(stor->storage_[i].nameid==0){
+ memcpy(&stor->storage_[i],item_data,sizeof(stor->storage_[0]));
+ stor->storage_[i].amount=amount;
stor->storage_amount++;
clif_guildstorageitemadded(sd,stor,i,amount);
clif_updateguildstorageamount(sd,stor);
@@ -437,6 +514,7 @@ int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor
if(i>=MAX_GUILD_STORAGE)
return 1;
}
+ stor->dirty = 1;
return 0;
}
@@ -445,17 +523,17 @@ int guild_storage_delitem(struct map_session_data *sd,struct guild_storage *stor
nullpo_retr(1, sd);
nullpo_retr(1, stor);
- if(stor->storage[n].nameid==0 || stor->storage[n].amount<amount)
+ if(stor->storage_[n].nameid==0 || stor->storage_[n].amount<amount)
return 1;
- stor->storage[n].amount-=amount;
- if(stor->storage[n].amount==0){
- memset(&stor->storage[n],0,sizeof(stor->storage[0]));
+ stor->storage_[n].amount-=amount;
+ if(stor->storage_[n].amount==0){
+ memset(&stor->storage_[n],0,sizeof(stor->storage_[0]));
stor->storage_amount--;
clif_updateguildstorageamount(sd,stor);
}
clif_storageitemremoved(sd,n,amount);
-
+ stor->dirty = 1;
return 0;
}
@@ -465,10 +543,11 @@ int storage_guild_storageadd(struct map_session_data *sd,int index,int amount)
nullpo_retr(0, sd);
- if((stor=guild2storage(sd->status.guild_id)) != NULL) {
+ if((stor=guild2storage2(sd->status.guild_id)) != NULL) {
if( (stor->storage_amount <= MAX_GUILD_STORAGE) && (stor->storage_status == 1) ) { // storage not full & storage open
if(index>=0 && index<MAX_INVENTORY) { // valid index
if( (amount <= sd->status.inventory[index].amount) && (amount > 0) ) { //valid amount
+// log_tostorage(sd, index, 1);
if(guild_storage_additem(sd,stor,&sd->status.inventory[index],amount)==0)
// remove item from inventory
pc_delitem(sd,index,amount,0);
@@ -487,14 +566,15 @@ int storage_guild_storageget(struct map_session_data *sd,int index,int amount)
nullpo_retr(0, sd);
- if((stor=guild2storage(sd->status.guild_id)) != NULL) {
+ if((stor=guild2storage2(sd->status.guild_id)) != NULL) {
if(stor->storage_status == 1) { // storage open
if(index>=0 && index<MAX_GUILD_STORAGE) { // valid index
- if( (amount <= stor->storage[index].amount) && (amount > 0) ) { //valid amount
- if((flag = pc_additem(sd,&stor->storage[index],amount)) == 0)
+ if( (amount <= stor->storage_[index].amount) && (amount > 0) ) { //valid amount
+ if((flag = pc_additem(sd,&stor->storage_[index],amount)) == 0)
guild_storage_delitem(sd,stor,index,amount);
else
clif_additem(sd,0,0,flag);
+// log_fromstorage(sd, index, 1);
} // valid amount
}// valid index
}// storage open
@@ -509,7 +589,7 @@ int storage_guild_storageaddfromcart(struct map_session_data *sd,int index,int a
nullpo_retr(0, sd);
- if((stor=guild2storage(sd->status.guild_id)) != NULL) {
+ if((stor=guild2storage2(sd->status.guild_id)) != NULL) {
if( (stor->storage_amount <= MAX_GUILD_STORAGE) && (stor->storage_status == 1) ) { // storage not full & storage open
if(index>=0 && index<MAX_INVENTORY) { // valid index
if( (amount <= sd->status.cart[index].amount) && (amount > 0) ) { //valid amount
@@ -529,11 +609,11 @@ int storage_guild_storagegettocart(struct map_session_data *sd,int index,int amo
nullpo_retr(0, sd);
- if((stor=guild2storage(sd->status.guild_id)) != NULL) {
+ if((stor=guild2storage2(sd->status.guild_id)) != NULL) {
if(stor->storage_status == 1) { // storage open
if(index>=0 && index<MAX_GUILD_STORAGE) { // valid index
- if( (amount <= stor->storage[index].amount) && (amount > 0) ) { //valid amount
- if(pc_cart_additem(sd,&stor->storage[index],amount)==0){
+ if( (amount <= stor->storage_[index].amount) && (amount > 0) ) { //valid amount
+ if(pc_cart_additem(sd,&stor->storage_[index],amount)==0){
guild_storage_delitem(sd,stor,index,amount);
}
} // valid amount
@@ -544,19 +624,45 @@ int storage_guild_storagegettocart(struct map_session_data *sd,int index,int amo
return 0;
}
+int storage_guild_storagesave(int account_id, int guild_id)
+{
+ struct guild_storage *stor = guild2storage2(guild_id);
+
+ if(stor && stor->dirty)
+ {
+ intif_send_guild_storage(account_id,stor);
+ return 1;
+ }
+ return 0;
+}
+
+int storage_guild_storagesaved(int account_id, int guild_id)
+{
+ struct guild_storage *stor;
+
+ if((stor=guild2storage2(guild_id)) != NULL) {
+ if (stor->dirty && stor->storage_status == 0)
+ { //Storage has been correctly saved.
+ stor->dirty = 0;
+ sortage_gsortitem(stor);
+ }
+ return 1;
+ }
+ return 0;
+}
+
int storage_guild_storageclose(struct map_session_data *sd)
{
struct guild_storage *stor;
nullpo_retr(0, sd);
+ nullpo_retr(0, stor=guild2storage2(sd->status.guild_id));
- if((stor=guild2storage(sd->status.guild_id)) != NULL) {
- intif_send_guild_storage(sd->status.account_id,stor);
- stor->storage_status = 0;
- sd->state.storage_flag = 0;
- sortage_gsortitem(stor);
- }
clif_storageclose(sd);
+ chrif_save(sd); //This one also saves the storage. [Skotlex]
+
+ stor->storage_status=0;
+ sd->state.storage_flag = 0;
return 0;
}
@@ -566,14 +672,16 @@ int storage_guild_storage_quit(struct map_session_data *sd,int flag)
struct guild_storage *stor;
nullpo_retr(0, sd);
+ nullpo_retr(0, stor=guild2storage2(sd->status.guild_id));
- stor = numdb_search(guild_storage_db,sd->status.guild_id);
- if(stor) {
- if(!flag)
- intif_send_guild_storage(sd->status.account_id,stor);
- stor->storage_status = 0;
- sd->state.storage_flag = 0;
- }
+ sd->state.storage_flag = 0;
+ stor->storage_status = 0;
+ chrif_save(sd);
+ if(!flag) //Only during a guild break flag is 1.
+ storage_guild_storagesave(sd->status.account_id,sd->status.guild_id);
+ else //When the guild was broken, close the storage of he who has it open.
+ clif_storageclose(sd);
+
return 0;
}