From 2570dda0665f7ca58df9e8d92613239aeab9522a Mon Sep 17 00:00:00 2001 From: wish Date: Thu, 4 Aug 2022 10:34:22 +1000 Subject: [PATCH] revert road shop changes --- patch-schema/revert-road-shop.sql | 9 +++++ server/channelserver/handlers_shop_gacha.go | 45 +++------------------ 2 files changed, 15 insertions(+), 39 deletions(-) create mode 100644 patch-schema/revert-road-shop.sql diff --git a/patch-schema/revert-road-shop.sql b/patch-schema/revert-road-shop.sql new file mode 100644 index 000000000..830f3aa0f --- /dev/null +++ b/patch-schema/revert-road-shop.sql @@ -0,0 +1,9 @@ +BEGIN; + +ALTER TABLE IF EXISTS public.normal_shop_items + DROP COLUMN IF EXISTS enable_weeks; + +ALTER TABLE IF EXISTS public.shop_item_state + DROP COLUMN IF EXISTS week; + +END; \ No newline at end of file diff --git a/server/channelserver/handlers_shop_gacha.go b/server/channelserver/handlers_shop_gacha.go index 8eca5b6c1..7ee712c1a 100644 --- a/server/channelserver/handlers_shop_gacha.go +++ b/server/channelserver/handlers_shop_gacha.go @@ -2,11 +2,8 @@ package channelserver import ( "encoding/hex" - "fmt" - "strings" "time" - //"erupe-ce/common/stringsupport" "erupe-ce/common/byteframe" "erupe-ce/network/mhfpacket" "github.com/lib/pq" @@ -14,16 +11,6 @@ import ( "go.uber.org/zap" ) -func contains(s []string, str string) bool { - for _, v := range s { - if v == str { - return true - } - } - - return false -} - func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfEnumerateShop) // SHOP TYPES: @@ -162,27 +149,19 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) { doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) } } else { - _, week := time.Now().ISOWeek() - season := fmt.Sprintf("%d", week%4) - shopEntries, err := s.server.db.Query("SELECT itemhash,itemID,Points,TradeQuantity,rankReqLow,rankReqHigh,rankReqG,storeLevelReq,maximumQuantity,boughtQuantity,roadFloorsRequired,weeklyFatalisKills, COALESCE(enable_weeks, '') FROM normal_shop_items WHERE shoptype=$1 AND shopid=$2", pkt.ShopType, pkt.ShopID) + shopEntries, err := s.server.db.Query("SELECT itemhash,itemID,Points,TradeQuantity,rankReqLow,rankReqHigh,rankReqG,storeLevelReq,maximumQuantity,boughtQuantity,roadFloorsRequired,weeklyFatalisKills FROM normal_shop_items WHERE shoptype=$1 AND shopid=$2", pkt.ShopType, pkt.ShopID) if err != nil { panic(err) } var ItemHash, entryCount int var itemID, Points, TradeQuantity, rankReqLow, rankReqHigh, rankReqG, storeLevelReq, maximumQuantity, boughtQuantity, roadFloorsRequired, weeklyFatalisKills, charQuantity uint16 - var itemWeeks string resp := byteframe.NewByteFrame() resp.WriteUint32(0) // total defs for shopEntries.Next() { - err = shopEntries.Scan(&ItemHash, &itemID, &Points, &TradeQuantity, &rankReqLow, &rankReqHigh, &rankReqG, &storeLevelReq, &maximumQuantity, &boughtQuantity, &roadFloorsRequired, &weeklyFatalisKills, &itemWeeks) + err = shopEntries.Scan(&ItemHash, &itemID, &Points, &TradeQuantity, &rankReqLow, &rankReqHigh, &rankReqG, &storeLevelReq, &maximumQuantity, &boughtQuantity, &roadFloorsRequired, &weeklyFatalisKills) if err != nil { panic(err) } - - if len(itemWeeks) > 0 && !contains(strings.Split(itemWeeks, ","), season) { - continue - } - resp.WriteUint32(uint32(ItemHash)) resp.WriteUint16(0) // unk, always 0 in existing packets resp.WriteUint16(itemID) @@ -195,13 +174,9 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) { resp.WriteUint16(storeLevelReq) resp.WriteUint16(maximumQuantity) if maximumQuantity > 0 { - var itemWeek int - err = s.server.db.QueryRow("SELECT COALESCE(usedquantity,0), COALESCE(week,-1) FROM shop_item_state WHERE itemhash=$1 AND char_id=$2", ItemHash, s.charID).Scan(&charQuantity, &itemWeek) + err = s.server.db.QueryRow("SELECT COALESCE(usedquantity,0) FROM shop_item_state WHERE itemhash=$1 AND char_id=$2", ItemHash, s.charID).Scan(&charQuantity) if err != nil { resp.WriteUint16(0) - } else if pkt.ShopID == 7 && itemWeek >= 0 && itemWeek != week { - clearShopItemState(s, s.charID, uint32(ItemHash)) - resp.WriteUint16(0) } else { resp.WriteUint16(charQuantity) } @@ -224,7 +199,6 @@ func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) { } func handleMsgMhfAcquireExchangeShop(s *Session, p mhfpacket.MHFPacket) { - _, week := time.Now().ISOWeek() // writing out to an editable shop enumeration pkt := p.(*mhfpacket.MsgMhfAcquireExchangeShop) if pkt.DataSize == 10 { @@ -232,10 +206,10 @@ func handleMsgMhfAcquireExchangeShop(s *Session, p mhfpacket.MHFPacket) { _ = bf.ReadUint16() // unk, always 1 in examples itemHash := bf.ReadUint32() buyCount := bf.ReadUint32() - _, err := s.server.db.Exec(`INSERT INTO shop_item_state (char_id, itemhash, usedquantity, week) - VALUES ($1,$2,$3,$4) ON CONFLICT (char_id, itemhash) + _, err := s.server.db.Exec(`INSERT INTO shop_item_state (char_id, itemhash, usedquantity) + VALUES ($1,$2,$3) ON CONFLICT (char_id, itemhash) DO UPDATE SET usedquantity = shop_item_state.usedquantity + $3 - WHERE EXCLUDED.char_id=$1 AND EXCLUDED.itemhash=$2`, s.charID, itemHash, buyCount, week) + WHERE EXCLUDED.char_id=$1 AND EXCLUDED.itemhash=$2`, s.charID, itemHash, buyCount) if err != nil { s.logger.Fatal("Failed to update shop_item_state in db", zap.Error(err)) } @@ -243,13 +217,6 @@ func handleMsgMhfAcquireExchangeShop(s *Session, p mhfpacket.MHFPacket) { doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) } -func clearShopItemState(s *Session, charId uint32, itemHash uint32) { - _, err := s.server.db.Exec(`DELETE FROM shop_item_state WHERE char_id=$1 AND itemhash=$2`, charId, itemHash) - if err != nil { - s.logger.Fatal("Failed to delete shop_item_state in db", zap.Error(err)) - } -} - func handleMsgMhfGetGachaPlayHistory(s *Session, p mhfpacket.MHFPacket) { // returns number of times the gacha was played, will need persistent db stuff pkt := p.(*mhfpacket.MsgMhfGetGachaPlayHistory)