mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-23 12:24:45 +01:00
binary cast fixes and support all ravi types
This commit is contained in:
@@ -14,6 +14,7 @@ type MsgMhfAnnounce struct {
|
||||
IPAddress uint32
|
||||
Port uint16
|
||||
StageID []byte
|
||||
Type uint8
|
||||
}
|
||||
|
||||
// Opcode returns the ID associated with this packet type.
|
||||
@@ -30,9 +31,8 @@ func (m *MsgMhfAnnounce) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientCon
|
||||
_ = bf.ReadUint16()
|
||||
m.StageID = bf.ReadNullTerminatedBytes()
|
||||
for {
|
||||
byte := bf.ReadUint8()
|
||||
if byte != 0 {
|
||||
_ = bf.ReadUint8()
|
||||
if bf.ReadUint8() != 0 {
|
||||
m.Type = bf.ReadUint8()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,13 @@ import (
|
||||
)
|
||||
|
||||
// MsgMhfSetRestrictionEvent represents the MSG_MHF_SET_RESTRICTION_EVENT
|
||||
type MsgMhfSetRestrictionEvent struct{}
|
||||
type MsgMhfSetRestrictionEvent struct {
|
||||
AckHandle uint32
|
||||
Unk0 uint32
|
||||
Unk1 uint32
|
||||
Unk2 uint32
|
||||
Unk3 uint8
|
||||
}
|
||||
|
||||
// Opcode returns the ID associated with this packet type.
|
||||
func (m *MsgMhfSetRestrictionEvent) Opcode() network.PacketID {
|
||||
@@ -18,7 +24,12 @@ func (m *MsgMhfSetRestrictionEvent) Opcode() network.PacketID {
|
||||
|
||||
// Parse parses the packet from binary
|
||||
func (m *MsgMhfSetRestrictionEvent) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
|
||||
return errors.New("NOT IMPLEMENTED")
|
||||
m.AckHandle = bf.ReadUint32()
|
||||
m.Unk0 = bf.ReadUint32()
|
||||
m.Unk1 = bf.ReadUint32()
|
||||
m.Unk2 = bf.ReadUint32()
|
||||
m.Unk3 = bf.ReadUint8()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Build builds a binary packet from the current data.
|
||||
|
||||
@@ -346,7 +346,7 @@ func handleMsgMhfServerCommand(s *Session, p mhfpacket.MHFPacket) {}
|
||||
|
||||
func handleMsgMhfAnnounce(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgMhfAnnounce)
|
||||
s.server.BroadcastRaviente(pkt.IPAddress, pkt.Port, pkt.StageID)
|
||||
s.server.BroadcastRaviente(pkt.IPAddress, pkt.Port, pkt.StageID, pkt.Type)
|
||||
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
}
|
||||
|
||||
|
||||
@@ -64,17 +64,22 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
|
||||
}
|
||||
|
||||
// Parse out the real casted binary payload
|
||||
var realPayload []byte
|
||||
var msgBinTargeted *binpacket.MsgBinTargeted
|
||||
var authorLen, msgLen uint16
|
||||
var msg []byte
|
||||
|
||||
isDiceCommand := false
|
||||
tmp.SetLE()
|
||||
tmp.Seek(int64(0), 0)
|
||||
_ = tmp.ReadUint32()
|
||||
authorLen := tmp.ReadUint16()
|
||||
msgLen := tmp.ReadUint16()
|
||||
msg := tmp.ReadNullTerminatedBytes()
|
||||
if pkt.MessageType == BinaryMessageTypeChat {
|
||||
tmp.SetLE()
|
||||
tmp.Seek(int64(0), 0)
|
||||
_ = tmp.ReadUint32()
|
||||
authorLen = tmp.ReadUint16()
|
||||
msgLen = tmp.ReadUint16()
|
||||
msg = tmp.ReadNullTerminatedBytes()
|
||||
}
|
||||
|
||||
// Customise payload
|
||||
realPayload := pkt.RawDataPayload
|
||||
if pkt.BroadcastType == BroadcastTypeTargeted {
|
||||
tmp.SetBE()
|
||||
tmp.Seek(int64(0), 0)
|
||||
@@ -85,21 +90,21 @@ func handleMsgSysCastBinary(s *Session, p mhfpacket.MHFPacket) {
|
||||
return
|
||||
}
|
||||
realPayload = msgBinTargeted.RawDataPayload
|
||||
} else if msgLen == 6 && string(msg) == "@dice" {
|
||||
isDiceCommand = true
|
||||
roll := byteframe.NewByteFrame()
|
||||
roll.WriteInt16(1) // Unk
|
||||
roll.SetLE()
|
||||
roll.WriteUint16(4) // Unk
|
||||
roll.WriteUint16(authorLen)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
dice := fmt.Sprintf("%d", rand.Intn(100)+1)
|
||||
roll.WriteUint16(uint16(len(dice)+1))
|
||||
roll.WriteNullTerminatedBytes([]byte(dice))
|
||||
roll.WriteNullTerminatedBytes(tmp.ReadNullTerminatedBytes())
|
||||
realPayload = roll.Data()
|
||||
} else {
|
||||
realPayload = pkt.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)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
dice := fmt.Sprintf("%d", rand.Intn(100)+1)
|
||||
roll.WriteUint16(uint16(len(dice)+1))
|
||||
roll.WriteNullTerminatedBytes([]byte(dice))
|
||||
roll.WriteNullTerminatedBytes(tmp.ReadNullTerminatedBytes())
|
||||
realPayload = roll.Data()
|
||||
}
|
||||
}
|
||||
|
||||
// Make the response to forward to the other client(s).
|
||||
|
||||
@@ -409,4 +409,7 @@ func handleMsgMhfPostBoostTimeLimit(s *Session, p mhfpacket.MHFPacket) {}
|
||||
|
||||
func handleMsgMhfGetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {}
|
||||
|
||||
func handleMsgMhfSetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {}
|
||||
func handleMsgMhfSetRestrictionEvent(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgMhfSetRestrictionEvent)
|
||||
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/Andoryuuta/byteframe"
|
||||
"erupe-ce/config"
|
||||
@@ -309,15 +308,25 @@ func (s *Server) BroadcastChatMessage(message string) {
|
||||
}, nil)
|
||||
}
|
||||
|
||||
func (s *Server) BroadcastRaviente(ip uint32, port uint16, stage []byte) {
|
||||
func (s *Server) BroadcastRaviente(ip uint32, port uint16, stage []byte, _type uint8) {
|
||||
bf := byteframe.NewByteFrame()
|
||||
bf.SetLE()
|
||||
bf.WriteUint16(0) // Unk
|
||||
bf.WriteUint16(0x43) // Data len
|
||||
bf.WriteUint16(3) // Unk len
|
||||
bf.WriteUint16(0x29) // String len
|
||||
d, _ := hex.DecodeString("3C91E593A294B0814696D28BB68AFA81798BC9817A3E82AA8A4A8DC382B382EA82DC82B582BD814900")
|
||||
bf.WriteBytes(d)
|
||||
var d []byte
|
||||
switch _type {
|
||||
case 2:
|
||||
d = []byte("<Great Slaying: Berserk> is being held!")
|
||||
case 4:
|
||||
d = []byte("<Great Slaying: Extreme> is being held!")
|
||||
case 5:
|
||||
d = []byte("<Great Slaying: Berserk Practice> is being held!")
|
||||
default:
|
||||
s.logger.Error("Unk raviente type", zap.Uint8("_type", _type))
|
||||
}
|
||||
bf.WriteUint16(uint16(len(d)+1))
|
||||
bf.WriteNullTerminatedBytes(d)
|
||||
bf.WriteBytes([]byte{0x5F, 0x53, 0x00})
|
||||
bf.WriteUint32(ip) // IP address
|
||||
bf.WriteUint16(port) // Port
|
||||
|
||||
Reference in New Issue
Block a user