prevent panic on nil stage

This commit is contained in:
wish
2022-10-24 05:04:28 +11:00
parent a71ad2aa3e
commit ae8741dbd2
3 changed files with 8 additions and 10 deletions

View File

@@ -191,13 +191,11 @@ func logoutPlayer(s *Session) {
for _, stage := range s.server.stages { for _, stage := range s.server.stages {
// Tell sessions registered to disconnecting players quest to unregister // Tell sessions registered to disconnecting players quest to unregister
if stage.hostCharID == s.charID { if stage.host.charID == s.charID {
if s.stage.id == "sl1Ns200p0a0u0" { for _, sess := range s.server.sessions {
for _, sess := range s.server.sessions { for rSlot := range stage.reservedClientSlots {
for rSlot := range stage.reservedClientSlots { if sess.charID == rSlot && sess.stage != nil && sess.stage.id == "sl1Ns200p0a0u0" {
if sess.charID == rSlot { sess.QueueSendMHF(&mhfpacket.MsgSysStageDestruct{})
sess.QueueSendMHF(&mhfpacket.MsgSysStageDestruct{})
}
} }
} }
} }

View File

@@ -19,7 +19,7 @@ func handleMsgSysCreateStage(s *Session, p mhfpacket.MHFPacket) {
doAckSimpleFail(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) doAckSimpleFail(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
} else { } else {
stage := NewStage(pkt.StageID) stage := NewStage(pkt.StageID)
stage.hostCharID = s.charID stage.host = s
stage.maxPlayers = uint16(pkt.PlayerCount) stage.maxPlayers = uint16(pkt.PlayerCount)
s.server.stages[stage.id] = stage s.server.stages[stage.id] = stage
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
@@ -43,7 +43,7 @@ func doStageTransfer(s *Session, ackHandle uint32, stageID string) {
stage = s.server.stages[stageID] stage = s.server.stages[stageID]
s.server.Unlock() s.server.Unlock()
stage.Lock() stage.Lock()
stage.hostCharID = s.charID stage.host = s
stage.clients[s] = s.charID stage.clients[s] = s.charID
stage.Unlock() stage.Unlock()
} }

View File

@@ -46,7 +46,7 @@ type Stage struct {
// other clients expect the server to echo them back in the exact same format. // other clients expect the server to echo them back in the exact same format.
rawBinaryData map[stageBinaryKey][]byte rawBinaryData map[stageBinaryKey][]byte
hostCharID uint32 host *Session
maxPlayers uint16 maxPlayers uint16
password string password string
createdAt string createdAt string