rewrite EnumerateStage & parse ReserveStage

This commit is contained in:
wish
2023-11-07 16:50:39 +11:00
parent cf8a5da0b2
commit 6ff20858ed
2 changed files with 12 additions and 15 deletions

View File

@@ -3,7 +3,6 @@ package mhfpacket
import (
"errors"
"erupe-ce/common/byteframe"
"erupe-ce/common/bfutil"
"erupe-ce/network"
"erupe-ce/network/clientctx"
)
@@ -24,8 +23,8 @@ func (m *MsgSysReserveStage) Opcode() network.PacketID {
func (m *MsgSysReserveStage) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32()
m.Ready = bf.ReadUint8()
stageIDLength := bf.ReadUint8()
m.StageID = string(bfutil.UpToNull(bf.ReadBytes(uint(stageIDLength))))
_ = bf.ReadUint8() // StageID length
m.StageID = string(bf.ReadNullTerminatedBytes())
return nil
}

View File

@@ -367,9 +367,9 @@ func handleMsgSysEnumerateStage(s *Session, p mhfpacket.MHFPacket) {
defer s.server.stagesLock.RUnlock()
// Build the response
resp := byteframe.NewByteFrame()
bf := byteframe.NewByteFrame()
var joinable int
var joinable uint16
bf.WriteUint16(0)
for sid, stage := range s.server.stages {
stage.RLock()
@@ -377,34 +377,32 @@ func handleMsgSysEnumerateStage(s *Session, p mhfpacket.MHFPacket) {
stage.RUnlock()
continue
}
if !strings.Contains(stage.id, pkt.StagePrefix) {
stage.RUnlock()
continue
}
joinable++
resp.WriteUint16(uint16(len(stage.reservedClientSlots))) // Reserved players.
resp.WriteUint16(0) // Unk
bf.WriteUint16(uint16(len(stage.reservedClientSlots)))
bf.WriteUint16(0) // Unk
if len(stage.clients) > 0 {
bf.WriteUint16(1)
} else {
bf.WriteUint16(0)
}
resp.WriteUint16(stage.maxPlayers) // Max players.
bf.WriteUint16(stage.maxPlayers)
if len(stage.password) > 0 {
// This byte has also been seen as 1
// The quest is also recognised as locked when this is 2
resp.WriteUint8(3)
bf.WriteUint8(2)
} else {
resp.WriteUint8(0)
bf.WriteUint8(0)
}
ps.Uint8(resp, sid, false)
ps.Uint8(bf, sid, false)
stage.RUnlock()
}
bf.WriteUint16(uint16(joinable))
bf.WriteBytes(resp.Data())
bf.Seek(0, 0)
bf.WriteUint16(joinable)
doAckBufSucceed(s, pkt.AckHandle, bf.Data())
}