Fix dangling rooms when multiplaying

This commit is contained in:
Sergey Stepanov 2023-10-18 21:28:37 +03:00
parent a8d47fd1bf
commit 7977bce8a3
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
2 changed files with 3 additions and 2 deletions

View file

@ -162,8 +162,8 @@ func (c *coordinator) HandleGameStart(rq api.StartGameRequest[com.Uid], w *Worke
func (c *coordinator) HandleTerminateSession(rq api.TerminateSessionRequest[com.Uid], w *Worker) {
if user := w.router.FindUser(rq.Id); user != nil {
w.router.Remove(user)
c.log.Debug().Msgf(">>> users: %v", w.router.Users())
user.Disconnect()
w.router.SetRoom(nil)
}
}
@ -171,7 +171,7 @@ func (c *coordinator) HandleTerminateSession(rq api.TerminateSessionRequest[com.
func (c *coordinator) HandleQuitGame(rq api.GameQuitRequest[com.Uid], w *Worker) {
if user := w.router.FindUser(rq.Id); user != nil {
w.router.Remove(user)
w.router.SetRoom(nil)
c.log.Debug().Msgf(">>> users: %v", w.router.Users())
}
}

View file

@ -119,6 +119,7 @@ func (r *Router[T]) FindRoom(id string) *Room[T] {
func (r *Router[T]) Remove(user T) {
if left := r.users.RemoveL(user); left == 0 {
r.Close()
r.SetRoom(nil)
}
}