Register for your free account! | Forgot your password?

You last visited: Today at 22:47

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Correction] item_proto load from db

Discussion on [Correction] item_proto load from db within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.

Reply
 
Old   #1
 
Zonni's Avatar
 
elite*gold: 100
Join Date: Feb 2008
Posts: 195
Received Thanks: 270
[Correction] item_proto load from db

Hi all, recently i discovered a bug in item_proto when loading data from database.

So, what's the bug?
In item_proto.txt when db encounter vnum like this "110000~99" or like this "110000~110099" bind 110000 as dwVnum and 99 as dwRange.

When we load item_proto from database we haven't any range for item because no one care of this (Ymir droped loading item_proto from database since 34k and DSS showed in 40k), anyway - range is needed for item used in dragon soul system.

Finally this is corrected iMer's InitializeItemTable
Code:
bool CClientManager::InitializeItemTable()
{
	std::ostringstream query;
	query << "SELECT vnum, type, subtype, name, " << g_stLocaleNameColumn << ", gold, shop_buy_price, weight, size, flag, wearflag, antiflag, immuneflag+0, refined_vnum, refine_set, magic_pct, socket_pct, addon_type, limittype0, limitvalue0, limittype1, limitvalue1, applytype0, applyvalue0, applytype1, applyvalue1, applytype2, applyvalue2, value0, value1, value2, value3, value4, value5, vnum_range, socket0, socket1, socket2 FROM item_proto ORDER BY vnum";
	SQLMsg* sqlMsg = CDBManager::instance().DirectQuery(query.str().c_str(), 0);
	if (sqlMsg == NULL) {
		sys_err("ClientManagerBoot::InitializeItemTable", __LINE__, "Could not load item_proto. Query failed!");
		return false;
	}

	MYSQL_RES* pRes = sqlMsg->vec_pkResult[0]->pSQLResult;

	if (pRes == NULL) {
		sys_err("ClientManagerBoot::InitializeItemTable", __LINE__, "Could not load item_proto. No result!");
		return 0;
	}

	if (!m_vec_itemTable.empty()) {
		sys_log(__LINE__, " Reloading item_proto");
		m_vec_itemTable.clear();
	}
	MYSQL_ROW row;
	while ((row = mysql_fetch_row(pRes))) {
		//SItemTable temp = {};
		SItemTable temp;
		memset(&temp, 0, sizeof(temp));
		if (row[0]&&*row[0]) temp.dwVnum = strtoul(row[0], NULL, 10);
		if (row[1]&&*row[1]) temp.bType = strtoul(row[1], NULL, 10);
		if (row[2]&&*row[2]) temp.bSubType = strtoul(row[2], NULL, 10);
		if (row[3]&&*row[3]) snprintf(temp.szName, 25, "%s", row[3]);
		if (row[4]&&*row[4]) snprintf(temp.szLocaleName, 25, "%s", row[4]);
		if (row[5]&&*row[5]) temp.dwGold = strtoul(row[5], NULL, 10);
		if (row[6]&&*row[6]) temp.dwShopBuyPrice = strtoul(row[6], NULL, 10);
		if (row[7]&&*row[7]) temp.bWeight = strtoul(row[7], NULL, 10);
		if (row[8]&&*row[8]) temp.bSize = strtoul(row[8], NULL, 10);
		if (row[9]&&*row[9]) temp.dwFlags = strtoul(row[9], NULL, 10);
		if (row[10]&&*row[10]) temp.dwWearFlags = strtoul(row[10], NULL, 10);
		if (row[11]&&*row[11]) temp.dwAntiFlags = strtoul(row[11], NULL, 10);
		if (row[12]&&*row[12]) temp.dwImmuneFlag = strtoul(row[12], NULL, 10);
		if (row[13]&&*row[13]) temp.dwRefinedVnum = strtoul(row[13], NULL, 10);
		if (row[14]&&*row[14]) temp.wRefineSet = strtoul(row[14], NULL, 10);
		if (row[15]&&*row[15]) temp.bAlterToMagicItemPct = strtoul(row[15], NULL, 10);
		if (row[16]&&*row[16]) temp.bGainSocketPct = strtoul(row[16], NULL, 10);
		if (row[17]&&*row[17]) temp.sAddonType = strtoul(row[17], NULL, 10);
		if (row[18]&&*row[18]) temp.aLimits[0].bType = strtoul(row[18], NULL, 10);
		if (row[19]&&*row[19]) temp.aLimits[0].lValue = strtoul(row[19], NULL, 10);
		if (row[20]&&*row[20]) temp.aLimits[1].bType = strtoul(row[20], NULL, 10);
		if (row[21]&&*row[21]) temp.aLimits[1].lValue = strtoul(row[21], NULL, 10);
		if (row[22]&&*row[22]) temp.aApplies[0].bType = strtoul(row[22], NULL, 10);
		if (row[23]&&*row[23]) temp.aApplies[0].lValue = strtoul(row[23], NULL, 10);
		if (row[24]&&*row[24]) temp.aApplies[1].bType = strtoul(row[24], NULL, 10);
		if (row[25]&&*row[25]) temp.aApplies[1].lValue = strtoul(row[25], NULL, 10);
		if (row[26]&&*row[26]) temp.aApplies[2].bType = strtoul(row[26], NULL, 10);
		if (row[27]&&*row[27]) temp.aApplies[2].lValue = strtoul(row[27], NULL, 10);
		if (row[28]&&*row[28]) temp.alValues[0] = strtoul(row[28], NULL, 10);
		if (row[29]&&*row[29]) temp.alValues[1] = strtoul(row[29], NULL, 10);
		if (row[30]&&*row[30]) temp.alValues[2] = strtoul(row[30], NULL, 10);
		if (row[31]&&*row[31]) temp.alValues[3] = strtoul(row[31], NULL, 10);
		if (row[32]&&*row[32]) temp.alValues[4] = strtoul(row[32], NULL, 10);
		if (row[33]&&*row[33]) temp.alValues[5] = strtoul(row[33], NULL, 10);
		if (row[34]&&*row[34]) temp.dwVnumRange = strtoul(row[34], NULL, 10);

		temp.cLimitRealTimeFirstUseIndex = -1;
		temp.cLimitTimerBasedOnWearIndex = -1;
		for (int i = 0; i < ITEM_LIMIT_MAX_NUM; ++i) {
			if (LIMIT_REAL_TIME_START_FIRST_USE == temp.aLimits[i].bType)
				temp.cLimitRealTimeFirstUseIndex = (char) i;

			if (LIMIT_TIMER_BASED_ON_WEAR == temp.aLimits[i].bType)
				temp.cLimitTimerBasedOnWearIndex = (char) i;
		}
		m_vec_itemTable.push_back(temp);
	}
	std::cout << "CClientManager::InitializeItemTable:: " << m_vec_itemTable.size() << " items loaded." << std::endl;
	mysql_free_result(pRes);
	m_map_itemTableByVnum.clear();

	itertype(m_vec_itemTable) it = m_vec_itemTable.begin();

	while (it != m_vec_itemTable.end()) {
		TItemTable * item_table = &(*(it++));

		sys_log(1, "ITEM: #%-5lu %-24s %-24s VAL: %ld %ld %ld %ld %ld %ld WEAR %lu ANTI %lu IMMUNE %lu REFINE %lu REFINE_SET %u MAGIC_PCT %u",
				item_table->dwVnum,
				item_table->szName,
				item_table->szLocaleName,
				item_table->alValues[0],
				item_table->alValues[1],
				item_table->alValues[2],
				item_table->alValues[3],
				item_table->alValues[4],
				item_table->alValues[5],
				item_table->dwWearFlags,
				item_table->dwAntiFlags,
				item_table->dwImmuneFlag,
				item_table->dwRefinedVnum,
				item_table->wRefineSet,
				item_table->bAlterToMagicItemPct);

		m_map_itemTableByVnum.insert(std::map<DWORD, TItemTable *>::value_type(item_table->dwVnum, item_table));
	}
	sort(m_vec_itemTable.begin(), m_vec_itemTable.end(), FCompareVnum());
	return true;
}
and item_proto.sql
Code:
SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `item_proto`
-- ----------------------------
DROP TABLE IF EXISTS `item_proto`;
CREATE TABLE `item_proto` (
  `vnum` int(11) unsigned NOT NULL DEFAULT '0',
  `type` tinyint(2) NOT NULL DEFAULT '0',
  `subtype` tinyint(2) NOT NULL DEFAULT '0',
  `name` varbinary(24) NOT NULL DEFAULT 'Noname',
  `locale_name` varbinary(24) NOT NULL DEFAULT 'Noname',
  `shop_buy_price` int(10) unsigned NOT NULL DEFAULT '0',
  `size` tinyint(3) DEFAULT '0',
  `flag` int(11) DEFAULT '0',
  `gold` int(11) DEFAULT '0',
  `wearflag` int(11) DEFAULT '0',
  `antiflag` int(11) DEFAULT '0',
  `immuneflag` set('PARA','CURSE','STUN','SLEEP','SLOW','POISON','TERROR') CHARACTER SET latin1 NOT NULL DEFAULT '',
  `refined_vnum` int(10) unsigned NOT NULL DEFAULT '0',
  `weight` tinyint(3) DEFAULT '0',
  `refine_set` smallint(11) unsigned NOT NULL DEFAULT '0',
  `magic_pct` tinyint(4) NOT NULL DEFAULT '0',
  `socket_pct` tinyint(4) NOT NULL DEFAULT '0',
  `addon_type` smallint(6) NOT NULL DEFAULT '0',
  `limittype0` tinyint(4) DEFAULT '0',
  `limitvalue0` int(11) DEFAULT '0',
  `limittype1` tinyint(4) DEFAULT '0',
  `limitvalue1` int(11) DEFAULT '0',
  `applytype0` tinyint(4) DEFAULT '0',
  `applyvalue0` int(11) DEFAULT '0',
  `applytype1` tinyint(4) DEFAULT '0',
  `applyvalue1` int(11) DEFAULT '0',
  `applytype2` tinyint(4) DEFAULT '0',
  `applyvalue2` int(11) DEFAULT '0',
  `value0` int(11) DEFAULT '0',
  `value1` int(11) DEFAULT '0',
  `value2` int(11) DEFAULT '0',
  `value3` int(11) DEFAULT '0',
  `value4` int(11) DEFAULT '0',
  `value5` int(11) DEFAULT '0',
  `socket0` tinyint(4) DEFAULT '-1',
  `socket1` tinyint(4) DEFAULT '-1',
  `socket2` tinyint(4) DEFAULT '-1',
  `socket3` tinyint(4) DEFAULT '-1',
  `specular` tinyint(4) NOT NULL DEFAULT '0',
  `vnum_range` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`vnum`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
you can delete specular from item_proto database because only client use this.

Everything's tested and working. (dev dir: mainline)


After you apply my correction you must set item range in database->item_proto->vnum_range.


For DSS you need to apply range for this items (simply run this query after you applied my fix)
Zonni is offline  
Thanks
9 Users
Old 08/16/2014, 19:26   #2
 
.Captor's Avatar
 
elite*gold: 0
Join Date: May 2013
Posts: 223
Received Thanks: 93
Nice Release, but i have a question.

What we need to input in 'vnum_range' (DragonSoul)? Like this: 110000~110099 or what?

Edit: BTW, the code doesn't work. 16 compiling errors.
.Captor is offline  
Old 08/16/2014, 19:44   #3
 
Zonni's Avatar
 
elite*gold: 100
Join Date: Feb 2008
Posts: 195
Received Thanks: 270
@.Captor
You must input for example 99 :P

For me everything's working.

Um, i can debug your code but i don't understand German as well for read your errors. PM me.
Zonni is offline  
Thanks
1 User
Old 08/16/2014, 19:48   #4
 
.Captor's Avatar
 
elite*gold: 0
Join Date: May 2013
Posts: 223
Received Thanks: 93
Quote:
Originally Posted by Zonni View Post
@.Captor
You must input for example 99 :P

Um, i can debug your code but i don't understand German as well for read your errors. PM me.
Ah, ok. That's nice.

Wait. i PM you.

Edit: Thanks for your Help, it work's.
.Captor is offline  
Old 08/17/2014, 13:12   #5
 
.Risan.'s Avatar
 
elite*gold: 30
Join Date: Jul 2010
Posts: 1,627
Received Thanks: 1,450
den sinn dahinter verstehe ich nicht..
.Risan. is offline  
Old 08/18/2014, 13:41   #6
 
elite*gold: 0
Join Date: Dec 2009
Posts: 113
Received Thanks: 44
Hint: Memory leak.
miguelmig is offline  
Old 08/18/2014, 15:23   #7
 
Yiv's Avatar
 
elite*gold: 47
Join Date: Feb 2012
Posts: 2,282
Received Thanks: 2,579
Quote:
Originally Posted by miguelmig View Post
Hint: Memory leak.
As he said you should delete the SQLMsg pointer "sqlMsg" after you don't need it anymore.

Anyway, thanks for your release

Regards
Yiv is offline  
Old 08/18/2014, 15:46   #8
 
lollo_9_1's Avatar
 
elite*gold: 100
Join Date: Jun 2009
Posts: 168
Received Thanks: 711
Quote:
Originally Posted by DaJuBi View Post
As he said you should delete the SQLMsg pointer "sqlMsg" after you don't need it anymore.

Anyway, thanks for your release

Regards
Just wrap it in a smart pointer.
lollo_9_1 is offline  
Old 08/18/2014, 22:29   #9
 
kstmr's Avatar
 
elite*gold: 0
Join Date: Feb 2012
Posts: 95
Received Thanks: 29
this is for sql user
what about txt users?
kstmr is offline  
Old 08/18/2014, 22:48   #10
 
Zonni's Avatar
 
elite*gold: 100
Join Date: Feb 2008
Posts: 195
Received Thanks: 270
Quote:
Originally Posted by kstmr View Post
this is for sql user
what about txt users?
They haven't any bug because database properly loading a text file.
Zonni is offline  
Old 08/18/2014, 23:57   #11
 
Yiv's Avatar
 
elite*gold: 47
Join Date: Feb 2012
Posts: 2,282
Received Thanks: 2,579
Please use a smart pointer, as lollo_9_1 said, or delete the sqlMsg pointer.

For example with
Code:
M2_DELETE(sqlMsg);
Regards
Yiv is offline  
Old 08/19/2014, 00:05   #12
 
lollo_9_1's Avatar
 
elite*gold: 100
Join Date: Jun 2009
Posts: 168
Received Thanks: 711
Code:
std::auto_ptr<SQLMsg> sqlMsg(CDBManager::instance().DirectQuery(query.str().c_str(), SQL_PLAYER));
Now it should be safe. (replace auto_ptr with unique_ptr in c++11)
lollo_9_1 is offline  
Thanks
1 User
Old 08/12/2015, 21:40   #13
 
elite*gold: 0
Join Date: Jul 2011
Posts: 9
Received Thanks: 0
It's safe ?
BaleweoO is offline  
Old 08/12/2015, 22:49   #14
 
elite*gold: 5
Join Date: Mar 2015
Posts: 499
Received Thanks: 376
Quote:
Originally Posted by BaleweoO View Post
It's safe ?
if lollo says it's safe then it's safe.
KΛIƬӨ is offline  
Reply


Similar Threads Similar Threads
Suche tool dass Clientside Item_proto zu serverside item_proto macht
08/07/2013 - Metin2 Private Server - 0 Replies
Hallo, Suche ein tool womit ich codes aus der clientside item_proto z.B <Item vnum="54800" name="'Áø±Í¾Æ°Ë+9'" gb2312name="Kristallklinge+0" type="1" subtype="0" weight="0" size="2" antiflag="300" flag="1" wearflag="16" immuneflag="0" gold="360000" buy_price="2770000" limittype0="1" limitvalue0="95" limittype1="0" limitvalue1="0" applytype0="7" applyvalue0="30" applytype1="15" applyvalue1="15" applytype2="17" applyvalue2="15" value0="0" value1="60" value2="80" value3="10" value4="50"...
i want to trade my 100m SRO gold to your levelup load or RF load
04/15/2008 - Silkroad Online Trading - 1 Replies
hi..........anyone want SRO gold i have 100m i want to trade this to your levelup load or RF load anyone have just pm me or contact me this email add. [email protected] or +639202300892



All times are GMT +1. The time now is 22:48.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.