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,17 +191,15 @@ func logoutPlayer(s *Session) {
for _, stage := range s.server.stages {
// Tell sessions registered to disconnecting players quest to unregister
if stage.hostCharID == s.charID {
if s.stage.id == "sl1Ns200p0a0u0" {
if stage.host.charID == s.charID {
for _, sess := range s.server.sessions {
for rSlot := range stage.reservedClientSlots {
if sess.charID == rSlot {
if sess.charID == rSlot && sess.stage != nil && sess.stage.id == "sl1Ns200p0a0u0" {
sess.QueueSendMHF(&mhfpacket.MsgSysStageDestruct{})
}
}
}
}
}
for session := range stage.clients {
if session.charID == s.charID {
delete(stage.clients, session)

View File

@@ -19,7 +19,7 @@ func handleMsgSysCreateStage(s *Session, p mhfpacket.MHFPacket) {
doAckSimpleFail(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
} else {
stage := NewStage(pkt.StageID)
stage.hostCharID = s.charID
stage.host = s
stage.maxPlayers = uint16(pkt.PlayerCount)
s.server.stages[stage.id] = stage
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]
s.server.Unlock()
stage.Lock()
stage.hostCharID = s.charID
stage.host = s
stage.clients[s] = s.charID
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.
rawBinaryData map[stageBinaryKey][]byte
hostCharID uint32
host *Session
maxPlayers uint16
password string
createdAt string