Jump to content

How To Fix Koray Offline Shop & The Offline Shop Corrupted Tables


Recommended Posts

  • Bot

EXPLAIN THE BUG:

 

A lot of time if you restart the server or the server was rebooted with the game alive, the TABLE of the offline shop of koray will be corrupted or deleted...

Why?

The reason we don't know, cause koray systems are full a lot of bug... (maybe because he's not a coder but a reseller...)

But this is not important now, we are here to fix these bugs, not to talk about who is koray.

 

FIX:

 

Find your InitializeOfflineShopTable function into ClientManagerBoot.cpp of the db source:

And use my function:

#ifdef __OFFLINE_SHOP__
bool CClientManager::InitializeOfflineShopTable()
{
	DWORD dwItems[SHOP_HOST_ITEM_MAX_NUM];

	char exist_table[QUERY_MAX_LEN];
	snprintf(exist_table, sizeof(exist_table), "SELECT * FROM offline_shop%s", GetTablePostfix());
	std::auto_ptr<SQLMsg> exist(CDBManager::instance().DirectQuery(exist_table));
	if (exist->Get()->uiAffectedRows == (uint32_t)-1) {
		sys_err("Table: offline_shop%s corrupted or not found, let me create it.", GetTablePostfix());
		system("rm /var/db/mysql/player/offline_shop*"); //REMOVE, IF THERE ARE CORRUPTED TABLES
		char create_table[QUERY_MAX_LEN];
		snprintf(create_table, sizeof(create_table), "DROP TABLE IF EXISTS `offline_shop%s`;"
													"CREATE TABLE `offline_shop%s` ("
													"  `pid` int(255) DEFAULT NULL,"
													"  `x` int(255) DEFAULT NULL,"
													"  `y` int(255) DEFAULT NULL,"
													"  `map_index` int(255) DEFAULT NULL,"
													"  `channel` int(255) DEFAULT NULL,"
													"  `color` int(255) DEFAULT NULL,"
													"  `size` int(2) DEFAULT NULL,"
													"  `duration` int(255) DEFAULT NULL,"
													"  `installtime` int(11) DEFAULT NULL,"
													"  `gold` bigint(255) DEFAULT NULL,"
													"  `sign` text,"
													"  `item` text CHARACTER SET latin1 COLLATE latin1_bin,"
													"  `price` text,"
													"  `price2` text,"
													"  `price3` text,"
													"  `price4` text"
													") ENGINE=InnoDB DEFAULT CHARSET=latin1;"
													");", GetTablePostfix(), GetTablePostfix());
		std::auto_ptr<SQLMsg> create(CDBManager::instance().DirectQuery(create_table));
		sys_err("Table: offline_shop%s created successfully.", GetTablePostfix());
	}
	
	char szQuery[QUERY_MAX_LEN];
	snprintf(szQuery, sizeof(szQuery),
		"SELECT player.account_id,shop.pid,shop.x,shop.y,shop.map_index,shop.channel,shop.duration,shop.installtime,shop.size,shop.gold,shop.item,shop.price,shop.price2,shop.price3,shop.price4,player.name,shop.sign,shop.color "
		"FROM offline_shop%s AS shop LEFT JOIN player%s AS player "
		"ON shop.pid=player.id WHERE player.name IS NOT NULL",
		GetTablePostfix(), GetTablePostfix());

	std::auto_ptr<SQLMsg> pMsg(CDBManager::instance().DirectQuery(szQuery));
	SQLResult* pRes = pMsg->Get();

	m_pOfflineShopTable = new TOfflineShopTable[pRes->uiNumRows];
	memset(m_pOfflineShopTable, 0, sizeof(TOfflineShopTable) * pRes->uiNumRows);

	while (MYSQL_ROW row = mysql_fetch_row(pRes->pSQLResult))
	{
		int idx = 0;

		TOfflineShopTable& shop_table = m_pOfflineShopTable[m_iOfflineShopTableSize++];
		str_to_number(shop_table.dwAID, row[idx++]);
		str_to_number(shop_table.dwPID, row[idx++]);
		str_to_number(shop_table.dwX, row[idx++]);
		str_to_number(shop_table.dwY, row[idx++]);
		str_to_number(shop_table.dwMapIndex, row[idx++]);
		str_to_number(shop_table.dwChannel, row[idx++]);
		str_to_number(shop_table.dwDuration, row[idx++]);
		str_to_number(shop_table.dwInstallTime, row[idx++]);
		str_to_number(shop_table.dwSize, row[idx++]);
		str_to_number(shop_table.ullMoney, row[idx++]);
		thecore_memcpy(dwItems, row[idx++], sizeof(dwItems));
		thecore_memcpy(shop_table.price, row[idx++], sizeof(shop_table.price));
		thecore_memcpy(shop_table.price2, row[idx++], sizeof(shop_table.price2));
		thecore_memcpy(shop_table.price3, row[idx++], sizeof(shop_table.price3));
		thecore_memcpy(shop_table.price4, row[idx++], sizeof(shop_table.price4));
		strlcpy(shop_table.szName, row[idx++], sizeof(shop_table.szName));
		strlcpy(shop_table.szSign, row[idx++], sizeof(shop_table.szSign));
		str_to_number(shop_table.dwColor, row[idx++]);

		CreateItemCacheSet(shop_table.dwPID);


		char szSockets[QUERY_MAX_LEN / 2] = { '\0' }, szAttrs[QUERY_MAX_LEN / 2] = { '\0' };
		char *pTmpSockets = szSockets, *pTmpAttrs = szAttrs;

		int i = 0;
		for (i = 0; i < ITEM_ATTRIBUTE_MAX_NUM; i++)
		{
			pTmpAttrs += (i < 7) ? sprintf(pTmpAttrs, "attrtype%d,attrvalue%d", i, i) : sprintf(pTmpAttrs, "applytype%d,applyvalue%d", i - 7, i - 7);
			if (i < ITEM_ATTRIBUTE_MAX_NUM - 1)
				pTmpAttrs += sprintf(pTmpAttrs, ",");
		}
		for (i = 0; i < ITEM_SOCKET_MAX_NUM; i++)
		{
			pTmpSockets += sprintf(pTmpSockets, "socket%d", i);
			if (i < ITEM_SOCKET_MAX_NUM - 1)
				pTmpSockets += sprintf(pTmpSockets, ",");
		}

		snprintf(szQuery, sizeof(szQuery),
			"SELECT id,pos,count,"
			"vnum,%s,%s "
			"FROM item%s WHERE owner_id=%d AND window=%d",
			szSockets, szAttrs, GetTablePostfix(), shop_table.dwPID, OFFLINE_SHOP);

		std::auto_ptr<SQLMsg> pMsg2(CDBManager::instance().DirectQuery(szQuery));
		SQLResult* pRes2 = pMsg2->Get();

		DWORD dwItemID, dwItemPos;
		while (MYSQL_ROW row2 = mysql_fetch_row(pRes2->pSQLResult))
		{
			int idx2 = 0;
			str_to_number(dwItemID, row2[idx2++]);
			str_to_number(dwItemPos, row2[idx2++]);

			if (dwItemID != dwItems[dwItemPos])
				continue;

			TPlayerItem& pItem = shop_table.items[dwItemPos];
			pItem.id = dwItemID;
			pItem.pos = dwItemPos;
			str_to_number(pItem.count, row2[idx2++]);
			str_to_number(pItem.vnum, row2[idx2++]);

			int i = 0;
			for (i = 0; i < ITEM_SOCKET_MAX_NUM; i++)
				str_to_number(pItem.alSockets[i], row2[idx2++]);

			for (i = 0; i < ITEM_ATTRIBUTE_MAX_NUM; i++)
			{
				str_to_number(pItem.aAttr[i].bType, row2[idx2++]);
				str_to_number(pItem.aAttr[i].sValue, row2[idx2++]);
			}

			pItem.window = OFFLINE_SHOP;
			pItem.owner = shop_table.dwPID;

			PutItemCache(&pItem, true);
		}
	}

	return true;
}
#endif

 

english_banner.gif

and you call that a "fix"?

shame on you!

Quote

(maybe because he's not a coder but a reseller...)

you should stop trying to ruin the system and stop accusing others. unlike you, koray had an idea about it when he did it. please don't try to fix anything else.

If you're really willing to fix this system you should separate items from shops. I've done it but I'm not going to share any fixes because I don't recommend anyone to implement it.

-- ----------------------------
-- Table structure for offline_shop
-- ----------------------------
DROP TABLE IF EXISTS `offline_shop`;
CREATE TABLE `offline_shop` (
  `pid` int(11) DEFAULT NULL,
  `x` int(11) DEFAULT NULL,
  `y` int(11) DEFAULT NULL,
  `map_index` int(11) DEFAULT NULL,
  `channel` int(11) DEFAULT NULL,
  `color` int(11) DEFAULT NULL,
  `size` int(11) DEFAULT NULL,
  `duration` int(11) DEFAULT NULL,
  `installtime` int(11) DEFAULT NULL,
  `gold` bigint(44) DEFAULT '0',
  `sign` varbinary(40) DEFAULT NULL,
  `sign_type` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- ----------------------------
-- Table structure for offline_shop_items
-- ----------------------------
DROP TABLE IF EXISTS `offline_shop_items`;
CREATE TABLE `offline_shop_items` (
  `pid` int(11) NOT NULL,
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  `map_index` int(11) NOT NULL,
  `channel` int(11) NOT NULL,
  `item_id` int(11) NOT NULL,
  `pos` int(11) NOT NULL,
  `price` bigint(20) unsigned NOT NULL DEFAULT '0',
  `price2` bigint(20) NOT NULL DEFAULT '0',
  `price3` bigint(20) unsigned NOT NULL DEFAULT '0',
  `price4` bigint(20) unsigned NOT NULL DEFAULT '0',
  UNIQUE KEY `ShopDetails&ItemID` (`pid`,`x`, `y`, `map_index`,`item_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

  • Premium
	if (exist->Get()->uiAffectedRows == (uint32_t)-1) {
system("rm /var/db/mysql/player/offline_shop*"); //REMOVE, IF THERE ARE CORRUPTED TABLES
		char create_table[QUERY_MAX_LEN];
		snprintf(create_table, sizeof(create_table), "DROP TABLE IF EXISTS `offline_shop%s`;"
													"CREATE TABLE `offline_shop%s` ("
				

k

 

  • Love 1
  • Bot
3 hours ago, metin2team said:

and you call that a "fix"?

shame on you!

you should stop trying to ruin the system and stop accusing others. unlike you, koray had an idea about it when he did it. please don't try to fix anything else.

If you're really willing to fix this system you should separate items from shops. I've done it but I'm not going to share any fixes because I don't recommend anyone to implement it.


-- ----------------------------
-- Table structure for offline_shop
-- ----------------------------
DROP TABLE IF EXISTS `offline_shop`;
CREATE TABLE `offline_shop` (
  `pid` int(11) DEFAULT NULL,
  `x` int(11) DEFAULT NULL,
  `y` int(11) DEFAULT NULL,
  `map_index` int(11) DEFAULT NULL,
  `channel` int(11) DEFAULT NULL,
  `color` int(11) DEFAULT NULL,
  `size` int(11) DEFAULT NULL,
  `duration` int(11) DEFAULT NULL,
  `installtime` int(11) DEFAULT NULL,
  `gold` bigint(44) DEFAULT '0',
  `sign` varbinary(40) DEFAULT NULL,
  `sign_type` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- ----------------------------
-- Table structure for offline_shop_items
-- ----------------------------
DROP TABLE IF EXISTS `offline_shop_items`;
CREATE TABLE `offline_shop_items` (
  `pid` int(11) NOT NULL,
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  `map_index` int(11) NOT NULL,
  `channel` int(11) NOT NULL,
  `item_id` int(11) NOT NULL,
  `pos` int(11) NOT NULL,
  `price` bigint(20) unsigned NOT NULL DEFAULT '0',
  `price2` bigint(20) NOT NULL DEFAULT '0',
  `price3` bigint(20) unsigned NOT NULL DEFAULT '0',
  `price4` bigint(20) unsigned NOT NULL DEFAULT '0',
  UNIQUE KEY `ShopDetails&ItemID` (`pid`,`x`, `y`, `map_index`,`item_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

I will do it. But this is a big fix cause if your table was corrupted the server doesn't start.

english_banner.gif

  • Bot
2 minutes ago, metin2team said:

omg you have no idea at all.

man why not trying to repair the damn table rather than delete it?

https://dev.mysql.com/doc/refman/5.7/en/repair-table.html

Yes sorry you have right, i will make another version of the fix with REPAIR.

thank you

english_banner.gif

So, you are deleting and recreating the table with the items on each server restart?

If I'm not wrong, koray's offline shop uses a different engine for tables. Change it to the metin2 default mysql engine and it won't corrupt (I think it is InnoDB or Mysam, I can't remember).

  • Love 1

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.