Enha: avoid nil panics
This commit is contained in:
		| @@ -42,8 +42,9 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	fi, err := getFullInfoByCtx(ctx) | 	fi, err := getFullInfoByCtx(ctx) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	if err := validateMove(fi, models.UserRoleGuesser); err != nil { | 	if err := validateMove(fi, models.UserRoleGuesser); err != nil { | ||||||
| @@ -206,8 +207,9 @@ func HandleMarkCard(w http.ResponseWriter, r *http.Request) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	fi, err := getFullInfoByCtx(ctx) | 	fi, err := getFullInfoByCtx(ctx) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	if err := validateMove(fi, models.UserRoleGuesser); err != nil { | 	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) { | func HandleActionHistory(w http.ResponseWriter, r *http.Request) { | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	tmpl, err := template.ParseGlob("components/*.html") | 	tmpl, err := template.ParseGlob("components/*.html") | ||||||
| @@ -293,8 +296,9 @@ func HandleAddBot(w http.ResponseWriter, r *http.Request) { | |||||||
| 	team := r.URL.Query().Get("team") | 	team := r.URL.Query().Get("team") | ||||||
| 	role := r.URL.Query().Get("role") | 	role := r.URL.Query().Get("role") | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	var botname string | 	var botname string | ||||||
| @@ -319,8 +323,9 @@ func HandleRemoveBot(w http.ResponseWriter, r *http.Request) { | |||||||
| 	botName := r.URL.Query().Get("bot") | 	botName := r.URL.Query().Get("bot") | ||||||
| 	log.Debug("got remove-bot request", "bot_name", botName) | 	log.Debug("got remove-bot request", "bot_name", botName) | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	if err := llmapi.RemoveBot(botName, fi.Room); err != nil { | 	if err := llmapi.RemoveBot(botName, fi.Room); err != nil { | ||||||
|   | |||||||
| @@ -72,8 +72,9 @@ func HandleJoinTeam(w http.ResponseWriter, r *http.Request) { | |||||||
| 	} | 	} | ||||||
| 	// get username | 	// get username | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	if fi.Room == nil { | 	if fi.Room == nil { | ||||||
| @@ -111,8 +112,9 @@ func HandleJoinTeam(w http.ResponseWriter, r *http.Request) { | |||||||
| func HandleEndTurn(w http.ResponseWriter, r *http.Request) { | func HandleEndTurn(w http.ResponseWriter, r *http.Request) { | ||||||
| 	// get username | 	// get username | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	// check if one who pressed it is from the team who has the turn | 	// 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) { | func HandleStartGame(w http.ResponseWriter, r *http.Request) { | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	// check if enough players | 	// check if enough players | ||||||
| @@ -293,8 +296,9 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) { | |||||||
| 	clue := r.PostFormValue("clue") | 	clue := r.PostFormValue("clue") | ||||||
| 	num := r.PostFormValue("number") | 	num := r.PostFormValue("number") | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	guessLimitU64, err := strconv.ParseUint(num, 10, 8) | 	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) { | func HandleRenotifyBot(w http.ResponseWriter, r *http.Request) { | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	notifyBotIfNeeded(fi.Room) | 	notifyBotIfNeeded(fi.Room) | ||||||
|   | |||||||
| @@ -75,8 +75,9 @@ func HandleExit(w http.ResponseWriter, r *http.Request) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	fi, err := getFullInfoByCtx(r.Context()) | 	fi, err := getFullInfoByCtx(r.Context()) | ||||||
| 	if err != nil { | 	if err != nil || fi == nil { | ||||||
| 		abortWithError(w, err.Error()) | 		log.Error("failed to fetch fi", "error", err) | ||||||
|  | 		http.Redirect(w, r, "/", 302) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	if fi.Room.IsRunning { | 	if fi.Room.IsRunning { | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								todos.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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; + | - 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; | - better styles and fluff; | ||||||
| - common auth system between sites; | - common auth system between sites; | ||||||
| - signup vs login; | - signup vs login; + | ||||||
| - passwords (to room and to 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; | - 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; | - gameover to backlog; | ||||||
| @@ -33,7 +33,7 @@ | |||||||
| - possibly turn markings into parts of names of users (first three letters?); + | - possibly turn markings into parts of names of users (first three letters?); + | ||||||
| - at game creation list languages and support them at backend; + | - at game creation list languages and support them at backend; + | ||||||
| - sql ping goroutine with reconnect on fail; + | - 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; | - at the end of the game, all colors should be revealed; | ||||||
| - tracing; | - tracing; | ||||||
|  |  | ||||||
| @@ -91,5 +91,5 @@ | |||||||
| - mime sees the clue input out of turn; (eh) | - 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. + | - 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; + | - 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; | - 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; | - exit endpoints delets player from db; + | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder