summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkzd <markzd@54d463be-8e91-2dee-dedb-b68131a5f0ec>2013-01-07 05:13:54 +0000
committermarkzd <markzd@54d463be-8e91-2dee-dedb-b68131a5f0ec>2013-01-07 05:13:54 +0000
commit24987d8513307094064f59d3c9f9c35d0f6a6e87 (patch)
treec535cefbdf72d7de8ec676f4d9d89fcaebbd8668
parent92880a66754afb8b3b4285276c70c0fc6aa75c1f (diff)
downloadhercules-24987d8513307094064f59d3c9f9c35d0f6a6e87.tar.gz
hercules-24987d8513307094064f59d3c9f9c35d0f6a6e87.tar.bz2
hercules-24987d8513307094064f59d3c9f9c35d0f6a6e87.tar.xz
hercules-24987d8513307094064f59d3c9f9c35d0f6a6e87.zip
* Implemented Unique identifier for Non stackable items. (tid:69380)
* Set as off by default, it can be changed in /src/config/core.h. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@17080 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--sql-files/logs.sql1
-rw-r--r--sql-files/main.sql6
-rw-r--r--sql-files/upgrades/upgrade_svn17080.sql16
-rw-r--r--src/char/char.c39
-rw-r--r--src/char/int_auction.c13
-rw-r--r--src/char/int_mail.c20
-rw-r--r--src/char/int_storage.c10
-rw-r--r--src/char/inter.c21
-rw-r--r--src/char/inter.h14
-rw-r--r--src/common/mmo.h1
-rw-r--r--src/config/core.h4
-rw-r--r--src/map/itemdb.c49
-rw-r--r--src/map/itemdb.h1
-rw-r--r--src/map/log.c10
-rw-r--r--src/map/pc.c6
15 files changed, 174 insertions, 37 deletions
diff --git a/sql-files/logs.sql b/sql-files/logs.sql
index a94106747..90e8924ca 100644
--- a/sql-files/logs.sql
+++ b/sql-files/logs.sql
@@ -18,6 +18,7 @@ CREATE TABLE `picklog` (
`card1` int(11) NOT NULL default '0',
`card2` int(11) NOT NULL default '0',
`card3` int(11) NOT NULL default '0',
+ `nsiuid` bigint(20) unsigned NOT NULL default '0',
`map` varchar(11) NOT NULL default '',
PRIMARY KEY (`id`),
INDEX (`type`)
diff --git a/sql-files/main.sql b/sql-files/main.sql
index caec3df63..206515176 100644
--- a/sql-files/main.sql
+++ b/sql-files/main.sql
@@ -21,6 +21,7 @@ CREATE TABLE IF NOT EXISTS `auction` (
`card1` smallint(11) NOT NULL default '0',
`card2` smallint(11) NOT NULL default '0',
`card3` smallint(11) NOT NULL default '0',
+ `nsiuid` bigint(20) unsigned NOT NULL default '0',
PRIMARY KEY (`auction_id`)
) ENGINE=MyISAM;
@@ -42,6 +43,7 @@ CREATE TABLE IF NOT EXISTS `cart_inventory` (
`card2` smallint(11) NOT NULL default '0',
`card3` smallint(11) NOT NULL default '0',
`expire_time` int(11) unsigned NOT NULL default '0',
+ `nsiuid` bigint(20) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `char_id` (`char_id`)
) ENGINE=MyISAM;
@@ -341,6 +343,7 @@ CREATE TABLE IF NOT EXISTS `guild_storage` (
`card2` smallint(11) NOT NULL default '0',
`card3` smallint(11) NOT NULL default '0',
`expire_time` int(11) unsigned NOT NULL default '0',
+ `nsiuid` bigint(20) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `guild_id` (`guild_id`)
) ENGINE=MyISAM;
@@ -404,6 +407,7 @@ CREATE TABLE IF NOT EXISTS `inventory` (
`card3` smallint(11) NOT NULL default '0',
`expire_time` int(11) unsigned NOT NULL default '0',
`favorite` tinyint(3) unsigned NOT NULL default '0',
+ `nsiuid` bigint(20) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `char_id` (`char_id`)
) ENGINE=MyISAM;
@@ -500,6 +504,7 @@ CREATE TABLE IF NOT EXISTS `mail` (
`card1` smallint(11) NOT NULL default '0',
`card2` smallint(11) NOT NULL default '0',
`card3` smallint(11) NOT NULL default '0',
+ `nsiuid` bigint(20) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
@@ -661,6 +666,7 @@ CREATE TABLE IF NOT EXISTS `storage` (
`card2` smallint(11) NOT NULL default '0',
`card3` smallint(11) NOT NULL default '0',
`expire_time` int(11) unsigned NOT NULL default '0',
+ `nsiuid` bigint(20) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `account_id` (`account_id`)
) ENGINE=MyISAM;
diff --git a/sql-files/upgrades/upgrade_svn17080.sql b/sql-files/upgrades/upgrade_svn17080.sql
new file mode 100644
index 000000000..a94b8b668
--- /dev/null
+++ b/sql-files/upgrades/upgrade_svn17080.sql
@@ -0,0 +1,16 @@
+CREATE TABLE IF NOT EXISTS `interreg` (
+ `varname` varchar(11) NOT NULL,
+ `value` varchar(20) NOT NULL,
+ PRIMARY KEY (`varname`)
+) ENGINE=InnoDB;
+INSERT INTO `interreg` (`varname`, `value`) VALUES
+('nsiuid', '0');
+
+ALTER TABLE `auction` ADD `nsiuid` BIGINT NOT NULL DEFAULT '0';
+ALTER TABLE `cart_inventory` ADD `nsiuid` BIGINT NOT NULL DEFAULT '0';
+ALTER TABLE `guild_storage` ADD `nsiuid` BIGINT NOT NULL DEFAULT '0';
+ALTER TABLE `inventory` ADD `nsiuid` BIGINT NOT NULL DEFAULT '0';
+ALTER TABLE `mail` ADD `nsiuid` BIGINT NOT NULL DEFAULT '0';
+ALTER TABLE `storage` ADD `nsiuid` BIGINT NOT NULL DEFAULT '0';
+
+ALTER TABLE `picklog` ADD `nsiuid` BIGINT NOT NULL DEFAULT '0' AFTER `card3`;
diff --git a/src/char/char.c b/src/char/char.c
index eb214fedf..e2b313ad9 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -12,7 +12,6 @@
#include "../common/strlib.h"
#include "../common/timer.h"
#include "../common/utils.h"
-#include "inter.h"
#include "int_guild.h"
#include "int_homun.h"
#include "int_mercenary.h"
@@ -20,6 +19,7 @@
#include "int_party.h"
#include "int_storage.h"
#include "char.h"
+#include "inter.h"
#include <sys/types.h>
#include <time.h>
@@ -811,7 +811,7 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
SqlStmt_Free(stmt);
StringBuf_Clear(&buf);
- StringBuf_Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`", tablename, selectoption);
+ StringBuf_Printf(&buf, "INSERT INTO `%s`(`%s`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `nsiuid`", tablename, selectoption);
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ", `card%d`", j);
StringBuf_AppendStr(&buf, ") VALUES ");
@@ -829,12 +829,16 @@ int memitemdata_to_sql(const struct item items[], int max, int id, int tableswit
else
found = true;
- StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u'",
- id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time);
+ StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%"PRIu64"'",
+ id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].nsiuid);
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ", '%d'", items[i].card[j]);
StringBuf_AppendStr(&buf, ")");
+
+ updateLastUid(items[i].nsiuid); // Unique Non Stackable Item ID
}
+ updateLastUid(0);
+ dbUpdateUid(sql_handle); // Unique Non Stackable Item ID
if( found && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) )
{
@@ -948,7 +952,7 @@ int inventory_to_sql(const struct item items[], int max, int id) {
SqlStmt_Free(stmt);
StringBuf_Clear(&buf);
- StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`", inventory_db);
+ StringBuf_Printf(&buf, "INSERT INTO `%s` (`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `nsiuid`", inventory_db);
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ", `card%d`", j);
StringBuf_AppendStr(&buf, ") VALUES ");
@@ -965,12 +969,15 @@ int inventory_to_sql(const struct item items[], int max, int id) {
else
found = true;
- StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d'",
- id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite);
+ StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%u', '%d', '%"PRIu64"'",
+ id, items[i].nameid, items[i].amount, items[i].equip, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].favorite, items[i].nsiuid);
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ", '%d'", items[i].card[j]);
StringBuf_AppendStr(&buf, ")");
+
+ updateLastUid(items[i].nsiuid);// Unique Non Stackable Item ID
}
+ dbUpdateUid(sql_handle);
if( found && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) {
Sql_ShowDebug(sql_handle);
@@ -1203,9 +1210,9 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
strcat(t_msg, " memo");
//read inventory
- //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`)
+ //`inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `expire_time`, `favorite`, `nsiuid`)
StringBuf_Init(&buf);
- StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`");
+ StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `favorite`, `nsiuid`");
for( i = 0; i < MAX_SLOTS; ++i )
StringBuf_Printf(&buf, ", `card%d`", i);
StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", inventory_db, MAX_INVENTORY);
@@ -1221,10 +1228,11 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL)
- || SQL_ERROR == SqlStmt_BindColumn(stmt, 8, SQLDT_CHAR, &tmp_item.favorite, 0, NULL, NULL) )
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 8, SQLDT_CHAR, &tmp_item.favorite, 0, NULL, NULL)
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 9, SQLDT_ULONGLONG, &tmp_item.nsiuid, 0, NULL, NULL) )
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_SLOTS; ++i )
- if( SQL_ERROR == SqlStmt_BindColumn(stmt, 9+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
+ if( SQL_ERROR == SqlStmt_BindColumn(stmt, 10+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_INVENTORY && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
@@ -1233,9 +1241,9 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
strcat(t_msg, " inventory");
//read cart
- //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`)
+ //`cart_inventory` (`id`,`char_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, expire_time`, `nsiuid`)
StringBuf_Clear(&buf);
- StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`");
+ StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `nsiuid`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ", `card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`=? LIMIT %d", cart_db, MAX_CART);
@@ -1250,10 +1258,11 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_CHAR, &tmp_item.identify, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_CHAR, &tmp_item.refine, 0, NULL, NULL)
|| SQL_ERROR == SqlStmt_BindColumn(stmt, 6, SQLDT_CHAR, &tmp_item.attribute, 0, NULL, NULL)
- || SQL_ERROR == SqlStmt_BindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL) )
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL)
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 8, SQLDT_ULONGLONG, &tmp_item.nsiuid, 0, NULL, NULL) )
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_SLOTS; ++i )
- if( SQL_ERROR == SqlStmt_BindColumn(stmt, 8+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
+ if( SQL_ERROR == SqlStmt_BindColumn(stmt, 9+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
SqlStmt_ShowDebug(stmt);
for( i = 0; i < MAX_CART && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
diff --git a/src/char/int_auction.c b/src/char/int_auction.c
index 4fc9215a0..e0373c936 100644
--- a/src/char/int_auction.c
+++ b/src/char/int_auction.c
@@ -81,15 +81,19 @@ unsigned int auction_create(struct auction_data *auction)
auction->timestamp = time(NULL) + (auction->hours * 3600);
StringBuf_Init(&buf);
- StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`", auction_db);
+ StringBuf_Printf(&buf, "INSERT INTO `%s` (`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`nsiuid`", auction_db);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
- StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d'",
- auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute);
+ StringBuf_Printf(&buf, ") VALUES ('%d',?,'%d',?,'%d','%d','%d','%lu','%d',?,'%d','%d','%d','%"PRIu64"'",
+ auction->seller_id, auction->buyer_id, auction->price, auction->buynow, auction->hours, (unsigned long)auction->timestamp, auction->item.nameid, auction->type, auction->item.refine, auction->item.attribute, auction->item.nsiuid);
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",'%d'", auction->item.card[j]);
StringBuf_AppendStr(&buf, ")");
+ //Unique Non Stackable Item ID
+ updateLastUid(auction->item.nsiuid);
+ dbUpdateUid(sql_handle);
+
stmt = SqlStmt_Malloc(sql_handle);
if( SQL_SUCCESS != SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
|| SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, auction->seller_name, strnlen(auction->seller_name, NAME_LENGTH))
@@ -182,7 +186,7 @@ void inter_auctions_fromsql(void)
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `auction_id`,`seller_id`,`seller_name`,`buyer_id`,`buyer_name`,"
- "`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`");
+ "`price`,`buynow`,`hours`,`timestamp`,`nameid`,`item_name`,`type`,`refine`,`attribute`,`nsiuid`");
for( i = 0; i < MAX_SLOTS; i++ )
StringBuf_Printf(&buf, ",`card%d`", i);
StringBuf_Printf(&buf, " FROM `%s` ORDER BY `auction_id` DESC", auction_db);
@@ -212,6 +216,7 @@ void inter_auctions_fromsql(void)
Sql_GetData(sql_handle,12, &data, NULL); item->refine = atoi(data);
Sql_GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data);
+ Sql_GetData(sql_handle,14, &data, NULL); item->nsiuid = strtoull(data, NULL, 10);
item->identify = 1;
item->amount = 1;
diff --git a/src/char/int_mail.c b/src/char/int_mail.c
index 98da43aeb..f327bb8a3 100644
--- a/src/char/int_mail.c
+++ b/src/char/int_mail.c
@@ -29,7 +29,7 @@ static int mail_fromsql(int char_id, struct mail_data* md)
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`,"
- "`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`");
+ "`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`,`nsiuid`");
for (i = 0; i < MAX_SLOTS; i++)
StringBuf_Printf(&buf, ",`card%d`", i);
@@ -61,11 +61,12 @@ static int mail_fromsql(int char_id, struct mail_data* md)
Sql_GetData(sql_handle,12, &data, NULL); item->refine = atoi(data);
Sql_GetData(sql_handle,13, &data, NULL); item->attribute = atoi(data);
Sql_GetData(sql_handle,14, &data, NULL); item->identify = atoi(data);
+ Sql_GetData(sql_handle,15, &data, NULL); item->nsiuid = strtoull(data, NULL, 10);
item->expire_time = 0;
for (j = 0; j < MAX_SLOTS; j++)
{
- Sql_GetData(sql_handle, 15 + j, &data, NULL);
+ Sql_GetData(sql_handle, 16 + j, &data, NULL);
item->card[j] = atoi(data);
}
}
@@ -106,14 +107,18 @@ int mail_savemessage(struct mail_message* msg)
// build message save query
StringBuf_Init(&buf);
- StringBuf_Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`", mail_db);
+ StringBuf_Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `nsiuid`", mail_db);
for (j = 0; j < MAX_SLOTS; j++)
StringBuf_Printf(&buf, ", `card%d`", j);
- StringBuf_Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d'",
- msg->send_id, msg->dest_id, (unsigned long)msg->timestamp, msg->status, msg->zeny, msg->item.amount, msg->item.nameid, msg->item.refine, msg->item.attribute, msg->item.identify);
+ StringBuf_Printf(&buf, ") VALUES (?, '%d', ?, '%d', ?, ?, '%lu', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%"PRIu64"'",
+ msg->send_id, msg->dest_id, (unsigned long)msg->timestamp, msg->status, msg->zeny, msg->item.amount, msg->item.nameid, msg->item.refine, msg->item.attribute, msg->item.identify, msg->item.nsiuid);
for (j = 0; j < MAX_SLOTS; j++)
StringBuf_Printf(&buf, ", '%d'", msg->item.card[j]);
StringBuf_AppendStr(&buf, ")");
+
+ //Unique Non Stackable Item ID
+ updateLastUid(msg->item.nsiuid);
+ dbUpdateUid(sql_handle);
// prepare and execute query
stmt = SqlStmt_Malloc(sql_handle);
@@ -144,7 +149,7 @@ static bool mail_loadmessage(int mail_id, struct mail_message* msg)
StringBuf_Init(&buf);
StringBuf_AppendStr(&buf, "SELECT `id`,`send_name`,`send_id`,`dest_name`,`dest_id`,`title`,`message`,`time`,`status`,"
- "`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`");
+ "`zeny`,`amount`,`nameid`,`refine`,`attribute`,`identify`,`nsiuid`");
for( j = 0; j < MAX_SLOTS; j++ )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `id` = '%d'", mail_db, mail_id);
@@ -176,11 +181,12 @@ static bool mail_loadmessage(int mail_id, struct mail_message* msg)
Sql_GetData(sql_handle,12, &data, NULL); msg->item.refine = atoi(data);
Sql_GetData(sql_handle,13, &data, NULL); msg->item.attribute = atoi(data);
Sql_GetData(sql_handle,14, &data, NULL); msg->item.identify = atoi(data);
+ Sql_GetData(sql_handle,15, &data, NULL); msg->item.nsiuid = strtoull(data, NULL, 10);
msg->item.expire_time = 0;
for( j = 0; j < MAX_SLOTS; j++ )
{
- Sql_GetData(sql_handle,15 + j, &data, NULL);
+ Sql_GetData(sql_handle,16 + j, &data, NULL);
msg->item.card[j] = atoi(data);
}
}
diff --git a/src/char/int_storage.c b/src/char/int_storage.c
index 248a4521f..629f47107 100644
--- a/src/char/int_storage.c
+++ b/src/char/int_storage.c
@@ -38,7 +38,7 @@ int storage_fromsql(int account_id, struct storage_data* p)
// storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
StringBuf_Init(&buf);
- StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`");
+ StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`expire_time`,`nsiuid`");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `account_id`='%d' ORDER BY `nameid`", storage_db, account_id);
@@ -59,9 +59,10 @@ int storage_fromsql(int account_id, struct storage_data* p)
Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data);
Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data);
Sql_GetData(sql_handle, 7, &data, NULL); item->expire_time = (unsigned int)atoi(data);
+ Sql_GetData(sql_handle, 8, &data, NULL); item->nsiuid = strtoull(data, NULL, 10);
for( j = 0; j < MAX_SLOTS; ++j )
{
- Sql_GetData(sql_handle, 8+j, &data, NULL); item->card[j] = atoi(data);
+ Sql_GetData(sql_handle, 9+j, &data, NULL); item->card[j] = atoi(data);
}
}
p->storage_amount = i;
@@ -94,7 +95,7 @@ int guild_storage_fromsql(int guild_id, struct guild_storage* p)
// storage {`guild_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`}
StringBuf_Init(&buf);
- StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`");
+ StringBuf_AppendStr(&buf, "SELECT `id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`nsiuidī");
for( j = 0; j < MAX_SLOTS; ++j )
StringBuf_Printf(&buf, ",`card%d`", j);
StringBuf_Printf(&buf, " FROM `%s` WHERE `guild_id`='%d' ORDER BY `nameid`", guild_storage_db, guild_id);
@@ -114,10 +115,11 @@ int guild_storage_fromsql(int guild_id, struct guild_storage* p)
Sql_GetData(sql_handle, 4, &data, NULL); item->identify = atoi(data);
Sql_GetData(sql_handle, 5, &data, NULL); item->refine = atoi(data);
Sql_GetData(sql_handle, 6, &data, NULL); item->attribute = atoi(data);
+ Sql_GetData(sql_handle, 7, &data, NULL); item->nsiuid = strtoull(data, NULL, 10);
item->expire_time = 0;
for( j = 0; j < MAX_SLOTS; ++j )
{
- Sql_GetData(sql_handle, 7+j, &data, NULL); item->card[j] = atoi(data);
+ Sql_GetData(sql_handle, 8+j, &data, NULL); item->card[j] = atoi(data);
}
}
p->storage_amount = i;
diff --git a/src/char/inter.c b/src/char/inter.c
index 8863b41d8..8faff42c1 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -1234,3 +1234,24 @@ int inter_parse_frommap(int fd)
RFIFOSKIP(fd, len);
return 1;
}
+
+uint64 inter_chk_lastuid(int8 flag, uint64 value){
+ static uint64 last_updt_uid = 0;
+ static int8 update = 0;
+ if(flag)
+ {
+ if(last_updt_uid < value){
+ last_updt_uid = value;
+ update = 1;
+ }
+
+ return 0;
+ }else if(update)
+ {
+ update = 0;
+ return last_updt_uid;
+ }
+ return 0;
+}
+
+
diff --git a/src/char/inter.h b/src/char/inter.h
index ac2e1785f..e5bfa1572 100644
--- a/src/char/inter.h
+++ b/src/char/inter.h
@@ -27,4 +27,18 @@ extern char main_chat_nick[16];
int inter_accreg_tosql(int account_id, int char_id, struct accreg *reg, int type);
+uint64 inter_chk_lastuid(int8 flag, uint64 value);
+#ifdef NSI_UNIQUE_ID
+ #define updateLastUid(val_) inter_chk_lastuid(1, val_)
+ #define dbUpdateUid(handler_)\
+ { \
+ uint64 nsiuid_ = inter_chk_lastuid(0, 0); \
+ if (nsiuid_ && SQL_ERROR == Sql_Query(handler_, "UPDATE `interreg` SET `value`='%"PRIu64"' WHERE `varname`='nsiuid'", nsiuid_)) \
+ Sql_ShowDebug(handler_);\
+ }
+#else
+ #define dbUpdateUid(handler_)
+ #define updateLastUid(val_)
+#endif
+
#endif /* _INTER_SQL_H_ */
diff --git a/src/common/mmo.h b/src/common/mmo.h
index cbdacdc0f..e83967404 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -201,6 +201,7 @@ struct item {
short card[MAX_SLOTS];
unsigned int expire_time;
char favorite;
+ uint64 nsiuid;
};
struct point {
diff --git a/src/config/core.h b/src/config/core.h
index c82ee72e0..1e8ce9992 100644
--- a/src/config/core.h
+++ b/src/config/core.h
@@ -48,6 +48,10 @@
/// - but is not the official behaviour.
//#define CIRCULAR_AREA
+/// Uncomment to enable Non Stackable items unique ID
+/// By enabling it, the system will create an unique id for each new non stackable item created
+//#define NSI_UNIQUE_ID
+
/**
* No settings past this point
**/
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index e0c964de3..810e85a4a 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -1252,6 +1252,51 @@ static int itemdb_read_sqldb(void) {
return 0;
}
+/*==========================================
+* Unique item ID function
+* Only one operation by once
+* Flag:
+* 0 return new id
+* 1 set new value, checked with current value
+* 2 set new value bypassing anything
+* 3/other return last value
+*------------------------------------------*/
+uint64 itemdb_nsiuid(int8 flag, int64 value) {
+ static uint64 item_uid = 0;
+
+ if(flag)
+ {
+ if(flag == 1)
+ { if(item_uid < value)
+ return (item_uid = value);
+ }else if(flag == 2)
+ return (item_uid = value);
+
+ return item_uid;
+ }
+
+ return ++item_uid;
+}
+int itemdb_uid_load(){
+
+ char * uid;
+ if (SQL_ERROR == Sql_Query(mmysql_handle, "SELECT `value` FROM `interreg` WHERE `varname`='nsiuid'"))
+ Sql_ShowDebug(mmysql_handle);
+
+ if( SQL_SUCCESS != Sql_NextRow(mmysql_handle) )
+ {
+ ShowError("itemdb_uid_load: Unable to fetch nsiuid data\n");
+ Sql_FreeResult(mmysql_handle);
+ return -1;
+ }
+
+ Sql_GetData(mmysql_handle, 0, &uid, NULL);
+ itemdb_nsiuid(1, (uint64)strtoull(uid, NULL, 10));
+ Sql_FreeResult(mmysql_handle);
+
+ return 0;
+}
+
/*====================================
* read all item-related databases
*------------------------------------*/
@@ -1269,7 +1314,9 @@ static void itemdb_read(void) {
sv_readdb(db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade);
sv_readdb(db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay);
sv_readdb(db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack);
- sv_readdb(db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore);
+ sv_readdb(db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore);
+
+ itemdb_uid_load();
}
/*==========================================
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index 2bc418cc4..e8c6d6487 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -219,6 +219,7 @@ int itemdb_isequip2(struct item_data *);
int itemdb_isidentified(int);
int itemdb_isstackable(int);
int itemdb_isstackable2(struct item_data *);
+uint64 itemdb_nsiuid(int8 flag, int64 value); // Unique Item ID
void itemdb_reload(void);
diff --git a/src/map/log.c b/src/map/log.c
index 8a114d989..9d50be62a 100644
--- a/src/map/log.c
+++ b/src/map/log.c
@@ -188,12 +188,12 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it
#ifdef BETA_THREAD_TEST
char entry[512];
int e_length = 0;
- e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')",
- log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"" );
+ e_length = sprintf(entry, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `nsiuid`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')",
+ log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->nsiuid);
queryThread_log(entry,e_length);
#else
- if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')",
- log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"") )
+ if( SQL_ERROR == Sql_Query(logmysql_handle, LOG_QUERY " INTO `%s` (`time`, `char_id`, `type`, `nameid`, `amount`, `refine`, `card0`, `card1`, `card2`, `card3`, `map`, `nsiuid`) VALUES (NOW(), '%d', '%c', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%"PRIu64"')",
+ log_config.log_pick, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->nsiuid) )
{
Sql_ShowDebug(logmysql_handle);
return;
@@ -210,7 +210,7 @@ void log_pick(int id, int16 m, e_log_pick_type type, int amount, struct item* it
return;
time(&curtime);
strftime(timestring, sizeof(timestring), "%m/%d/%Y %H:%M:%S", localtime(&curtime));
- fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"");
+ fprintf(logfp,"%s - %d\t%c\t%d,%d,%d,%d,%d,%d,%d,%s,'%"PRIu64"'\n", timestring, id, log_picktype2char(type), itm->nameid, amount, itm->refine, itm->card[0], itm->card[1], itm->card[2], itm->card[3], map[m].name?map[m].name:"", itm->nsiuid);
fclose(logfp);
}
}
diff --git a/src/map/pc.c b/src/map/pc.c
index c7d5b87f0..0ad272d1d 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -3820,7 +3820,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l
}
}
}
-
+
if( i >= MAX_INVENTORY )
{
i = pc_search_inventory(sd,0);
@@ -3836,6 +3836,10 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l
sd->inventory_data[i] = data;
clif_additem(sd,i,amount,0);
}
+#ifdef NSI_UNIQUE_ID
+ if( !itemdb_isstackable2(data) && !item_data->nsiuid )
+ sd->status.inventory[i].nsiuid = itemdb_nsiuid(0,0);
+#endif
log_pick_pc(sd, log_type, amount, &sd->status.inventory[i]);
sd->weight += w;