shop enumeration pass 2

This commit is contained in:
wish
2022-11-21 11:42:19 +11:00
parent 9103debe99
commit d21ecf2b31
4 changed files with 75 additions and 67 deletions

View File

@@ -3,15 +3,15 @@ package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/network/clientctx"
"erupe-ce/network"
"erupe-ce/common/byteframe" "erupe-ce/common/byteframe"
"erupe-ce/network"
"erupe-ce/network/clientctx"
) )
// MsgMhfExchangeFpoint2Item represents the MSG_MHF_EXCHANGE_FPOINT_2_ITEM // MsgMhfExchangeFpoint2Item represents the MSG_MHF_EXCHANGE_FPOINT_2_ITEM
type MsgMhfExchangeFpoint2Item struct { type MsgMhfExchangeFpoint2Item struct {
AckHandle uint32 AckHandle uint32
ItemHash uint32 TradeID uint32
ItemType uint16 ItemType uint16
ItemId uint16 ItemId uint16
Quantity byte Quantity byte
@@ -25,7 +25,7 @@ func (m *MsgMhfExchangeFpoint2Item) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfExchangeFpoint2Item) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfExchangeFpoint2Item) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.ItemHash = bf.ReadUint32() m.TradeID = bf.ReadUint32()
m.ItemType = bf.ReadUint16() m.ItemType = bf.ReadUint16()
m.ItemId = bf.ReadUint16() m.ItemId = bf.ReadUint16()
m.Quantity = bf.ReadUint8() m.Quantity = bf.ReadUint8()

View File

@@ -3,15 +3,15 @@ package mhfpacket
import ( import (
"errors" "errors"
"erupe-ce/network/clientctx"
"erupe-ce/network"
"erupe-ce/common/byteframe" "erupe-ce/common/byteframe"
"erupe-ce/network"
"erupe-ce/network/clientctx"
) )
// MsgMhfExchangeItem2Fpoint represents the MSG_MHF_EXCHANGE_ITEM_2_FPOINT // MsgMhfExchangeItem2Fpoint represents the MSG_MHF_EXCHANGE_ITEM_2_FPOINT
type MsgMhfExchangeItem2Fpoint struct { type MsgMhfExchangeItem2Fpoint struct {
AckHandle uint32 AckHandle uint32
ItemHash uint32 TradeID uint32
ItemType uint16 ItemType uint16
ItemId uint16 ItemId uint16
Quantity byte Quantity byte
@@ -25,7 +25,7 @@ func (m *MsgMhfExchangeItem2Fpoint) Opcode() network.PacketID {
// Parse parses the packet from binary // Parse parses the packet from binary
func (m *MsgMhfExchangeItem2Fpoint) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { func (m *MsgMhfExchangeItem2Fpoint) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32() m.AckHandle = bf.ReadUint32()
m.ItemHash = bf.ReadUint32() m.TradeID = bf.ReadUint32()
m.ItemType = bf.ReadUint16() m.ItemType = bf.ReadUint16()
m.ItemId = bf.ReadUint16() m.ItemId = bf.ReadUint16()
m.Quantity = bf.ReadUint8() m.Quantity = bf.ReadUint8()

View File

@@ -15,4 +15,15 @@ CREATE TABLE IF NOT EXISTS public.gacha_shop(
hide boolean hide boolean
); );
DROP TABLE IF EXISTS public.fpoint_items;
CREATE TABLE IF NOT EXISTS public.fpoint_items (
id serial PRIMARY KEY,
item_type integer,
item_id integer,
quantity integer,
fpoints integer,
trade_type integer
);
END; END;

View File

@@ -28,16 +28,16 @@ type ShopItem struct {
} }
type Gacha struct { type Gacha struct {
ID uint32 ID uint32 `db:"id"`
MinGR uint32 MinGR uint32 `db:"min_gr"`
MinHR uint32 MinHR uint32 `db:"min_hr"`
Name string Name string `db:"name"`
Link1 string Link1 string `db:"link1"`
Link2 string Link2 string `db:"link2"`
Link3 string Link3 string `db:"link3"`
Icon uint16 Icon uint16 `db:"icon"`
Type uint16 Type uint16 `db:"type"`
Hide bool Hide bool `db:"hide"`
} }
func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfEnumerateShop(s *Session, p mhfpacket.MHFPacket) {
@@ -319,31 +319,26 @@ func handleMsgMhfUseGachaPoint(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfExchangeFpoint2Item(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfExchangeFpoint2Item(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfExchangeFpoint2Item) pkt := p.(*mhfpacket.MsgMhfExchangeFpoint2Item)
var balance uint32
var itemValue, quant int var itemValue, quantity int
_ = s.server.db.QueryRow("SELECT quant, itemValue FROM fpoint_items WHERE hash=$1", pkt.ItemHash).Scan(&quant, &itemValue) _ = s.server.db.QueryRow("SELECT quantity, fpoints FROM fpoint_items WHERE id=$1", pkt.TradeID).Scan(&quantity, &itemValue)
itemCost := (int(pkt.Quantity) * quant) * itemValue cost := (int(pkt.Quantity) * quantity) * itemValue
s.server.db.QueryRow("UPDATE characters SET frontier_points=frontier_points::int - $1 WHERE id=$2 RETURNING frontier_points", cost, s.charID).Scan(&balance)
// also update frontierpoints entry in database bf := byteframe.NewByteFrame()
_, err := s.server.db.Exec("UPDATE characters SET frontier_points=frontier_points::int - $1 WHERE id=$2", itemCost, s.charID) bf.WriteUint32(balance)
if err != nil { doAckSimpleSucceed(s, pkt.AckHandle, bf.Data())
s.logger.Fatal("Failed to update minidata in db", zap.Error(err))
}
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
} }
func handleMsgMhfExchangeItem2Fpoint(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfExchangeItem2Fpoint(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfExchangeItem2Fpoint) pkt := p.(*mhfpacket.MsgMhfExchangeItem2Fpoint)
var balance uint32
var itemValue, quant int var itemValue, quantity int
_ = s.server.db.QueryRow("SELECT quant, itemValue FROM fpoint_items WHERE hash=$1", pkt.ItemHash).Scan(&quant, &itemValue) s.server.db.QueryRow("SELECT quantity, fpoints FROM fpoint_items WHERE id=$1", pkt.TradeID).Scan(&quantity, &itemValue)
itemCost := (int(pkt.Quantity) / quant) * itemValue cost := (int(pkt.Quantity) / quantity) * itemValue
// also update frontierpoints entry in database s.server.db.QueryRow("UPDATE characters SET frontier_points=COALESCE(frontier_points::int + $1, $1) WHERE id=$2 RETURNING frontier_points", cost, s.charID).Scan(&balance)
_, err := s.server.db.Exec("UPDATE characters SET frontier_points=COALESCE(frontier_points::int + $1, $1) WHERE id=$2", itemCost, s.charID) bf := byteframe.NewByteFrame()
if err != nil { bf.WriteUint32(balance)
s.logger.Fatal("Failed to update minidata in db", zap.Error(err)) doAckSimpleSucceed(s, pkt.AckHandle, bf.Data())
}
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
} }
func handleMsgMhfGetFpointExchangeList(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfGetFpointExchangeList(s *Session, p mhfpacket.MHFPacket) {
@@ -351,48 +346,50 @@ func handleMsgMhfGetFpointExchangeList(s *Session, p mhfpacket.MHFPacket) {
resp := byteframe.NewByteFrame() resp := byteframe.NewByteFrame()
resp.WriteUint32(0) resp.WriteUint32(0)
var buyables, sellables uint16 var buyables, sellables uint16
var hash uint32 var id uint32
var itemType uint8 var itemType uint8
var itemID, quant, itemValue uint16 var itemID, quantity, fPoints uint16
buyRows, err := s.server.db.Query("SELECT hash,itemType,itemID,quant,itemValue FROM fpoint_items WHERE tradeType=0") buyRows, err := s.server.db.Query("SELECT id,item_type,item_id,quantity,fpoints FROM fpoint_items WHERE trade_type=0")
if err == nil { if err == nil {
for buyRows.Next() { for buyRows.Next() {
err = buyRows.Scan(&hash, &itemType, &itemID, &quant, &itemValue) err = buyRows.Scan(&id, &itemType, &itemID, &quantity, &fPoints)
if err != nil { if err != nil {
continue continue
} }
resp.WriteUint32(hash) resp.WriteUint32(id)
resp.WriteUint32(0) // this and following only 0 in known packets resp.WriteUint16(0)
resp.WriteUint16(0)
resp.WriteUint16(0) resp.WriteUint16(0)
resp.WriteUint8(itemType) resp.WriteUint8(itemType)
resp.WriteUint16(itemID) resp.WriteUint16(itemID)
resp.WriteUint16(quant) resp.WriteUint16(quantity)
resp.WriteUint16(itemValue) resp.WriteUint16(fPoints)
buyables++ buyables++
} }
} }
sellRows, err := s.server.db.Query("SELECT hash,itemType,itemID,quant,itemValue FROM fpoint_items WHERE tradeType=1") sellRows, err := s.server.db.Query("SELECT id,item_type,item_id,quantity,fpoints FROM fpoint_items WHERE trade_type=1")
if err == nil { if err == nil {
for sellRows.Next() { for sellRows.Next() {
err = sellRows.Scan(&hash, &itemType, &itemID, &quant, &itemValue) err = sellRows.Scan(&id, &itemType, &itemID, &quantity, &fPoints)
if err != nil { if err != nil {
continue continue
} }
resp.WriteUint32(hash) resp.WriteUint32(id)
resp.WriteUint32(0) // this and following only 0 in known packets resp.WriteUint16(0)
resp.WriteUint16(0)
resp.WriteUint16(0) resp.WriteUint16(0)
resp.WriteUint8(itemType) resp.WriteUint8(itemType)
resp.WriteUint16(itemID) resp.WriteUint16(itemID)
resp.WriteUint16(quant) resp.WriteUint16(quantity)
resp.WriteUint16(itemValue) resp.WriteUint16(fPoints)
sellables++ sellables++
} }
} }
resp.Seek(0, 0) resp.Seek(0, 0)
resp.WriteUint16(sellables)
resp.WriteUint16(buyables) resp.WriteUint16(buyables)
resp.WriteUint16(sellables)
doAckBufSucceed(s, pkt.AckHandle, resp.Data()) doAckBufSucceed(s, pkt.AckHandle, resp.Data())
} }