feat: output game id with every log message
This commit is contained in:
parent
c90fabf022
commit
5f58208140
@ -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")
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user