From 440b73f69658fdae79430fa3162d258ba01b66f1 Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 13 Aug 2022 21:23:02 +1000 Subject: [PATCH] implement netcafe points and boost time --- ...g_mhf_post_cafe_duration_bonus_received.go | 9 +-- patch-schema/netcafe.sql | 11 +++- server/channelserver/handlers_cafe.go | 66 +++++++++++++++++-- server/channelserver/handlers_event.go | 26 -------- 4 files changed, 74 insertions(+), 38 deletions(-) diff --git a/network/mhfpacket/msg_mhf_post_cafe_duration_bonus_received.go b/network/mhfpacket/msg_mhf_post_cafe_duration_bonus_received.go index be8947f2c..baa102f61 100644 --- a/network/mhfpacket/msg_mhf_post_cafe_duration_bonus_received.go +++ b/network/mhfpacket/msg_mhf_post_cafe_duration_bonus_received.go @@ -11,8 +11,7 @@ import ( // MsgMhfPostCafeDurationBonusReceived represents the MSG_MHF_POST_CAFE_DURATION_BONUS_RECEIVED type MsgMhfPostCafeDurationBonusReceived struct { AckHandle uint32 - Unk0 uint32 - CafeBonusID uint32 + CafeBonusID []uint32 } // Opcode returns the ID associated with this packet type. @@ -23,8 +22,10 @@ func (m *MsgMhfPostCafeDurationBonusReceived) Opcode() network.PacketID { // Parse parses the packet from binary func (m *MsgMhfPostCafeDurationBonusReceived) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { m.AckHandle = bf.ReadUint32() - m.Unk0 = bf.ReadUint32() - m.CafeBonusID = bf.ReadUint32() + ids := int(bf.ReadUint32()) + for i := 0; i < ids; i++ { + m.CafeBonusID = append(m.CafeBonusID, bf.ReadUint32()) + } return nil } diff --git a/patch-schema/netcafe.sql b/patch-schema/netcafe.sql index 077adc7bd..e284742ce 100644 --- a/patch-schema/netcafe.sql +++ b/patch-schema/netcafe.sql @@ -1,7 +1,16 @@ BEGIN; ALTER TABLE IF EXISTS public.characters - ADD COLUMN cafe_time integer DEFAULT 0; + ADD COLUMN IF NOT EXISTS cafe_time integer DEFAULT 0; + +ALTER TABLE IF EXISTS public.characters + DROP COLUMN IF EXISTS netcafe_points; + +ALTER TABLE IF EXISTS public.characters + ADD COLUMN IF NOT EXISTS netcafe_points int DEFAULT 0; + +ALTER TABLE IF EXISTS public.characters + ADD COLUMN IF NOT EXISTS boost_time timestamp without time zone; CREATE TABLE IF NOT EXISTS public.cafebonus ( diff --git a/server/channelserver/handlers_cafe.go b/server/channelserver/handlers_cafe.go index a020d38a0..041304ed7 100644 --- a/server/channelserver/handlers_cafe.go +++ b/server/channelserver/handlers_cafe.go @@ -29,7 +29,6 @@ func handleMsgMhfUpdateCafepoint(s *Session, p mhfpacket.MHFPacket) { s.logger.Fatal("Failed to get netcate points from db", zap.Error(err)) } resp := byteframe.NewByteFrame() - resp.WriteUint32(0) resp.WriteUint32(netcafePoints) doAckSimpleSucceed(s, pkt.AckHandle, resp.Data()) } @@ -58,7 +57,7 @@ func handleMsgMhfCheckDailyCafepoint(s *Session, p mhfpacket.MHFPacket) { if t.After(dailyTime) { // +5 netcafe points and setting next valid window - _, err := s.server.db.Exec("UPDATE characters SET daily_time=$1, netcafe_points=netcafe_points::int + 5 WHERE id=$2", midday, s.charID) + _, err := s.server.db.Exec("UPDATE characters SET daily_time=$1, netcafe_points=netcafe_points+5 WHERE id=$2", midday, s.charID) if err != nil { s.logger.Fatal("Failed to update daily_time and netcafe_points savedata in db", zap.Error(err)) } @@ -172,16 +171,69 @@ func handleMsgMhfReceiveCafeDurationBonus(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfPostCafeDurationBonusReceived(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfPostCafeDurationBonusReceived) - - _, err := s.server.db.Exec("INSERT INTO public.cafe_accepted VALUES ($1, $2)", pkt.CafeBonusID, s.charID) - if err != nil { - s.logger.Error("Error updating accepted CafeBonus count", zap.Error(err)) + var cafeBonus CafeBonus + for _, cbID := range pkt.CafeBonusID { + err := s.server.db.QueryRow(` + SELECT cb.id, item_type, quantity FROM cafebonus cb WHERE cb.id=$1 + `, cbID).Scan(&cafeBonus.ID, &cafeBonus.ItemType, &cafeBonus.Quantity) + if err == nil { + if cafeBonus.ItemType == 17 { + s.server.db.Exec("UPDATE characters SET netcafe_points=netcafe_points+$1 WHERE id=$2", cafeBonus.Quantity, s.charID) + } + } + s.server.db.Exec("INSERT INTO public.cafe_accepted VALUES ($1, $2)", cbID, s.charID) } - doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4)) } func handleMsgMhfStartBoostTime(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfStartBoostTime) + bf := byteframe.NewByteFrame() + boostLimit := Time_Current_Adjusted().Add(100 * time.Minute) + s.server.db.Exec("UPDATE characters SET boost_time=$1 WHERE id=$2", boostLimit, s.charID) + bf.WriteUint32(uint32(boostLimit.Unix())) + doAckBufSucceed(s, pkt.AckHandle, bf.Data()) +} + +func handleMsgMhfGetBoostTime(s *Session, p mhfpacket.MHFPacket) { + pkt := p.(*mhfpacket.MsgMhfGetBoostTime) + doAckBufSucceed(s, pkt.AckHandle, []byte{}) +} + +func handleMsgMhfGetBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) { + pkt := p.(*mhfpacket.MsgMhfGetBoostTimeLimit) + bf := byteframe.NewByteFrame() + var boostLimit time.Time + err := s.server.db.QueryRow("SELECT boost_time FROM characters WHERE id=$1", s.charID).Scan(&boostLimit) + if err != nil { + bf.WriteUint32(0) + } else { + bf.WriteUint32(uint32(boostLimit.Unix())) + } + doAckBufSucceed(s, pkt.AckHandle, bf.Data()) doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4)) } + +func handleMsgMhfGetBoostRight(s *Session, p mhfpacket.MHFPacket) { + pkt := p.(*mhfpacket.MsgMhfGetBoostRight) + var boostLimit time.Time + err := s.server.db.QueryRow("SELECT boost_time FROM characters WHERE id=$1", s.charID).Scan(&boostLimit) + if err != nil { + doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) + return + } + if boostLimit.Unix() < Time_Current_Adjusted().Unix() { + doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x02}) + } else { + doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01}) + } +} + +func handleMsgMhfPostBoostTimeQuestReturn(s *Session, p mhfpacket.MHFPacket) { + pkt := p.(*mhfpacket.MsgMhfPostBoostTimeQuestReturn) + doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) +} + +func handleMsgMhfPostBoostTime(s *Session, p mhfpacket.MHFPacket) {} + +func handleMsgMhfPostBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {} diff --git a/server/channelserver/handlers_event.go b/server/channelserver/handlers_event.go index 87ae246af..7ec7c30e7 100644 --- a/server/channelserver/handlers_event.go +++ b/server/channelserver/handlers_event.go @@ -303,32 +303,6 @@ func handleMsgMhfGetUdInfo(s *Session, p mhfpacket.MHFPacket) { doAckBufSucceed(s, pkt.AckHandle, resp.Data()) } -func handleMsgMhfGetBoostTime(s *Session, p mhfpacket.MHFPacket) { - pkt := p.(*mhfpacket.MsgMhfGetBoostTime) - - doAckBufSucceed(s, pkt.AckHandle, []byte{}) - updateRights(s) -} - -func handleMsgMhfGetBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) { - pkt := p.(*mhfpacket.MsgMhfGetBoostTimeLimit) - doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) -} - -func handleMsgMhfGetBoostRight(s *Session, p mhfpacket.MHFPacket) { - pkt := p.(*mhfpacket.MsgMhfGetBoostRight) - doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) -} - -func handleMsgMhfPostBoostTimeQuestReturn(s *Session, p mhfpacket.MHFPacket) { - pkt := p.(*mhfpacket.MsgMhfPostBoostTimeQuestReturn) - doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) -} - -func handleMsgMhfPostBoostTime(s *Session, p mhfpacket.MHFPacket) {} - -func handleMsgMhfPostBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {} - func handleMsgMhfGetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {} func handleMsgMhfSetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {