From 0ee011a010744ab792c88022bf37d011de357dc2 Mon Sep 17 00:00:00 2001 From: wishu Date: Thu, 7 Jul 2022 20:05:44 +1000 Subject: [PATCH] binary cast fixes and support all ravi types --- Erupe/network/mhfpacket/msg_mhf_announce.go | 6 +-- .../msg_mhf_set_restriction_event.go | 19 +++++-- Erupe/server/channelserver/handlers.go | 2 +- .../channelserver/handlers_cast_binary.go | 49 ++++++++++--------- Erupe/server/channelserver/handlers_event.go | 5 +- .../channelserver/sys_channel_server.go | 19 +++++-- 6 files changed, 64 insertions(+), 36 deletions(-) diff --git a/Erupe/network/mhfpacket/msg_mhf_announce.go b/Erupe/network/mhfpacket/msg_mhf_announce.go index a658c3b05..deef66cbb 100644 --- a/Erupe/network/mhfpacket/msg_mhf_announce.go +++ b/Erupe/network/mhfpacket/msg_mhf_announce.go @@ -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 } } diff --git a/Erupe/network/mhfpacket/msg_mhf_set_restriction_event.go b/Erupe/network/mhfpacket/msg_mhf_set_restriction_event.go index 8506cf5e0..3a0e550c7 100644 --- a/Erupe/network/mhfpacket/msg_mhf_set_restriction_event.go +++ b/Erupe/network/mhfpacket/msg_mhf_set_restriction_event.go @@ -1,7 +1,7 @@ package mhfpacket -import ( - "errors" +import ( + "errors" "erupe-ce/network/clientctx" "erupe-ce/network" @@ -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. diff --git a/Erupe/server/channelserver/handlers.go b/Erupe/server/channelserver/handlers.go index 163ec83df..44f69a64a 100644 --- a/Erupe/server/channelserver/handlers.go +++ b/Erupe/server/channelserver/handlers.go @@ -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)) } diff --git a/Erupe/server/channelserver/handlers_cast_binary.go b/Erupe/server/channelserver/handlers_cast_binary.go index 363e15817..9c6a08b6d 100644 --- a/Erupe/server/channelserver/handlers_cast_binary.go +++ b/Erupe/server/channelserver/handlers_cast_binary.go @@ -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). diff --git a/Erupe/server/channelserver/handlers_event.go b/Erupe/server/channelserver/handlers_event.go index 8ee59e81d..c6e08c644 100644 --- a/Erupe/server/channelserver/handlers_event.go +++ b/Erupe/server/channelserver/handlers_event.go @@ -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)) +} diff --git a/Erupe/server/channelserver/sys_channel_server.go b/Erupe/server/channelserver/sys_channel_server.go index c3c82c854..32309e9ba 100644 --- a/Erupe/server/channelserver/sys_channel_server.go +++ b/Erupe/server/channelserver/sys_channel_server.go @@ -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(" is being held!") + case 4: + d = []byte(" is being held!") + case 5: + d = []byte(" 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