clean up InfoScenarioCounter

This commit is contained in:
wish
2023-07-09 00:34:56 +10:00
parent 229e9323ba
commit 3fc9a6f2ac

View File

@@ -776,42 +776,53 @@ func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) {
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
} }
type ScenarioCounterItem struct { type Scenario struct {
MainID uint32 `db:"scenario_id"` MainID uint32
CategoryID uint8 `db:"category_id"` // 0 = basic, 1 = veteran, 3 = other, 6 = pallone, 7 = diva // 0 = Basic
// 1 = Veteran
// 3 = Other
// 6 = Pallone
// 7 = Diva
CategoryID uint8
} }
func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfInfoScenarioCounter) pkt := p.(*mhfpacket.MsgMhfInfoScenarioCounter)
var scenarios []Scenario
var scenario Scenario
scenarioData, err := s.server.db.Queryx("SELECT scenario_id, category_id FROM scenario_counter") scenarioData, err := s.server.db.Queryx("SELECT scenario_id, category_id FROM scenario_counter")
if err != nil { if err != nil {
scenarioData.Close()
s.logger.Error("Failed to get scenario counter info from db", zap.Error(err)) s.logger.Error("Failed to get scenario counter info from db", zap.Error(err))
doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4)) doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4))
return return
} }
bf := byteframe.NewByteFrame()
var scenarioCount uint8
for scenarioData.Next() { for scenarioData.Next() {
scenario := &ScenarioCounterItem{} err = scenarioData.Scan(&scenario.MainID, &scenario.CategoryID)
err = scenarioData.StructScan(&scenario)
if err != nil { if err != nil {
continue continue
} }
scenarioCount++ }
// Trim excess scenarios
if len(scenarios) > 128 {
scenarios = scenarios[:128]
}
bf := byteframe.NewByteFrame()
bf.WriteUint8(uint8(len(scenarios)))
for _, scenario := range scenarios {
bf.WriteUint32(scenario.MainID) bf.WriteUint32(scenario.MainID)
// if item exchange // If item exchange
if scenario.CategoryID == 3 || scenario.CategoryID == 6 || scenario.CategoryID == 7 { switch scenario.CategoryID {
case 3, 6, 7:
bf.WriteBool(true) bf.WriteBool(true)
} else { default:
bf.WriteBool(false) bf.WriteBool(false)
} }
bf.WriteUint8(scenario.CategoryID) bf.WriteUint8(scenario.CategoryID)
} }
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
data := byteframe.NewByteFrame()
data.WriteUint8(scenarioCount)
data.WriteBytes(bf.Data())
doAckBufSucceed(s, pkt.AckHandle, data.Data())
} }
func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) {