Skip to content

Commit

Permalink
rewrite CastBinary payload handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sekaiwish committed Jan 4, 2024
1 parent 8cd1149 commit f73bdd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
3 changes: 2 additions & 1 deletion network/binpacket/msg_bin_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type ChatType uint8

// Chat types
const (
ChatTypeLocal ChatType = 1
ChatTypeWorld ChatType = 0
ChatTypeStage = 1
ChatTypeGuild = 2
ChatTypeAlliance = 3
ChatTypeParty = 4
Expand Down
40 changes: 18 additions & 22 deletions server/channelserver/handlers_cast_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 381 in server/channelserver/handlers_cast_binary.go

View workflow job for this annotation

GitHub Actions / build

returnToSender declared and not used
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 {
Expand All @@ -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()
Expand Down

0 comments on commit f73bdd7

Please sign in to comment.