From ac40e679fe2364481fdcf871633109c0091a5b69 Mon Sep 17 00:00:00 2001 From: Sophie Date: Fri, 6 Mar 2020 21:23:57 +0000 Subject: [PATCH] Add mhfpacket wrapper for party join message --- .../binpacket/msg_bin_player_joined_party.go | 46 +++++++++++++++++++ server/channelserver/handlers.go | 31 ++++++------- 2 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 network/binpacket/msg_bin_player_joined_party.go diff --git a/network/binpacket/msg_bin_player_joined_party.go b/network/binpacket/msg_bin_player_joined_party.go new file mode 100644 index 000000000..5170ef276 --- /dev/null +++ b/network/binpacket/msg_bin_player_joined_party.go @@ -0,0 +1,46 @@ +package binpacket + +import ( + "github.com/Andoryuuta/Erupe/network" + "github.com/Andoryuuta/Erupe/network/mhfpacket" + "github.com/Andoryuuta/byteframe" +) + +type PartyJoinType uint8 + +const ( + JoinedLocalParty PartyJoinType = 0x01 + JoinedYourParty PartyJoinType = 0x04 +) + +type MsgBinPlayerJoinedParty struct { + CharID uint32 + PartyJoinType PartyJoinType +} + +// Opcode returns the ID associated with this packet type. +func (m *MsgBinPlayerJoinedParty) Opcode() network.PacketID { + return network.MSG_SYS_CASTED_BINARY +} + +func (m *MsgBinPlayerJoinedParty) Parse(bf *byteframe.ByteFrame) error { + panic("Not implemented") +} + +// Build builds a binary packet from the current data. +func (m *MsgBinPlayerJoinedParty) Build(bf *byteframe.ByteFrame) error { + payload := byteframe.NewByteFrame() + + payload.WriteUint16(0x2) + payload.WriteUint8(uint8(m.PartyJoinType)) + payload.WriteBytes([]byte{0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) + + pkt := &mhfpacket.MsgSysCastedBinary{ + CharID: m.CharID, + Type0: 0x03, + Type1: 0x03, + RawDataPayload: payload.Data(), + } + + return pkt.Build(bf) +} diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index d8214fba1..c710c2ee6 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "encoding/hex" "fmt" + "github.com/Andoryuuta/Erupe/network/binpacket" "io" "io/ioutil" "os" @@ -700,29 +701,20 @@ func handleMsgSysReserveStage(s *Session, p mhfpacket.MHFPacket) { s.stage.BroadcastMHF(notify, s) - joinMsgA := &mhfpacket.MsgSysCastedBinary{ - CharID: s.charID, - Type0: 0x03, - Type1: 0x03, - RawDataPayload: []byte{ - 0x00, 0x02, 0x01, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }, + //TODO these messages should be directed to the correct recipients + joinedAPartyMessage := &binpacket.MsgBinPlayerJoinedParty{ + CharID: s.charID, + PartyJoinType: binpacket.JoinedLocalParty, } - s.stage.BroadcastMHF(joinMsgA, s) + s.stage.BroadcastMHF(joinedAPartyMessage, s) - joinMsgB := &mhfpacket.MsgSysCastedBinary{ - CharID: s.charID, - Type0: 0x03, - Type1: 0x03, - RawDataPayload: []byte{ - 0x00, 0x02, 0x04, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }, + joinedYourPartyMessage := &binpacket.MsgBinPlayerJoinedParty{ + CharID: s.charID, + PartyJoinType: binpacket.JoinedYourParty, } - s.stage.BroadcastMHF(joinMsgB, s) + s.stage.BroadcastMHF(joinedYourPartyMessage, s) } func handleMsgSysUnreserveStage(s *Session, p mhfpacket.MHFPacket) {} @@ -814,7 +806,10 @@ func handleMsgSysGetStageBinary(s *Session, p mhfpacket.MHFPacket) { if gotBinary { doSizedAckResp(s, pkt.AckHandle, stageBinary) + } else if pkt.BinaryType1 == 4 { + // This particular type seems to be expecting data that isn't set + // is it required before the party joining can be completed s.QueueAck(pkt.AckHandle, []byte{0x01, 0x00, 0x00, 0x00, 0x10}) } else { s.logger.Warn("Failed to get stage binary", zap.Uint8("BinaryType0", pkt.BinaryType0), zap.Uint8("pkt.BinaryType1", pkt.BinaryType1))