From a6650bb3927761deb0f8c54d9d53c96da05e26e4 Mon Sep 17 00:00:00 2001 From: straticspaff Date: Mon, 3 Jul 2023 20:29:56 +0100 Subject: [PATCH 1/6] feat: added scenario counter driven by database --- patch-schema/scenarios-counter.sql | 9 + server/channelserver/handlers.go | 754 ++--------------------------- 2 files changed, 46 insertions(+), 717 deletions(-) create mode 100644 patch-schema/scenarios-counter.sql diff --git a/patch-schema/scenarios-counter.sql b/patch-schema/scenarios-counter.sql new file mode 100644 index 000000000..3ea2c65b2 --- /dev/null +++ b/patch-schema/scenarios-counter.sql @@ -0,0 +1,9 @@ +BEGIN; + +CREATE TABLE IF NOT EXISTS scenario_counter ( + id serial primary key, + scenario_id numeric not null, + category_id numeric not null +); + +END; \ No newline at end of file diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index 4647b8021..f853675a1 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -15,8 +15,9 @@ import ( "crypto/rand" "erupe-ce/common/byteframe" "erupe-ce/network/mhfpacket" - "go.uber.org/zap" "math/bits" + + "go.uber.org/zap" ) // Temporary function to just return no results for a MSG_MHF_ENUMERATE* packet @@ -776,726 +777,45 @@ func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) { } func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) { + type ScenarioCounterItem struct { + MainID uint32 `db:"scenario_id"` + CategoryID uint8 `db:"category_id"` // 0 = basic, 1 = veteran, 3 = other, 6 = pallone, 7 = diva + } + pkt := p.(*mhfpacket.MsgMhfInfoScenarioCounter) - scenarioCounter := []struct { - MainID uint32 - Unk1 uint8 // Bool item exchange? - // 0 = basic, 1 = veteran, 3 = other, 6 = pallone, 7 = diva - CategoryID uint8 - }{ - //000000110000 - { - MainID: 0x00000011, Unk1: 0, CategoryID: 0, - }, - // 0000005D0001 - { - MainID: 0x0000005D, Unk1: 0, CategoryID: 1, - }, - // 0000005C0001 - { - MainID: 0x0000005C, Unk1: 0, CategoryID: 1, - }, - // 000000510001 - { - MainID: 0x00000051, Unk1: 0, CategoryID: 1, - }, - // 0000005B0001 - { - MainID: 0x0000005B, Unk1: 0, CategoryID: 1, - }, - // 0000005A0001 - { - MainID: 0x0000005A, Unk1: 0, CategoryID: 1, - }, - // 000000590001 - { - MainID: 0x00000059, Unk1: 0, CategoryID: 1, - }, - // 000000580001 - { - MainID: 0x00000058, Unk1: 0, CategoryID: 1, - }, - // 000000570001 - { - MainID: 0x00000057, Unk1: 0, CategoryID: 1, - }, - // 000000560001 - { - MainID: 0x00000056, Unk1: 0, CategoryID: 1, - }, - // 000000550001 - { - MainID: 0x00000055, Unk1: 0, CategoryID: 1, - }, - // 000000540001 - { - MainID: 0x00000054, Unk1: 0, CategoryID: 1, - }, - // 000000530001 - { - MainID: 0x00000053, Unk1: 0, CategoryID: 1, - }, - // 000000520001 - { - MainID: 0x00000052, Unk1: 0, CategoryID: 1, - }, - // 000000570103 - { - MainID: 0x00000057, Unk1: 1, CategoryID: 3, - }, - // 000000580103 - { - MainID: 0x00000058, Unk1: 1, CategoryID: 3, - }, - // 000000590103 - { - MainID: 0x00000059, Unk1: 1, CategoryID: 3, - }, - // 0000005A0103 - { - MainID: 0x0000005A, Unk1: 1, CategoryID: 3, - }, - // 0000005B0103 - { - MainID: 0x0000005B, Unk1: 1, CategoryID: 3, - }, - // 0000005C0103 - { - MainID: 0x0000005C, Unk1: 1, CategoryID: 3, - }, - // 000000530103 - { - MainID: 0x00000053, Unk1: 1, CategoryID: 3, - }, - // 000000560103 - { - MainID: 0x00000056, Unk1: 1, CategoryID: 3, - }, - // 0000003C0103 - { - MainID: 0x0000003C, Unk1: 1, CategoryID: 3, - }, - // 0000003A0103 - { - MainID: 0x0000003A, Unk1: 1, CategoryID: 3, - }, - // 0000003B0103 - { - MainID: 0x0000003B, Unk1: 1, CategoryID: 3, - }, - // 0000001B0103 - { - MainID: 0x0000001B, Unk1: 1, CategoryID: 3, - }, - // 000000190103 - { - MainID: 0x00000019, Unk1: 1, CategoryID: 3, - }, - // 0000001A0103 - { - MainID: 0x0000001A, Unk1: 1, CategoryID: 3, - }, - // 000000170103 - { - MainID: 0x00000017, Unk1: 1, CategoryID: 3, - }, - // 000000020103 - { - MainID: 0x00000002, Unk1: 1, CategoryID: 3, - }, - // 000000030103 - { - MainID: 0x00000003, Unk1: 1, CategoryID: 3, - }, - // 000000040103 - { - MainID: 0x00000004, Unk1: 1, CategoryID: 3, - }, - // 0000001F0103 - { - MainID: 0x0000001F, Unk1: 1, CategoryID: 3, - }, - // 000000200103 - { - MainID: 0x00000020, Unk1: 1, CategoryID: 3, - }, - // 000000210103 - { - MainID: 0x00000021, Unk1: 1, CategoryID: 3, - }, - // 000000220103 - { - MainID: 0x00000022, Unk1: 1, CategoryID: 3, - }, - // 000000230103 - { - MainID: 0x00000023, Unk1: 1, CategoryID: 3, - }, - // 000000240103 - { - MainID: 0x00000024, Unk1: 1, CategoryID: 3, - }, - // 000000250103 - { - MainID: 0x00000025, Unk1: 1, CategoryID: 3, - }, - // 000000280103 - { - MainID: 0x00000028, Unk1: 1, CategoryID: 3, - }, - // 000000260103 - { - MainID: 0x00000026, Unk1: 1, CategoryID: 3, - }, - // 000000270103 - { - MainID: 0x00000027, Unk1: 1, CategoryID: 3, - }, - // 000000300103 - { - MainID: 0x00000030, Unk1: 1, CategoryID: 3, - }, - // 0000000C0103 - { - MainID: 0x0000000C, Unk1: 1, CategoryID: 3, - }, - // 0000000D0103 - { - MainID: 0x0000000D, Unk1: 1, CategoryID: 3, - }, - // 0000001E0103 - { - MainID: 0x0000001E, Unk1: 1, CategoryID: 3, - }, - // 0000001D0103 - { - MainID: 0x0000001D, Unk1: 1, CategoryID: 3, - }, - // 0000002E0003 - { - MainID: 0x0000002E, Unk1: 0, CategoryID: 3, - }, - // 000000000004 - { - MainID: 0x00000000, Unk1: 0, CategoryID: 4, - }, - // 000000010004 - { - MainID: 0x00000001, Unk1: 0, CategoryID: 4, - }, - // 000000020004 - { - MainID: 0x00000002, Unk1: 0, CategoryID: 4, - }, - // 000000030004 - { - MainID: 0x00000003, Unk1: 0, CategoryID: 4, - }, - // 000000040004 - { - MainID: 0x00000004, Unk1: 0, CategoryID: 4, - }, - // 000000050004 - { - MainID: 0x00000005, Unk1: 0, CategoryID: 4, - }, - // 000000060004 - { - MainID: 0x00000006, Unk1: 0, CategoryID: 4, - }, - // 000000070004 - { - MainID: 0x00000007, Unk1: 0, CategoryID: 4, - }, - // 000000080004 - { - MainID: 0x00000008, Unk1: 0, CategoryID: 4, - }, - // 000000090004 - { - MainID: 0x00000009, Unk1: 0, CategoryID: 4, - }, - // 0000000A0004 - { - MainID: 0x0000000A, Unk1: 0, CategoryID: 4, - }, - // 0000000B0004 - { - MainID: 0x0000000B, Unk1: 0, CategoryID: 4, - }, - // 0000000C0004 - { - MainID: 0x0000000C, Unk1: 0, CategoryID: 4, - }, - // 0000000D0004 - { - MainID: 0x0000000D, Unk1: 0, CategoryID: 4, - }, - // 0000000E0004 - { - MainID: 0x0000000E, Unk1: 0, CategoryID: 4, - }, - // 000000320005 - { - MainID: 0x00000032, Unk1: 0, CategoryID: 5, - }, - // 000000330005 - { - MainID: 0x00000033, Unk1: 0, CategoryID: 5, - }, - // 000000340005 - { - MainID: 0x00000034, Unk1: 0, CategoryID: 5, - }, - // 000000350005 - { - MainID: 0x00000035, Unk1: 0, CategoryID: 5, - }, - // 000000360005 - { - MainID: 0x00000036, Unk1: 0, CategoryID: 5, - }, - // 000000370005 - { - MainID: 0x00000037, Unk1: 0, CategoryID: 5, - }, - // 000000380005 - { - MainID: 0x00000038, Unk1: 0, CategoryID: 5, - }, - // 0000003A0005 - { - MainID: 0x0000003A, Unk1: 0, CategoryID: 5, - }, - // 0000003F0005 - { - MainID: 0x0000003F, Unk1: 0, CategoryID: 5, - }, - // 000000400005 - { - MainID: 0x00000040, Unk1: 0, CategoryID: 5, - }, - // 000000410005 - { - MainID: 0x00000041, Unk1: 0, CategoryID: 5, - }, - // 000000430005 - { - MainID: 0x00000043, Unk1: 0, CategoryID: 5, - }, - // 000000470005 - { - MainID: 0x00000047, Unk1: 0, CategoryID: 5, - }, - // 0000004B0005 - { - MainID: 0x0000004B, Unk1: 0, CategoryID: 5, - }, - // 0000003D0005 - { - MainID: 0x0000003D, Unk1: 0, CategoryID: 5, - }, - // 000000440005 - { - MainID: 0x00000044, Unk1: 0, CategoryID: 5, - }, - // 000000420005 - { - MainID: 0x00000042, Unk1: 0, CategoryID: 5, - }, - // 0000004C0005 - { - MainID: 0x0000004C, Unk1: 0, CategoryID: 5, - }, - // 000000460005 - { - MainID: 0x00000046, Unk1: 0, CategoryID: 5, - }, - // 0000004D0005 - { - MainID: 0x0000004D, Unk1: 0, CategoryID: 5, - }, - // 000000480005 - { - MainID: 0x00000048, Unk1: 0, CategoryID: 5, - }, - // 0000004A0005 - { - MainID: 0x0000004A, Unk1: 0, CategoryID: 5, - }, - // 000000490005 - { - MainID: 0x00000049, Unk1: 0, CategoryID: 5, - }, - // 0000004E0005 - { - MainID: 0x0000004E, Unk1: 0, CategoryID: 5, - }, - // 000000450005 - { - MainID: 0x00000045, Unk1: 0, CategoryID: 5, - }, - // 0000003E0005 - { - MainID: 0x0000003E, Unk1: 0, CategoryID: 5, - }, - // 0000004F0005 - { - MainID: 0x0000004F, Unk1: 0, CategoryID: 5, - }, - // 000000000106 - { - MainID: 0x00000000, Unk1: 1, CategoryID: 6, - }, - // 000000010106 - { - MainID: 0x00000001, Unk1: 1, CategoryID: 6, - }, - // 000000020106 - { - MainID: 0x00000002, Unk1: 1, CategoryID: 6, - }, - // 000000030106 - { - MainID: 0x00000003, Unk1: 1, CategoryID: 6, - }, - // 000000040106 - { - MainID: 0x00000004, Unk1: 1, CategoryID: 6, - }, - // 000000050106 - { - MainID: 0x00000005, Unk1: 1, CategoryID: 6, - }, - // 000000060106 - { - MainID: 0x00000006, Unk1: 1, CategoryID: 6, - }, - // 000000070106 - { - MainID: 0x00000007, Unk1: 1, CategoryID: 6, - }, - // 000000080106 - { - MainID: 0x00000008, Unk1: 1, CategoryID: 6, - }, - // 000000090106 - { - MainID: 0x00000009, Unk1: 1, CategoryID: 6, - }, - // 000000110106 - { - MainID: 0x00000011, Unk1: 1, CategoryID: 6, - }, - // 0000000A0106 - { - MainID: 0x0000000A, Unk1: 1, CategoryID: 6, - }, - // 0000000B0106 - { - MainID: 0x0000000B, Unk1: 1, CategoryID: 6, - }, - // 0000000C0106 - { - MainID: 0x0000000C, Unk1: 1, CategoryID: 6, - }, - // 0000000D0106 - { - MainID: 0x0000000D, Unk1: 1, CategoryID: 6, - }, - // 0000000E0106 - { - MainID: 0x0000000E, Unk1: 1, CategoryID: 6, - }, - // 0000000F0106 - { - MainID: 0x0000000F, Unk1: 1, CategoryID: 6, - }, - // 000000100106 - { - MainID: 0x00000010, Unk1: 1, CategoryID: 6, - }, - // 000000320107 - { - MainID: 0x00000032, Unk1: 1, CategoryID: 7, - }, - // 000000350107 - { - MainID: 0x00000035, Unk1: 1, CategoryID: 7, - }, - // 0000003E0107 - { - MainID: 0x0000003E, Unk1: 1, CategoryID: 7, - }, - // 000000340107 - { - MainID: 0x00000034, Unk1: 1, CategoryID: 7, - }, - // 000000380107 - { - MainID: 0x00000038, Unk1: 1, CategoryID: 7, - }, - // 000000330107 - { - MainID: 0x00000033, Unk1: 1, CategoryID: 7, - }, - // 000000310107 - { - MainID: 0x00000031, Unk1: 1, CategoryID: 7, - }, - // 000000360107 - { - MainID: 0x00000036, Unk1: 1, CategoryID: 7, - }, - // 000000390107 - { - MainID: 0x00000039, Unk1: 1, CategoryID: 7, - }, - // 000000370107 - { - MainID: 0x00000037, Unk1: 1, CategoryID: 7, - }, - // 0000003D0107 - { - MainID: 0x0000003D, Unk1: 1, CategoryID: 7, - }, - // 0000003A0107 - { - MainID: 0x0000003A, Unk1: 1, CategoryID: 7, - }, - // 0000003C0107 - { - MainID: 0x0000003C, Unk1: 1, CategoryID: 7, - }, - // 0000003B0107 - { - MainID: 0x0000003B, Unk1: 1, CategoryID: 7, - }, - // 0000002A0107 - { - MainID: 0x0000002A, Unk1: 1, CategoryID: 7, - }, - // 000000300107 - { - MainID: 0x00000030, Unk1: 1, CategoryID: 7, - }, - // 000000280107 - { - MainID: 0x00000028, Unk1: 1, CategoryID: 7, - }, - // 000000270107 - { - MainID: 0x00000027, Unk1: 1, CategoryID: 7, - }, - // 0000002B0107 - { - MainID: 0x0000002B, Unk1: 1, CategoryID: 7, - }, - // 0000002E0107 - { - MainID: 0x0000002E, Unk1: 1, CategoryID: 7, - }, - // 000000290107 - { - MainID: 0x00000029, Unk1: 1, CategoryID: 7, - }, - // 0000002C0107 - { - MainID: 0x0000002C, Unk1: 1, CategoryID: 7, - }, - // 0000002D0107 - { - MainID: 0x0000002D, Unk1: 1, CategoryID: 7, - }, - // 0000002F0107 - { - MainID: 0x0000002F, Unk1: 1, CategoryID: 7, - }, - // 000000250107 - { - MainID: 0x00000025, Unk1: 1, CategoryID: 7, - }, - // 000000220107 - { - MainID: 0x00000022, Unk1: 1, CategoryID: 7, - }, - // 000000210107 - { - MainID: 0x00000021, Unk1: 1, CategoryID: 7, - }, - // 000000200107 - { - MainID: 0x00000020, Unk1: 1, CategoryID: 7, - }, - // 0000001C0107 - { - MainID: 0x0000001C, Unk1: 1, CategoryID: 7, - }, - // 0000001A0107 - { - MainID: 0x0000001A, Unk1: 1, CategoryID: 7, - }, - // 000000240107 - { - MainID: 0x00000024, Unk1: 1, CategoryID: 7, - }, - // 000000260107 - { - MainID: 0x00000026, Unk1: 1, CategoryID: 7, - }, - // 000000230107 - { - MainID: 0x00000023, Unk1: 1, CategoryID: 7, - }, - // 0000001B0107 - { - MainID: 0x0000001B, Unk1: 1, CategoryID: 7, - }, - // 0000001E0107 - { - MainID: 0x0000001E, Unk1: 1, CategoryID: 7, - }, - // 0000001F0107 - { - MainID: 0x0000001F, Unk1: 1, CategoryID: 7, - }, - // 0000001D0107 - { - MainID: 0x0000001D, Unk1: 1, CategoryID: 7, - }, - // 000000180107 - { - MainID: 0x00000018, Unk1: 1, CategoryID: 7, - }, - // 000000170107 - { - MainID: 0x00000017, Unk1: 1, CategoryID: 7, - }, - // 000000160107 - { - MainID: 0x00000016, Unk1: 1, CategoryID: 7, - }, - // 000000150107 - // Missing file - // { - // MainID: 0x00000015, Unk1: 1, CategoryID: 7, - // }, - // 000000190107 - { - MainID: 0x00000019, Unk1: 1, CategoryID: 7, - }, - // 000000140107 - // Missing file - // { - // MainID: 0x00000014, Unk1: 1, CategoryID: 7, - // }, - // 000000070107 - // Missing file - // { - // MainID: 0x00000007, Unk1: 1, CategoryID: 7, - // }, - // 000000090107 - // Missing file - // { - // MainID: 0x00000009, Unk1: 1, CategoryID: 7, - // }, - // 0000000D0107 - // Missing file - // { - // MainID: 0x0000000D, Unk1: 1, CategoryID: 7, - // }, - // 000000100107 - // Missing file - // { - // MainID: 0x00000010, Unk1: 1, CategoryID: 7, - // }, - // 0000000C0107 - // Missing file - // { - // MainID: 0x0000000C, Unk1: 1, CategoryID: 7, - // }, - // 0000000E0107 - // Missing file - // { - // MainID: 0x0000000E, Unk1: 1, CategoryID: 7, - // }, - // 0000000F0107 - // Missing file - // { - // MainID: 0x0000000F, Unk1: 1, CategoryID: 7, - // }, - // 000000130107 - // Missing file - // { - // MainID: 0x00000013, Unk1: 1, CategoryID: 7, - // }, - // 0000000A0107 - // Missing file - // { - // MainID: 0x0000000A, Unk1: 1, CategoryID: 7, - // }, - // 000000080107 - // Missing file - // { - // MainID: 0x00000008, Unk1: 1, CategoryID: 7, - // }, - // 0000000B0107 - // Missing file - // { - // MainID: 0x0000000B, Unk1: 1, CategoryID: 7, - // }, - // 000000120107 - // Missing file - // { - // MainID: 0x00000012, Unk1: 1, CategoryID: 7, - // }, - // 000000110107 - // Missing file - // { - // MainID: 0x00000011, Unk1: 1, CategoryID: 7, - // }, - // 000000060107 - // Missing file - // { - // MainID: 0x00000006, Unk1: 1, CategoryID: 7, - // }, - // 000000050107 - // Missing file - // { - // MainID: 0x00000005, Unk1: 1, CategoryID: 7, - // }, - // 000000040107 - // Missing file - // { - // MainID: 0x00000004, Unk1: 1, CategoryID: 7, - // }, - // 000000030107 - { - MainID: 0x00000003, Unk1: 1, CategoryID: 7, - }, - // 000000020107 - { - MainID: 0x00000002, Unk1: 1, CategoryID: 7, - }, - // 000000010107 - { - MainID: 0x00000001, Unk1: 1, CategoryID: 7, - }, - // 000000000107 - { - MainID: 0x00000000, Unk1: 1, CategoryID: 7, - }, + + scenarioData, err := s.server.db.Queryx("SELECT scenario_id, category_id FROM scenario_counter") + if err != nil { + s.logger.Error("Failed to get scenario counter info from db", zap.Error(err)) + doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4)) + return + } + bf := byteframe.NewByteFrame() + var scenarioCount uint32 + for scenarioData.Next() { + postData := &ScenarioCounterItem{} + err = scenarioData.StructScan(&postData) + if err != nil { + continue + } + scenarioCount++ + bf.WriteUint32(postData.MainID) + // if item exchange + if postData.CategoryID == 3 || postData.CategoryID == 6 || postData.CategoryID == 7 { + bf.WriteUint8(1) + + } else { + bf.WriteUint8(0) + + } + bf.WriteUint8(postData.CategoryID) } - resp := byteframe.NewByteFrame() - resp.WriteUint8(uint8(len(scenarioCounter))) // Entry count - for _, entry := range scenarioCounter { - resp.WriteUint32(entry.MainID) - resp.WriteUint8(entry.Unk1) - resp.WriteUint8(entry.CategoryID) - } + data := byteframe.NewByteFrame() + data.WriteUint8(uint8(scenarioCount)) // Entry count + data.WriteBytes(bf.Data()) + doAckBufSucceed(s, pkt.AckHandle, data.Data()) - doAckBufSucceed(s, pkt.AckHandle, resp.Data()) } func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) { From b46f0354d61c7b015a4ceee6f1ea1b0e0f7932fe Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 8 Jul 2023 00:41:03 +1000 Subject: [PATCH 2/6] typing and formatting review --- server/channelserver/handlers.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index f853675a1..bb6aa75b4 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -776,14 +776,13 @@ func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) { doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) } +type ScenarioCounterItem struct { + MainID uint32 `db:"scenario_id"` + CategoryID uint8 `db:"category_id"` // 0 = basic, 1 = veteran, 3 = other, 6 = pallone, 7 = diva +} + func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) { - type ScenarioCounterItem struct { - MainID uint32 `db:"scenario_id"` - CategoryID uint8 `db:"category_id"` // 0 = basic, 1 = veteran, 3 = other, 6 = pallone, 7 = diva - } - pkt := p.(*mhfpacket.MsgMhfInfoScenarioCounter) - scenarioData, err := s.server.db.Queryx("SELECT scenario_id, category_id FROM scenario_counter") if err != nil { s.logger.Error("Failed to get scenario counter info from db", zap.Error(err)) @@ -791,31 +790,28 @@ func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) { return } bf := byteframe.NewByteFrame() - var scenarioCount uint32 + var scenarioCount uint8 for scenarioData.Next() { - postData := &ScenarioCounterItem{} - err = scenarioData.StructScan(&postData) + scenario := &ScenarioCounterItem{} + err = scenarioData.StructScan(&scenario) if err != nil { continue } scenarioCount++ - bf.WriteUint32(postData.MainID) + bf.WriteUint32(scenario.MainID) // if item exchange - if postData.CategoryID == 3 || postData.CategoryID == 6 || postData.CategoryID == 7 { - bf.WriteUint8(1) - + if scenario.CategoryID == 3 || scenario.CategoryID == 6 || scenario.CategoryID == 7 { + bf.WriteBool(true) } else { - bf.WriteUint8(0) - + bf.WriteBool(false) } - bf.WriteUint8(postData.CategoryID) + bf.WriteUint8(scenario.CategoryID) } data := byteframe.NewByteFrame() - data.WriteUint8(uint8(scenarioCount)) // Entry count + data.WriteUint8(scenarioCount) data.WriteBytes(bf.Data()) doAckBufSucceed(s, pkt.AckHandle, data.Data()) - } func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) { From 229e9323ba4bfc6579a917cb248984b0445d20da Mon Sep 17 00:00:00 2001 From: straticspaff Date: Fri, 7 Jul 2023 23:38:24 +0100 Subject: [PATCH 3/6] feat: added veteran + beginner scenarios --- bundled-schema/DefaultScenarios.sql | 120 ++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 bundled-schema/DefaultScenarios.sql diff --git a/bundled-schema/DefaultScenarios.sql b/bundled-schema/DefaultScenarios.sql new file mode 100644 index 000000000..d3eb2899a --- /dev/null +++ b/bundled-schema/DefaultScenarios.sql @@ -0,0 +1,120 @@ +BEGIN; + +INSERT INTO public.scenario_counter +(scenario_id, category_id) +VALUES + (0,0), + (1,0), + (2,0), + (3,0), + (4,0), + (5,0), + (6,0), + (7,0), + (8,0), + (9,0), + (10,0), + (11,0), + (12,0), + (13,0), + (14,0), + (15,0), + (16,0), + (17,0), + (18,0), + (19,0), + (0,1), + (1,1), + (2,1), + (3,1), + (4,1), + (5,1), + (6,1), + (7,1), + (8,1), + (9,1), + (10,1), + (11,1), + (12,1), + (13,1), + (16,1), + (17,1), + (19,1), + (21,1), + (22,1), + (23,1), + (27,1), + (28,1), + (29,1), + (30,1), + (31,1), + (32,1), + (33,1), + (34,1), + (35,1), + (36,1), + (37,1), + (38,1), + (39,1), + (41,1), + (42,1), + (43,1), + (46,1), + (47,1), + (48,1), + (49,1), + (58,1), + (59,1), + (60,1), + (61,1), + (62,1), + (63,1), + (64,1), + (65,1), + (66,1), + (67,1), + (68,1), + (69,1), + (70,1), + (77,1), + (79,1), + (81,1), + (82,1), + (83,1), + (84,1), + (85,1), + (86,1), + (87,1), + (88,1), + (89,1), + (90,1), + (92,1), + (93,1), + (13,1), + (14,1), + (15,1), + (18,1), + (20,1), + (24,1), + (25,1), + (26,1), + (40,1), + (50,1), + (51,1), + (52,1), + (53,1), + (54,1), + (55,1), + (56,1), + (57,1), + (71,1), + (72,1), + (73,1), + (74,1), + (75,1), + (76,1), + (78,1), + (80,1), + (91,1); + +END; \ No newline at end of file From 3fc9a6f2ac33d9abcb62afa135215c28e9196346 Mon Sep 17 00:00:00 2001 From: wish Date: Sun, 9 Jul 2023 00:34:56 +1000 Subject: [PATCH 4/6] clean up InfoScenarioCounter --- server/channelserver/handlers.go | 43 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index bb6aa75b4..c94003ffb 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -776,42 +776,53 @@ func handleMsgMhfUpdateGuacot(s *Session, p mhfpacket.MHFPacket) { doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) } -type ScenarioCounterItem struct { - MainID uint32 `db:"scenario_id"` - CategoryID uint8 `db:"category_id"` // 0 = basic, 1 = veteran, 3 = other, 6 = pallone, 7 = diva +type Scenario struct { + MainID uint32 + // 0 = Basic + // 1 = Veteran + // 3 = Other + // 6 = Pallone + // 7 = Diva + CategoryID uint8 } func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfInfoScenarioCounter) + var scenarios []Scenario + var scenario Scenario scenarioData, err := s.server.db.Queryx("SELECT scenario_id, category_id FROM scenario_counter") if err != nil { + scenarioData.Close() s.logger.Error("Failed to get scenario counter info from db", zap.Error(err)) doAckBufSucceed(s, pkt.AckHandle, make([]byte, 4)) return } - bf := byteframe.NewByteFrame() - var scenarioCount uint8 for scenarioData.Next() { - scenario := &ScenarioCounterItem{} - err = scenarioData.StructScan(&scenario) + err = scenarioData.Scan(&scenario.MainID, &scenario.CategoryID) if err != nil { 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) - // if item exchange - if scenario.CategoryID == 3 || scenario.CategoryID == 6 || scenario.CategoryID == 7 { + // If item exchange + switch scenario.CategoryID { + case 3, 6, 7: bf.WriteBool(true) - } else { + default: bf.WriteBool(false) } bf.WriteUint8(scenario.CategoryID) } - - data := byteframe.NewByteFrame() - data.WriteUint8(scenarioCount) - data.WriteBytes(bf.Data()) - doAckBufSucceed(s, pkt.AckHandle, data.Data()) + doAckBufSucceed(s, pkt.AckHandle, bf.Data()) } func handleMsgMhfGetEtcPoints(s *Session, p mhfpacket.MHFPacket) { From 9886f81b2b62d68cd63fb47931811241c1e790f3 Mon Sep 17 00:00:00 2001 From: wish Date: Sun, 9 Jul 2023 01:05:27 +1000 Subject: [PATCH 5/6] fix scenario responses --- server/channelserver/handlers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index c94003ffb..4ff31dab3 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -794,7 +794,7 @@ func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) { if err != nil { scenarioData.Close() 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, 1)) return } for scenarioData.Next() { @@ -802,6 +802,7 @@ func handleMsgMhfInfoScenarioCounter(s *Session, p mhfpacket.MHFPacket) { if err != nil { continue } + scenarios = append(scenarios, scenario) } // Trim excess scenarios From 80a2822214d92a48f04b2b56f28540ef97c54b89 Mon Sep 17 00:00:00 2001 From: wish Date: Sat, 7 Oct 2023 17:33:40 +1100 Subject: [PATCH 6/6] #74 update file names & default scenarios --- bundled-schema/DefaultScenarios.sql | 120 ------------ bundled-schema/ScenarioDefaults.sql | 178 ++++++++++++++++++ ...s-counter.sql => 07-scenarios-counter.sql} | 0 3 files changed, 178 insertions(+), 120 deletions(-) delete mode 100644 bundled-schema/DefaultScenarios.sql create mode 100644 bundled-schema/ScenarioDefaults.sql rename patch-schema/{scenarios-counter.sql => 07-scenarios-counter.sql} (100%) diff --git a/bundled-schema/DefaultScenarios.sql b/bundled-schema/DefaultScenarios.sql deleted file mode 100644 index d3eb2899a..000000000 --- a/bundled-schema/DefaultScenarios.sql +++ /dev/null @@ -1,120 +0,0 @@ -BEGIN; - -INSERT INTO public.scenario_counter -(scenario_id, category_id) -VALUES - (0,0), - (1,0), - (2,0), - (3,0), - (4,0), - (5,0), - (6,0), - (7,0), - (8,0), - (9,0), - (10,0), - (11,0), - (12,0), - (13,0), - (14,0), - (15,0), - (16,0), - (17,0), - (18,0), - (19,0), - (0,1), - (1,1), - (2,1), - (3,1), - (4,1), - (5,1), - (6,1), - (7,1), - (8,1), - (9,1), - (10,1), - (11,1), - (12,1), - (13,1), - (16,1), - (17,1), - (19,1), - (21,1), - (22,1), - (23,1), - (27,1), - (28,1), - (29,1), - (30,1), - (31,1), - (32,1), - (33,1), - (34,1), - (35,1), - (36,1), - (37,1), - (38,1), - (39,1), - (41,1), - (42,1), - (43,1), - (46,1), - (47,1), - (48,1), - (49,1), - (58,1), - (59,1), - (60,1), - (61,1), - (62,1), - (63,1), - (64,1), - (65,1), - (66,1), - (67,1), - (68,1), - (69,1), - (70,1), - (77,1), - (79,1), - (81,1), - (82,1), - (83,1), - (84,1), - (85,1), - (86,1), - (87,1), - (88,1), - (89,1), - (90,1), - (92,1), - (93,1), - (13,1), - (14,1), - (15,1), - (18,1), - (20,1), - (24,1), - (25,1), - (26,1), - (40,1), - (50,1), - (51,1), - (52,1), - (53,1), - (54,1), - (55,1), - (56,1), - (57,1), - (71,1), - (72,1), - (73,1), - (74,1), - (75,1), - (76,1), - (78,1), - (80,1), - (91,1); - -END; \ No newline at end of file diff --git a/bundled-schema/ScenarioDefaults.sql b/bundled-schema/ScenarioDefaults.sql new file mode 100644 index 000000000..ec7b3d99e --- /dev/null +++ b/bundled-schema/ScenarioDefaults.sql @@ -0,0 +1,178 @@ +BEGIN; + +INSERT INTO public.scenario_counter +(scenario_id, category_id) +VALUES + (17,0), + (93,1), + (92,1), + (81,1), + (91,1), + (90,1), + (89,1), + (88,1), + (87,1), + (86,1), + (85,1), + (84,1), + (83,1), + (82,1), + (87,3), + (88,3), + (89,3), + (90,3), + (91,3), + (92,3), + (83,3), + (86,3), + (60,3), + (58,3), + (59,3), + (27,3), + (25,3), + (26,3), + (23,3), + (2,3), + (3,3), + (4,3), + (31,3), + (32,3), + (33,3), + (34,3), + (35,3), + (36,3), + (37,3), + (40,3), + (38,3), + (39,3), + (48,3), + (12,3), + (13,3), + (30,3), + (29,3), + (46,3), + (0,4), + (1,4), + (2,4), + (3,4), + (4,4), + (5,4), + (6,4), + (7,4), + (8,4), + (9,4), + (10,4), + (11,4), + (12,4), + (13,4), + (14,4), + (50,5), + (51,5), + (52,5), + (53,5), + (54,5), + (55,5), + (56,5), + (58,5), + (63,5), + (64,5), + (65,5), + (67,5), + (71,5), + (75,5), + (61,5), + (68,5), + (66,5), + (76,5), + (70,5), + (77,5), + (72,5), + (74,5), + (73,5), + (78,5), + (69,5), + (62,5), + (79,5), + (0,6), + (1,6), + (2,6), + (3,6), + (4,6), + (5,6), + (6,6), + (7,6), + (8,6), + (9,6), + (17,6), + (10,6), + (11,6), + (12,6), + (13,6), + (14,6), + (15,6), + (16,6), + (50,7), + (53,7), + (62,7), + (52,7), + (56,7), + (51,7), + (49,7), + (54,7), + (57,7), + (55,7), + (61,7), + (58,7), + (60,7), + (59,7), + (42,7), + (48,7), + (40,7), + (39,7), + (43,7), + (46,7), + (41,7), + (44,7), + (45,7), + (47,7), + (37,7), + (34,7), + (33,7), + (32,7), + (28,7), + (26,7), + (36,7), + (38,7), + (35,7), + (27,7), + (30,7), + (31,7), + (29,7), + (24,7), + (23,7), + (22,7), + (21,7), + (25,7), + (20,7), + (7,7), + (9,7), + (13,7), + (16,7), + (12,7), + (14,7), + (15,7), + (19,7), + (10,7), + (8,7), + (11,7), + (18,7), + (17,7), + (6,7), + (5,7), + (4,7), + (3,7), + (2,7), + (1,7), + (0,7); + +END; \ No newline at end of file diff --git a/patch-schema/scenarios-counter.sql b/patch-schema/07-scenarios-counter.sql similarity index 100% rename from patch-schema/scenarios-counter.sql rename to patch-schema/07-scenarios-counter.sql