diff --git a/handlers/elements.go b/handlers/elements.go index 061edbf..d450e68 100644 --- a/handlers/elements.go +++ b/handlers/elements.go @@ -42,8 +42,9 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { return } fi, err := getFullInfoByCtx(ctx) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } if err := validateMove(fi, models.UserRoleGuesser); err != nil { @@ -206,8 +207,9 @@ func HandleMarkCard(w http.ResponseWriter, r *http.Request) { return } fi, err := getFullInfoByCtx(ctx) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } if err := validateMove(fi, models.UserRoleGuesser); err != nil { @@ -274,8 +276,9 @@ func HandleMarkCard(w http.ResponseWriter, r *http.Request) { func HandleActionHistory(w http.ResponseWriter, r *http.Request) { fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } tmpl, err := template.ParseGlob("components/*.html") @@ -293,8 +296,9 @@ func HandleAddBot(w http.ResponseWriter, r *http.Request) { team := r.URL.Query().Get("team") role := r.URL.Query().Get("role") fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } var botname string @@ -319,8 +323,9 @@ func HandleRemoveBot(w http.ResponseWriter, r *http.Request) { botName := r.URL.Query().Get("bot") log.Debug("got remove-bot request", "bot_name", botName) fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } if err := llmapi.RemoveBot(botName, fi.Room); err != nil { diff --git a/handlers/game.go b/handlers/game.go index 11a286c..a34e657 100644 --- a/handlers/game.go +++ b/handlers/game.go @@ -72,8 +72,9 @@ func HandleJoinTeam(w http.ResponseWriter, r *http.Request) { } // get username fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } if fi.Room == nil { @@ -111,8 +112,9 @@ func HandleJoinTeam(w http.ResponseWriter, r *http.Request) { func HandleEndTurn(w http.ResponseWriter, r *http.Request) { // get username fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } // check if one who pressed it is from the team who has the turn @@ -143,8 +145,9 @@ func HandleEndTurn(w http.ResponseWriter, r *http.Request) { func HandleStartGame(w http.ResponseWriter, r *http.Request) { fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } // check if enough players @@ -293,8 +296,9 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) { clue := r.PostFormValue("clue") num := r.PostFormValue("number") fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } guessLimitU64, err := strconv.ParseUint(num, 10, 8) @@ -360,8 +364,9 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) { func HandleRenotifyBot(w http.ResponseWriter, r *http.Request) { fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } notifyBotIfNeeded(fi.Room) diff --git a/handlers/handlers.go b/handlers/handlers.go index 20b9398..f7b56c0 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -75,8 +75,9 @@ func HandleExit(w http.ResponseWriter, r *http.Request) { return } fi, err := getFullInfoByCtx(r.Context()) - if err != nil { - abortWithError(w, err.Error()) + if err != nil || fi == nil { + log.Error("failed to fetch fi", "error", err) + http.Redirect(w, r, "/", 302) return } if fi.Room.IsRunning { diff --git a/todos.md b/todos.md index 3f1fb02..e725224 100644 --- a/todos.md +++ b/todos.md @@ -21,8 +21,8 @@ - redo card .revealed use: it should mean that card is revealed for everybody, while mime should be able to see cards as is; + - better styles and fluff; - common auth system between sites; -- signup vs login; -- passwords (to room and to login); +- signup vs login; + +- passwords (to room and to login); + === - show in backlog (and with that in prompt to llm) how many cards are left to open, also additional comment: if guess was right; - gameover to backlog; @@ -33,7 +33,7 @@ - possibly turn markings into parts of names of users (first three letters?); + - at game creation list languages and support them at backend; + - sql ping goroutine with reconnect on fail; + -- player stats: played games, lost, won, rating elo, opened opposite words, opened white words, opened black words. +- player stats: played games, lost, won, rating elo, opened opposite words, opened white words, opened black words. + - at the end of the game, all colors should be revealed; - tracing; @@ -91,5 +91,5 @@ - mime sees the clue input out of turn; (eh) - there is a problem of two timers, they both could switch turn, but it is not easy to stop them from llmapi or handlers. + - journal still does not work; + -- lose/win game; then exit room (while being the creator), then press to stats -> cannot find session in db, although cookie in place and session in db; -- exit endpoints delets player from db; +- lose/win game; then exit room (while being the creator), then press to stats -> cannot find session in db, although cookie in place and session in db; + +- exit endpoints delets player from db; +