clean out stale matches
This commit is contained in:
parent
351e5eebc6
commit
f5eac37b06
@ -60,6 +60,13 @@ func MatchCleaner(c *Coordinator) {
|
||||
delete(c.Matches, v.ID)
|
||||
v.Watcher <- true
|
||||
}
|
||||
if time.Now().After(v.LastMove.Add(time.Minute * 10)) {
|
||||
log.Println("clearing stale match")
|
||||
v.Game = nil
|
||||
v.Active = false
|
||||
delete(c.Matches, v.ID)
|
||||
v.Watcher <- true
|
||||
}
|
||||
}
|
||||
c.MatchLock.Unlock()
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package coordinator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.saintnet.tech/stryan/snengame/internal/game"
|
||||
"github.com/google/uuid"
|
||||
@ -49,6 +50,7 @@ type Session struct {
|
||||
Game *game.Game
|
||||
Watcher chan bool
|
||||
Broadcasts map[uuid.UUID]chan SessionResp
|
||||
LastMove time.Time
|
||||
}
|
||||
|
||||
func NewSession() *Session {
|
||||
@ -61,6 +63,7 @@ func NewSession() *Session {
|
||||
Game: nil,
|
||||
Watcher: make(chan bool),
|
||||
Broadcasts: make(map[uuid.UUID]chan SessionResp),
|
||||
LastMove: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,6 +105,9 @@ func (s *Session) Play(id uuid.UUID, cmd *game.Command) *game.CommandResult {
|
||||
if s.pMap[id] != cmd.PlayerID {
|
||||
return nil
|
||||
}
|
||||
if cmd.Type != SessionCmdPoll {
|
||||
s.LastMove = time.Now()
|
||||
}
|
||||
res := s.Game.Parse(cmd)
|
||||
return res
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user