Advertisement
idontusemyphone

Untitled

Nov 5th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. #if defined(ENABLE_REOPEN_OFFLINE_SHOP)
  2. bool COfflineShopManager::ReopenOfflineShop(LPCHARACTER ch, const char * c_pszSign, BYTE bTime)
  3. {
  4. if (ch)
  5. {
  6. quest::PC * pPC = quest::CQuestManager::Instance().GetPC(ch->GetPlayerID());
  7. if (pPC->IsRunning()) return false;
  8. if (ch->GetShop() || ch->GetOfflineShop()) return false;
  9. #ifdef FAST_ACTIONS_PROTECTION
  10. int iPulse = thecore_pulse();
  11. if (iPulse - ch->GetWarpTime() < PASSES_PER_SEC(g_nPortalLimitTime)) return false;
  12. if (iPulse - ch->GetMyShopTime() < PASSES_PER_SEC(g_nPortalLimitTime)) return false;
  13. if (iPulse - ch->GetExchangeTime() < PASSES_PER_SEC(g_nPortalLimitTime)) return false;
  14. if (iPulse - ch->GetRefineTime() < PASSES_PER_SEC(g_nPortalLimitTime)) return false;
  15. if (ch->m_pkTimedEvent) return false;
  16. if (ch->GetExchange() || ch->IsOpenSafebox() || ch->IsCubeOpen()) return false;
  17. #ifdef __SASH_SYSTEM__
  18. if (ch->isSashOpened(false) || ch->isSashOpened(true)) return false;
  19. #endif
  20. #endif
  21.  
  22. #endif
  23. char szSign[SHOP_SIGN_MAX_LEN + 1];
  24. strlcpy(szSign, c_pszSign, sizeof(szSign));
  25. m_stOfflineShopSign = szSign;
  26. #ifdef OFFLINE_SHOP_NAME_FIX
  27. char BlacklistChars[] = {'/', '>', '<', '|', ';', ':', '}', '{', '[', ']', '%', '#', '@', '^', '&', '"'};
  28. size_t stringPos;
  29.  
  30. for (int i = 0; i < _countof(BlacklistChars); ++i)
  31. {
  32. stringPos = m_stOfflineShopSign.find(BlacklistChars[i]);
  33. if (stringPos != std::string::npos)
  34. {
  35. ch->ChatPacket(CHAT_TYPE_INFO, "Niepoprawne znaki w nazwie sklepu.");
  36. return false;
  37. }
  38. }
  39.  
  40. stringPos = m_stOfflineShopSign.find("'");
  41. if (stringPos != std::string::npos)
  42. {
  43. ch->ChatPacket(CHAT_TYPE_INFO, "Niepoprawne znaki w nazwie sklepu: '");
  44. return false;
  45. }
  46. #endif
  47.  
  48. if (m_stOfflineShopSign.length() == 0) return false;
  49.  
  50. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_item WHERE owner_id = %u and status = 1", get_table_postfix(), GetPlayerID()));
  51. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  52.  
  53. BYTE bCount;
  54. str_to_number(bCount, row[0]);
  55.  
  56. if (bCount > 0)
  57. {
  58. LPCHARACTER npc = NULL;
  59. if ((npc = CHARACTER_MANAGER::instance().SpawnMob(30000, ch->GetMapIndex(), ch->GetX(), ch->GetY(), ch->GetZ(), false, -1, false, true, ch->GetPlayerID())))
  60. {
  61. int iTime = 0;
  62. switch (bTime)
  63. {
  64. case 1:
  65. iTime = 1 * 60 * 60;
  66. break;
  67. case 2:
  68. iTime = 2 * 60 * 60;
  69. break;
  70. case 3:
  71. iTime = 4 * 60 * 60;
  72. break;
  73. }
  74.  
  75. npc->SetOfflineShopTimer(iTime);
  76. npc->StartOfflineShopUpdateEvent();
  77.  
  78. DBManager::Instance().DirectQuery("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(), ch->GetPlayerID(), c_pszSign, ch->GetName(), iTime, ch->GetX(), ch->GetY(), ch->GetZ(), ch->GetMapIndex(), g_bChannel);
  79. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 0 WHERE owner_id = %u and status = 1", get_table_postfix(), GetPlayerID());
  80.  
  81. LPOFFLINESHOP pkOfflineShop = NULL;
  82. if ((pkOfflineShop = CreateOfflineShop(npc, ch->GetPlayerID())))
  83. {
  84. npc->SetOfflineShop(pkOfflineShop);
  85. npc->SetOfflineShopChannel(g_bChannel);
  86.  
  87. char szName[CHARACTER_NAME_MAX_LEN + 1];
  88. snprintf(szName, sizeof(szName), "%s's offline shop", ch->GetName());
  89. npc->SetName(szName);
  90.  
  91. ch->SetOfflineShopVID(npc->GetVID());
  92. npc->Show(ch->GetMapIndex(), ch->GetX(), ch->GetY(), ch->GetZ(), true);
  93.  
  94. TPacketGCShopSign p;
  95. p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
  96. p.dwVID = npc->GetVID();
  97. strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
  98.  
  99. ch->PacketAround(&p, sizeof(TPacketGCShopSign));
  100.  
  101. if (bTime != 4)
  102. ch->ChatPacket(CHAT_TYPE_INFO, "<Offline Shop> Your offline shop's was reopened and time is expired after %d hour(s)", bTime);
  103. else
  104. ch->ChatPacket(CHAT_TYPE_INFO, "<Offline Shop> Your offline shop's was reopened and time is configured as unlimited!");
  105.  
  106. return true;
  107. }
  108. }
  109. }
  110. }
  111.  
  112. return false;
  113. }
  114. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement