From 0d1ee983f8c6192eb23b9d7ad3e243d07ccf2fea Mon Sep 17 00:00:00 2001 From: wish Date: Mon, 10 Jul 2023 22:23:22 +1000 Subject: [PATCH] decode Tournament handlers --- .../mhfpacket/msg_mhf_acquire_tournament.go | 17 +- network/mhfpacket/msg_mhf_entry_tournament.go | 19 ++- server/channelserver/handlers_tournament.go | 146 +++++++++++++----- 3 files changed, 132 insertions(+), 50 deletions(-) diff --git a/network/mhfpacket/msg_mhf_acquire_tournament.go b/network/mhfpacket/msg_mhf_acquire_tournament.go index d1d293288..2e65e0984 100644 --- a/network/mhfpacket/msg_mhf_acquire_tournament.go +++ b/network/mhfpacket/msg_mhf_acquire_tournament.go @@ -1,15 +1,18 @@ package mhfpacket -import ( - "errors" +import ( + "errors" - "erupe-ce/network/clientctx" - "erupe-ce/network" "erupe-ce/common/byteframe" + "erupe-ce/network" + "erupe-ce/network/clientctx" ) // MsgMhfAcquireTournament represents the MSG_MHF_ACQUIRE_TOURNAMENT -type MsgMhfAcquireTournament struct{} +type MsgMhfAcquireTournament struct { + AckHandle uint32 + TournamentID uint32 +} // Opcode returns the ID associated with this packet type. func (m *MsgMhfAcquireTournament) Opcode() network.PacketID { @@ -18,7 +21,9 @@ func (m *MsgMhfAcquireTournament) Opcode() network.PacketID { // Parse parses the packet from binary func (m *MsgMhfAcquireTournament) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { - return errors.New("NOT IMPLEMENTED") + m.AckHandle = bf.ReadUint32() + m.TournamentID = bf.ReadUint32() + return nil } // Build builds a binary packet from the current data. diff --git a/network/mhfpacket/msg_mhf_entry_tournament.go b/network/mhfpacket/msg_mhf_entry_tournament.go index dbd600cab..6f6550cf0 100644 --- a/network/mhfpacket/msg_mhf_entry_tournament.go +++ b/network/mhfpacket/msg_mhf_entry_tournament.go @@ -1,15 +1,19 @@ package mhfpacket -import ( - "errors" +import ( + "errors" - "erupe-ce/network/clientctx" - "erupe-ce/network" "erupe-ce/common/byteframe" + "erupe-ce/network" + "erupe-ce/network/clientctx" ) // MsgMhfEntryTournament represents the MSG_MHF_ENTRY_TOURNAMENT -type MsgMhfEntryTournament struct{} +type MsgMhfEntryTournament struct { + AckHandle uint32 + TournamentID uint32 + Unk0 uint8 +} // Opcode returns the ID associated with this packet type. func (m *MsgMhfEntryTournament) Opcode() network.PacketID { @@ -18,7 +22,10 @@ func (m *MsgMhfEntryTournament) Opcode() network.PacketID { // Parse parses the packet from binary func (m *MsgMhfEntryTournament) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error { - return errors.New("NOT IMPLEMENTED") + m.AckHandle = bf.ReadUint32() + m.TournamentID = bf.ReadUint32() + m.Unk0 = bf.ReadUint8() + return nil } // Build builds a binary packet from the current data. diff --git a/server/channelserver/handlers_tournament.go b/server/channelserver/handlers_tournament.go index 84c2c8e8f..87fc95330 100644 --- a/server/channelserver/handlers_tournament.go +++ b/server/channelserver/handlers_tournament.go @@ -7,54 +7,124 @@ import ( "time" ) +type TournamentInfo0 struct { + ID uint32 + MaxPlayers uint32 + CurrentPlayers uint32 + Unk1 uint16 + TextColor uint16 + Unk2 uint32 + Time1 time.Time + Time2 time.Time + Time3 time.Time + Time4 time.Time + Time5 time.Time + Time6 time.Time + Unk3 uint8 + Unk4 uint8 + MinHR uint32 + MaxHR uint32 + Unk5 string + Unk6 string +} + +type TournamentInfo21 struct { + Unk0 uint32 + Unk1 uint32 + Unk2 uint32 + Unk3 uint8 +} + +type TournamentInfo22 struct { + Unk0 uint32 + Unk1 uint32 + Unk2 uint32 + Unk3 uint8 + Unk4 string +} + func handleMsgMhfInfoTournament(s *Session, p mhfpacket.MHFPacket) { pkt := p.(*mhfpacket.MsgMhfInfoTournament) bf := byteframe.NewByteFrame() + tournamentInfo0 := []TournamentInfo0{} + tournamentInfo21 := []TournamentInfo21{} + tournamentInfo22 := []TournamentInfo22{} + switch pkt.Unk0 { case 0: - bf.WriteUint32(uint32(TimeAdjusted().Unix())) - bf.WriteUint32(0) // Tied to schedule ID? - case 1: - - bf.WriteBytes(make([]byte, 21)) - ps.Uint8(bf, "", false) - break - - bf.WriteUint32(0xACEDCAFE) - - bf.WriteUint32(5) // Active schedule? - - bf.WriteUint32(1) // Schedule ID? - - bf.WriteUint32(32) // Max players - bf.WriteUint32(0) // Registered players - - bf.WriteUint16(0) - bf.WriteUint16(2) // Color code for schedule item bf.WriteUint32(0) - - bf.WriteUint32(uint32(time.Now().Add(time.Hour * -10).Unix())) - bf.WriteUint32(uint32(time.Now().Add(time.Hour * 10).Unix())) - bf.WriteUint32(uint32(time.Now().Add(time.Hour * 10).Unix())) - bf.WriteUint32(uint32(time.Now().Add(time.Hour * 10).Unix())) - bf.WriteUint32(uint32(time.Now().Add(time.Hour * 10).Unix())) - bf.WriteUint32(uint32(time.Now().Add(time.Hour * 10).Unix())) - - bf.WriteBool(true) // Unk - bf.WriteBool(false) // Cafe-only - - bf.WriteUint32(0) // Min HR - bf.WriteUint32(0) // Max HR - - ps.Uint8(bf, "Test", false) - - // ... + bf.WriteUint32(uint32(len(tournamentInfo0))) + for _, tinfo := range tournamentInfo0 { + bf.WriteUint32(tinfo.ID) + bf.WriteUint32(tinfo.MaxPlayers) + bf.WriteUint32(tinfo.CurrentPlayers) + bf.WriteUint16(tinfo.Unk1) + bf.WriteUint16(tinfo.TextColor) + bf.WriteUint32(tinfo.Unk2) + bf.WriteUint32(uint32(tinfo.Time1.Unix())) + bf.WriteUint32(uint32(tinfo.Time2.Unix())) + bf.WriteUint32(uint32(tinfo.Time3.Unix())) + bf.WriteUint32(uint32(tinfo.Time4.Unix())) + bf.WriteUint32(uint32(tinfo.Time5.Unix())) + bf.WriteUint32(uint32(tinfo.Time6.Unix())) + bf.WriteUint8(tinfo.Unk3) + bf.WriteUint8(tinfo.Unk4) + bf.WriteUint32(tinfo.MinHR) + bf.WriteUint32(tinfo.MaxHR) + ps.Uint8(bf, tinfo.Unk5, true) + ps.Uint16(bf, tinfo.Unk6, true) + } + case 1: + bf.WriteUint32(uint32(TimeAdjusted().Unix())) + bf.WriteUint32(0) // Registered ID + bf.WriteUint32(0) + bf.WriteUint32(0) + bf.WriteUint8(0) + bf.WriteUint32(0) + ps.Uint8(bf, "", true) + case 2: + bf.WriteUint32(0) + bf.WriteUint32(uint32(len(tournamentInfo21))) + for _, info := range tournamentInfo21 { + bf.WriteUint32(info.Unk0) + bf.WriteUint32(info.Unk1) + bf.WriteUint32(info.Unk2) + bf.WriteUint8(info.Unk3) + } + bf.WriteUint32(uint32(len(tournamentInfo22))) + for _, info := range tournamentInfo22 { + bf.WriteUint32(info.Unk0) + bf.WriteUint32(info.Unk1) + bf.WriteUint32(info.Unk2) + bf.WriteUint8(info.Unk3) + ps.Uint8(bf, info.Unk4, true) + } } doAckBufSucceed(s, pkt.AckHandle, bf.Data()) } -func handleMsgMhfEntryTournament(s *Session, p mhfpacket.MHFPacket) {} +func handleMsgMhfEntryTournament(s *Session, p mhfpacket.MHFPacket) { + pkt := p.(*mhfpacket.MsgMhfEntryTournament) + doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4)) +} -func handleMsgMhfAcquireTournament(s *Session, p mhfpacket.MHFPacket) {} +type TournamentReward struct { + Unk0 uint16 + Unk1 uint16 + Unk2 uint16 +} + +func handleMsgMhfAcquireTournament(s *Session, p mhfpacket.MHFPacket) { + pkt := p.(*mhfpacket.MsgMhfAcquireTournament) + rewards := []TournamentReward{} + bf := byteframe.NewByteFrame() + bf.WriteUint8(uint8(len(rewards))) + for _, reward := range rewards { + bf.WriteUint16(reward.Unk0) + bf.WriteUint16(reward.Unk1) + bf.WriteUint16(reward.Unk2) + } + doAckBufSucceed(s, pkt.AckHandle, bf.Data()) +}