Terminate completed matches after two minutes when only one client remains connected

This commit is contained in:
Trevor Slocum 2024-10-31 22:01:50 -07:00
parent d7cada8f2f
commit 619204e8b5
2 changed files with 15 additions and 0 deletions

View file

@ -118,6 +118,9 @@ msgstr ""
msgid "Joined match: %s"
msgstr ""
msgid "Left completed match."
msgstr ""
msgid "Match not found."
msgstr ""

View file

@ -332,6 +332,18 @@ func (s *server) handleGames() {
}
}
// Terminate completed matches after two minutes when only one client remains connected.
if !g.terminated() && g.Ended != 0 && g.Winner != 0 && ((g.client1 != nil && g.client2 == nil) || (g.client1 == nil && g.client2 != nil)) && time.Now().Unix()-g.Ended >= 120 {
var clients []*serverClient
g.eachClient(func(client *serverClient) {
clients = append(clients, client)
})
for _, sc := range clients {
sc.sendNotice(gotext.GetD(sc.language, "Left completed match."))
g.removeClient(sc)
}
}
if !g.terminated() {
s.games[i] = g
i++