From 1209707c7db9738715ce3182cd0e858cc9012a82 Mon Sep 17 00:00:00 2001 From: celest Date: Tue, 8 Mar 2005 05:05:04 +0000 Subject: Speedup inventory and storage saving git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1210 54d463be-8e91-2dee-dedb-b68131a5f0ec --- Changelog-SVN.txt | 5 +- src/char_sql/char.c | 337 +++++++++++++-------------------------------- src/char_sql/char.h | 2 +- src/char_sql/int_storage.c | 106 +++++--------- 4 files changed, 134 insertions(+), 316 deletions(-) diff --git a/Changelog-SVN.txt b/Changelog-SVN.txt index ca73c81e6..300dacf55 100644 --- a/Changelog-SVN.txt +++ b/Changelog-SVN.txt @@ -1,6 +1,7 @@ Date Added 03/08 + * Speedup inventory and storage saving, thanks to Ilpalazzo-sama [celest] * Reverted a jA change in event loading [celest] 03/07 @@ -9,6 +10,8 @@ Date Added #define LOG_UPTIME 0 To-do: Add this as an option to log config * Fixed 'make clean' not removing the .o files in /common [celest] + * Removed some unused code for Breaker and temporarily set Emperium to be + immune to Breaker [celest] * Updated core and map-server to jA 1115~1137 [celest] - Added monster_delay_damage to battle conf @@ -18,8 +21,6 @@ Date Added - Added monster skill NPC_EXPLOSIONSPIRITS - Corrected Mindbreaker level to 5 - Updated Meteor Assault to instant-cast - - Removed some unused code for Breaker - - Temporarily set Emperium to be immune to Breaker - Added command @users - shows the percentage of users in all maps - Don't save status if the player is set for disconnection - Added free block lock-checking system diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 24c765ea8..b920e8eb3 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -310,13 +310,14 @@ int compare_item(struct item *a, struct item *b) { //===================================================================================================== int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ int i=0,party_exist,guild_exist; - int eqcount=1; - int noteqcount=1; +// int eqcount=1; +// int noteqcount=1; + int count = 0; int diff = 0; char temp_str[1024]; char *tmp_p = tmp_sql; struct mmo_charstatus *cp; - struct itemtemp mapitem; + struct itemtmp mapitem[MAX_GUILD_STORAGE]; if (char_id!=p->char_id) return 0; @@ -344,48 +345,32 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ //map inventory data for(i=0;iinventory[i], &cp->inventory[i])) - diff = 1; + if (!compare_item(&p->inventory[i], &cp->inventory[i])) + diff = 1; if(p->inventory[i].nameid>0){ - if(itemdb_isequip(p->inventory[i].nameid)==1){ - mapitem.equip[eqcount].flag=0; - mapitem.equip[eqcount].id = p->inventory[i].id; - mapitem.equip[eqcount].nameid=p->inventory[i].nameid; - mapitem.equip[eqcount].amount = p->inventory[i].amount; - mapitem.equip[eqcount].equip = p->inventory[i].equip; - mapitem.equip[eqcount].identify = p->inventory[i].identify; - mapitem.equip[eqcount].refine = p->inventory[i].refine; - mapitem.equip[eqcount].attribute = p->inventory[i].attribute; - mapitem.equip[eqcount].card[0] = p->inventory[i].card[0]; - mapitem.equip[eqcount].card[1] = p->inventory[i].card[1]; - mapitem.equip[eqcount].card[2] = p->inventory[i].card[2]; - mapitem.equip[eqcount].card[3] = p->inventory[i].card[3]; - eqcount++; - } - else if(itemdb_isequip(p->inventory[i].nameid)==0){ - mapitem.notequip[noteqcount].flag=0; - mapitem.notequip[noteqcount].id = p->inventory[i].id; - mapitem.notequip[noteqcount].nameid=p->inventory[i].nameid; - mapitem.notequip[noteqcount].amount = p->inventory[i].amount; - mapitem.notequip[noteqcount].equip = p->inventory[i].equip; - mapitem.notequip[noteqcount].identify = p->inventory[i].identify; - mapitem.notequip[noteqcount].refine = p->inventory[i].refine; - mapitem.notequip[noteqcount].attribute = p->inventory[i].attribute; - mapitem.notequip[noteqcount].card[0] = p->inventory[i].card[0]; - mapitem.notequip[noteqcount].card[1] = p->inventory[i].card[1]; - mapitem.notequip[noteqcount].card[2] = p->inventory[i].card[2]; - mapitem.notequip[noteqcount].card[3] = p->inventory[i].card[3]; - noteqcount++; - } + mapitem[count].flag=0; + mapitem[count].id = p->inventory[i].id; + mapitem[count].nameid=p->inventory[i].nameid; + mapitem[count].amount = p->inventory[i].amount; + mapitem[count].equip = p->inventory[i].equip; + mapitem[count].identify = p->inventory[i].identify; + mapitem[count].refine = p->inventory[i].refine; + mapitem[count].attribute = p->inventory[i].attribute; + mapitem[count].card[0] = p->inventory[i].card[0]; + mapitem[count].card[1] = p->inventory[i].card[1]; + mapitem[count].card[2] = p->inventory[i].card[2]; + mapitem[count].card[3] = p->inventory[i].card[3]; + count++; } } //printf("- Save item data to MySQL!\n"); if (diff) - memitemdata_to_sql(mapitem, eqcount, noteqcount, p->char_id,TABLE_INVENTORY); + memitemdata_to_sql(mapitem, count, p->char_id,TABLE_INVENTORY); //=========================================map cart data > memory ==================================== - eqcount=1; - noteqcount=1; +// eqcount=1; +// noteqcount=1; + count = 0; diff = 0; //map cart data @@ -393,42 +378,25 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ if (!compare_item(&p->cart[i], &cp->cart[i])) diff = 1; if(p->cart[i].nameid>0){ - if(itemdb_isequip(p->cart[i].nameid)==1){ - mapitem.equip[eqcount].flag=0; - mapitem.equip[eqcount].id = p->cart[i].id; - mapitem.equip[eqcount].nameid=p->cart[i].nameid; - mapitem.equip[eqcount].amount = p->cart[i].amount; - mapitem.equip[eqcount].equip = p->cart[i].equip; - mapitem.equip[eqcount].identify = p->cart[i].identify; - mapitem.equip[eqcount].refine = p->cart[i].refine; - mapitem.equip[eqcount].attribute = p->cart[i].attribute; - mapitem.equip[eqcount].card[0] = p->cart[i].card[0]; - mapitem.equip[eqcount].card[1] = p->cart[i].card[1]; - mapitem.equip[eqcount].card[2] = p->cart[i].card[2]; - mapitem.equip[eqcount].card[3] = p->cart[i].card[3]; - eqcount++; - } - else if(itemdb_isequip(p->cart[i].nameid)==0){ - mapitem.notequip[noteqcount].flag=0; - mapitem.notequip[noteqcount].id = p->cart[i].id; - mapitem.notequip[noteqcount].nameid=p->cart[i].nameid; - mapitem.notequip[noteqcount].amount = p->cart[i].amount; - mapitem.notequip[noteqcount].equip = p->cart[i].equip; - mapitem.notequip[noteqcount].identify = p->cart[i].identify; - mapitem.notequip[noteqcount].refine = p->cart[i].refine; - mapitem.notequip[noteqcount].attribute = p->cart[i].attribute; - mapitem.notequip[noteqcount].card[0] = p->cart[i].card[0]; - mapitem.notequip[noteqcount].card[1] = p->cart[i].card[1]; - mapitem.notequip[noteqcount].card[2] = p->cart[i].card[2]; - mapitem.notequip[noteqcount].card[3] = p->cart[i].card[3]; - noteqcount++; - } + mapitem[count].flag=0; + mapitem[count].id = p->cart[i].id; + mapitem[count].nameid=p->cart[i].nameid; + mapitem[count].amount = p->cart[i].amount; + mapitem[count].equip = p->cart[i].equip; + mapitem[count].identify = p->cart[i].identify; + mapitem[count].refine = p->cart[i].refine; + mapitem[count].attribute = p->cart[i].attribute; + mapitem[count].card[0] = p->cart[i].card[0]; + mapitem[count].card[1] = p->cart[i].card[1]; + mapitem[count].card[2] = p->cart[i].card[2]; + mapitem[count].card[3] = p->cart[i].card[3]; + count++; } } //printf("- Save cart data to MySQL!\n"); if (diff) - memitemdata_to_sql(mapitem, eqcount, noteqcount, p->char_id,TABLE_CART); + memitemdata_to_sql(mapitem, count, p->char_id,TABLE_CART); //===================================================================================================== @@ -652,216 +620,97 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ return 0; } -int memitemdata_to_sql(struct itemtemp mapitem, int eqcount, int noteqcount, int char_id, int tableswitch){ - //equ - int i, j; - int dbeqcount = 1; - int dbnoteqcount = 1; - struct itemtemp dbitem; - char tablename[16]; +// [Ilpalazzo-sama] +int memitemdata_to_sql(struct itemtmp mapitem[], int count, int char_id, int tableswitch) +{ + int i, flag, id; + char *tablename; char selectoption[16]; - switch (tableswitch){ + switch (tableswitch) { case TABLE_INVENTORY: - sprintf(tablename,"%s",inventory_db); + tablename = inventory_db; // no need for sprintf here as *_db are char*. sprintf(selectoption,"char_id"); break; case TABLE_CART: - sprintf(tablename,"%s",cart_db); + tablename = cart_db; sprintf(selectoption,"char_id"); break; case TABLE_STORAGE: - sprintf(tablename,"%s",storage_db); + tablename = storage_db; sprintf(selectoption,"account_id"); break; case TABLE_GUILD_STORAGE: - sprintf(tablename,"%s",guild_storage_db); + tablename = guild_storage_db; sprintf(selectoption,"guild_id"); break; + default: + printf("Invalid table name!\n"); + return 1; } //printf("Working Table : %s \n",tablename); //=======================================mysql database data > memory=============================================== - sprintf(tmp_sql, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3` " - "FROM `%s` WHERE `%s`='%d'",tablename ,selectoption ,char_id); // TBR + "FROM `%s` WHERE `%s`='%d'", tablename, selectoption, char_id); if (mysql_query(&mysql_handle, tmp_sql)) { printf("DB server Error (select `%s` to Memory)- %s\n",tablename ,mysql_error(&mysql_handle)); + return 1; } sql_res = mysql_store_result(&mysql_handle); if (sql_res) { - for(i=0;(sql_row = mysql_fetch_row(sql_res));i++){ - if (itemdb_isequip(atoi(sql_row[1]))==1){ - dbitem.equip[dbeqcount].flag=0; - dbitem.equip[dbeqcount].id = atoi(sql_row[0]); - dbitem.equip[dbeqcount].nameid = atoi(sql_row[1]); - dbitem.equip[dbeqcount].amount = atoi(sql_row[2]); - dbitem.equip[dbeqcount].equip = atoi(sql_row[3]); - dbitem.equip[dbeqcount].identify = atoi(sql_row[4]); - dbitem.equip[dbeqcount].refine = atoi(sql_row[5]); - dbitem.equip[dbeqcount].attribute = atoi(sql_row[6]); - dbitem.equip[dbeqcount].card[0] = atoi(sql_row[7]); - dbitem.equip[dbeqcount].card[1] = atoi(sql_row[8]); - dbitem.equip[dbeqcount].card[2] = atoi(sql_row[9]); - dbitem.equip[dbeqcount].card[3] = atoi(sql_row[10]); - dbeqcount++; - }else { - dbitem.notequip[dbnoteqcount].flag=0; - dbitem.notequip[dbnoteqcount].id = atoi(sql_row[0]); - dbitem.notequip[dbnoteqcount].nameid = atoi(sql_row[1]); - dbitem.notequip[dbnoteqcount].amount = atoi(sql_row[2]); - dbitem.notequip[dbnoteqcount].equip = atoi(sql_row[3]); - dbitem.notequip[dbnoteqcount].identify = atoi(sql_row[4]); - dbitem.notequip[dbnoteqcount].refine = atoi(sql_row[5]); - dbitem.notequip[dbnoteqcount].attribute = atoi(sql_row[6]); - dbitem.notequip[dbnoteqcount].card[0] = atoi(sql_row[7]); - dbitem.notequip[dbnoteqcount].card[1] = atoi(sql_row[8]); - dbitem.notequip[dbnoteqcount].card[2] = atoi(sql_row[9]); - dbitem.notequip[dbnoteqcount].card[3] = atoi(sql_row[10]); - dbnoteqcount++; - } - } - mysql_free_result(sql_res); - } - - //==============================================Memory data > SQL =============================== - //======================================Equip ITEM======================================= - if((eqcount==1) && (dbeqcount==1)){//printf("%s Equip Empty\n",tablename); - //item empty - } else { - - for(i=1;i SQL =============================== + if(itemdb_isequip(mapitem[i].nameid) || (mapitem[i].card[0] == atoi(sql_row[7]))) { sprintf(tmp_sql,"UPDATE `%s` SET `equip`='%d', `identify`='%d', `refine`='%d'," - "`attribute`='%d', `card0`='%d', `card1`='%d', `card2`='%d', `card3`='%d', `amount`='%d' WHERE `id`='%d' LIMIT 1", - tablename, mapitem.equip[i].equip, mapitem.equip[i].identify, mapitem.equip[i].refine,mapitem.equip[i].attribute, mapitem.equip[i].card[0], - mapitem.equip[i].card[1], mapitem.equip[i].card[2], mapitem.equip[i].card[3], mapitem.equip[i].amount, dbitem.equip[j].id); - //printf("%s\n",tmp_sql); + "`attribute`='%d', `card0`='%d', `card1`='%d', `card2`='%d', `card3`='%d', `amount`='%d' WHERE `id`='%d' LIMIT 1", + tablename, mapitem[i].equip, mapitem[i].identify, mapitem[i].refine, mapitem[i].attribute, mapitem[i].card[0], + mapitem[i].card[1], mapitem[i].card[2], mapitem[i].card[3], mapitem[i].amount, id); if(mysql_query(&mysql_handle, tmp_sql)) printf("DB server Error (UPdate `equ %s`)- %s\n", tablename, mysql_error(&mysql_handle)); - mapitem.equip[i].flag=1; - dbitem.equip[j].flag=1; - //printf("not the same item : %d ; i : %d ; flag : %d\n", mapitem.equip[i].nameid, i, mapitem.equip[i].flag); } + //printf("not the same item : %d ; i : %d ; flag : %d\n", mapitem.equip[i].nameid, i, mapitem.equip[i].flag); } + flag = mapitem[i].flag = 1; + break; } } - } - - //printf("dbeqcount = %d\n",dbeqcount); - - for(i=1;i 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;istorage[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++; - } + 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; @@ -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;istorage[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++; - } + 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; @@ -198,7 +166,7 @@ int inter_storage_sql_init(){ return 1; } -// 倉庫データ削除 +// q?f[^? int inter_storage_delete(int account_id) { sprintf(tmp_sql, "DELETE FROM `%s` WHERE `account_id`='%d'",storage_db, account_id); -- cgit v1.2.3-70-g09d2