diff options
author | amber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2005-04-07 18:00:13 +0000 |
---|---|---|
committer | amber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2005-04-07 18:00:13 +0000 |
commit | 1a348ede4934a1ba78f337ee1dffe11a699f4bef (patch) | |
tree | 883d4c1ae282fb67e1720f81c20f564499298ff4 /src/map/storage.c | |
parent | 7cb0d361f1b4260b47ab1da99224332947320553 (diff) | |
parent | a6cd6538e4271ea08dc86803e8b7e8c8f235960b (diff) | |
download | hercules-1a348ede4934a1ba78f337ee1dffe11a699f4bef.tar.gz hercules-1a348ede4934a1ba78f337ee1dffe11a699f4bef.tar.bz2 hercules-1a348ede4934a1ba78f337ee1dffe11a699f4bef.tar.xz hercules-1a348ede4934a1ba78f337ee1dffe11a699f4bef.zip |
branch for major stability breakage
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@1440 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/storage.c')
-rw-r--r-- | src/map/storage.c | 207 |
1 files changed, 118 insertions, 89 deletions
diff --git a/src/map/storage.c b/src/map/storage.c index fc6f63cdd..82ecd9321 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -3,14 +3,18 @@ #include <stdlib.h> #include <string.h> -#include "db.h" +#include "../common/db.h" +#include "../common/nullpo.h" +#include "../common/malloc.h" + #include "itemdb.h" #include "clif.h" #include "intif.h" #include "pc.h" #include "storage.h" #include "guild.h" -#include "nullpo.h" +#include "battle.h" +#include "atcommand.h" #ifdef MEMWATCH #include "memwatch.h" @@ -42,13 +46,13 @@ struct item *i2=(struct item *)_i2; 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){ 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,17 +65,32 @@ int do_init_storage(void) // map.c::do_init()から呼ばれる guild_storage_db=numdb_init(); return 1; } - -void do_final_storage(void) // map.c::do_final()から呼ばれる +static int guild_storage_db_final(void *key,void *data,va_list ap) +{ + struct guild_storage *gstor=(struct guild_storage *) data; + aFree(gstor); + return 0; +} +static int storage_db_final(void *key,void *data,va_list ap) { + struct storage *stor=(struct storage *) data; + aFree(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); } struct storage *account2storage(int account_id) { struct storage *stor; - stor=numdb_search(storage_db,account_id); + stor=(struct storage *) numdb_search(storage_db,account_id); if(stor == NULL) { - stor = calloc(sizeof(struct storage), 1); + stor = (struct storage *) aCallocA(sizeof(struct storage), 1); if(stor == NULL){ printf("storage: out of memory!\n"); exit(0); @@ -85,15 +104,15 @@ struct storage *account2storage(int account_id) // Just to ask storage, without creation struct storage *account2storage2(int account_id) { - return numdb_search(storage_db, 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); + aFree(stor); } return 0; } @@ -108,38 +127,25 @@ int storage_storageopen(struct map_session_data *sd) 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; + if(pc_isGM(sd) && pc_isGM(sd) < battle_config.gm_can_drop_lv) { + clif_displaymessage(sd->fd, msg_txt(246)); + return 1; + } + 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 = 0; + clif_storageitemlist(sd,stor); + clif_storageequiplist(sd,stor); + clif_updatestorageamount(sd,stor); + return 0; + } } else intif_request_storage(sd->status.account_id); return 1; } -int storage_storageopen2(struct map_session_data *sd, struct map_session_data *pl_sd) -{ - struct storage *stor; - if(sd == NULL || pl_sd == NULL) - { - printf("storage_storageopen nullpo\n"); - return 0; - } - - if((stor = numdb_search(storage_db,pl_sd->status.account_id)) != NULL) - { - clif_storageitemlist(sd,stor); - clif_storageequiplist(sd,stor); - clif_updatestorageamount(sd,stor); - return 1; - } - return 0; -} - /*========================================== * カプラ倉庫へアイテム追加 *------------------------------------------ @@ -153,6 +159,8 @@ int storage_additem(struct map_session_data *sd,struct storage *stor,struct item nullpo_retr(1, stor); nullpo_retr(1, item_data); + stor->dirty = 1; + if(item_data->nameid <= 0 || amount <= 0) return 1; nullpo_retr(1, data = itemdb_search(item_data->nameid)); @@ -161,12 +169,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; } @@ -175,9 +181,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); @@ -187,6 +193,7 @@ int storage_additem(struct map_session_data *sd,struct storage *stor,struct item if(i>=MAX_STORAGE) return 1; } + return 0; } /*========================================== @@ -198,17 +205,19 @@ 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; } /*========================================== @@ -220,15 +229,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 @@ -245,15 +255,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); +// log_fromstorage(sd, index, 0); } // valid amount }// valid index }// storage open @@ -269,7 +280,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 @@ -292,12 +303,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 @@ -317,12 +328,14 @@ int storage_storageclose(struct map_session_data *sd) 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)); stor->storage_status=0; sd->state.storage_flag = 0; clif_storageclose(sd); + storage_storage_save(sd); + sortage_sortitem(stor); return 0; } @@ -337,20 +350,36 @@ 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 = (struct storage *) numdb_search(storage_db,sd->status.account_id); + if(stor) { + stor->storage_status = 0; + storage_storage_save(sd); + } return 0; } +void storage_storage_dirty(struct map_session_data *sd) +{ + struct storage *stor; + + stor=(struct storage *) numdb_search(storage_db,sd->status.account_id); + + if(stor) + stor->dirty = 1; +} + int storage_storage_save(struct map_session_data *sd) { struct storage *stor; nullpo_retr(0, sd); - stor=numdb_search(storage_db,sd->status.account_id); - if(stor) intif_send_storage(stor); + stor=(struct storage *) numdb_search(storage_db,sd->status.account_id); + if(stor && stor->dirty) { + intif_send_storage(stor); + stor->dirty = 0; + } return 0; } @@ -359,9 +388,9 @@ 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); @@ -375,10 +404,10 @@ struct guild_storage *guild2storage(int 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); + aFree(gstor); } return 0; } @@ -391,7 +420,7 @@ 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 = (struct guild_storage *) numdb_search(guild_storage_db,sd->status.guild_id)) != NULL) { if(gstor->storage_status) return 1; gstor->storage_status = 1; @@ -427,12 +456,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; } @@ -441,9 +468,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); @@ -461,12 +488,12 @@ 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); } @@ -485,6 +512,7 @@ int storage_guild_storageadd(struct map_session_data *sd,int index,int amount) 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); @@ -506,11 +534,12 @@ int storage_guild_storageget(struct map_session_data *sd,int index,int amount) if((stor=guild2storage(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 @@ -548,8 +577,8 @@ int storage_guild_storagegettocart(struct map_session_data *sd,int index,int amo if((stor=guild2storage(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 @@ -583,7 +612,7 @@ int storage_guild_storage_quit(struct map_session_data *sd,int flag) nullpo_retr(0, sd); - stor = numdb_search(guild_storage_db,sd->status.guild_id); + stor = (struct guild_storage *) numdb_search(guild_storage_db,sd->status.guild_id); if(stor) { if(!flag) intif_send_guild_storage(sd->status.account_id,stor); |