mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-15 08:25:09 +01:00
enforce Stage.maxPlayers on MoveStage & BackStage
This commit is contained in:
@@ -148,15 +148,20 @@ func removeSessionFromStage(s *Session) {
|
|||||||
destructEmptySemaphores(s)
|
destructEmptySemaphores(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isStageFull(s *Session, StageID string) bool {
|
||||||
|
if stage, exists := s.server.stages[StageID]; exists {
|
||||||
|
return len(stage.reservedClientSlots)+len(stage.clients) >= int(stage.maxPlayers)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func handleMsgSysEnterStage(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysEnterStage(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgSysEnterStage)
|
pkt := p.(*mhfpacket.MsgSysEnterStage)
|
||||||
|
|
||||||
if stage, exists := s.server.stages[pkt.StageID]; exists {
|
if isStageFull(s, pkt.StageID) {
|
||||||
if len(stage.reservedClientSlots)+len(stage.clients) == int(stage.maxPlayers) {
|
|
||||||
doAckSimpleFail(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01})
|
doAckSimpleFail(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Push our current stage ID to the movement stack before entering another one.
|
// Push our current stage ID to the movement stack before entering another one.
|
||||||
if s.stage != nil {
|
if s.stage != nil {
|
||||||
@@ -182,6 +187,12 @@ func handleMsgSysBackStage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
backStage = "sl1Ns200p0a0u0"
|
backStage = "sl1Ns200p0a0u0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isStageFull(s, backStage) {
|
||||||
|
s.stageMoveStack.Push(backStage)
|
||||||
|
doAckSimpleFail(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if _, exists := s.stage.reservedClientSlots[s.charID]; exists {
|
if _, exists := s.stage.reservedClientSlots[s.charID]; exists {
|
||||||
delete(s.stage.reservedClientSlots, s.charID)
|
delete(s.stage.reservedClientSlots, s.charID)
|
||||||
}
|
}
|
||||||
@@ -195,6 +206,12 @@ func handleMsgSysBackStage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
|
|
||||||
func handleMsgSysMoveStage(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysMoveStage(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgSysMoveStage)
|
pkt := p.(*mhfpacket.MsgSysMoveStage)
|
||||||
|
|
||||||
|
if isStageFull(s, pkt.StageID) {
|
||||||
|
doAckSimpleFail(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x01})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
doStageTransfer(s, pkt.AckHandle, pkt.StageID)
|
doStageTransfer(s, pkt.AckHandle, pkt.StageID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user