refactor(mhfpacket): rename 15 Unk fields with identified meanings

Replace unknown field names with descriptive names based on handler
logic analysis, switch dispatch patterns, DB query context, and
inline comments:

- ObjectHandleID, IsQuest, ItemIDCount, MaxCount, TokenLength,
  FormatVersion, LogoutType (high confidence from comments/constants)
- QueryType, DataType, MissionIndex, CheckOnly, RequestType,
  ExchangeType, TournamentID (confirmed by handler switch/if usage)

Also fix MsgSysLogout.Build calling ReadUint8 instead of WriteUint8.
This commit is contained in:
Houmgaor
2026-02-18 21:48:08 +01:00
parent 2bd5f98f32
commit 0d07a1f698
35 changed files with 104 additions and 104 deletions

View File

@@ -134,13 +134,13 @@ func TestHandleMsgMhfOperationInvGuild(t *testing.T) {
// Tests for mercenary handlers that do not require database access.
func TestHandleMsgMhfMercenaryHuntdata_Unk0Is1(t *testing.T) {
func TestHandleMsgMhfMercenaryHuntdata_RequestTypeIs1(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
pkt := &mhfpacket.MsgMhfMercenaryHuntdata{
AckHandle: 12345,
Unk0: 1,
RequestType: 1,
}
handleMsgMhfMercenaryHuntdata(session, pkt)
@@ -155,13 +155,13 @@ func TestHandleMsgMhfMercenaryHuntdata_Unk0Is1(t *testing.T) {
}
}
func TestHandleMsgMhfMercenaryHuntdata_Unk0Is0(t *testing.T) {
func TestHandleMsgMhfMercenaryHuntdata_RequestTypeIs0(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
pkt := &mhfpacket.MsgMhfMercenaryHuntdata{
AckHandle: 12345,
Unk0: 0,
RequestType: 0,
}
handleMsgMhfMercenaryHuntdata(session, pkt)
@@ -176,18 +176,18 @@ func TestHandleMsgMhfMercenaryHuntdata_Unk0Is0(t *testing.T) {
}
}
func TestHandleMsgMhfMercenaryHuntdata_Unk0Is2(t *testing.T) {
func TestHandleMsgMhfMercenaryHuntdata_RequestTypeIs2(t *testing.T) {
server := createMockServer()
session := createMockSession(1, server)
pkt := &mhfpacket.MsgMhfMercenaryHuntdata{
AckHandle: 12345,
Unk0: 2,
RequestType: 2,
}
handleMsgMhfMercenaryHuntdata(session, pkt)
// Unk0=2 takes the else branch (same as 0)
// RequestType=2 takes the else branch (same as 0)
select {
case p := <-session.sendPackets:
if len(p.data) == 0 {
@@ -557,7 +557,7 @@ func TestHandlersConcurrentInvocations(t *testing.T) {
handleMsgSysIssueLogkey(session, &mhfpacket.MsgSysIssueLogkey{AckHandle: id})
<-session.sendPackets
handleMsgMhfMercenaryHuntdata(session, &mhfpacket.MsgMhfMercenaryHuntdata{AckHandle: id, Unk0: 1})
handleMsgMhfMercenaryHuntdata(session, &mhfpacket.MsgMhfMercenaryHuntdata{AckHandle: id, RequestType: 1})
<-session.sendPackets
handleMsgMhfEnumerateMercenaryLog(session, &mhfpacket.MsgMhfEnumerateMercenaryLog{AckHandle: id})

View File

@@ -640,7 +640,7 @@ func TestNonTrivialHandlers_TowerGo(t *testing.T) {
handleMsgMhfGetTenrouirai(s, &mhfpacket.MsgMhfGetTenrouirai{AckHandle: 1, Unk0: 1})
}},
{"handleMsgMhfGetTenrouirai_Unknown", func(s *Session) {
handleMsgMhfGetTenrouirai(s, &mhfpacket.MsgMhfGetTenrouirai{AckHandle: 1, Unk0: 0, Unk1: 0})
handleMsgMhfGetTenrouirai(s, &mhfpacket.MsgMhfGetTenrouirai{AckHandle: 1, Unk0: 0, DataType: 0})
}},
// handleMsgMhfGetTenrouirai_Type4, handleMsgMhfPostTenrouirai, handleMsgMhfGetGemInfo removed: require DB
{"handleMsgMhfGetWeeklySeibatuRankingReward", func(s *Session) {

View File

@@ -17,7 +17,7 @@ func TestHandleMsgMhfGetPaperData_Case0(t *testing.T) {
handleMsgMhfGetPaperData(session, &mhfpacket.MsgMhfGetPaperData{
AckHandle: 1,
Unk2: 0,
DataType: 0,
})
select {
@@ -36,7 +36,7 @@ func TestHandleMsgMhfGetPaperData_Case5(t *testing.T) {
handleMsgMhfGetPaperData(session, &mhfpacket.MsgMhfGetPaperData{
AckHandle: 1,
Unk2: 5,
DataType: 5,
})
select {
@@ -55,7 +55,7 @@ func TestHandleMsgMhfGetPaperData_Case6(t *testing.T) {
handleMsgMhfGetPaperData(session, &mhfpacket.MsgMhfGetPaperData{
AckHandle: 1,
Unk2: 6,
DataType: 6,
})
select {
@@ -75,7 +75,7 @@ func TestHandleMsgMhfGetPaperData_GreaterThan1000_KnownKey(t *testing.T) {
// 6001 is a known key in paperGiftData
handleMsgMhfGetPaperData(session, &mhfpacket.MsgMhfGetPaperData{
AckHandle: 1,
Unk2: 6001,
DataType: 6001,
})
select {
@@ -95,7 +95,7 @@ func TestHandleMsgMhfGetPaperData_GreaterThan1000_UnknownKey(t *testing.T) {
// 9999 is not a known key in paperGiftData
handleMsgMhfGetPaperData(session, &mhfpacket.MsgMhfGetPaperData{
AckHandle: 1,
Unk2: 9999,
DataType: 9999,
})
select {
@@ -114,7 +114,7 @@ func TestHandleMsgMhfGetPaperData_DefaultUnknownLessThan1000(t *testing.T) {
// Unknown type < 1000, hits default case then falls to else branch
handleMsgMhfGetPaperData(session, &mhfpacket.MsgMhfGetPaperData{
AckHandle: 1,
Unk2: 99,
DataType: 99,
})
select {

View File

@@ -60,7 +60,7 @@ func handleMsgMhfGetPaperData(s *Session, p mhfpacket.MHFPacket) {
var paperMissions PaperMission
var paperGift []PaperGift
switch pkt.Unk2 {
switch pkt.DataType {
case 0:
paperMissions = PaperMission{
[]PaperMissionTimetable{{TimeMidnight(), TimeMidnight().Add(24 * time.Hour)}},
@@ -565,17 +565,17 @@ func handleMsgMhfGetPaperData(s *Session, p mhfpacket.MHFPacket) {
{4202, 2, 0, 11469, 1, 1400, 1},
}
default:
if pkt.Unk2 < 1000 {
s.logger.Info("PaperData request for unknown type", zap.Uint32("Unk2", pkt.Unk2))
if pkt.DataType < 1000 {
s.logger.Info("PaperData request for unknown type", zap.Uint32("DataType", pkt.DataType))
}
}
if pkt.Unk2 > 1000 {
_, ok := paperGiftData[pkt.Unk2]
if pkt.DataType > 1000 {
_, ok := paperGiftData[pkt.DataType]
if ok {
paperGift = paperGiftData[pkt.Unk2]
paperGift = paperGiftData[pkt.DataType]
} else {
s.logger.Info("PaperGift request for unknown type", zap.Uint32("Unk2", pkt.Unk2))
s.logger.Info("PaperGift request for unknown type", zap.Uint32("DataType", pkt.DataType))
}
for _, gift := range paperGift {
bf := byteframe.NewByteFrame()
@@ -586,7 +586,7 @@ func handleMsgMhfGetPaperData(s *Session, p mhfpacket.MHFPacket) {
data = append(data, bf)
}
doAckEarthSucceed(s, pkt.AckHandle, data)
} else if pkt.Unk2 == 0 {
} else if pkt.DataType == 0 {
bf := byteframe.NewByteFrame()
bf.WriteUint16(uint16(len(paperMissions.Timetables)))
bf.WriteUint16(uint16(len(paperMissions.Data)))

View File

@@ -70,7 +70,7 @@ func updateRights(s *Session) {
ClientRespAckHandle: 0,
Bitfield: rightsInt,
Rights: s.courses,
UnkSize: 0,
TokenLength: 0,
}
s.QueueSendMHFNonBlocking(update)
}

View File

@@ -261,7 +261,7 @@ func handleMsgMhfExchangeWeeklyStamp(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfExchangeWeeklyStamp)
var total, redeemed uint16
var tktStack mhfitem.MHFItemStack
if pkt.Unk1 == 10 { // Yearly Sub Ex
if pkt.ExchangeType == 10 { // Yearly Sub Ex
_ = s.server.db.QueryRow("UPDATE stamps SET hl_total=hl_total-48, hl_redeemed=hl_redeemed-48 WHERE character_id=$1 RETURNING hl_total, hl_redeemed", s.charID).Scan(&total, &redeemed)
tktStack = mhfitem.MHFItemStack{Item: mhfitem.MHFItem{ItemID: 2210}, Quantity: 1}
} else {

View File

@@ -148,7 +148,7 @@ func handleMsgMhfSaveHunterNavi(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfMercenaryHuntdata(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfMercenaryHuntdata)
if pkt.Unk0 == 1 {
if pkt.RequestType == 1 {
// Format:
// uint8 Hunts
// struct Hunt

View File

@@ -239,7 +239,7 @@ func TestHandleMsgMhfMercenaryHuntdata_Unk0_1(t *testing.T) {
pkt := &mhfpacket.MsgMhfMercenaryHuntdata{
AckHandle: 12345,
Unk0: 1,
RequestType: 1,
}
handleMsgMhfMercenaryHuntdata(session, pkt)
@@ -261,7 +261,7 @@ func TestHandleMsgMhfMercenaryHuntdata_Unk0_0(t *testing.T) {
pkt := &mhfpacket.MsgMhfMercenaryHuntdata{
AckHandle: 12345,
Unk0: 0,
RequestType: 0,
}
handleMsgMhfMercenaryHuntdata(session, pkt)

View File

@@ -9,7 +9,7 @@ func handleMsgMhfRegisterEvent(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfRegisterEvent)
bf := byteframe.NewByteFrame()
// Some kind of check if there's already a session
if pkt.Unk1 && s.server.getRaviSemaphore() == nil {
if pkt.CheckOnly && s.server.getRaviSemaphore() == nil {
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
return
}

View File

@@ -54,7 +54,7 @@ func handleMsgMhfInfoTournament(s *Session, p mhfpacket.MHFPacket) {
tournamentInfo21 := []TournamentInfo21{}
tournamentInfo22 := []TournamentInfo22{}
switch pkt.Unk0 {
switch pkt.QueryType {
case 0:
bf.WriteUint32(0)
bf.WriteUint32(uint32(len(tournamentInfo0)))

View File

@@ -12,7 +12,7 @@ func TestHandleMsgMhfInfoTournament_Type0(t *testing.T) {
pkt := &mhfpacket.MsgMhfInfoTournament{
AckHandle: 12345,
Unk0: 0,
QueryType: 0,
}
handleMsgMhfInfoTournament(session, pkt)
@@ -34,7 +34,7 @@ func TestHandleMsgMhfInfoTournament_Type1(t *testing.T) {
pkt := &mhfpacket.MsgMhfInfoTournament{
AckHandle: 12345,
Unk0: 1,
QueryType: 1,
}
handleMsgMhfInfoTournament(session, pkt)

View File

@@ -273,7 +273,7 @@ func handleMsgMhfGetTenrouirai(s *Session, p mhfpacket.MHFPacket) {
Ticket: []TenrouiraiTicket{{0, 0, 0}},
}
switch pkt.Unk1 {
switch pkt.DataType {
case 1:
for _, tdata := range tenrouirai.Data {
bf := byteframe.NewByteFrame()
@@ -329,13 +329,13 @@ func handleMsgMhfGetTenrouirai(s *Session, p mhfpacket.MHFPacket) {
data = append(data, bf)
}
case 5:
if pkt.Unk3 > 3 {
pkt.Unk3 %= 3
if pkt.Unk3 == 0 {
pkt.Unk3 = 3
if pkt.MissionIndex > 3 {
pkt.MissionIndex %= 3
if pkt.MissionIndex == 0 {
pkt.MissionIndex = 3
}
}
rows, err := s.server.db.Query(fmt.Sprintf(`SELECT name, tower_mission_%d FROM guild_characters gc INNER JOIN characters c ON gc.character_id = c.id WHERE guild_id=$1 AND tower_mission_%d IS NOT NULL ORDER BY tower_mission_%d DESC`, pkt.Unk3, pkt.Unk3, pkt.Unk3), pkt.GuildID)
rows, err := s.server.db.Query(fmt.Sprintf(`SELECT name, tower_mission_%d FROM guild_characters gc INNER JOIN characters c ON gc.character_id = c.id WHERE guild_id=$1 AND tower_mission_%d IS NOT NULL ORDER BY tower_mission_%d DESC`, pkt.MissionIndex, pkt.MissionIndex, pkt.MissionIndex), pkt.GuildID)
if err != nil {
s.logger.Error("Failed to query tower mission scores", zap.Error(err))
} else {
@@ -470,7 +470,7 @@ func handleMsgMhfGetGemInfo(s *Session, p mhfpacket.MHFPacket) {
gemInfo = append(gemInfo, GemInfo{uint16((i / 5 << 8) + (i%5 + 1)), uint16(v)})
}
switch pkt.Unk0 {
switch pkt.QueryType {
case 1:
for _, info := range gemInfo {
bf := byteframe.NewByteFrame()

View File

@@ -35,7 +35,7 @@ func TestHandleMsgMhfGetTenrouirai_Default(t *testing.T) {
pkt := &mhfpacket.MsgMhfGetTenrouirai{
AckHandle: 12345,
Unk0: 0,
Unk1: 0,
DataType: 0,
}
handleMsgMhfGetTenrouirai(session, pkt)