Files
Erupe/network/mhfpacket/msg_sys_ack.go
stratic-dev 62fe5cf277 moved bin 8 out and removed clientctx
moved crypto bin8 out of entrance server

removed unused clientctx

missed import

fix accidental commit and rename ack_helpers
2024-10-09 18:36:34 +01:00

71 lines
1.5 KiB
Go

package mhfpacket
import (
"erupe-ce/network"
"erupe-ce/utils/byteframe"
)
// MsgSysAck represents the MSG_SYS_ACK
type MsgSysAck struct {
AckHandle uint32
IsBufferResponse bool
ErrorCode uint8
AckData []byte
}
// Opcode returns the ID associated with this packet type.
func (m *MsgSysAck) Opcode() network.PacketID {
return network.MSG_SYS_ACK
}
// Parse parses the packet from binary
func (m *MsgSysAck) Parse(bf *byteframe.ByteFrame) error {
m.AckHandle = bf.ReadUint32()
m.IsBufferResponse = bf.ReadBool()
m.ErrorCode = bf.ReadUint8()
payloadSize := uint(bf.ReadUint16())
// Extended data size field
if payloadSize == 0xFFFF {
payloadSize = uint(bf.ReadUint32())
}
if m.IsBufferResponse {
m.AckData = bf.ReadBytes(payloadSize)
} else {
// endian-swapped 4 bytes, could be any type. Unknown purpose.
// Probably a fixed type like (int32 or uint32), but unknown.
m.AckData = bf.ReadBytes(4)
}
return nil
}
// Build builds a binary packet from the current data.
func (m *MsgSysAck) Build(bf *byteframe.ByteFrame) error {
bf.WriteUint32(m.AckHandle)
bf.WriteBool(m.IsBufferResponse)
bf.WriteUint8(m.ErrorCode)
if m.IsBufferResponse {
if len(m.AckData) < 0xFFFF {
bf.WriteUint16(uint16(len(m.AckData)))
} else {
bf.WriteUint16(0xFFFF)
bf.WriteUint32(uint32(len(m.AckData)))
}
} else {
bf.WriteUint16(0x00)
}
if m.IsBufferResponse {
bf.WriteBytes(m.AckData)
} else if len(m.AckData) >= 4 {
bf.WriteBytes(m.AckData[:4])
} else {
bf.WriteBytes([]byte{0x00, 0x00, 0x00, 0x00})
}
return nil
}