Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined(ENABLE_REOPEN_OFFLINE_SHOP)
- bool COfflineShopManager::ReopenOfflineShop(LPCHARACTER ch, const char * c_pszSign, BYTE bTime)
- {
- if (ch)
- {
- quest::PC * pPC = quest::CQuestManager::Instance().GetPC(ch->GetPlayerID());
- if (pPC->IsRunning()) return false;
- if (ch->GetShop() || ch->GetOfflineShop()) return false;
- #ifdef FAST_ACTIONS_PROTECTION
- int iPulse = thecore_pulse();
- if (iPulse - ch->GetWarpTime() < PASSES_PER_SEC(g_nPortalLimitTime)) return false;
- if (iPulse - ch->GetMyShopTime() < PASSES_PER_SEC(g_nPortalLimitTime)) return false;
- if (iPulse - ch->GetExchangeTime() < PASSES_PER_SEC(g_nPortalLimitTime)) return false;
- if (iPulse - ch->GetRefineTime() < PASSES_PER_SEC(g_nPortalLimitTime)) return false;
- if (ch->m_pkTimedEvent) return false;
- if (ch->GetExchange() || ch->IsOpenSafebox() || ch->IsCubeOpen()) return false;
- #ifdef __SASH_SYSTEM__
- if (ch->isSashOpened(false) || ch->isSashOpened(true)) return false;
- #endif
- #endif
- #endif
- char szSign[SHOP_SIGN_MAX_LEN + 1];
- strlcpy(szSign, c_pszSign, sizeof(szSign));
- m_stOfflineShopSign = szSign;
- #ifdef OFFLINE_SHOP_NAME_FIX
- char BlacklistChars[] = {'/', '>', '<', '|', ';', ':', '}', '{', '[', ']', '%', '#', '@', '^', '&', '"'};
- size_t stringPos;
- for (int i = 0; i < _countof(BlacklistChars); ++i)
- {
- stringPos = m_stOfflineShopSign.find(BlacklistChars[i]);
- if (stringPos != std::string::npos)
- {
- ch->ChatPacket(CHAT_TYPE_INFO, "Niepoprawne znaki w nazwie sklepu.");
- return false;
- }
- }
- stringPos = m_stOfflineShopSign.find("'");
- if (stringPos != std::string::npos)
- {
- ch->ChatPacket(CHAT_TYPE_INFO, "Niepoprawne znaki w nazwie sklepu: '");
- return false;
- }
- #endif
- if (m_stOfflineShopSign.length() == 0) return false;
- 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()));
- MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
- BYTE bCount;
- str_to_number(bCount, row[0]);
- if (bCount > 0)
- {
- LPCHARACTER npc = NULL;
- if ((npc = CHARACTER_MANAGER::instance().SpawnMob(30000, ch->GetMapIndex(), ch->GetX(), ch->GetY(), ch->GetZ(), false, -1, false, true, ch->GetPlayerID())))
- {
- int iTime = 0;
- switch (bTime)
- {
- case 1:
- iTime = 1 * 60 * 60;
- break;
- case 2:
- iTime = 2 * 60 * 60;
- break;
- case 3:
- iTime = 4 * 60 * 60;
- break;
- }
- npc->SetOfflineShopTimer(iTime);
- npc->StartOfflineShopUpdateEvent();
- 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);
- DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 0 WHERE owner_id = %u and status = 1", get_table_postfix(), GetPlayerID());
- LPOFFLINESHOP pkOfflineShop = NULL;
- if ((pkOfflineShop = CreateOfflineShop(npc, ch->GetPlayerID())))
- {
- npc->SetOfflineShop(pkOfflineShop);
- npc->SetOfflineShopChannel(g_bChannel);
- char szName[CHARACTER_NAME_MAX_LEN + 1];
- snprintf(szName, sizeof(szName), "%s's offline shop", ch->GetName());
- npc->SetName(szName);
- ch->SetOfflineShopVID(npc->GetVID());
- npc->Show(ch->GetMapIndex(), ch->GetX(), ch->GetY(), ch->GetZ(), true);
- TPacketGCShopSign p;
- p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
- p.dwVID = npc->GetVID();
- strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
- ch->PacketAround(&p, sizeof(TPacketGCShopSign));
- if (bTime != 4)
- ch->ChatPacket(CHAT_TYPE_INFO, "<Offline Shop> Your offline shop's was reopened and time is expired after %d hour(s)", bTime);
- else
- ch->ChatPacket(CHAT_TYPE_INFO, "<Offline Shop> Your offline shop's was reopened and time is configured as unlimited!");
- return true;
- }
- }
- }
- }
- return false;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement