Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 KB | None | 0 0
  1. void CHARACTER::OpenMyOfflineShop(const char * c_pszSign, TOfflineShopItemTable * pTable, BYTE bItemCount, BYTE bTime)
  2. {
  3.  
  4. int iPulse = thecore_pulse();
  5. if (iPulse - GetWarpTime() < PASSES_PER_SEC(g_nPortalLimitTime))
  6. return;
  7.  
  8. quest::PC * pPC = quest::CQuestManager::instance().GetPC(GetPlayerID());
  9.  
  10. if (pPC && pPC->IsRunning())
  11. return;
  12.  
  13. if (bItemCount == 0)
  14. return;
  15.  
  16. if (GetShop() || GetOfflineShop())
  17. return;
  18.  
  19. if (g_bEnableEmpireLimit)
  20. {
  21. if (GetEmpire() == 1 && (GetMapIndex() == 41 || GetMapIndex() == 21))
  22. {
  23. ChatPacket(CHAT_TYPE_INFO, "You can't build offline shop in this village!");
  24. return;
  25. }
  26. else if (GetEmpire() == 2 && (GetMapIndex() == 1 || GetMapIndex() == 41))
  27. {
  28. ChatPacket(CHAT_TYPE_INFO, "You can't build offline shop in this village!");
  29. return;
  30. }
  31. else if (GetEmpire() == 3 && (GetMapIndex() == 1 || GetMapIndex() == 21))
  32. {
  33. ChatPacket(CHAT_TYPE_INFO, "You can't build offline shop in this village!");
  34. return;
  35. }
  36. }
  37.  
  38. {
  39. std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_item WHERE owner_id = %u and status = 1", get_table_postfix(), GetPlayerID()));
  40. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  41.  
  42. BYTE bResult = 0;
  43. str_to_number(bResult, row[0]);
  44.  
  45. if (bResult)
  46. {
  47. ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "get_items_first"));
  48. return;
  49. }
  50. memset(&bResult, 0, sizeof(bResult));
  51.  
  52. }
  53.  
  54. {
  55. std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), GetPlayerID()));
  56. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  57.  
  58. BYTE bResult = 0;
  59. str_to_number(bResult, row[0]);
  60.  
  61. if (bResult)
  62. {
  63. ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "already_have_offlineshop"));
  64. return;
  65. }
  66. memset(&bResult, 0, sizeof(bResult));
  67.  
  68. }
  69.  
  70. if (g_bOfflineShopMapAllowLimit)
  71. {
  72. if (!offlineshop_map_allow_find(GetMapIndex()))
  73. {
  74. ChatPacket(CHAT_TYPE_INFO, "You cannot open an offline-shop here!");
  75. return;
  76. }
  77. }
  78.  
  79. if (g_bNeededItem)
  80. {
  81. BYTE bCount = quest::CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem(g_iItemVnum);
  82. if (bCount < g_iItemVnum)
  83. {
  84. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(g_iItemVnum);
  85. ChatPacket(CHAT_TYPE_INFO, "You cannot open an offline-shop at the moment. You need to x%d %s", g_bItemCount, pItem->GetName());
  86. return;
  87. }
  88. }
  89.  
  90. if (g_bNeededMoney)
  91. {
  92. if (GetGold() < static_cast<long long>(g_dwNeedMoney))
  93. {
  94. ChatPacket(CHAT_TYPE_INFO, "You do not have enough money to open an offline-shop at the moment.");
  95. ChatPacket(CHAT_TYPE_INFO, "Required money : %u", g_dwNeedMoney);
  96. return;
  97. }
  98. }
  99.  
  100. if (g_bNeedMinLevel && GetLevel() < g_bMinLevel)
  101. {
  102. ChatPacket(CHAT_TYPE_INFO, "Your level is not enough to open an offline shop!");
  103. return;
  104. }
  105.  
  106. {
  107. if (g_wCoinsForUnlimited > 0 && bTime == 4)
  108. {
  109. std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = %u", GetAID()));
  110. if (pMsg->Get()->uiNumRows == 0) return;
  111. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  112. long lCoins = 0;
  113. str_to_number(lCoins, row[0]);
  114.  
  115. if (lCoins < static_cast<long>(g_wCoinsForUnlimited))
  116. {
  117. ChatPacket(CHAT_TYPE_INFO, "You can't open an offline shop. You need to %d coins to open an offline shop!", g_wCoinsForUnlimited);
  118. return;
  119. }
  120.  
  121. DBManager::instance().DirectQuery("UPDATE account.account SET coins = coins - %d where id = %u", g_wCoinsForUnlimited, GetAID());
  122. memset(&lCoins, 0, sizeof(lCoins));
  123.  
  124. }
  125. }
  126.  
  127. char szSign[SHOP_SIGN_MAX_LEN + 1] = { 0 };
  128. DBManager::instance().EscapeString(szSign, sizeof(szSign), c_pszSign, strlen(c_pszSign));
  129.  
  130. if (strlen(szSign) == 0)
  131. {
  132. ChatPacket(CHAT_TYPE_INFO, "Nie mozesz otworzyc sklepu bez jego nazwy!");
  133. return;
  134. }
  135.  
  136. m_stOfflineShopSign = szSign;
  137. memset(&szSign, 0, sizeof(szSign));
  138. if (CBanwordManager::instance().CheckString(m_stOfflineShopSign.c_str(), m_stOfflineShopSign.length()))
  139. {
  140. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("şńĽÓľîłŞ Ŕşľî°ˇ Ć÷ÇÔµČ »óÁˇ Ŕ̸§Ŕ¸·Î »óÁˇŔ» ż­ Ľö ľř˝Ŕ´Ď´Ů."));
  141. return;
  142. }
  143.  
  144. if (m_stOfflineShopSign.length() == 0)
  145. return;
  146.  
  147. LPCHARACTER npc = CHARACTER_MANAGER::instance().SpawnMob(30000, GetMapIndex(), GetX(), GetY(), GetZ(), false, -1, false, true, GetPlayerID());
  148.  
  149. if (!npc)
  150. {
  151. ChatPacket(CHAT_TYPE_INFO, "Offline shop npc can not create! Please try again.");
  152. return;
  153. }
  154. SetOfflineShopTime();
  155.  
  156. bool bIsWrong = false;
  157.  
  158. // First check the items
  159. for (BYTE i = 0; i < bItemCount; ++i)
  160. {
  161. LPITEM pItem = GetItem((pTable + i)->pos);
  162. if (!pItem)
  163. continue;
  164.  
  165. if (pItem->IsEquipped())
  166. {
  167. bIsWrong = true;
  168. ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "CANNOT_SELL_EQUIPPED_ITEM"));
  169. return;
  170. }
  171.  
  172. if (pItem->isLocked())
  173. {
  174. bIsWrong = true;
  175. ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "CANNOT_SELL_LOCKED_ITEM"));
  176. return;
  177. }
  178.  
  179. if ((pTable + i)->price >= GOLD_MAX)
  180. {
  181. bIsWrong = true;
  182. ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "OVERFLOW_OF_GOLD_ON_ITEMS"));
  183. return;
  184. }
  185. }
  186.  
  187. if (!bIsWrong)
  188. {
  189. for (BYTE i = 0; i < bItemCount; ++i)
  190. {
  191. LPITEM pkItem = GetItem((pTable + i)->pos);
  192. if (!pkItem)
  193. continue;
  194.  
  195. char szColumns[QUERY_MAX_LEN], szValues[QUERY_MAX_LEN];
  196.  
  197. int iLen = snprintf(szColumns, sizeof(szColumns), "id,owner_id,pos,count,price,vnum");
  198. int iUpdateLen = snprintf(szValues, sizeof(szValues), "%u,%u,%d,%u,%lld,%u", pkItem->GetID(), GetPlayerID(), (pTable + i)->display_pos, pkItem->GetCount(), (pTable + i)->price, pkItem->GetVnum());
  199. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2");
  200. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2));
  201.  
  202. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6");
  203. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
  204. pkItem->GetAttributeType(0), pkItem->GetAttributeValue(0),
  205. pkItem->GetAttributeType(1), pkItem->GetAttributeValue(1),
  206. pkItem->GetAttributeType(2), pkItem->GetAttributeValue(2),
  207. pkItem->GetAttributeType(3), pkItem->GetAttributeValue(3),
  208. pkItem->GetAttributeType(4), pkItem->GetAttributeValue(4),
  209. pkItem->GetAttributeType(5), pkItem->GetAttributeValue(5),
  210. pkItem->GetAttributeType(6), pkItem->GetAttributeValue(6));
  211.  
  212. char szInsertQuery[QUERY_MAX_LEN];
  213. snprintf(szInsertQuery, sizeof(szInsertQuery), "INSERT INTO %soffline_shop_item (%s) VALUES (%s)", get_table_postfix(), szColumns, szValues);
  214. std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szInsertQuery));
  215. pkItem->RemoveFromCharacter();
  216. ITEM_MANAGER::instance().FlushDelayedSave(pkItem);
  217.  
  218. memset(&szColumns, 0, sizeof(szColumns));
  219. memset(&szValues, 0, sizeof(szValues));
  220. memset(&szInsertQuery, 0, sizeof(szInsertQuery));
  221.  
  222.  
  223. }
  224. }
  225.  
  226. int iTime = 0;
  227. switch (bTime)
  228. {
  229. case 1:
  230. iTime = 6 * 60 * 60;
  231. break;
  232. case 2:
  233. iTime = 12 * 60 * 60;
  234. break;
  235. case 3:
  236. iTime = 24 * 60 * 60;
  237. break;
  238. }
  239.  
  240. // If bTime is not equal to unlimited time, start the time!
  241. if (bTime != 4)
  242. {
  243. npc->SetOfflineShopTimer(iTime);
  244. npc->StartOfflineShopUpdateEvent();
  245. }
  246. else
  247. {
  248. int iTime = 24 * 60 * 60;
  249. npc->SetOfflineShopTimer(iTime);
  250. npc->StartOfflineShopUpdateEvent();
  251. }
  252. //unsigned char const* text = (unsigned char const*) c_pszSign;
  253. //
  254. //std::string encodedText = base64_encode(text, strlen(c_pszSign));
  255. //
  256. //const char * convert = encodedText.c_str();
  257.  
  258. // Insert
  259. //char query_sign[8096+1];
  260. //snprintf(query_sign, sizeof(query_sign), "INSERT INTO %soffline_shop_npc(owner_id, sign, name, time, x, y, z, mapIndex, channel) VALUES(%u, '%s', '%s', %d, %ld, %ld, %ld, %ld, %d)", get_table_postfix(), GetPlayerID(), convert, GetName(), iTime, GetX(), GetY(), GetZ(), GetMapIndex(), g_bChannel);
  261. //std::unique_ptr<SQLMsg> query_sign(DBManager::instance().DirectQuery(query_sign));
  262. //
  263. //memset(&query_sign, 0, sizeof(query_sign));
  264.  
  265. // Create Offline Shop
  266. LPOFFLINESHOP pkOfflineShop = COfflineShopManager::instance().CreateOfflineShop(npc, GetPlayerID());
  267.  
  268. if (!pkOfflineShop)
  269. {
  270. ChatPacket(CHAT_TYPE_INFO, "Offline shop npc cannot create. Please try again.");
  271. return;
  272. }
  273.  
  274. npc->SetOfflineShop(pkOfflineShop);
  275. npc->SetOfflineShopChannel(g_bChannel);
  276. // End Of Create Offline Shop
  277.  
  278. // Set Name
  279. char szName[CHARACTER_NAME_MAX_LEN + 1];
  280. snprintf(szName, sizeof(szName), "%s - Sklep", GetName());
  281. npc->SetName(szName);
  282. memset(&szName, 0, sizeof(szName));
  283.  
  284. // End Of Set Name
  285.  
  286. SetOfflineShopVID(npc->GetVID());
  287. npc->Show(GetMapIndex(), GetX(), GetY(), GetZ(), true);
  288.  
  289. //std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT sign FROM %soffline_shop_npc WHERE owner_id = %u",get_table_postfix(), GetOfflineShopRealOwner()));
  290. //if (pMsg->Get()->uiNumRows > 0)
  291. //{
  292. // MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  293. //
  294. // std::string base64_sign = row[0] ;
  295. // std::string normal_sign = base64_decode(base64_sign);
  296. // const char * final_sign = normal_sign.c_str() ;
  297. // //-----------//
  298. // TPacketGCShopSign p;
  299. // p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
  300. // p.dwVID = npc->GetVID();
  301. // strlcpy(p.szSign, final_sign, sizeof(p.szSign));
  302. //
  303. // PacketAround(&p, sizeof(TPacketGCShopSign));
  304. // //-----------//
  305. //}
  306. //delete pMsg;
  307. //memset(&pMsg, 0, sizeof(pMsg));
  308.  
  309. // Send Offline Shop Sign to Everyone
  310. //TPacketGCShopSign p;
  311. //p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
  312. //p.dwVID = npc->GetVID();
  313. //strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
  314. //
  315. //PacketAround(&p, sizeof(TPacketGCShopSign));
  316. // End Of Send Offline Shop Sign to Everyone
  317.  
  318. if (g_bNeededItem)
  319. {
  320. LPITEM item = FindSpecifyItem(g_iItemVnum);
  321. if (!item)
  322. {
  323. ChatPacket(CHAT_TYPE_INFO, "Ups! Something went wrong!");
  324. return;
  325. }
  326.  
  327. if (item->IsStackable())
  328. if (item->GetCount() == g_bItemCount)
  329. ITEM_MANAGER::instance().RemoveItem(item);
  330. else
  331. item->SetCount(item->GetCount() - g_bItemCount);
  332. else
  333. ITEM_MANAGER::instance().RemoveItem(item);
  334. }
  335.  
  336. if (g_bNeededMoney)
  337. PointChange(POINT_GOLD, -g_dwNeedMoney, false);
  338.  
  339. SetOfflineShopStatus(2);
  340.  
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement