From 15440fcac643b0acda278272ec62491912e84d71 Mon Sep 17 00:00:00 2001 From: wish Date: Mon, 25 Jul 2022 19:55:40 +1000 Subject: [PATCH] merge gook simplification --- Erupe/server/channelserver/handlers.go | 13 +++++++------ Erupe/server/channelserver/handlers_house.go | 17 +++-------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Erupe/server/channelserver/handlers.go b/Erupe/server/channelserver/handlers.go index 3adab427f..6dd69381b 100644 --- a/Erupe/server/channelserver/handlers.go +++ b/Erupe/server/channelserver/handlers.go @@ -577,7 +577,7 @@ func handleMsgMhfCheckWeeklyStamp(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfExchangeWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {} -func getGookData(s *Session, cid uint32) []byte { +func getGookData(s *Session, cid uint32) (uint16, []byte) { var data []byte var count uint16 bf := byteframe.NewByteFrame() @@ -597,15 +597,16 @@ func getGookData(s *Session, cid uint32) []byte { } } } - resp := byteframe.NewByteFrame() - resp.WriteUint16(count) - resp.WriteBytes(bf.Data()) - return resp.Data() + return count, bf.Data() } func handleMsgMhfEnumerateGuacot(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfEnumerateGuacot) - doAckBufSucceed(s, pkt.AckHandle, getGookData(s, s.charID)) + bf := byteframe.NewByteFrame() + count, data := getGookData(s, s.charID) + bf.WriteUint16(count) + bf.WriteBytes(data) + doAckBufSucceed(s, pkt.AckHandle, bf.Data()) } func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) { diff --git a/Erupe/server/channelserver/handlers_house.go b/Erupe/server/channelserver/handlers_house.go index eeda39a5e..3408d356f 100644 --- a/Erupe/server/channelserver/handlers_house.go +++ b/Erupe/server/channelserver/handlers_house.go @@ -5,7 +5,6 @@ import ( ps "erupe-ce/common/pascalstring" "erupe-ce/common/stringsupport" "erupe-ce/network/mhfpacket" - "fmt" "go.uber.org/zap" ) @@ -173,20 +172,10 @@ func handleMsgMhfLoadHouse(s *Session, p mhfpacket.MHFPacket) { for _, session := range s.server.sessions { if session.charID == pkt.CharID { bf.WriteBytes(session.myseries.gardenData) - // TODO: Convert EnumerateGuacot to function this can also call - var data []byte - var count uint16 - gooks := byteframe.NewByteFrame() - for i := 0; i < 5; i++ { - err := s.server.db.QueryRow(fmt.Sprintf("SELECT gook%d FROM gook WHERE id=$1", i), pkt.CharID).Scan(&data) - if err == nil && data != nil { - count++ - gooks.WriteBytes(data) - } - } - bf.WriteUint16(count) + c, d := getGookData(s, pkt.CharID) + bf.WriteUint16(c) bf.WriteUint16(0) - bf.WriteBytes(gooks.Data()) + bf.WriteBytes(d) } } }