From f73bdd7445ca2a5e210d81a1ee2c21a40dcfa052 Mon Sep 17 00:00:00 2001 From: wish Date: Fri, 5 Jan 2024 02:39:25 +1100 Subject: [PATCH] rewrite CastBinary payload handling --- network/binpacket/msg_bin_chat.go | 3 +- server/channelserver/handlers_cast_binary.go | 40 +++++++++----------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/network/binpacket/msg_bin_chat.go b/network/binpacket/msg_bin_chat.go index 44bd587ca..b39a43795 100644 --- a/network/binpacket/msg_bin_chat.go +++ b/network/binpacket/msg_bin_chat.go @@ -11,7 +11,8 @@ type ChatType uint8 // Chat types const ( - ChatTypeLocal ChatType = 1 + ChatTypeWorld ChatType = 0 + ChatTypeStage = 1 ChatTypeGuild = 2 ChatTypeAlliance = 3 ChatTypeParty = 4 diff --git a/server/channelserver/handlers_cast_binary.go b/server/channelserver/handlers_cast_binary.go index 043403216..0f6b736e7 100644 --- a/server/channelserver/handlers_cast_binary.go +++ b/server/channelserver/handlers_cast_binary.go @@ -377,24 +377,20 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) { // Parse out the real casted binary payload var msgBinTargeted *binpacket.MsgBinTargeted - var authorLen, msgLen uint16 - var msg []byte - - isDiceCommand := false + var message, author string + var returnToSender bool if pkt.MessageType == BinaryMessageTypeChat { tmp.SetLE() - tmp.Seek(int64(0), 0) - _ = tmp.ReadUint32() - authorLen = tmp.ReadUint16() - msgLen = tmp.ReadUint16() - msg = tmp.ReadNullTerminatedBytes() + tmp.Seek(8, 0) + message = string(tmp.ReadNullTerminatedBytes()) + author = string(tmp.ReadNullTerminatedBytes()) } // Customise payload realPayload := pkt.RawDataPayload if pkt.BroadcastType == BroadcastTypeTargeted { tmp.SetBE() - tmp.Seek(int64(0), 0) + tmp.Seek(0, 0) msgBinTargeted = &binpacket.MsgBinTargeted{} err := msgBinTargeted.Parse(tmp) if err != nil { @@ -403,18 +399,18 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) { } realPayload = msgBinTargeted.RawDataPayload } else if pkt.MessageType == BinaryMessageTypeChat { - if msgLen == 6 && string(msg) == "@dice" { - isDiceCommand = true - roll := byteframe.NewByteFrame() - roll.WriteInt16(1) // Unk - roll.SetLE() - roll.WriteUint16(4) // Unk - roll.WriteUint16(authorLen) - dice := fmt.Sprintf("%d", token.RNG().Intn(100)+1) - roll.WriteUint16(uint16(len(dice) + 1)) - roll.WriteNullTerminatedBytes([]byte(dice)) - roll.WriteNullTerminatedBytes(tmp.ReadNullTerminatedBytes()) - realPayload = roll.Data() + if message == "@dice" { + returnToSender = true + m := binpacket.MsgBinChat{ + Type: BinaryMessageTypeChat, + Flags: 4, + Message: fmt.Sprintf(`%d`, token.RNG().Intn(100)+1), + SenderName: author, + } + bf := byteframe.NewByteFrame() + bf.SetLE() + m.Build(bf) + realPayload = bf.Data() } else { bf := byteframe.NewByteFrameFromBytes(pkt.RawDataPayload) bf.SetLE()