diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-07-13 11:21:33 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-07-13 11:21:33 +0000 |
commit | 19acefafcb2677030a84ed3e39383c0a25c2047b (patch) | |
tree | 784834075263847f932bbdb06c547af153f5e037 /src | |
parent | aa5eb06a2b9087d8765c4e42f3a748259b995315 (diff) | |
download | hercules-19acefafcb2677030a84ed3e39383c0a25c2047b.tar.gz hercules-19acefafcb2677030a84ed3e39383c0a25c2047b.tar.bz2 hercules-19acefafcb2677030a84ed3e39383c0a25c2047b.tar.xz hercules-19acefafcb2677030a84ed3e39383c0a25c2047b.zip |
storage code cleanup (no behavioral changes yet)
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12948 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/char/int_storage.c | 94 | ||||
-rw-r--r-- | src/map/charcommand.c | 2 | ||||
-rw-r--r-- | src/map/chrif.c | 6 | ||||
-rw-r--r-- | src/map/clif.c | 128 | ||||
-rw-r--r-- | src/map/clif.h | 16 | ||||
-rw-r--r-- | src/map/intif.c | 4 | ||||
-rw-r--r-- | src/map/storage.c | 154 | ||||
-rw-r--r-- | src/map/storage.h | 5 |
8 files changed, 207 insertions, 202 deletions
diff --git a/src/char/int_storage.c b/src/char/int_storage.c index bb539b411..a1b4d33f1 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -24,19 +24,20 @@ char storage_txt[1024]="save/storage.txt"; char guild_storage_txt[1024]="save/g_storage.txt"; #ifndef TXT_SQL_CONVERT -static DBMap* storage_db; // int account_id -> struct storage* +static DBMap* storage_db; // int account_id -> struct storage_data* static DBMap* guild_storage_db; // int guild_id -> struct guild_storage* // 倉庫データを文字列に変換 -int storage_tostr(char *str,struct storage_data *p) +int storage_tostr(char* str, struct storage_data* p) { int i,j,f=0; char *str_p = str; str_p += sprintf(str_p,"%d,%d\t",p->account_id,p->storage_amount); for(i=0;i<MAX_STORAGE;i++) - if( (p->items[i].nameid) && (p->items[i].amount) ){ - str_p += sprintf(str_p,"%d,%d,%d,%d,%d,%d,%d", + if( (p->items[i].nameid) && (p->items[i].amount) ) + { + str_p += sprintf(str_p, "%d,%d,%d,%d,%d,%d,%d", p->items[i].id,p->items[i].nameid,p->items[i].amount,p->items[i].equip, p->items[i].identify,p->items[i].refine,p->items[i].attribute); for(j=0; j<MAX_SLOTS; j++) @@ -50,11 +51,13 @@ int storage_tostr(char *str,struct storage_data *p) *str_p='\0'; if(!f) str[0]=0; + return 0; } #endif //TXT_SQL_CONVERT + // 文字列を倉庫データに変換 -int storage_fromstr(char *str,struct storage_data *p) +int storage_fromstr(char* str, struct storage_data* p) { int tmp_int[256]; char tmp_str[256]; @@ -68,7 +71,8 @@ int storage_fromstr(char *str,struct storage_data *p) if(str[next]=='\n' || str[next]=='\r') return 0; next++; - for(i=0;str[next] && str[next]!='\t' && i < MAX_STORAGE;i++){ + for(i=0;str[next] && str[next]!='\t' && i < MAX_STORAGE;i++) + { if(sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d%[0-9,-]%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], tmp_str, &len) == 8) { @@ -93,6 +97,7 @@ int storage_fromstr(char *str,struct storage_data *p) ShowWarning("storage_fromstr: Found a storage line with more items than MAX_STORAGE (%d), remaining items have been discarded!\n", MAX_STORAGE); return 0; } + #ifndef TXT_SQL_CONVERT int guild_storage_tostr(char *str,struct guild_storage *p) { @@ -119,6 +124,7 @@ int guild_storage_tostr(char *str,struct guild_storage *p) return 0; } #endif //TXT_SQL_CONVERT + int guild_storage_fromstr(char *str,struct guild_storage *p) { int tmp_int[256]; @@ -157,8 +163,10 @@ int guild_storage_fromstr(char *str,struct guild_storage *p) ShowWarning("guild_storage_fromstr: Found a storage line with more items than MAX_GUILD_STORAGE (%d), remaining items have been discarded!\n", MAX_GUILD_STORAGE); return 0; } + #ifndef TXT_SQL_CONVERT -static void* create_storage(DBKey key, va_list args) { +static void* create_storage(DBKey key, va_list args) +{ struct storage_data *s; s = (struct storage_data *) aCalloc(sizeof(struct storage_data), 1); s->account_id=key.i; @@ -168,13 +176,11 @@ static void* create_storage(DBKey key, va_list args) { // アカウントから倉庫データインデックスを得る(新規倉庫追加可能) struct storage_data *account2storage(int account_id) { - struct storage_data *s; - s = (struct storage_data*)idb_ensure(storage_db, account_id, create_storage); - return s; + return (struct storage_data*)idb_ensure(storage_db, account_id, create_storage); } static void* create_guildstorage(DBKey key, va_list args) { - struct guild_storage *gs = NULL; + struct guild_storage* gs = NULL; gs = (struct guild_storage *) aCalloc(sizeof(struct guild_storage), 1); gs->guild_id=key.i; return gs; @@ -182,7 +188,7 @@ static void* create_guildstorage(DBKey key, va_list args) { struct guild_storage *guild2storage(int guild_id) { - struct guild_storage *gs = NULL; + struct guild_storage* gs = NULL; if(inter_guild_search(guild_id) != NULL) gs = (struct guild_storage*)idb_ensure(guild_storage_db, guild_id, create_guildstorage); return gs; @@ -213,7 +219,6 @@ int inter_storage_init() ShowFatalError("int_storage: out of memory!\n"); exit(EXIT_FAILURE); } -// memset(s,0,sizeof(struct storage)); aCalloc does this... s->account_id=tmp_int; if(s->account_id > 0 && storage_fromstr(line,s) == 0) { idb_put(storage_db,s->account_id,s); @@ -264,54 +269,59 @@ void inter_storage_final() { return; } -int inter_storage_save_sub(DBKey key,void *data,va_list ap) -{ - char line[65536]; - FILE *fp; - storage_tostr(line,(struct storage_data *)data); - fp=va_arg(ap,FILE *); - if(*line) - fprintf(fp,"%s\n",line); - return 0; -} //--------------------------------------------------------- // 倉庫データを書き込む int inter_storage_save() { + struct DBIterator* iter; + struct storage_data* data; FILE *fp; int lock; if( (fp=lock_fopen(storage_txt,&lock))==NULL ){ ShowError("int_storage: can't write [%s] !!! data is lost !!!\n",storage_txt); return 1; } - storage_db->foreach(storage_db,inter_storage_save_sub,fp); + + iter = storage_db->iterator(storage_db); + for( data = (struct storage_data*)iter->first(iter,NULL); iter->exists(iter); data = (struct storage_data*)iter->next(iter,NULL) ) + { + char line[65536]; + storage_tostr(line,data); + if(*line) + fprintf(fp,"%s\n",line); + } + iter->destroy(iter); + lock_fclose(fp,storage_txt,&lock); return 0; } -int inter_guild_storage_save_sub(DBKey key,void *data,va_list ap) -{ - char line[65536]; - FILE *fp; - if(inter_guild_search(((struct guild_storage *)data)->guild_id) != NULL) { - guild_storage_tostr(line,(struct guild_storage *)data); - fp=va_arg(ap,FILE *); - if(*line) - fprintf(fp,"%s\n",line); - } - return 0; -} //--------------------------------------------------------- // 倉庫データを書き込む int inter_guild_storage_save() { + struct DBIterator* iter; + struct guild_storage* data; FILE *fp; int lock; if( (fp=lock_fopen(guild_storage_txt,&lock))==NULL ){ ShowError("int_storage: can't write [%s] !!! data is lost !!!\n",guild_storage_txt); return 1; } - guild_storage_db->foreach(guild_storage_db,inter_guild_storage_save_sub,fp); + + iter = guild_storage_db->iterator(guild_storage_db); + for( data = (struct guild_storage*)iter->first(iter,NULL); iter->exists(iter); data = (struct guild_storage*)iter->next(iter,NULL) ) + { + char line[65536]; + if(inter_guild_search(data->guild_id) != NULL) + { + guild_storage_tostr(line,data); + if(*line) + fprintf(fp,"%s\n",line); + } + } + iter->destroy(iter); + lock_fclose(fp,guild_storage_txt,&lock); return 0; } @@ -353,7 +363,7 @@ int inter_guild_storage_delete(int guild_id) int mapif_load_storage(int fd,int account_id) { struct storage_data *s=account2storage(account_id); - WFIFOHEAD(fd, sizeof(struct storage_data)+8); + WFIFOHEAD(fd, sizeof(struct storage_data)+8); WFIFOW(fd,0)=0x3810; WFIFOW(fd,2)=sizeof(struct storage_data)+8; WFIFOL(fd,4)=account_id; @@ -364,7 +374,7 @@ int mapif_load_storage(int fd,int account_id) // 倉庫データ保存完了送信 int mapif_save_storage_ack(int fd,int account_id) { - WFIFOHEAD(fd, 7); + WFIFOHEAD(fd,7); WFIFOW(fd,0)=0x3811; WFIFOL(fd,2)=account_id; WFIFOB(fd,6)=0; @@ -375,7 +385,7 @@ int mapif_save_storage_ack(int fd,int account_id) int mapif_load_guild_storage(int fd,int account_id,int guild_id) { struct guild_storage *gs=guild2storage(guild_id); - WFIFOHEAD(fd, sizeof(struct guild_storage)+12); + WFIFOHEAD(fd, sizeof(struct guild_storage)+12); WFIFOW(fd,0)=0x3818; if(gs) { WFIFOW(fd,2)=sizeof(struct guild_storage)+12; @@ -392,9 +402,10 @@ int mapif_load_guild_storage(int fd,int account_id,int guild_id) return 0; } + int mapif_save_guild_storage_ack(int fd,int account_id,int guild_id,int fail) { - WFIFOHEAD(fd, 11); + WFIFOHEAD(fd,11); WFIFOW(fd,0)=0x3819; WFIFOL(fd,2)=account_id; WFIFOL(fd,6)=guild_id; @@ -438,6 +449,7 @@ int mapif_parse_LoadGuildStorage(int fd) mapif_load_guild_storage(fd,RFIFOL(fd,2),RFIFOL(fd,6)); return 0; } + int mapif_parse_SaveGuildStorage(int fd) { struct guild_storage *gs; diff --git a/src/map/charcommand.c b/src/map/charcommand.c index 4ba77200a..7afcabc15 100644 --- a/src/map/charcommand.c +++ b/src/map/charcommand.c @@ -3205,7 +3205,7 @@ int charcommand_storeall(const int fd, struct map_session_data* sd, const char* if (pl_sd->status.inventory[i].amount) { if(pl_sd->status.inventory[i].equip != 0) pc_unequipitem(pl_sd, i, 3); - storage_storageadd(pl_sd, i, sd->status.inventory[i].amount); + storage_storageadd(pl_sd, i, sd->status.inventory[i].amount); } } storage_storageclose(pl_sd); diff --git a/src/map/chrif.c b/src/map/chrif.c index 87e174e49..57fef3863 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -484,9 +484,11 @@ int chrif_sendmapack(int fd) //If there are players online, send them to the char-server. [Skotlex] send_users_tochar(); - - //Re-save any storages that were modified in the disconnection time. [Skotlex] + + //Auth db reconnect handling auth_db->foreach(auth_db,chrif_reconnect); + + //Re-save any storages that were modified in the disconnection time. [Skotlex] do_reconnect_storage(); return 0; diff --git a/src/map/clif.c b/src/map/clif.c index b4e309184..21cf8d208 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -3184,124 +3184,107 @@ void clif_tradecompleted(struct map_session_data* sd, int fail) /*========================================== * カプラ倉庫のアイテム数を更新 *------------------------------------------*/ -int clif_updatestorageamount(struct map_session_data *sd,struct storage_data *stor) +void clif_updatestorageamount(struct map_session_data* sd, int amount) { int fd; - nullpo_retr(0, sd); - nullpo_retr(0, stor); + nullpo_retv(sd); fd=sd->fd; WFIFOHEAD(fd,packet_len(0xf2)); WFIFOW(fd,0) = 0xf2; // update storage amount - WFIFOW(fd,2) = stor->storage_amount; //items + WFIFOW(fd,2) = amount; //items WFIFOW(fd,4) = MAX_STORAGE; //items max WFIFOSET(fd,packet_len(0xf2)); - - return 0; } /*========================================== * カプラ倉庫にアイテムを追加する *------------------------------------------*/ -int clif_storageitemadded(struct map_session_data *sd,struct storage_data *stor,int index,int amount) +void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount) { int view,fd; - nullpo_retr(0, sd); - nullpo_retr(0, stor); + nullpo_retv(sd); + nullpo_retv(i); fd=sd->fd; + view = itemdb_viewid(i->nameid); #if PACKETVER < 5 WFIFOHEAD(fd,packet_len(0xf4)); - WFIFOW(fd,0) =0xf4; // Storage item added - WFIFOW(fd,2) =index+1; // index - WFIFOL(fd,4) =amount; // amount - if((view = itemdb_viewid(stor->items[index].nameid)) > 0) - WFIFOW(fd,8) =view; - else - WFIFOW(fd,8) =stor->items[index].nameid; // id - WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag - WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute - WFIFOB(fd,12)=stor->storage_[index].refine; //refine - clif_addcards(WFIFOP(fd,13), &stor->items[index]); + WFIFOW(fd, 0) = 0xf4; // Storage item added + WFIFOW(fd, 2) = index+1; // index + WFIFOL(fd, 4) = amount; // amount + WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id + WFIFOB(fd,10) = i->identify; //identify flag + WFIFOB(fd,11) = i->attribute; // attribute + WFIFOB(fd,12) = i->refine; //refine + clif_addcards(WFIFOP(fd,13), i); WFIFOSET(fd,packet_len(0xf4)); #else WFIFOHEAD(fd,packet_len(0x1c4)); - WFIFOW(fd,0) =0x1c4; // Storage item added - WFIFOW(fd,2) =index+1; // index - WFIFOL(fd,4) =amount; // amount - if((view = itemdb_viewid(stor->items[index].nameid)) > 0) - WFIFOW(fd,8) =view; - else - WFIFOW(fd,8) =stor->items[index].nameid; // id - WFIFOB(fd,10)=itemdb_type(stor->items[index].nameid); //type - WFIFOB(fd,11)=stor->items[index].identify; //identify flag - WFIFOB(fd,12)=stor->items[index].attribute; // attribute - WFIFOB(fd,13)=stor->items[index].refine; //refine - clif_addcards(WFIFOP(fd,14), &stor->items[index]); + WFIFOW(fd, 0) = 0x1c4; // Storage item added + WFIFOW(fd, 2) = index+1; // index + WFIFOL(fd, 4) = amount; // amount + WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id + WFIFOB(fd,10) = itemdb_type(i->nameid); //type + WFIFOB(fd,11) = i->identify; //identify flag + WFIFOB(fd,12) = i->attribute; // attribute + WFIFOB(fd,13) = i->refine; //refine + clif_addcards(WFIFOP(fd,14), i); WFIFOSET(fd,packet_len(0x1c4)); #endif - - return 0; } /*========================================== * *------------------------------------------*/ -int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor) +void clif_updateguildstorageamount(struct map_session_data* sd, int amount) { int fd; - nullpo_retr(0, sd); - nullpo_retr(0, stor); + nullpo_retv(sd); fd=sd->fd; WFIFOHEAD(fd,packet_len(0xf2)); WFIFOW(fd,0) = 0xf2; // update storage amount - WFIFOW(fd,2) = stor->storage_amount; //items + WFIFOW(fd,2) = amount; //items WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max WFIFOSET(fd,packet_len(0xf2)); - - return 0; } /*========================================== * *------------------------------------------*/ -int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount) +void clif_guildstorageitemadded(struct map_session_data* sd, struct item* i, int index, int amount) { int view,fd; - nullpo_retr(0, sd); - nullpo_retr(0, stor); - + nullpo_retv(sd); + nullpo_retv(i); fd=sd->fd; + view = itemdb_viewid(i->nameid); + WFIFOHEAD(fd,packet_len(0xf4)); - WFIFOW(fd,0) =0xf4; // Storage item added - WFIFOW(fd,2) =index+1; // index - WFIFOL(fd,4) =amount; // amount - if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0) - WFIFOW(fd,8) =view; - else - WFIFOW(fd,8) =stor->storage_[index].nameid; // id - WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag - WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute - WFIFOB(fd,12)=stor->storage_[index].refine; //refine - clif_addcards(WFIFOP(fd,13), &stor->storage_[index]); + WFIFOW(fd, 0) = 0xf4; // Storage item added + WFIFOW(fd, 2) = index+1; // index + WFIFOL(fd, 4) = amount; // amount + WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id + WFIFOB(fd,10) = i->identify; //identify flag + WFIFOB(fd,11) = i->attribute; // attribute + WFIFOB(fd,12) = i->refine; //refine + clif_addcards(WFIFOP(fd,13), i); WFIFOSET(fd,packet_len(0xf4)); - - return 0; } /*========================================== * カプラ倉庫からアイテムを取り去る *------------------------------------------*/ -int clif_storageitemremoved(struct map_session_data *sd,int index,int amount) +void clif_storageitemremoved(struct map_session_data* sd, int index, int amount) { int fd; - nullpo_retr(0, sd); + nullpo_retv(sd); fd=sd->fd; WFIFOHEAD(fd,packet_len(0xf6)); @@ -3309,25 +3292,21 @@ int clif_storageitemremoved(struct map_session_data *sd,int index,int amount) WFIFOW(fd,2)=index+1; WFIFOL(fd,4)=amount; WFIFOSET(fd,packet_len(0xf6)); - - return 0; } /*========================================== * カプラ倉庫を閉じる *------------------------------------------*/ -int clif_storageclose(struct map_session_data *sd) +void clif_storageclose(struct map_session_data* sd) { int fd; - nullpo_retr(0, sd); + nullpo_retv(sd); fd=sd->fd; WFIFOHEAD(fd,packet_len(0xf8)); - WFIFOW(fd,0)=0xf8; // Storage Closed + WFIFOW(fd,0) = 0xf8; // Storage Closed WFIFOSET(fd,packet_len(0xf8)); - - return 0; } /*========================================== @@ -9696,7 +9675,8 @@ void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) if (sd->state.storage_flag == 1) storage_storageadd(sd, item_index, item_amount); - else if (sd->state.storage_flag == 2) + else + if (sd->state.storage_flag == 2) storage_guild_storageadd(sd, item_index, item_amount); } @@ -9712,7 +9692,8 @@ void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) if (sd->state.storage_flag == 1) storage_storageget(sd, item_index, item_amount); - else if(sd->state.storage_flag == 2) + else + if(sd->state.storage_flag == 2) storage_guild_storageget(sd, item_index, item_amount); } @@ -9725,9 +9706,11 @@ void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) return; if (!pc_iscarton(sd)) return; + if (sd->state.storage_flag == 1) storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4)); - else if (sd->state.storage_flag == 2) + else + if (sd->state.storage_flag == 2) storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4)); } @@ -9740,9 +9723,11 @@ void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) return; if (!pc_iscarton(sd)) return; + if (sd->state.storage_flag == 1) storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4)); - else if (sd->state.storage_flag == 2) + else + if (sd->state.storage_flag == 2) storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4)); } @@ -9753,7 +9738,8 @@ void clif_parse_CloseKafra(int fd, struct map_session_data *sd) { if (sd->state.storage_flag == 1) storage_storageclose(sd); - else if (sd->state.storage_flag == 2) + else + if (sd->state.storage_flag == 2) storage_guild_storageclose(sd); } diff --git a/src/map/clif.h b/src/map/clif.h index 500c385af..f3ad31fbe 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -192,14 +192,14 @@ void clif_tradecompleted(struct map_session_data* sd, int fail); // storage #include "storage.h" -void clif_storagelist(struct map_session_data *sd,struct storage_data *stor); -int clif_updatestorageamount(struct map_session_data *sd,struct storage_data *stor); -int clif_storageitemadded(struct map_session_data *sd,struct storage_data *stor,int index,int amount); -int clif_storageitemremoved(struct map_session_data *sd,int index,int amount); -int clif_storageclose(struct map_session_data *sd); -void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor); -int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor); -int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount); +void clif_storagelist(struct map_session_data* sd, struct storage_data* stor); +void clif_updatestorageamount(struct map_session_data* sd, int amount); +void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount); +void clif_storageitemremoved(struct map_session_data* sd, int index, int amount); +void clif_storageclose(struct map_session_data* sd); +void clif_guildstoragelist(struct map_session_data* sd, struct guild_storage* stor); +void clif_updateguildstorageamount(struct map_session_data* sd, int amount); +void clif_guildstorageitemadded(struct map_session_data* sd, struct item* i, int index, int amount); int clif_insight(struct block_list *,va_list); // map_forallinmovearea callback int clif_outsight(struct block_list *,va_list); // map_forallinmovearea callback diff --git a/src/map/intif.c b/src/map/intif.c index 99e054119..705171f7f 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -1001,7 +1001,7 @@ int intif_parse_LoadStorage(int fd) stor->storage_status=1; sd->state.storage_flag = 1; clif_storagelist(sd,stor); - clif_updatestorageamount(sd,stor); + clif_updatestorageamount(sd,stor->storage_amount); return 0; } @@ -1053,7 +1053,7 @@ int intif_parse_LoadGuildStorage(int fd) gstor->storage_status = 1; sd->state.storage_flag = 2; clif_guildstoragelist(sd,gstor); - clif_updateguildstorageamount(sd,gstor); + clif_updateguildstorageamount(sd,gstor->storage_amount); return 0; } int intif_parse_SaveGuildStorage(int fd) diff --git a/src/map/storage.c b/src/map/storage.c index eb6ce0363..964d3008c 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -30,7 +30,7 @@ static DBMap* guild_storage_db; // int guild_id -> struct guild_storage* /*========================================== * 倉庫内アイテムソート *------------------------------------------*/ -int storage_comp_item(const void *_i1, const void *_i2) +static int storage_comp_item(const void *_i1, const void *_i2) { struct item *i1 = (struct item *)_i1; struct item *i2 = (struct item *)_i2; @@ -44,13 +44,13 @@ int storage_comp_item(const void *_i1, const void *_i2) return i1->nameid - i2->nameid; } -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); } -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); @@ -90,7 +90,7 @@ static int storage_reconnect_sub(DBKey key,void *data,va_list ap) return 0; } -//Function to be invoked upon server reconnection to char. To save all 'dirty' storages [Skotlex +//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); @@ -153,7 +153,7 @@ int storage_storageopen(struct map_session_data *sd) stor->storage_status = 1; sd->state.storage_flag = 1; clif_storagelist(sd,stor); - clif_updatestorageamount(sd,stor); + clif_updatestorageamount(sd,stor->storage_amount); return 0; } @@ -175,29 +175,32 @@ 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 storage_data* stor,struct item *item_data,int amount) { struct item_data *data; int i; - if(item_data->nameid <= 0 || amount <= 0) + if( item_data->nameid <= 0 || amount <= 0 ) return 1; data = itemdb_search(item_data->nameid); - if (!itemdb_canstore(item_data, pc_isGM(sd))) + if( !itemdb_canstore(item_data, pc_isGM(sd)) ) { //Check if item is storable. [Skotlex] clif_displaymessage (sd->fd, msg_txt(264)); return 1; } - if(itemdb_isstackable2(data)){ //Stackable - for(i=0;i<MAX_STORAGE;i++){ - if( compare_item (&stor->items[i], item_data)) { - if(amount > MAX_AMOUNT - stor->items[i].amount) + if( itemdb_isstackable2(data) ) + {//Stackable + for( i = 0; i < MAX_STORAGE; i++ ) + { + 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; - clif_storageitemadded(sd,stor,i,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); @@ -205,69 +208,73 @@ static int storage_additem(struct map_session_data *sd,struct storage_data *stor } } } - //Add item - for(i=0;i<MAX_STORAGE && stor->items[i].nameid;i++); - - if(i>=MAX_STORAGE) + + // find free slot + ARR_FIND( 0, MAX_STORAGE, i, stor->items[i].nameid == 0 ); + if( i >= MAX_STORAGE ) return 1; + // add item to slot memcpy(&stor->items[i],item_data,sizeof(stor->items[0])); stor->items[i].amount=amount; stor->storage_amount++; - clif_storageitemadded(sd,stor,i,amount); - clif_updatestorageamount(sd,stor); + 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); + return 0; } + /*========================================== * 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, struct storage_data* stor, int n, int amount) { - - if(stor->items[n].nameid==0 || stor->items[n].amount<amount) + if( stor->items[n].nameid == 0 || stor->items[n].amount < amount ) return 1; - stor->items[n].amount-=amount; - if(log_config.enable_logs&0x800) + stor->items[n].amount -= amount; + + if( log_config.enable_logs&0x800 ) log_pick_pc(sd, "R", stor->items[n].nameid, amount, &stor->items[n]); - if(stor->items[n].amount==0){ + + if( stor->items[n].amount == 0 ) + { memset(&stor->items[n],0,sizeof(stor->items[0])); stor->storage_amount--; - clif_updatestorageamount(sd,stor); + clif_updatestorageamount(sd,stor->storage_amount); } clif_storageitemremoved(sd,n,amount); stor->dirty = 1; return 0; } + /*========================================== * Add an item to the storage from the inventory. *------------------------------------------*/ -int storage_storageadd(struct map_session_data *sd,int index,int amount) +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) + if( stor->storage_amount > MAX_STORAGE || !stor->storage_status ) return 0; // storage full / storage closed - if(index<0 || index>=MAX_INVENTORY) + if( index < 0 || index >= MAX_INVENTORY ) return 0; - if(sd->status.inventory[index].nameid <= 0) + if( sd->status.inventory[index].nameid <= 0 ) return 0; //No item on that spot - if(amount < 1 || amount > sd->status.inventory[index].amount) + if( amount < 1 || amount > sd->status.inventory[index].amount ) return 0; -// log_tostorage(sd, index, 0); - if(storage_additem(sd,stor,&sd->status.inventory[index],amount)==0) - // remove item from inventory + if( storage_additem(sd,stor,&sd->status.inventory[index],amount) == 0 ) pc_delitem(sd,index,amount,0); return 1; @@ -276,7 +283,7 @@ int storage_storageadd(struct map_session_data *sd,int index,int amount) /*========================================== * Retrieve an item from the storage. *------------------------------------------*/ -int storage_storageget(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; @@ -285,45 +292,46 @@ int storage_storageget(struct map_session_data *sd,int index,int amount) nullpo_retr(0, stor=account2storage2(sd->status.account_id)); - if(index<0 || index>=MAX_STORAGE) + if( index < 0 || index >= MAX_STORAGE ) return 0; - if(stor->items[index].nameid <= 0) + if( stor->items[index].nameid <= 0 ) return 0; //Nothing there - if(amount < 1 || amount > stor->items[index].amount) + if( amount < 1 || amount > stor->items[index].amount ) return 0; - if((flag = pc_additem(sd,&stor->items[index],amount)) == 0) + if( (flag = pc_additem(sd,&stor->items[index],amount)) == 0 ) storage_delitem(sd,stor,index,amount); else clif_additem(sd,0,0,flag); -// log_fromstorage(sd, index, 0); + return 1; } + /*========================================== * Move an item from cart to storage. *------------------------------------------*/ -int storage_storageaddfromcart(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( stor->storage_amount > MAX_STORAGE || !stor->storage_status ) return 0; // storage full / storage closed - if(index< 0 || index>=MAX_CART) + if( index < 0 || index >= MAX_CART ) return 0; - if(sd->status.cart[index].nameid <= 0) + if( sd->status.cart[index].nameid <= 0 ) return 0; //No item there. - if(amount < 1 || amount > sd->status.cart[index].amount) + 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,stor,&sd->status.cart[index],amount) == 0 ) pc_cart_delitem(sd,index,amount,0); return 1; @@ -332,26 +340,26 @@ int storage_storageaddfromcart(struct map_session_data *sd,int index,int amount) /*========================================== * Get from Storage to the Cart *------------------------------------------*/ -int storage_storagegettocart(struct map_session_data *sd,int index,int amount) +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) + if( !stor->storage_status ) return 0; - if(index< 0 || index>=MAX_STORAGE) + if( index < 0 || index >= MAX_STORAGE ) return 0; - if(stor->items[index].nameid <= 0) + if( stor->items[index].nameid <= 0 ) return 0; //Nothing there. - if(amount < 1 || amount > stor->items[index].amount) + if( amount < 1 || amount > stor->items[index].amount ) return 0; - if(pc_cart_additem(sd,&stor->items[index],amount)==0) + if( pc_cart_additem(sd,&stor->items[index],amount) == 0 ) storage_delitem(sd,stor,index,amount); return 1; @@ -361,7 +369,7 @@ 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) +int storage_storageclose(struct map_session_data* sd) { struct storage_data *stor; @@ -376,22 +384,23 @@ int storage_storageclose(struct map_session_data *sd) else storage_storage_save(sd->status.account_id, 0); } - stor->storage_status=0; - sd->state.storage_flag=0; + stor->storage_status = 0; + sd->state.storage_flag = 0; + return 0; } /*========================================== * When quitting the game. *------------------------------------------*/ -int storage_storage_quit(struct map_session_data *sd, int flag) +int 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)); - if (stor->storage_status) + if( stor->storage_status ) { if (save_settings&4) chrif_save(sd, flag); //Invokes the storage saving as well. @@ -400,10 +409,11 @@ int storage_storage_quit(struct map_session_data *sd, int flag) } stor->storage_status = 0; sd->state.storage_flag = 0; + return 0; } -void storage_storage_dirty(struct map_session_data *sd) +void storage_storage_dirty(struct map_session_data* sd) { struct storage_data *stor; @@ -487,7 +497,7 @@ int guild_storage_delete(int guild_id) return 0; } -int storage_guild_storageopen(struct map_session_data *sd) +int storage_guild_storageopen(struct map_session_data* sd) { struct guild_storage *gstor; @@ -514,11 +524,11 @@ int storage_guild_storageopen(struct map_session_data *sd) gstor->storage_status = 1; sd->state.storage_flag = 2; clif_guildstoragelist(sd,gstor); - clif_updateguildstorageamount(sd,gstor); + clif_updateguildstorageamount(sd,gstor->storage_amount); return 0; } -int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor,struct item *item_data,int amount) +int guild_storage_additem(struct map_session_data* sd, struct guild_storage* stor, struct item* item_data, int amount) { struct item_data *data; int i; @@ -543,7 +553,7 @@ int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor if(stor->storage_[i].amount+amount > MAX_AMOUNT) return 1; stor->storage_[i].amount+=amount; - clif_guildstorageitemadded(sd,stor,i,amount); + clif_guildstorageitemadded(sd,&stor->storage_[i],i,amount); stor->dirty = 1; if(log_config.enable_logs&0x1000) log_pick_pc(sd, "G", item_data->nameid, -amount, item_data); @@ -560,15 +570,15 @@ int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor 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); + clif_guildstorageitemadded(sd,&stor->storage_[i],i,amount); + clif_updateguildstorageamount(sd,stor->storage_amount); stor->dirty = 1; if(log_config.enable_logs&0x1000) log_pick_pc(sd, "G", item_data->nameid, -amount, item_data); return 0; } -int guild_storage_delitem(struct map_session_data *sd,struct guild_storage *stor,int n,int amount) +int guild_storage_delitem(struct map_session_data* sd, struct guild_storage* stor, int n, int amount) { nullpo_retr(1, sd); nullpo_retr(1, stor); @@ -582,14 +592,14 @@ int guild_storage_delitem(struct map_session_data *sd,struct guild_storage *stor if(stor->storage_[n].amount==0){ memset(&stor->storage_[n],0,sizeof(stor->storage_[0])); stor->storage_amount--; - clif_updateguildstorageamount(sd,stor); + clif_updateguildstorageamount(sd,stor->storage_amount); } clif_storageitemremoved(sd,n,amount); stor->dirty = 1; return 0; } -int storage_guild_storageadd(struct map_session_data *sd,int index,int amount) +int storage_guild_storageadd(struct map_session_data* sd, int index, int amount) { struct guild_storage *stor; @@ -615,7 +625,7 @@ int storage_guild_storageadd(struct map_session_data *sd,int index,int amount) return 1; } -int storage_guild_storageget(struct map_session_data *sd,int index,int amount) +int storage_guild_storageget(struct map_session_data* sd, int index, int amount) { struct guild_storage *stor; int flag; @@ -644,7 +654,7 @@ int storage_guild_storageget(struct map_session_data *sd,int index,int amount) return 0; } -int storage_guild_storageaddfromcart(struct map_session_data *sd,int index,int amount) +int storage_guild_storageaddfromcart(struct map_session_data* sd, int index, int amount) { struct guild_storage *stor; @@ -669,7 +679,7 @@ int storage_guild_storageaddfromcart(struct map_session_data *sd,int index,int a return 1; } -int storage_guild_storagegettocart(struct map_session_data *sd,int index,int amount) +int storage_guild_storagegettocart(struct map_session_data* sd, int index, int amount) { struct guild_storage *stor; @@ -724,7 +734,7 @@ int storage_guild_storagesaved(int guild_id) return 0; } -int storage_guild_storageclose(struct map_session_data *sd) +int storage_guild_storageclose(struct map_session_data* sd) { struct guild_storage *stor; @@ -745,7 +755,7 @@ int storage_guild_storageclose(struct map_session_data *sd) return 0; } -int storage_guild_storage_quit(struct map_session_data *sd,int flag) +int storage_guild_storage_quit(struct map_session_data* sd, int flag) { struct guild_storage *stor; diff --git a/src/map/storage.h b/src/map/storage.h index 20257471a..221bc109d 100644 --- a/src/map/storage.h +++ b/src/map/storage.h @@ -41,9 +41,4 @@ int storage_guild_storage_quit(struct map_session_data *sd,int flag); int storage_guild_storagesave(int account_id, int guild_id, int flag); int storage_guild_storagesaved(int guild_id); //Ack from char server that guild store was saved. -int storage_comp_item(const void *_i1, const void *_i2); -//int storage_comp_item(const struct item* i1, const struct item* i2); -void storage_sortitem(struct storage_data* stor); -void storage_gsortitem(struct guild_storage* gstor); - #endif /* _STORAGE_H_ */ |