repository cleanup

This commit is contained in:
wish
2022-07-29 03:25:23 +10:00
parent a0be6c627c
commit 2c0e7a5267
645 changed files with 996 additions and 903 deletions

View File

@@ -0,0 +1,59 @@
package binpacket
import (
"erupe-ce/common/byteframe"
"erupe-ce/common/stringsupport"
"erupe-ce/network"
)
// ChatType represents the chat message type (Thanks to @Alice on discord for identifying these!)
type ChatType uint8
// Chat types
const (
ChatTypeLocal ChatType = 1
ChatTypeGuild = 2
ChatTypeAlliance = 3
ChatTypeParty = 4
ChatTypeWhisper = 5
)
// MsgBinChat is a binpacket for chat messages.
type MsgBinChat struct {
Unk0 uint8
Type ChatType
Flags uint16
Message string
SenderName string
}
// Opcode returns the ID associated with this packet type.
func (m *MsgBinChat) Opcode() network.PacketID {
return network.MSG_SYS_CAST_BINARY
}
// Parse parses the packet from binary
func (m *MsgBinChat) Parse(bf *byteframe.ByteFrame) error {
m.Unk0 = bf.ReadUint8()
m.Type = ChatType(bf.ReadUint8())
m.Flags = bf.ReadUint16()
_ = bf.ReadUint16() // lenSenderName
_ = bf.ReadUint16() // lenMessage
m.Message = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
m.SenderName = stringsupport.SJISToUTF8(bf.ReadNullTerminatedBytes())
return nil
}
// Build builds a binary packet from the current data.
func (m *MsgBinChat) Build(bf *byteframe.ByteFrame) error {
bf.WriteUint8(m.Unk0)
bf.WriteUint8(uint8(m.Type))
bf.WriteUint16(m.Flags)
cMessage := stringsupport.UTF8ToSJIS(m.Message)
cSenderName := stringsupport.UTF8ToSJIS(m.SenderName)
bf.WriteUint16(uint16(len(cSenderName) + 1))
bf.WriteUint16(uint16(len(cMessage) + 1))
bf.WriteNullTerminatedBytes(cMessage)
bf.WriteNullTerminatedBytes(cSenderName)
return nil
}

View File

@@ -0,0 +1,29 @@
package binpacket
import (
"erupe-ce/common/byteframe"
"erupe-ce/common/stringsupport"
"erupe-ce/network"
)
type MsgBinMailNotify struct {
SenderName string
}
func (m MsgBinMailNotify) Parse(bf *byteframe.ByteFrame) error {
panic("implement me")
}
func (m MsgBinMailNotify) Build(bf *byteframe.ByteFrame) error {
bf.WriteUint8(0x01) // Unk
byteName, _ := stringsupport.ConvertUTF8ToShiftJIS(m.SenderName)
bf.WriteBytes(byteName)
bf.WriteBytes(make([]byte, 21-len(byteName)))
return nil
}
func (m MsgBinMailNotify) Opcode() network.PacketID {
return network.MSG_SYS_CASTED_BINARY
}

View File

@@ -0,0 +1,46 @@
package binpacket
import (
"erupe-ce/common/byteframe"
"erupe-ce/network"
)
// MsgBinTargeted is a format used for some broadcast types
// to target specific players, instead of groups (world, stage, etc).
// It forwards a normal binpacket in it's RawDataPayload
type MsgBinTargeted struct {
TargetCount uint16
TargetCharIDs []uint32
RawDataPayload []byte // The regular binary payload to be forwarded to the targets.
}
// Opcode returns the ID associated with this packet type.
func (m *MsgBinTargeted) Opcode() network.PacketID {
return network.MSG_SYS_CAST_BINARY
}
// Parse parses the packet from binary
func (m *MsgBinTargeted) Parse(bf *byteframe.ByteFrame) error {
m.TargetCount = bf.ReadUint16()
m.TargetCharIDs = make([]uint32, m.TargetCount)
for i := uint16(0); i < m.TargetCount; i++ {
m.TargetCharIDs[i] = bf.ReadUint32()
}
m.RawDataPayload = bf.DataFromCurrent()
return nil
}
// Build builds a binary packet from the current data.
func (m *MsgBinTargeted) Build(bf *byteframe.ByteFrame) error {
bf.WriteUint16(m.TargetCount)
for i := 0; i < int(m.TargetCount); i++ {
bf.WriteUint32(m.TargetCharIDs[i])
}
bf.WriteBytes(m.RawDataPayload)
return nil
}