Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.64 KB | None | 0 0
  1. void CInputMain::Shop2(LPCHARACTER ch, const char * data)
  2. {
  3.     struct command_shop2 * p = (struct command_shop2 *) data;
  4.     int shop2_subheader = (int)p->subheader;
  5.  
  6.     if (!ch){
  7.         sys_err("TPacketCGShop2 packet coming from unknown target");
  8.         return;
  9.     }
  10.  
  11.     if (test_server)
  12.         sys_log(0, "CInputMain::Shop2() ==> SubHeader %d", shop2_subheader);
  13.  
  14.  
  15.     int iFloodResult = ch->GetQuestFlag("item_search.flood_check");
  16.     if (iFloodResult){
  17.         if (get_global_time() < iFloodResult + 5 /* limit */) {
  18.             ch->ChatPacket(CHAT_TYPE_INFO, "You can not use too fast");
  19.             return;
  20.         }
  21.     }
  22.  
  23.  
  24.     if (shop2_subheader == SHOP2_SUBHEADER_CG_SEARCH)
  25.     {
  26.         if (!p->iType && !p->iSubtype){
  27.             sys_err("TPacketCGShop2: SHOP2_SUBHEADER_CG_SEARCH  USER: %s -- HAVE A EMPTY ARGUMENT", ch->GetName());
  28.             return;
  29.         }
  30.  
  31.         sys_log(0, "TPacketCGShop2: SHOP2_SUBHEADER_CG_SEARCH  USER: %s", ch->GetName());
  32.  
  33.  
  34.         if (quest::CQuestManager::instance().GetPCForce(ch->GetPlayerID())->IsRunning())
  35.         {
  36.             ch->ChatPacket(CHAT_TYPE_INFO, "You can not use this in now");
  37.             return;
  38.         }
  39.  
  40.  
  41.         char szQuery[1024];
  42.         if (p->iType == 99) {
  43.             sprintf(szQuery,
  44.             "SELECT * FROM shop_onsales_items \
  45.             WHERE item_type=5 OR item_type=6 OR item_type=7 OR item_type=8 OR item_type=9 OR item_type=11 \
  46.             OR item_type=15 OR item_type=19 OR item_type=21 OR item_type=25 OR item_type=26 OR item_type=27 \
  47.             OR item_type=30 OR item_type=31 OR item_type=32 OR item_type=33 OR item_type=36 OR item_type > 36 \
  48.             AND item_level >= %d AND item_level <= %d \
  49.             AND item_refine >= %d AND item_refine <= %d AND item_price >= %d AND item_price <= %d \
  50.             ORDER BY item_price ASC LIMIT 120",
  51.             p->iMinLevel, p->iMaxLevel,
  52.             p->iMinRefine, p->iMaxRefine, p->iMinPrice, p->iMaxPrice);
  53.         }
  54.         if (p->iSubtype == 99) {
  55.             sprintf(szQuery,
  56.             "SELECT * FROM shop_onsales_items \
  57.             WHERE item_type=%d AND item_level >= %d AND item_level <= %d \
  58.             AND item_refine >= %d AND item_refine <= %d AND item_price >= %d AND item_price <= %d \
  59.             ORDER BY item_price ASC LIMIT 120",
  60.             p->iType, p->iMinLevel, p->iMaxLevel,
  61.             p->iMinRefine, p->iMaxRefine, p->iMinPrice, p->iMaxPrice);
  62.         }
  63.         else if (p->iType == 12) {
  64.             sprintf(szQuery,
  65.             "SELECT * FROM shop_onsales_items \
  66.             WHERE item_type=%d OR item_type=%d AND item_subtype=%d AND item_level >= %d AND item_level <= %d \
  67.             AND item_refine >= %d AND item_refine <= %d AND item_price >= %d AND item_price <= %d \
  68.             ORDER BY item_price ASC LIMIT 120",
  69.             12, 6, p->iSubtype, p->iMinLevel, p->iMaxLevel,
  70.             p->iMinRefine, p->iMaxRefine, p->iMinPrice, p->iMaxPrice);
  71.         }
  72.         else{
  73.             sprintf(szQuery,
  74.             "SELECT * FROM shop_onsales_items \
  75.             WHERE item_type=%d AND item_subtype=%d AND item_level >= %d AND item_level <= %d \
  76.             AND item_refine >= %d AND item_refine <= %d AND item_price >= %d AND item_price <= %d \
  77.             ORDER BY item_price ASC LIMIT 120",
  78.             p->iType, p->iSubtype, p->iMinLevel, p->iMaxLevel,
  79.             p->iMinRefine, p->iMaxRefine, p->iMinPrice, p->iMaxPrice);
  80.         }
  81.         std::auto_ptr<SQLMsg> pSearchQuery(DBManager::instance().DirectQuery(szQuery));
  82.  
  83.  
  84.         if (pSearchQuery->uiSQLErrno != 0) {
  85.             sys_err("Item Search Query Failed, Error code: %ld", pSearchQuery->uiSQLErrno);
  86.             return;
  87.         }
  88.         if (!pSearchQuery->Get()->uiNumRows){
  89.             ch->ChatPacket(CHAT_TYPE_INFO, "Search failed. Doesn't found result.");
  90.             sys_err("Item Search Query Failed, Rows couldn't get");
  91.             return;
  92.         }
  93.  
  94.         int i_x = 0;
  95.         while (MYSQL_ROW row1 = mysql_fetch_row(pSearchQuery->Get()->pSQLResult))
  96.         {
  97.             const char * c_szSellerName = row1[1]; const char * c_szItemName = row1[2]; const char * c_szItemVnum = row1[3];
  98.             const char * c_szItemCount = row1[4]; const char * c_szItemRefine = row1[5]; const char * c_szItemPrice = row1[6];
  99.             const char * c_szItemLevel = row1[7]; const char * c_szItemPos = row1[8];
  100.  
  101.             const char * c_szSocket0 = row1[12]; const char * c_szSocket1 = row1[13]; const char * c_szSocket2 = row1[14];
  102.  
  103.             const char * c_szAttrType1 = row1[15]; const char * c_szAttrValue1 = row1[16]; const char * c_szAttrType2 = row1[17];
  104.             const char * c_szAttrValue2 = row1[18]; const char * c_szAttrType3 = row1[19]; const char * c_szAttrValue3 = row1[20];
  105.             const char * c_szAttrType4 = row1[21]; const char * c_szAttrValue4 = row1[22]; const char * c_szAttrType5 = row1[23];
  106.             const char * c_szAttrValue5 = row1[24]; const char * c_szAttrType6 = row1[25]; const char * c_szAttrValue6 = row1[26];
  107.             const char * c_szAttrType7 = row1[27]; const char * c_szAttrValue7 = row1[28];
  108.  
  109.             /*const char * c_szApplyType1 = row1[29]; const char * c_szApplyValue1 = row1[30]; const char * c_szApplyType2 = row1[31];
  110.             const char * c_szApplyValue2 = row1[32]; const char * c_szApplyType3 = row1[33]; const char * c_szApplyValue3 = row1[34];
  111.             const char * c_szApplyType4 = row1[35]; const char * c_szApplyValue4 = row1[36]; const char * c_szApplyType5 = row1[37];
  112.             const char * c_szApplyValue5 = row1[38]; const char * c_szApplyType6 = row1[39]; const char * c_szApplyValue6 = row1[40];
  113.             const char * c_szApplyType7 = row1[41]; const char * c_szApplyValue7 = row1[42]; const char * c_szApplyType8 = row1[43];
  114.             const char * c_szApplyValue8 = row1[44];*/
  115.  
  116.             const char* c_szItemNameForSearch = p->cItemNameForSearch;
  117.             DWORD dwVnumFromTable = 0;
  118.             str_to_number(dwVnumFromTable, c_szItemVnum);
  119.  
  120.             TItemTable* table = ITEM_MANAGER::instance().GetTable(dwVnumFromTable);
  121.             if (p->iType == 1 || p->iType == 2)
  122.             {
  123.                 if (table && p->iJob == 0 && (table->dwAntiFlags & ITEM_ANTIFLAG_ASSASSIN && table->dwAntiFlags & ITEM_ANTIFLAG_SHAMAN && table->dwAntiFlags & ITEM_ANTIFLAG_SURA) ||
  124.                     table && p->iJob == 1 && (table->dwAntiFlags & ITEM_ANTIFLAG_WARRIOR  && table->dwAntiFlags & ITEM_ANTIFLAG_SHAMAN && table->dwAntiFlags & ITEM_ANTIFLAG_SURA) ||
  125.                     table && p->iJob == 2 && (table->dwAntiFlags & ITEM_ANTIFLAG_ASSASSIN && table->dwAntiFlags & ITEM_ANTIFLAG_SHAMAN && table->dwAntiFlags & ITEM_ANTIFLAG_WARRIOR) ||
  126.                     table && p->iJob == 3 && (table->dwAntiFlags & ITEM_ANTIFLAG_ASSASSIN && table->dwAntiFlags & ITEM_ANTIFLAG_WARRIOR && table->dwAntiFlags & ITEM_ANTIFLAG_SURA))
  127.                 {
  128.                     if (strlen(p->cItemNameForSearch) && strstr(c_szItemName, c_szItemNameForSearch)){
  129.                         if (ch)
  130.                         {
  131.                             ch->ChatPacket(CHAT_TYPE_COMMAND,
  132.                                 "GetSearchedItemData %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
  133.  
  134.                                 i_x, c_szSellerName, c_szItemVnum, c_szItemCount, c_szItemRefine, c_szItemPrice, c_szItemLevel,
  135.  
  136.                                 c_szSocket0, c_szSocket1, c_szSocket2,
  137.  
  138.                                 c_szAttrType1, c_szAttrValue1, c_szAttrType2, c_szAttrValue2, c_szAttrType3, c_szAttrValue3,
  139.                                 c_szAttrType4, c_szAttrValue4, c_szAttrType5, c_szAttrValue5, c_szAttrType6, c_szAttrValue6,
  140.                                 c_szAttrType7, c_szAttrValue7,
  141.  
  142.                                 /*c_szApplyType1, c_szApplyValue1, c_szApplyType2, c_szApplyValue2, c_szApplyType3, c_szApplyValue3,
  143.                                 c_szApplyType4, c_szApplyValue4, c_szApplyType5, c_szApplyValue5, c_szApplyType6, c_szApplyValue6,
  144.                                 c_szApplyType7, c_szApplyValue8,*/
  145.  
  146.                                 c_szItemPos
  147.                                 );
  148.                         }
  149.                     }
  150.                 }
  151.             }
  152.             else{
  153.                 if (ch)
  154.                 {
  155.                     ch->ChatPacket(CHAT_TYPE_COMMAND,
  156.                         "GetSearchedItemData %d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s",
  157.  
  158.                         i_x, c_szSellerName, c_szItemVnum, c_szItemCount, c_szItemRefine, c_szItemPrice, c_szItemLevel,
  159.  
  160.                         c_szSocket0, c_szSocket1, c_szSocket2,
  161.  
  162.                         c_szAttrType1, c_szAttrValue1, c_szAttrType2, c_szAttrValue2, c_szAttrType3, c_szAttrValue3,
  163.                         c_szAttrType4, c_szAttrValue4, c_szAttrType5, c_szAttrValue5, c_szAttrType6, c_szAttrValue6,
  164.                         c_szAttrType7, c_szAttrValue7,
  165.  
  166.                         /*c_szApplyType1, c_szApplyValue1, c_szApplyType2, c_szApplyValue2, c_szApplyType3, c_szApplyValue3,
  167.                         c_szApplyType4, c_szApplyValue4, c_szApplyType5, c_szApplyValue5, c_szApplyType6, c_szApplyValue6,
  168.                         c_szApplyType7, c_szApplyValue8,*/
  169.  
  170.                         c_szItemPos
  171.                         );
  172.                 }
  173.             }
  174.  
  175.  
  176.             ++i_x;
  177.         }
  178.         if (ch){
  179.             ch->ChatPacket(CHAT_TYPE_COMMAND, "CreateSearchedItemList");
  180.             ch->SetQuestFlag("item_search.flood_check", get_global_time());
  181.         }
  182.  
  183.     }
  184.     else if (shop2_subheader == SHOP2_SUBHEADER_CG_BUY)
  185.     {
  186.         if (!strlen(p->cSellerName)){
  187.             sys_err("TPacketCGShop2: SHOP2_SUBHEADER_CG_BUY  USER: %s -- HAVE A EMPTY ARGUMENT", ch->GetName());
  188.             return;
  189.         }
  190.  
  191.         //if (!isdigit(p->bItemPos)){
  192.         //  sys_err("TPacketCGShop2: SHOP2_SUBHEADER_CG_BUY  USER: %s -- ITEM POS ISN'T NUMBER", ch->GetName());
  193.         //  return;
  194.         //}
  195.  
  196.         sys_log(0, "TPacketCGShop2: SHOP2_SUBHEADER_CG_BUY  USER: %s POS: %d SELLER: %s", ch->GetName(), p->bItemPos, p->cSellerName);
  197.  
  198.         LPCHARACTER seller_ch = CHARACTER_MANAGER::instance().FindPC(p->cSellerName);
  199.         if (!seller_ch){
  200.             ch->ChatPacket(CHAT_TYPE_INFO, "%s isn't online or in other channel", p->cSellerName);
  201.             return;
  202.         }
  203.         if (!seller_ch->IsPC() || !seller_ch->GetDesc()){
  204.             ch->ChatPacket(CHAT_TYPE_INFO, "%s isn't PC or isn't active", p->cSellerName);
  205.             return;
  206.         }
  207.         if (seller_ch == ch){
  208.             ch->ChatPacket(CHAT_TYPE_INFO, "You can not buy item from yourself");
  209.             return;
  210.         }
  211.         if (quest::CQuestManager::instance().GetPCForce(ch->GetPlayerID())->IsRunning() ||
  212.             quest::CQuestManager::instance().GetPCForce(seller_ch->GetPlayerID())->IsRunning())
  213.         {
  214.             ch->ChatPacket(CHAT_TYPE_INFO, "You can not use this in now");
  215.             return;
  216.         }
  217.  
  218.         ch->SetQuestFlag("item_search.flood_check", get_global_time());
  219.         if (p->iBuyType == SHOP2_SEARCHER_TYPE_FIND)
  220.             CShopManager::instance().FindFromGlass(seller_ch, ch);
  221.         else
  222.             CShopManager::instance().BuyFromGlass(seller_ch, ch, p->bItemPos, p->iBuyType);
  223.     }
  224.     else
  225.     {
  226.         sys_err("CInputMain::Shop2 : Unknown subheader '%d' - From: %s", shop2_subheader, ch->GetName());
  227.         return;
  228.     }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement