mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
Add full Diva Defense / United Defense system: schema, repo layer, i18n bead names, and RE-verified packet handler implementations. Schema (0011_diva.sql): diva_beads, diva_beads_assignment, diva_beads_points, diva_prizes tables; interception_maps/points columns on guilds and guild_characters. Seed (DivaDefaults.sql): 26 prize milestones for personal and guild reward tracks (item_type=26 diva coins). Repo (DivaRepo): 11 new methods covering bead assignment, point accumulation, interception point tracking, prize queries, and cleanup. Mocks wired in test_helpers_test.go. i18n: Bead struct with EN/JP names for all 18 bead types (IDs 1–25). Session tracks currentBeadIndex (-1 = none assigned). Packet handlers corrected against mhfo-hd.dll RE findings: - GetKijuInfo: u8 count, 512-byte desc, color_id+bead_type per entry - SetKiju: 1-byte ACK; persists bead assignment to DB - GetUdMyPoint: 8×18-byte entries, no count prefix - GetUdTotalPointInfo: u8 error + u64[64] + u8[64] + u64 (~585 B) - GetUdSelectedColorInfo: u8 error + u8[8] = 9 bytes - GetUdDailyPresentList: correct u16 count format (was wrong hex) - GetUdNormaPresentList: correct u16 count format (was wrong hex) - GetUdRankingRewardList: correct u16 count with u32 item_id/qty - GetRewardSong: 22-byte layout with 0xFFFFFFFF prayer_end sentinel - AddRewardSongCount: parse implemented (was NOT IMPLEMENTED stub)
234 lines
5.4 KiB
Go
234 lines
5.4 KiB
Go
package channelserver
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"erupe-ce/network/mhfpacket"
|
|
)
|
|
|
|
func TestHandleMsgMhfGetAdditionalBeatReward(t *testing.T) {
|
|
server := createMockServer()
|
|
session := createMockSession(1, server)
|
|
|
|
pkt := &mhfpacket.MsgMhfGetAdditionalBeatReward{
|
|
AckHandle: 12345,
|
|
}
|
|
|
|
handleMsgMhfGetAdditionalBeatReward(session, pkt)
|
|
|
|
select {
|
|
case p := <-session.sendPackets:
|
|
if len(p.data) == 0 {
|
|
t.Error("Response packet should have data")
|
|
}
|
|
default:
|
|
t.Error("No response packet queued")
|
|
}
|
|
}
|
|
|
|
func TestHandleMsgMhfGetUdRankingRewardList(t *testing.T) {
|
|
server := createMockServer()
|
|
session := createMockSession(1, server)
|
|
|
|
pkt := &mhfpacket.MsgMhfGetUdRankingRewardList{
|
|
AckHandle: 12345,
|
|
}
|
|
|
|
handleMsgMhfGetUdRankingRewardList(session, pkt)
|
|
|
|
select {
|
|
case p := <-session.sendPackets:
|
|
if len(p.data) == 0 {
|
|
t.Error("Response packet should have data")
|
|
}
|
|
default:
|
|
t.Error("No response packet queued")
|
|
}
|
|
}
|
|
|
|
func TestHandleMsgMhfGetRewardSong(t *testing.T) {
|
|
server := createMockServer()
|
|
session := createMockSession(1, server)
|
|
|
|
pkt := &mhfpacket.MsgMhfGetRewardSong{
|
|
AckHandle: 12345,
|
|
}
|
|
|
|
handleMsgMhfGetRewardSong(session, pkt)
|
|
|
|
select {
|
|
case p := <-session.sendPackets:
|
|
if len(p.data) == 0 {
|
|
t.Error("Response packet should have data")
|
|
}
|
|
default:
|
|
t.Error("No response packet queued")
|
|
}
|
|
}
|
|
|
|
func TestHandleMsgMhfUseRewardSong(t *testing.T) {
|
|
server := createMockServer()
|
|
session := createMockSession(1, server)
|
|
|
|
pkt := &mhfpacket.MsgMhfUseRewardSong{AckHandle: 12345}
|
|
handleMsgMhfUseRewardSong(session, pkt)
|
|
|
|
select {
|
|
case p := <-session.sendPackets:
|
|
if len(p.data) == 0 {
|
|
t.Error("Response packet should have data")
|
|
}
|
|
default:
|
|
t.Error("No response packet queued")
|
|
}
|
|
}
|
|
|
|
func TestHandleMsgMhfAddRewardSongCount(t *testing.T) {
|
|
server := createMockServer()
|
|
session := createMockSession(1, server)
|
|
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("handleMsgMhfAddRewardSongCount panicked: %v", r)
|
|
}
|
|
}()
|
|
|
|
handleMsgMhfAddRewardSongCount(session, nil)
|
|
}
|
|
|
|
func TestHandleMsgMhfAcquireMonthlyReward(t *testing.T) {
|
|
server := createMockServer()
|
|
session := createMockSession(1, server)
|
|
|
|
pkt := &mhfpacket.MsgMhfAcquireMonthlyReward{
|
|
AckHandle: 12345,
|
|
}
|
|
|
|
handleMsgMhfAcquireMonthlyReward(session, pkt)
|
|
|
|
select {
|
|
case p := <-session.sendPackets:
|
|
if len(p.data) == 0 {
|
|
t.Error("Response packet should have data")
|
|
}
|
|
default:
|
|
t.Error("No response packet queued")
|
|
}
|
|
}
|
|
|
|
func TestHandleMsgMhfAcceptReadReward(t *testing.T) {
|
|
server := createMockServer()
|
|
session := createMockSession(1, server)
|
|
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("handleMsgMhfAcceptReadReward panicked: %v", r)
|
|
}
|
|
}()
|
|
|
|
handleMsgMhfAcceptReadReward(session, nil)
|
|
}
|
|
|
|
// Tests consolidated from handlers_coverage3_test.go
|
|
|
|
func TestSimpleAckHandlers_RewardGo(t *testing.T) {
|
|
server := createMockServer()
|
|
|
|
tests := []struct {
|
|
name string
|
|
fn func(s *Session)
|
|
}{
|
|
{"handleMsgMhfGetRewardSong", func(s *Session) {
|
|
handleMsgMhfGetRewardSong(s, &mhfpacket.MsgMhfGetRewardSong{AckHandle: 1})
|
|
}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
session := createMockSession(1, server)
|
|
tt.fn(session)
|
|
select {
|
|
case p := <-session.sendPackets:
|
|
if len(p.data) == 0 {
|
|
t.Errorf("%s: response should have data", tt.name)
|
|
}
|
|
default:
|
|
t.Errorf("%s: no response queued", tt.name)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNonTrivialHandlers_RewardGo(t *testing.T) {
|
|
server := createMockServer()
|
|
|
|
tests := []struct {
|
|
name string
|
|
fn func(s *Session)
|
|
}{
|
|
{"handleMsgMhfGetAdditionalBeatReward", func(s *Session) {
|
|
handleMsgMhfGetAdditionalBeatReward(s, &mhfpacket.MsgMhfGetAdditionalBeatReward{AckHandle: 1})
|
|
}},
|
|
{"handleMsgMhfGetUdRankingRewardList", func(s *Session) {
|
|
handleMsgMhfGetUdRankingRewardList(s, &mhfpacket.MsgMhfGetUdRankingRewardList{AckHandle: 1})
|
|
}},
|
|
{"handleMsgMhfAcquireMonthlyReward", func(s *Session) {
|
|
handleMsgMhfAcquireMonthlyReward(s, &mhfpacket.MsgMhfAcquireMonthlyReward{AckHandle: 1})
|
|
}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
session := createMockSession(1, server)
|
|
tt.fn(session)
|
|
select {
|
|
case p := <-session.sendPackets:
|
|
if len(p.data) == 0 {
|
|
t.Errorf("%s: response should have data", tt.name)
|
|
}
|
|
default:
|
|
t.Errorf("%s: no response queued", tt.name)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestEmptyHandlers_MiscFiles_Reward(t *testing.T) {
|
|
server := createMockServer()
|
|
session := createMockSession(1, server)
|
|
|
|
// Handlers that accept nil and take no action (no AckHandle).
|
|
nilSafeTests := []struct {
|
|
name string
|
|
fn func()
|
|
}{
|
|
{"handleMsgMhfAddRewardSongCount", func() { handleMsgMhfAddRewardSongCount(session, nil) }},
|
|
{"handleMsgMhfAcceptReadReward", func() { handleMsgMhfAcceptReadReward(session, nil) }},
|
|
}
|
|
|
|
for _, tt := range nilSafeTests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("%s panicked: %v", tt.name, r)
|
|
}
|
|
}()
|
|
tt.fn()
|
|
})
|
|
}
|
|
|
|
// handleMsgMhfUseRewardSong is a real handler (requires a typed packet).
|
|
t.Run("handleMsgMhfUseRewardSong", func(t *testing.T) {
|
|
pkt := &mhfpacket.MsgMhfUseRewardSong{AckHandle: 1}
|
|
handleMsgMhfUseRewardSong(session, pkt)
|
|
select {
|
|
case p := <-session.sendPackets:
|
|
if len(p.data) == 0 {
|
|
t.Error("handleMsgMhfUseRewardSong: response should have data")
|
|
}
|
|
default:
|
|
t.Error("handleMsgMhfUseRewardSong: no response queued")
|
|
}
|
|
})
|
|
}
|