diff --git a/server/src/application/getGames.go b/server/src/application/getGames.go index 3ebb781..0626bed 100644 --- a/server/src/application/getGames.go +++ b/server/src/application/getGames.go @@ -19,15 +19,28 @@ func (app *Application) GetGames(usr *user.User, w http.ResponseWriter, r *http. return } - app.mu.Lock() - defer app.mu.Unlock() - games := Games{ Games: make(map[string]*game.GameInfoJson), } + app.mu.Lock() for k, gm := range app.games { games.Games[k] = gm.GetGameInfo() } + app.mu.Unlock() + + for k, gameInfo := range games.Games { + for i, _ := range gameInfo.Players { + if playerUser, err := app.GetUserById(gameInfo.Players[i].Id); err != nil { + fmt.Printf("GetUserById() failed: couldn't find player %s\n", gameInfo.Players[i].Id) + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "internal server error") + return + } else { + gameInfo.Players[i].AuthCode = playerUser.GetAuthCode() + } + } + games.Games[k] = gameInfo + } w.Header().Add("Content-Type", "application/json") jsonString, _ := json.Marshal(games) diff --git a/server/src/game/getGameInfo.go b/server/src/game/getGameInfo.go index 273a2ff..4d746e8 100644 --- a/server/src/game/getGameInfo.go +++ b/server/src/game/getGameInfo.go @@ -26,6 +26,7 @@ func (gm *Game) initGameInfoJson() *GameInfoJson { Score: player.score, IsPlaying: player.isPlaying, IsIdle: player.isIdle, + Role: player.role, }) } diff --git a/server/src/game/player.go b/server/src/game/player.go index 78ae8b6..1330c87 100644 --- a/server/src/game/player.go +++ b/server/src/game/player.go @@ -19,6 +19,7 @@ func (gm *Game) EventPlayerJoins(usr *user.User) { isPlaying: true, isIdle: false, score: prevPlayer.score, + role: usr.GetRole(), } gm.players[usrId] = player @@ -66,6 +67,7 @@ func (gm *Game) AddPlayer(usr *user.User) { isPlaying: false, isIdle: true, score: 0, + role: usr.GetRole(), } } diff --git a/server/src/game/struct.go b/server/src/game/struct.go index b876dc6..ea5f3c4 100644 --- a/server/src/game/struct.go +++ b/server/src/game/struct.go @@ -35,6 +35,7 @@ type playerInfo struct { isPlaying bool isIdle bool score int + role string } type Source struct { @@ -88,6 +89,7 @@ type PlayerInfoJson struct { IsIdle bool `json:"isIdle"` NumberOfQuotes int `json:"numQuotes"` AuthCode string `json:"authcode"` + Role string `json:"role"` } type GameInfoJson struct {