summaryrefslogtreecommitdiff
path: root/src/char_sql/int_storage.c
diff options
context:
space:
mode:
authoramber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-04-07 18:00:13 +0000
committeramber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-04-07 18:00:13 +0000
commit1a348ede4934a1ba78f337ee1dffe11a699f4bef (patch)
tree883d4c1ae282fb67e1720f81c20f564499298ff4 /src/char_sql/int_storage.c
parent7cb0d361f1b4260b47ab1da99224332947320553 (diff)
parenta6cd6538e4271ea08dc86803e8b7e8c8f235960b (diff)
downloadhercules-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/char_sql/int_storage.c')
-rw-r--r--src/char_sql/int_storage.c195
1 files changed, 86 insertions, 109 deletions
diff --git a/src/char_sql/int_storage.c b/src/char_sql/int_storage.c
index 18100e02a..c13c782a6 100644
--- a/src/char_sql/int_storage.c
+++ b/src/char_sql/int_storage.c
@@ -2,62 +2,46 @@
// original code from athena
// SQL conversion by Jioh L. Jung
//
-#include "char.h"
-#include "itemdb.h"
#include <string.h>
#include <stdlib.h>
+#include "char.h"
+#include "itemdb.h"
+
#define STORAGE_MEMINC 16
// reset by inter_config_read()
struct storage *storage_pt=NULL;
struct guild_storage *guild_storage_pt=NULL;
-
#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y)
// storage data -> DB conversion
int storage_tosql(int account_id,struct storage *p){
int i;
- int eqcount=1;
- int noteqcount=1;
- struct itemtemp mapitem;
+// int eqcount=1;
+// int noteqcount=1;
+ int count=0;
+ struct itemtmp mapitem[MAX_GUILD_STORAGE];
for(i=0;i<MAX_STORAGE;i++){
- if(p->storage[i].nameid>0){
- if(itemdb_isequip(p->storage[i].nameid)==1){
- mapitem.equip[eqcount].flag=0;
- mapitem.equip[eqcount].id = p->storage[i].id;
- mapitem.equip[eqcount].nameid=p->storage[i].nameid;
- mapitem.equip[eqcount].amount = p->storage[i].amount;
- mapitem.equip[eqcount].equip = p->storage[i].equip;
- mapitem.equip[eqcount].identify = p->storage[i].identify;
- mapitem.equip[eqcount].refine = p->storage[i].refine;
- mapitem.equip[eqcount].attribute = p->storage[i].attribute;
- mapitem.equip[eqcount].card[0] = p->storage[i].card[0];
- mapitem.equip[eqcount].card[1] = p->storage[i].card[1];
- mapitem.equip[eqcount].card[2] = p->storage[i].card[2];
- mapitem.equip[eqcount].card[3] = p->storage[i].card[3];
- eqcount++;
- }
- else if(itemdb_isequip(p->storage[i].nameid)==0){
- mapitem.notequip[noteqcount].flag=0;
- mapitem.notequip[noteqcount].id = p->storage[i].id;
- mapitem.notequip[noteqcount].nameid=p->storage[i].nameid;
- mapitem.notequip[noteqcount].amount = p->storage[i].amount;
- mapitem.notequip[noteqcount].equip = p->storage[i].equip;
- mapitem.notequip[noteqcount].identify = p->storage[i].identify;
- mapitem.notequip[noteqcount].refine = p->storage[i].refine;
- mapitem.notequip[noteqcount].attribute = p->storage[i].attribute;
- mapitem.notequip[noteqcount].card[0] = p->storage[i].card[0];
- mapitem.notequip[noteqcount].card[1] = p->storage[i].card[1];
- mapitem.notequip[noteqcount].card[2] = p->storage[i].card[2];
- mapitem.notequip[noteqcount].card[3] = p->storage[i].card[3];
- noteqcount++;
- }
+ if(p->storage_[i].nameid>0){
+ mapitem[count].flag=0;
+ mapitem[count].id = p->storage_[i].id;
+ mapitem[count].nameid=p->storage_[i].nameid;
+ mapitem[count].amount = p->storage_[i].amount;
+ mapitem[count].equip = p->storage_[i].equip;
+ mapitem[count].identify = p->storage_[i].identify;
+ mapitem[count].refine = p->storage_[i].refine;
+ mapitem[count].attribute = p->storage_[i].attribute;
+ mapitem[count].card[0] = p->storage_[i].card[0];
+ mapitem[count].card[1] = p->storage_[i].card[1];
+ mapitem[count].card[2] = p->storage_[i].card[2];
+ mapitem[count].card[3] = p->storage_[i].card[3];
+ count++;
}
}
- memitemdata_to_sql(mapitem, eqcount, noteqcount, account_id,TABLE_STORAGE);
+ memitemdata_to_sql(mapitem, count, account_id,TABLE_STORAGE);
//printf ("storage dump to DB - id: %d (total: %d)\n", account_id, j);
return 0;
@@ -66,36 +50,36 @@ int storage_tosql(int account_id,struct storage *p){
// DB -> storage data conversion
int storage_fromsql(int account_id, struct storage *p){
int i=0;
-
+
memset(p,0,sizeof(struct storage)); //clean up memory
p->storage_amount = 0;
p->account_id = account_id;
-
+
// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
sprintf(tmp_sql,"SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`card0`,`card1`,`card2`,`card3` FROM `%s` WHERE `account_id`='%d'",storage_db, account_id);
if(mysql_query(&mysql_handle, tmp_sql) ) {
printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
}
sql_res = mysql_store_result(&mysql_handle) ;
-
+
if (sql_res) {
while((sql_row = mysql_fetch_row(sql_res))) { //start to fetch
- p->storage[i].id= atoi(sql_row[0]);
- p->storage[i].nameid= atoi(sql_row[1]);
- p->storage[i].amount= atoi(sql_row[2]);
- p->storage[i].equip= atoi(sql_row[3]);
- p->storage[i].identify= atoi(sql_row[4]);
- p->storage[i].refine= atoi(sql_row[5]);
- p->storage[i].attribute= atoi(sql_row[6]);
- p->storage[i].card[0]= atoi(sql_row[7]);
- p->storage[i].card[1]= atoi(sql_row[8]);
- p->storage[i].card[2]= atoi(sql_row[9]);
- p->storage[i].card[3]= atoi(sql_row[10]);
+ p->storage_[i].id= atoi(sql_row[0]);
+ p->storage_[i].nameid= atoi(sql_row[1]);
+ p->storage_[i].amount= atoi(sql_row[2]);
+ p->storage_[i].equip= atoi(sql_row[3]);
+ p->storage_[i].identify= atoi(sql_row[4]);
+ p->storage_[i].refine= atoi(sql_row[5]);
+ p->storage_[i].attribute= atoi(sql_row[6]);
+ p->storage_[i].card[0]= atoi(sql_row[7]);
+ p->storage_[i].card[1]= atoi(sql_row[8]);
+ p->storage_[i].card[2]= atoi(sql_row[9]);
+ p->storage_[i].card[3]= atoi(sql_row[10]);
p->storage_amount = ++i;
}
mysql_free_result(sql_res);
}
-
+
printf ("storage load complete from DB - id: %d (total: %d)\n", account_id, p->storage_amount);
return 1;
}
@@ -103,45 +87,29 @@ int storage_fromsql(int account_id, struct storage *p){
// Save guild_storage data to sql
int guild_storage_tosql(int guild_id, struct guild_storage *p){
int i;
- int eqcount=1;
- int noteqcount=1;
- struct itemtemp mapitem;
+// int eqcount=1;
+// int noteqcount=1;
+ int count=0;
+ struct itemtmp mapitem[MAX_GUILD_STORAGE];
for(i=0;i<MAX_GUILD_STORAGE;i++){
- if(p->storage[i].nameid>0){
- if(itemdb_isequip(p->storage[i].nameid)==1){
- mapitem.equip[eqcount].flag=0;
- mapitem.equip[eqcount].id = p->storage[i].id;
- mapitem.equip[eqcount].nameid=p->storage[i].nameid;
- mapitem.equip[eqcount].amount = p->storage[i].amount;
- mapitem.equip[eqcount].equip = p->storage[i].equip;
- mapitem.equip[eqcount].identify = p->storage[i].identify;
- mapitem.equip[eqcount].refine = p->storage[i].refine;
- mapitem.equip[eqcount].attribute = p->storage[i].attribute;
- mapitem.equip[eqcount].card[0] = p->storage[i].card[0];
- mapitem.equip[eqcount].card[1] = p->storage[i].card[1];
- mapitem.equip[eqcount].card[2] = p->storage[i].card[2];
- mapitem.equip[eqcount].card[3] = p->storage[i].card[3];
- eqcount++;
- }
- else if(itemdb_isequip(p->storage[i].nameid)==0){
- mapitem.notequip[noteqcount].flag=0;
- mapitem.notequip[noteqcount].id = p->storage[i].id;
- mapitem.notequip[noteqcount].nameid=p->storage[i].nameid;
- mapitem.notequip[noteqcount].amount = p->storage[i].amount;
- mapitem.notequip[noteqcount].equip = p->storage[i].equip;
- mapitem.notequip[noteqcount].identify = p->storage[i].identify;
- mapitem.notequip[noteqcount].refine = p->storage[i].refine;
- mapitem.notequip[noteqcount].attribute = p->storage[i].attribute;
- mapitem.notequip[noteqcount].card[0] = p->storage[i].card[0];
- mapitem.notequip[noteqcount].card[1] = p->storage[i].card[1];
- mapitem.notequip[noteqcount].card[2] = p->storage[i].card[2];
- mapitem.notequip[noteqcount].card[3] = p->storage[i].card[3];
- noteqcount++;
- }
+ if(p->storage_[i].nameid>0){
+ mapitem[count].flag=0;
+ mapitem[count].id = p->storage_[i].id;
+ mapitem[count].nameid=p->storage_[i].nameid;
+ mapitem[count].amount = p->storage_[i].amount;
+ mapitem[count].equip = p->storage_[i].equip;
+ mapitem[count].identify = p->storage_[i].identify;
+ mapitem[count].refine = p->storage_[i].refine;
+ mapitem[count].attribute = p->storage_[i].attribute;
+ mapitem[count].card[0] = p->storage_[i].card[0];
+ mapitem[count].card[1] = p->storage_[i].card[1];
+ mapitem[count].card[2] = p->storage_[i].card[2];
+ mapitem[count].card[3] = p->storage_[i].card[3];
+ count++;
}
}
- memitemdata_to_sql(mapitem, eqcount, noteqcount, guild_id,TABLE_GUILD_STORAGE);
+ memitemdata_to_sql(mapitem, count, guild_id,TABLE_GUILD_STORAGE);
printf ("guild storage save to DB - id: %d (total: %d)\n", guild_id,i);
return 0;
@@ -163,21 +131,23 @@ int guild_storage_fromsql(int guild_id, struct guild_storage *p){
printf("DB server Error - %s\n", mysql_error(&mysql_handle) );
}
sql_res = mysql_store_result(&mysql_handle) ;
-
+
if (sql_res) {
while((sql_row = mysql_fetch_row(sql_res))) { //start to fetch
- p->storage[i].id= atoi(sql_row[0]);
- p->storage[i].nameid= atoi(sql_row[1]);
- p->storage[i].amount= atoi(sql_row[2]);
- p->storage[i].equip= atoi(sql_row[3]);
- p->storage[i].identify= atoi(sql_row[4]);
- p->storage[i].refine= atoi(sql_row[5]);
- p->storage[i].attribute= atoi(sql_row[6]);
- p->storage[i].card[0]= atoi(sql_row[7]);
- p->storage[i].card[1]= atoi(sql_row[8]);
- p->storage[i].card[2]= atoi(sql_row[9]);
- p->storage[i].card[3]= atoi(sql_row[10]);
+ p->storage_[i].id= atoi(sql_row[0]);
+ p->storage_[i].nameid= atoi(sql_row[1]);
+ p->storage_[i].amount= atoi(sql_row[2]);
+ p->storage_[i].equip= atoi(sql_row[3]);
+ p->storage_[i].identify= atoi(sql_row[4]);
+ p->storage_[i].refine= atoi(sql_row[5]);
+ p->storage_[i].attribute= atoi(sql_row[6]);
+ p->storage_[i].card[0]= atoi(sql_row[7]);
+ p->storage_[i].card[1]= atoi(sql_row[8]);
+ p->storage_[i].card[2]= atoi(sql_row[9]);
+ p->storage_[i].card[3]= atoi(sql_row[10]);
p->storage_amount = ++i;
+ if (i >= MAX_GUILD_STORAGE)
+ break;
}
mysql_free_result(sql_res);
}
@@ -188,17 +158,24 @@ int guild_storage_fromsql(int guild_id, struct guild_storage *p){
//---------------------------------------------------------
// storage data initialize
int inter_storage_sql_init(){
-
+
//memory alloc
printf("interserver storage memory initialize....(%d byte)\n",sizeof(struct storage));
- storage_pt=calloc(sizeof(struct storage), 1);
- guild_storage_pt=calloc(sizeof(struct guild_storage), 1);
+ storage_pt = (struct storage*)aCalloc(sizeof(struct storage), 1);
+ guild_storage_pt = (struct guild_storage*)aCalloc(sizeof(struct guild_storage), 1);
memset(storage_pt,0,sizeof(struct storage));
memset(guild_storage_pt,0,sizeof(struct guild_storage));
-
+
return 1;
}
-// 倉庫データ削除
+// storage data finalize
+void inter_storage_sql_final()
+{
+ if (storage_pt) aFree(storage_pt);
+ if (guild_storage_pt) aFree(guild_storage_pt);
+ return;
+}
+// q?f[^?
int inter_storage_delete(int account_id)
{
sprintf(tmp_sql, "DELETE FROM `%s` WHERE `account_id`='%d'",storage_db, account_id);
@@ -243,7 +220,7 @@ int mapif_load_guild_storage(int fd,int account_id,int guild_id)
{
int guild_exist=0;
WFIFOW(fd,0)=0x3818;
-
+
// Check if guild exists, I may write a function for this later, coz I use it several times.
//printf("- Check if guild %d exists\n",g->guild_id);
sprintf(tmp_sql, "SELECT count(*) FROM `%s` WHERE `guild_id`='%d'",guild_db, guild_id);
@@ -257,7 +234,7 @@ int mapif_load_guild_storage(int fd,int account_id,int guild_id)
//printf("- Check if guild %d exists : %s\n",g->guild_id,((guild_exist==0)?"No":"Yes"));
}
mysql_free_result(sql_res) ; //resource free
-
+
if(guild_exist==1) {
guild_storage_fromsql(guild_id,guild_storage_pt);
WFIFOW(fd,2)=sizeof(struct guild_storage)+12;
@@ -296,7 +273,7 @@ int mapif_parse_LoadStorage(int fd){
int mapif_parse_SaveStorage(int fd){
int account_id=RFIFOL(fd,4);
int len=RFIFOW(fd,2);
-
+
if(sizeof(struct storage)!=len-8){
printf("inter storage: data size error %d %d\n",sizeof(struct storage),len-8);
}else{
@@ -335,7 +312,7 @@ int mapif_parse_SaveGuildStorage(int fd)
//printf("- Check if guild %d exists : %s\n",g->guild_id,((guild_exist==0)?"No":"Yes"));
}
mysql_free_result(sql_res) ; //resource free
-
+
if(guild_exist==1) {
memcpy(guild_storage_pt,RFIFOP(fd,12),sizeof(struct guild_storage));
guild_storage_tosql(guild_id,guild_storage_pt);