From 5f582081406389048ba46282603623ca7fe6cc22 Mon Sep 17 00:00:00 2001 From: Settel Date: Wed, 16 Mar 2022 09:16:40 +0100 Subject: [PATCH] feat: output game id with every log message --- server/src/application/savePlayer.go | 8 ++++++++ server/src/engine/publish.go | 2 +- server/src/game/changeGameState.go | 6 +++--- server/src/game/finishGame.go | 2 +- server/src/game/player.go | 6 +++--- server/src/game/populateGetRoundInfo.go | 2 +- server/src/game/revealShowCount.go | 2 +- server/src/game/runFinal.go | 2 +- server/src/game/runRound.go | 2 +- server/src/game/saveSelection.go | 2 +- server/src/handler/private.go | 1 - 11 files changed, 21 insertions(+), 14 deletions(-) diff --git a/server/src/application/savePlayer.go b/server/src/application/savePlayer.go index 4c089fd..8a71c7f 100644 --- a/server/src/application/savePlayer.go +++ b/server/src/application/savePlayer.go @@ -52,6 +52,10 @@ func (app *Application) SavePlayer(usr *user.User, w http.ResponseWriter, r *htt } func (app *Application) modifyUser(id string, gm *game.Game, name, authcode string) error { + if usr, err := app.GetUserByAuthcode(authcode); err == nil && usr.GetId() != id { + return fmt.Errorf("authcode already in use") + } + modifyUser := app.users[id] if modifyUser.GetId() != id || modifyUser.GetGameId() != gm.GetId() { return fmt.Errorf("couldn't find player %s in game %s", id, gm.GetId()) @@ -66,6 +70,10 @@ func (app *Application) modifyUser(id string, gm *game.Game, name, authcode stri } func (app *Application) createUser(gm *game.Game, name, authcode string) error { + if _, err := app.GetUserByAuthcode(authcode); err == nil { + return fmt.Errorf("authcode already in use") + } + dirName := path.Join(app.config.DataDir, "users") userNewUuid := uuid.NewString() fileName := path.Join(dirName, userNewUuid+".json") diff --git a/server/src/engine/publish.go b/server/src/engine/publish.go index 1120ca1..6d14179 100644 --- a/server/src/engine/publish.go +++ b/server/src/engine/publish.go @@ -18,6 +18,6 @@ func (eng *Engine) publish(populateSyncDataCb PopulateSyncDataCb) { populateSyncDataCb(&data) } - fmt.Printf("engine versionRef %d\n", eng.versionRef) + fmt.Printf("%s engine versionRef %d\n", data.GameInfo.GameId, eng.versionRef) eng.obs.Update(data) } diff --git a/server/src/game/changeGameState.go b/server/src/game/changeGameState.go index 4fb4341..f1dc9bc 100644 --- a/server/src/game/changeGameState.go +++ b/server/src/game/changeGameState.go @@ -9,7 +9,7 @@ func (gm *Game) changeGameState(expectedState, newState, newPhase string) error defer gm.mu.Unlock() if expectedState != STATE_ANY && gm.state != expectedState { - return fmt.Errorf("game state \"%s\" != expected state \"%s\"", gm.state, expectedState) + return fmt.Errorf("%s game state \"%s\" != expected state \"%s\"", gm.id, gm.state, expectedState) } gm.state = newState gm.phase = newPhase @@ -22,10 +22,10 @@ func (gm *Game) changeGamePhase(expectedState, expectedPhase, newPhase string) e defer gm.mu.Unlock() if expectedState != STATE_ANY && gm.state != expectedState { - return fmt.Errorf("game state \"%s\" != expected state \"%s\"", gm.state, expectedState) + return fmt.Errorf("%s game state \"%s\" != expected state \"%s\"", gm.id, gm.state, expectedState) } if gm.phase != expectedPhase { - return fmt.Errorf("game phase \"%s\" != expected phase \"%s\"", gm.phase, expectedPhase) + return fmt.Errorf("%s game phase \"%s\" != expected phase \"%s\"", gm.id, gm.phase, expectedPhase) } gm.phase = newPhase diff --git a/server/src/game/finishGame.go b/server/src/game/finishGame.go index dbbce27..49b0409 100644 --- a/server/src/game/finishGame.go +++ b/server/src/game/finishGame.go @@ -7,7 +7,7 @@ import ( func (gm *Game) FinishGame() { state, _ := gm.GetState() if state != STATE_IDLE && state != STATE_PLAY { - fmt.Printf("invalid state, can't finish game in %s state\n", state) + fmt.Printf("%s invalid state, can't finish game in %s state\n", gm.id, state) return } diff --git a/server/src/game/player.go b/server/src/game/player.go index f3d5de3..78ae8b6 100644 --- a/server/src/game/player.go +++ b/server/src/game/player.go @@ -23,9 +23,9 @@ func (gm *Game) EventPlayerJoins(usr *user.User) { gm.players[usrId] = player if prevPlayer.id != "" { - fmt.Printf("player \"%s\" re-joined\n", gm.players[usrId].name) + fmt.Printf("%s player \"%s\" re-joined\n", gm.id, gm.players[usrId].name) } else { - fmt.Printf("player \"%s\" joined\n", usrName) + fmt.Printf("%s player \"%s\" joined\n", gm.id, usrName) } gm.eng.Update() @@ -44,7 +44,7 @@ func (gm *Game) EventPlayerLeaves(usr *user.User) { player.isIdle = true gm.players[usrId] = player - fmt.Printf("player \"%s\" is idle\n", usr.GetName()) + fmt.Printf("%s player \"%s\" is idle\n", gm.id, usr.GetName()) gm.eng.Update() } diff --git a/server/src/game/populateGetRoundInfo.go b/server/src/game/populateGetRoundInfo.go index 1437a8c..78249f8 100644 --- a/server/src/game/populateGetRoundInfo.go +++ b/server/src/game/populateGetRoundInfo.go @@ -12,7 +12,7 @@ func (gm *Game) populateGetRoundInfo() *syncdata.RoundInfo { quote := gm.quotes[gm.round.quoteId] if quote == nil { - fmt.Printf("fatal error: quote id \"%s\" not found\n", gm.round.quoteId) + fmt.Printf("%s fatal error: quote id \"%s\" not found\n", gm.id, gm.round.quoteId) return nil } diff --git a/server/src/game/revealShowCount.go b/server/src/game/revealShowCount.go index 9c476d9..06157b4 100644 --- a/server/src/game/revealShowCount.go +++ b/server/src/game/revealShowCount.go @@ -6,7 +6,7 @@ import ( func (gm *Game) revealShowCount() { if !gm.allPlayersHaveSelectedAQuote() { - fmt.Println("not all players have selected a quote yet") + fmt.Printf("%s not all players have selected a quote yet\n", gm.GetId()) return } diff --git a/server/src/game/runFinal.go b/server/src/game/runFinal.go index be28935..33869cc 100644 --- a/server/src/game/runFinal.go +++ b/server/src/game/runFinal.go @@ -7,7 +7,7 @@ import ( func (gm *Game) runFinal() { state, _ := gm.GetState() if state != STATE_IDLE && state != STATE_PLAY { - fmt.Println(fmt.Errorf("expected state \"IDLE\" | \"PLAY\" != \"%s\"", state)) + fmt.Printf("%s expected state \"IDLE\" | \"PLAY\" != \"%s\"", gm.GetId(), state) return } diff --git a/server/src/game/runRound.go b/server/src/game/runRound.go index 5f78115..0d37055 100644 --- a/server/src/game/runRound.go +++ b/server/src/game/runRound.go @@ -7,7 +7,7 @@ import ( func (gm *Game) runRound() { state, _ := gm.GetState() if state != STATE_IDLE && state != STATE_PLAY && state != STATE_COLLECT { - fmt.Println(fmt.Errorf("expected state \"IDLE\" | \"PLAY\" | \"COLLECT\" != \"%s\"", state)) + fmt.Printf("%s expected state \"IDLE\" | \"PLAY\" | \"COLLECT\" != \"%s\"", gm.GetId(), state) return } diff --git a/server/src/game/saveSelection.go b/server/src/game/saveSelection.go index 2b2451a..5bc9f12 100644 --- a/server/src/game/saveSelection.go +++ b/server/src/game/saveSelection.go @@ -26,5 +26,5 @@ func (gm *Game) updateSelection(usr *user.User, selection string) { } } - fmt.Printf("invalid selection id \"%s\"\n", selection) + fmt.Printf("%s invalid selection id \"%s\"\n", gm.id, selection) } diff --git a/server/src/handler/private.go b/server/src/handler/private.go index 0bcbe05..d573e66 100644 --- a/server/src/handler/private.go +++ b/server/src/handler/private.go @@ -27,7 +27,6 @@ func (authMux *AuthMux) accessDenied(w http.ResponseWriter, r *http.Request) { func (authMux *AuthMux) getUserFromSession(r *http.Request) (*user.User, error) { authCookie, err := r.Cookie("knowyt-auth") if err != nil { - fmt.Printf("%v\n", err) return nil, fmt.Errorf("invalid cookie") }