Feat: turn timer

This commit is contained in:
Grail Finder
2025-07-01 09:00:59 +03:00
parent a51668e321
commit e6177df5d8
7 changed files with 81 additions and 11 deletions

View File

@ -9,6 +9,7 @@ import (
"net/http"
"strconv"
"strings"
"time"
)
func HandleCreateRoom(w http.ResponseWriter, r *http.Request) {
@ -122,6 +123,7 @@ func HandleEndTurn(w http.ResponseWriter, r *http.Request) {
}
fi.Room.ChangeTurn()
fi.Room.MimeDone = false
StopTurnTimer(fi.Room.ID)
if err := saveFullInfo(fi); err != nil {
abortWithError(w, err.Error())
return
@ -132,7 +134,7 @@ func HandleEndTurn(w http.ResponseWriter, r *http.Request) {
abortWithError(w, err.Error())
return
}
notifyBotIfNeeded(fi)
notifyBotIfNeeded(fi.Room)
notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "")
if err := tmpl.ExecuteTemplate(w, "base", fi); err != nil {
log.Error("failed to execute base template", "error", err)
@ -181,7 +183,7 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) {
abortWithError(w, err.Error())
return
}
notifyBotIfNeeded(fi)
notifyBotIfNeeded(fi.Room)
// to update only the room that should be updated
notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "")
// notify(models.NotifyBacklogPrefix+fi.Room.ID, "game started")
@ -283,9 +285,11 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) {
fi.Room.ThisTurnLimit = 9
}
fi.Room.OpenedThisTurn = 0
fi.Room.Settings.TurnSecondsLeft = fi.Room.Settings.RoundTime
StartTurnTimer(fi.Room.ID, time.Duration(fi.Room.Settings.RoundTime)*time.Second)
log.Debug("given clue", "clue", clue, "limit", fi.Room.ThisTurnLimit)
notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num)
notifyBotIfNeeded(fi)
notifyBotIfNeeded(fi.Room)
if err := saveFullInfo(fi); err != nil {
abortWithError(w, err.Error())
return
@ -298,5 +302,5 @@ func HandleRenotifyBot(w http.ResponseWriter, r *http.Request) {
abortWithError(w, err.Error())
return
}
notifyBotIfNeeded(fi)
notifyBotIfNeeded(fi.Room)
}