summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDennis Friis <peavey@inspircd.org>2009-06-24 23:20:16 +0200
committerDennis Friis <peavey@inspircd.org>2009-06-25 01:13:21 +0200
commit575164bfde702bc6239c61a51dafbf6df51b5120 (patch)
tree434fbdba25c70e86936efbb61c8fbff691febf39 /src
parent4f99e5d5f04cc89d69fa407360b3597f31ca7215 (diff)
downloadtmwa-575164bfde702bc6239c61a51dafbf6df51b5120.tar.gz
tmwa-575164bfde702bc6239c61a51dafbf6df51b5120.tar.bz2
tmwa-575164bfde702bc6239c61a51dafbf6df51b5120.tar.xz
tmwa-575164bfde702bc6239c61a51dafbf6df51b5120.zip
Storage cleanup, derived from ea stable
Diffstat (limited to 'src')
-rw-r--r--src/map/storage.c424
-rw-r--r--src/map/storage.h6
2 files changed, 230 insertions, 200 deletions
diff --git a/src/map/storage.c b/src/map/storage.c
index f02fd3b..a2f8cf2 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -1,4 +1,6 @@
-// $Id: storage.c,v 1.3 2004/09/25 02:05:22 MouseJstr Exp $
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -37,7 +39,21 @@ int storage_comp_item(const void *_i1, const void *_i2)
return -1;
return i1->nameid - i2->nameid;
}
-
+
+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 sortage_sortitem (struct storage *stor)
{
nullpo_retv(stor);
@@ -60,24 +76,12 @@ 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);
+ if (storage_db)
+ numdb_final(storage_db,storage_db_final);
+ if (guild_storage_db)
+ numdb_final(guild_storage_db,guild_storage_db_final);
}
@@ -139,86 +143,75 @@ 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);
-//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 && sd->state.storage_flag == 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
+ if(sd->state.storage_flag)
+ return 1; //Already open?
+
+ if((stor = (struct storage *) numdb_search(storage_db,sd->status.account_id)) == NULL)
+ { //Request storage.
intif_request_storage(sd->status.account_id);
+ return 1;
+ }
- return 1;
+ if (stor->storage_status)
+ return 1; //Already open/player already has it open...
+
+ stor->storage_status = 1;
+ sd->state.storage_flag = 1;
+ clif_storageitemlist(sd,stor);
+ clif_storageequiplist(sd,stor);
+ clif_updatestorageamount(sd,stor);
+ return 0;
}
/*==========================================
- * カプラ倉庫へアイテム追加
+ * Internal add-item function.
*------------------------------------------
*/
-int storage_additem(struct map_session_data *sd,struct storage *stor,struct item *item_data,int amount)
+static int storage_additem(struct map_session_data *sd,struct storage *stor,struct item *item_data,int amount)
{
struct item_data *data;
int i;
- nullpo_retr(1, sd);
- nullpo_retr(1, stor);
- nullpo_retr(1, item_data);
-
if(item_data->nameid <= 0 || amount <= 0)
return 1;
- nullpo_retr(1, data = itemdb_search(item_data->nameid));
- i=MAX_STORAGE;
- if(!itemdb_isequip2(data)){
- // 装備品ではないので、既所有品なら個数のみ変化させる
+ data = itemdb_search(item_data->nameid);
+
+ if(!itemdb_isequip2(data)){ //Stackable
for(i=0;i<MAX_STORAGE;i++){
if( compare_item (&stor->storage_[i], item_data)) {
- if(stor->storage_[i].amount+amount > MAX_AMOUNT)
+ if(amount > MAX_AMOUNT - stor->storage_[i].amount)
return 1;
stor->storage_[i].amount+=amount;
clif_storageitemadded(sd,stor,i,amount);
- break;
- }
- }
- }
- 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;
- stor->storage_amount++;
- clif_storageitemadded(sd,stor,i,amount);
- clif_updatestorageamount(sd,stor);
- break;
+ stor->dirty = 1;
+ return 0;
}
}
- if(i>=MAX_STORAGE)
- return 1;
}
+ //Add item
+ for(i=0;i<MAX_STORAGE && stor->storage_[i].nameid;i++);
+ if(i>=MAX_STORAGE)
+ return 1;
+
+ 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);
stor->dirty = 1;
return 0;
}
/*==========================================
- * カプラ倉庫アイテムを減らす
+ * Internal del-item function
*------------------------------------------
*/
-int storage_delitem(struct map_session_data *sd,struct storage *stor,int n,int amount)
+static int storage_delitem(struct map_session_data *sd,struct storage *stor,int n,int amount)
{
- nullpo_retr(1, sd);
- nullpo_retr(1, stor);
if(stor->storage_[n].nameid==0 || stor->storage_[n].amount<amount)
return 1;
@@ -235,7 +228,7 @@ int storage_delitem(struct map_session_data *sd,struct storage *stor,int n,int a
return 0;
}
/*==========================================
- * カプラ倉庫へ入れる
+ * Add an item to the storage from the inventory.
*------------------------------------------
*/
int storage_storageadd(struct map_session_data *sd,int index,int amount)
@@ -245,22 +238,28 @@ int storage_storageadd(struct map_session_data *sd,int index,int amount)
nullpo_retr(0, sd);
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
-// 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
+ if((stor->storage_amount > MAX_STORAGE) || !stor->storage_status)
+ return 0; // storage full / storage closed
- return 0;
+ if(index<0 || index>=MAX_INVENTORY)
+ return 0;
+
+ if(sd->status.inventory[index].nameid <= 0)
+ return 0; //No item on that spot
+
+ 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
+ pc_delitem(sd,index,amount,0);
+
+ return 1;
}
/*==========================================
- * カプラ倉庫から出す
+ * Retrieve an item from the storage.
*------------------------------------------
*/
int storage_storageget(struct map_session_data *sd,int index,int amount)
@@ -271,22 +270,25 @@ int storage_storageget(struct map_session_data *sd,int index,int amount)
nullpo_retr(0, sd);
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)
- storage_delitem(sd,stor,index,amount);
- //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
- return 0;
+ if(index<0 || index>=MAX_STORAGE)
+ return 0;
+
+ if(stor->storage_[index].nameid <= 0)
+ return 0; //Nothing there
+
+ if(amount < 1 || amount > stor->storage_[index].amount)
+ return 0;
+
+ 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);
+ return 1;
}
/*==========================================
- * カプラ倉庫へカートから入れる
+ * Move an item from cart to storage.
*------------------------------------------
*/
int storage_storageaddfromcart(struct map_session_data *sd,int index,int amount)
@@ -296,20 +298,26 @@ int storage_storageaddfromcart(struct map_session_data *sd,int index,int amount)
nullpo_retr(0, sd);
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.cart[index].amount) && (amount > 0) ) { //valid amount
- if(storage_additem(sd,stor,&sd->status.cart[index],amount)==0)
- pc_cart_delitem(sd,index,amount,0);
- } // valid amount
- }// valid index
- }// storage not full & storage open
+ if(stor->storage_amount > MAX_STORAGE || !stor->storage_status)
+ return 0; // storage full / storage closed
- return 0;
+ if(index< 0 || index>=MAX_CART)
+ return 0;
+
+ if(sd->status.cart[index].nameid <= 0)
+ return 0; //No item there.
+
+ if(amount < 1 || amount > sd->status.cart[index].amount)
+ return 0;
+
+ if(storage_additem(sd,stor,&sd->status.cart[index],amount)==0)
+ pc_cart_delitem(sd,index,amount,0);
+
+ return 1;
}
/*==========================================
- * カプラ倉庫からカートへ出す
+ * Get from Storage to the Cart
*------------------------------------------
*/
int storage_storagegettocart(struct map_session_data *sd,int index,int amount)
@@ -319,17 +327,22 @@ int storage_storagegettocart(struct map_session_data *sd,int index,int amount)
nullpo_retr(0, sd);
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){
- storage_delitem(sd,stor,index,amount);
- }
- } // valid amount
- }// valid index
- }// storage open
+ if(!stor->storage_status)
+ return 0;
- return 0;
+ if(index< 0 || index>=MAX_STORAGE)
+ return 0;
+
+ if(stor->storage_[index].nameid <= 0)
+ return 0; //Nothing there.
+
+ if(amount < 1 || amount > stor->storage_[index].amount)
+ return 0;
+
+ if(pc_cart_additem(sd,&stor->storage_[index],amount)==0)
+ storage_delitem(sd,stor,index,amount);
+
+ return 1;
}
@@ -345,15 +358,16 @@ int storage_storageclose(struct map_session_data *sd)
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]
-
+ if (stor->storage_status)
+ chrif_save(sd); //This will invoke the storage save function as well. [Skotlex]
+
stor->storage_status=0;
- sd->state.storage_flag = 0;
+ sd->state.storage_flag=0;
return 0;
}
/*==========================================
- * ログアウト時開いているカプラ倉庫の保存
+ * When quitting the game.
*------------------------------------------
*/
int storage_storage_quit(struct map_session_data *sd)
@@ -400,7 +414,7 @@ int storage_storage_save(int account_id)
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)
@@ -436,7 +450,7 @@ struct guild_storage *guild2storage2(int guild_id)
return (struct guild_storage *) numdb_search(guild_storage_db,guild_id);
}
-int guild_storage_delete(int guild_id)
+int guild_storage_delete(int guild_id)
{
struct guild_storage *gstor = (struct guild_storage *) numdb_search(guild_storage_db,guild_id);
if(gstor) {
@@ -454,21 +468,22 @@ int storage_guild_storageopen(struct map_session_data *sd)
if(sd->status.guild_id <= 0)
return 2;
- if((gstor = guild2storage2(sd->status.guild_id)) != NULL) {
- if(gstor->storage_status)
- return 1;
- if(sd->state.storage_flag)
- return 1; //Can't open both storages at a time.
- gstor->storage_status = 1;
- sd->state.storage_flag = 2;
- clif_guildstorageitemlist(sd,gstor);
- clif_guildstorageequiplist(sd,gstor);
- clif_updateguildstorageamount(sd,gstor);
+
+ if(sd->state.storage_flag)
+ return 1; //Can't open both storages at a time.
+
+ if((gstor = guild2storage2(sd->status.guild_id)) == NULL) {
+ intif_request_guild_storage(sd->status.account_id,sd->status.guild_id);
return 0;
}
- else
- intif_request_guild_storage(sd->status.account_id,sd->status.guild_id);
+ if(gstor->storage_status)
+ return 1;
+ gstor->storage_status = 1;
+ sd->state.storage_flag = 2;
+ clif_guildstorageitemlist(sd,gstor);
+ clif_guildstorageequiplist(sd,gstor);
+ clif_updateguildstorageamount(sd,gstor);
return 0;
}
@@ -485,34 +500,29 @@ int guild_storage_additem(struct map_session_data *sd,struct guild_storage *stor
if(item_data->nameid <= 0 || amount <= 0)
return 1;
- i=MAX_GUILD_STORAGE;
- if(!itemdb_isequip2(data)){
- // 装備品ではないので、既所有品なら個数のみ変化させる
+ if(!itemdb_isequip2(data)){ //Stackable
for(i=0;i<MAX_GUILD_STORAGE;i++){
if(compare_item(&stor->storage_[i], item_data)) {
if(stor->storage_[i].amount+amount > MAX_AMOUNT)
return 1;
stor->storage_[i].amount+=amount;
clif_guildstorageitemadded(sd,stor,i,amount);
- break;
+ stor->dirty = 1;
+ return 0;
}
}
}
- 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;
- stor->storage_amount++;
- clif_guildstorageitemadded(sd,stor,i,amount);
- clif_updateguildstorageamount(sd,stor);
- break;
- }
- }
- if(i>=MAX_GUILD_STORAGE)
- return 1;
- }
+ //Add item
+ for(i=0;i<MAX_GUILD_STORAGE && stor->storage_[i].nameid;i++);
+
+ if(i>=MAX_GUILD_STORAGE)
+ return 1;
+
+ 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);
stor->dirty = 1;
return 0;
}
@@ -541,21 +551,25 @@ int storage_guild_storageadd(struct map_session_data *sd,int index,int amount)
struct guild_storage *stor;
nullpo_retr(0, sd);
+ nullpo_retr(0, stor=guild2storage2(sd->status.guild_id));
- 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);
- } // valid amount
- }// valid index
- }// storage not full & storage open
- }
+ if (!stor->storage_status || stor->storage_amount > MAX_GUILD_STORAGE)
+ return 0;
- return 0;
+ if(index<0 || index>=MAX_INVENTORY)
+ return 0;
+
+ if(sd->status.inventory[index].nameid <= 0)
+ return 0;
+
+ if(amount < 1 || amount > sd->status.inventory[index].amount)
+ return 0;
+
+// log_tostorage(sd, index, 1);
+ if(guild_storage_additem(sd,stor,&sd->status.inventory[index],amount)==0)
+ pc_delitem(sd,index,amount,0);
+
+ return 1;
}
int storage_guild_storageget(struct map_session_data *sd,int index,int amount)
@@ -564,20 +578,25 @@ int storage_guild_storageget(struct map_session_data *sd,int index,int amount)
int flag;
nullpo_retr(0, sd);
+ nullpo_retr(0, stor=guild2storage2(sd->status.guild_id));
- 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)
- 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
- }
+ if(!stor->storage_status)
+ return 0;
+
+ if(index<0 || index>=MAX_GUILD_STORAGE)
+ return 0;
+
+ if(stor->storage_[index].nameid <= 0)
+ return 0;
+
+ if(amount < 1 || amount > stor->storage_[index].amount)
+ return 0;
+
+ 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);
return 0;
}
@@ -587,19 +606,24 @@ int storage_guild_storageaddfromcart(struct map_session_data *sd,int index,int a
struct guild_storage *stor;
nullpo_retr(0, sd);
+ nullpo_retr(0, stor=guild2storage2(sd->status.guild_id));
- 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
- if(guild_storage_additem(sd,stor,&sd->status.cart[index],amount)==0)
- pc_cart_delitem(sd,index,amount,0);
- } // valid amount
- }// valid index
- }// storage not full & storage open
- }
+ if(!stor->storage_status || stor->storage_amount > MAX_GUILD_STORAGE)
+ return 0;
- return 0;
+ if(index<0 || index>=MAX_CART)
+ return 0;
+
+ if(sd->status.cart[index].nameid <= 0)
+ return 0;
+
+ if(amount < 1 || amount > sd->status.cart[index].amount)
+ return 0;
+
+ if(guild_storage_additem(sd,stor,&sd->status.cart[index],amount)==0)
+ pc_cart_delitem(sd,index,amount,0);
+
+ return 1;
}
int storage_guild_storagegettocart(struct map_session_data *sd,int index,int amount)
@@ -607,20 +631,24 @@ int storage_guild_storagegettocart(struct map_session_data *sd,int index,int amo
struct guild_storage *stor;
nullpo_retr(0, sd);
+ nullpo_retr(0, stor=guild2storage2(sd->status.guild_id));
- 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){
- guild_storage_delitem(sd,stor,index,amount);
- }
- } // valid amount
- }// valid index
- }// storage open
- }
+ if(!stor->storage_status)
+ return 0;
- return 0;
+ if(index<0 || index>=MAX_GUILD_STORAGE)
+ return 0;
+
+ if(stor->storage_[index].nameid<=0)
+ return 0;
+
+ if(amount < 1 || amount > stor->storage_[index].amount)
+ return 0;
+
+ if(pc_cart_additem(sd,&stor->storage_[index],amount)==0)
+ guild_storage_delitem(sd,stor,index,amount);
+
+ return 1;
}
int storage_guild_storagesave(int account_id, int guild_id)
@@ -681,6 +709,6 @@ int storage_guild_storage_quit(struct map_session_data *sd,int flag)
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;
}
diff --git a/src/map/storage.h b/src/map/storage.h
index 774937d..67966cf 100644
--- a/src/map/storage.h
+++ b/src/map/storage.h
@@ -1,8 +1,10 @@
-// $Id: storage.h,v 1.3 2004/09/25 05:32:19 MouseJstr Exp $
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+
#ifndef _STORAGE_H_
#define _STORAGE_H_
-#include "mmo.h"
+#include "../common/mmo.h"
int storage_storageopen(struct map_session_data *sd);
int storage_storageadd(struct map_session_data *sd,int index,int amount);