From 6be1e0c92789f93f43f0ce46fe923a4e36915aa5 Mon Sep 17 00:00:00 2001 From: wish Date: Sun, 22 Jan 2023 22:43:34 +1100 Subject: [PATCH] handle stampcard progression --- network/mhfpacket/msg_mhf_stampcard_stamp.go | 48 ++++++++++---------- patch-schema/stampcard.sql | 5 ++ server/channelserver/handlers.go | 28 ++++++++++-- 3 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 patch-schema/stampcard.sql diff --git a/network/mhfpacket/msg_mhf_stampcard_stamp.go b/network/mhfpacket/msg_mhf_stampcard_stamp.go index fd0e0ef1e..8d18ae971 100644 --- a/network/mhfpacket/msg_mhf_stampcard_stamp.go +++ b/network/mhfpacket/msg_mhf_stampcard_stamp.go @@ -1,27 +1,25 @@ package mhfpacket -import ( - "errors" +import ( + "errors" - "erupe-ce/network/clientctx" - "erupe-ce/network" "erupe-ce/common/byteframe" + "erupe-ce/network" + "erupe-ce/network/clientctx" ) // MsgMhfStampcardStamp represents the MSG_MHF_STAMPCARD_STAMP type MsgMhfStampcardStamp struct { - // Field-size accurate. AckHandle uint32 - Unk0 uint16 - Unk1 uint16 - Unk2 uint16 - Unk3 uint16 // Hardcoded 0 in binary - Unk4 uint32 - Unk5 uint32 - Unk6 uint32 - Unk7 uint32 - Unk8 uint32 - Unk9 uint32 + HR uint16 + GR uint16 + Stamps uint16 + Reward1 uint16 + Reward2 uint16 + Item1 uint16 + Item2 uint16 + Quantity1 uint16 + Quantity2 uint16 } // Opcode returns the ID associated with this packet type. @@ -32,16 +30,16 @@ func (m *MsgMhfStampcardStamp) Opcode() network.PacketID { // Parse parses the packet from binary func (m *MsgMhfStampcardStamp) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { m.AckHandle = bf.ReadUint32() - m.Unk0 = bf.ReadUint16() - m.Unk1 = bf.ReadUint16() - m.Unk2 = bf.ReadUint16() - m.Unk3 = bf.ReadUint16() - m.Unk4 = bf.ReadUint32() - m.Unk5 = bf.ReadUint32() - m.Unk6 = bf.ReadUint32() - m.Unk7 = bf.ReadUint32() - m.Unk8 = bf.ReadUint32() - m.Unk9 = bf.ReadUint32() + m.HR = bf.ReadUint16() + m.GR = bf.ReadUint16() + m.Stamps = bf.ReadUint16() + _ = bf.ReadUint16() + m.Reward1 = uint16(bf.ReadUint32()) + m.Reward2 = uint16(bf.ReadUint32()) + m.Item1 = uint16(bf.ReadUint32()) + m.Item2 = uint16(bf.ReadUint32()) + m.Quantity1 = uint16(bf.ReadUint32()) + m.Quantity2 = uint16(bf.ReadUint32()) return nil } diff --git a/patch-schema/stampcard.sql b/patch-schema/stampcard.sql new file mode 100644 index 000000000..f2c6b7d10 --- /dev/null +++ b/patch-schema/stampcard.sql @@ -0,0 +1,5 @@ +BEGIN; + +ALTER TABLE characters ADD stampcard INT NOT NULL DEFAULT 0; + +END; \ No newline at end of file diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index 78c012ced..0194e18e6 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -1545,9 +1545,31 @@ func handleMsgMhfUpdateEtcPoint(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfStampcardStamp(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfStampcardStamp) - // TODO: Work out where it gets existing stamp count from, its format and then - // update the actual sent values to be correct - doAckBufSucceed(s, pkt.AckHandle, []byte{0x03, 0xe7, 0x03, 0xe7, 0x02, 0x99, 0x02, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x14, 0xf8, 0x69, 0x54}) + bf := byteframe.NewByteFrame() + bf.WriteUint16(pkt.HR) + bf.WriteUint16(pkt.GR) + var stamps uint16 + _ = s.server.db.QueryRow(`SELECT stampcard FROM characters WHERE id = $1`, s.charID).Scan(&stamps) + bf.WriteUint16(stamps) + stamps += pkt.Stamps + bf.WriteUint16(stamps) + s.server.db.Exec(`UPDATE characters SET stampcard = $1 WHERE id = $2`, stamps, s.charID) + if stamps%30 == 0 { + bf.WriteUint16(2) + bf.WriteUint16(pkt.Reward2) + bf.WriteUint16(pkt.Item2) + bf.WriteUint16(pkt.Quantity2) + addWarehouseGift(s, "item", mhfpacket.WarehouseStack{ItemID: pkt.Item2, Quantity: pkt.Quantity2}) + } else if stamps%15 == 0 { + bf.WriteUint16(1) + bf.WriteUint16(pkt.Reward1) + bf.WriteUint16(pkt.Item1) + bf.WriteUint16(pkt.Quantity1) + addWarehouseGift(s, "item", mhfpacket.WarehouseStack{ItemID: pkt.Item1, Quantity: pkt.Quantity1}) + } else { + bf.WriteBytes(make([]byte, 8)) + } + doAckBufSucceed(s, pkt.AckHandle, bf.Data()) } func handleMsgMhfStampcardPrize(s *Session, p mhfpacket.MHFPacket) {}