diff --git a/client/src/components/AdminTile.vue b/client/src/components/AdminTile.vue new file mode 100644 index 0000000..1bf63ba --- /dev/null +++ b/client/src/components/AdminTile.vue @@ -0,0 +1,34 @@ + + + + + diff --git a/client/src/components/Final.vue b/client/src/components/Final.vue index b791539..5cef8b1 100644 --- a/client/src/components/Final.vue +++ b/client/src/components/Final.vue @@ -22,7 +22,7 @@ export default { computed: { title() { - return 'Hall of Fame' + return this.$store.state.game.name }, players() { var players = [...this.$store.state.players.players] diff --git a/client/src/components/GameControls.vue b/client/src/components/GameControls.vue index 116f30a..105f89f 100644 --- a/client/src/components/GameControls.vue +++ b/client/src/components/GameControls.vue @@ -5,6 +5,7 @@ + @@ -35,6 +36,9 @@ export default { finishGame() { this.$engine.finishGame() }, + admin() { + this.$router.push({ path: '/admin' }) + }, }, } diff --git a/client/src/pages/admin.vue b/client/src/pages/admin.vue new file mode 100644 index 0000000..4c1f0d1 --- /dev/null +++ b/client/src/pages/admin.vue @@ -0,0 +1,71 @@ + + + + + diff --git a/client/src/plugins/engine/fetchGameInfo.js b/client/src/plugins/engine/fetchGameInfo.js new file mode 100644 index 0000000..413958b --- /dev/null +++ b/client/src/plugins/engine/fetchGameInfo.js @@ -0,0 +1,13 @@ +export default async function({ g }) { + const { store } = this.context + + try { + const response = await this.callApi('/api/gameinfo', { g }) + store.commit('engine/setGameInfo', response.data) + } catch(e) { + store.commit('engine/setGameInfo', undefined) + return false + } + + return true +} diff --git a/client/src/plugins/engine/index.js b/client/src/plugins/engine/index.js index 1029b65..5db706b 100644 --- a/client/src/plugins/engine/index.js +++ b/client/src/plugins/engine/index.js @@ -3,6 +3,7 @@ import start from './start' import stop from './stop' import fetchUpdate from './fetchUpdate' import fetchUserInfo from './fetchUserInfo' +import fetchGameInfo from './fetchGameInfo' import collectQuotes from './collectQuotes' import startGame from './startGame' import resetGame from './resetGame' @@ -27,6 +28,7 @@ export default (context, inject) => { stop, fetchUpdate, fetchUserInfo, + fetchGameInfo, collectQuotes, getMyQuotes, saveQuote, diff --git a/client/src/store/engine.js b/client/src/store/engine.js index 8db658e..e1491eb 100644 --- a/client/src/store/engine.js +++ b/client/src/store/engine.js @@ -2,6 +2,7 @@ export const state = () => ({ json: {}, version: -1, user: undefined, + gameinfo: undefined, }) export const mutations = { @@ -15,4 +16,7 @@ export const mutations = { setUser(state, user) { state.user = user }, + setGameInfo(state, gameinfo) { + state.gameinfo = gameinfo + }, } diff --git a/client/src/store/game.js b/client/src/store/game.js index dcf9e04..37b27b2 100644 --- a/client/src/store/game.js +++ b/client/src/store/game.js @@ -1,17 +1,20 @@ export const state = () => ({ state: "", phase: "", + name: "", }) export const mutations = { setStateAndPhase(state, game) { if (game) { - const { state: gameState, phase } = game + const { state: gameState, phase, name } = game state.state = gameState state.phase = phase + state.name = name } else { state.state = "" state.phase = "" + state.name = "" } }, } diff --git a/server/src/application/getGameInfo.go b/server/src/application/getGameInfo.go new file mode 100644 index 0000000..a290722 --- /dev/null +++ b/server/src/application/getGameInfo.go @@ -0,0 +1,30 @@ +package application + +import ( + "encoding/json" + "fmt" + "net/http" + "sirlab.de/go/knyt/user" +) + +func (app *Application) GetGameInfo(usr *user.User, w http.ResponseWriter, r *http.Request) { + gameRef := r.URL.Query().Get("g") + gm, err := app.GetGameById(gameRef) + if err != nil { + w.WriteHeader(http.StatusNotFound) + fmt.Fprintf(w, "game not found") + return + } + + if usr.GetGameId() != gameRef || !usr.IsGamemaster() { + w.WriteHeader(http.StatusForbidden) + fmt.Fprintf(w, "forbidden") + return + } + + gameInfo := gm.GetGameInfo() + + w.Header().Add("Content-Type", "application/json") + jsonString, _ := json.Marshal(gameInfo) + fmt.Fprintf(w, string(jsonString)) +} diff --git a/server/src/game/getGameInfo.go b/server/src/game/getGameInfo.go new file mode 100644 index 0000000..7229a79 --- /dev/null +++ b/server/src/game/getGameInfo.go @@ -0,0 +1,13 @@ +package game + +import () + +func (gm *Game) GetGameInfo() *GameInfoJson { + gm.mu.Lock() + defer gm.mu.Unlock() + + gameInfo := GameInfoJson{ + Name: gm.name, + } + return &gameInfo +} diff --git a/server/src/game/populateSyncDataCb.go b/server/src/game/populateSyncDataCb.go index 025f158..1e99580 100644 --- a/server/src/game/populateSyncDataCb.go +++ b/server/src/game/populateSyncDataCb.go @@ -16,6 +16,7 @@ func (gm *Game) populateGameInfo() syncdata.GameInfo { return syncdata.GameInfo{ GameId: gm.id, + Name: gm.name, State: gm.state, Phase: gm.phase, Players: gm.populateGetPlayers(), diff --git a/server/src/game/startGame.go b/server/src/game/startGame.go index 9b74659..3803ca2 100644 --- a/server/src/game/startGame.go +++ b/server/src/game/startGame.go @@ -5,8 +5,8 @@ import ( ) func (gm *Game) StartGame() { - // go gm.runCountdown() - go gm.runRound() + go gm.runCountdown() + // go gm.runRound() } func (gm *Game) ResetGame() { diff --git a/server/src/game/struct.go b/server/src/game/struct.go index 38517e7..e2eb012 100644 --- a/server/src/game/struct.go +++ b/server/src/game/struct.go @@ -70,6 +70,11 @@ type GameJson struct { Name string `json:"name"` } +type GameInfoJson struct { + Name string `json:"name"` + Players map[string]playerInfo `json:"players"` +} + type GameStateJson struct { Scores map[string]int `json:"scores"` QuotesPlayed []string `json:"quotesPlayed"` diff --git a/server/src/knowyt.go b/server/src/knowyt.go index 0e77e7c..4b8b5eb 100644 --- a/server/src/knowyt.go +++ b/server/src/knowyt.go @@ -22,6 +22,7 @@ func main() { mux.PublicHandleFunc("/api/login", mux.Login) mux.PublicHandleFunc("/api/logout", mux.Logout) mux.PrivateHandleFunc("/api/userinfo", mux.GetUserInfo) + mux.PrivateHandleFunc("/api/gameinfo", app.GetGameInfo) mux.PrivateHandleFunc("/api/sync", app.SyncHandler) mux.PrivateHandleFunc("/api/collectQuotes", app.CollectQuotes) mux.PrivateHandleFunc("/api/startGame", app.StartGame) diff --git a/server/src/syncdata/syncdata.go b/server/src/syncdata/syncdata.go index d386d69..91d6f79 100644 --- a/server/src/syncdata/syncdata.go +++ b/server/src/syncdata/syncdata.go @@ -32,6 +32,7 @@ type RoundInfo struct { type GameInfo struct { GameId string `json:"id"` + Name string `json:"name"` State string `json:"state"` Phase string `json:"phase"` Players []PlayerInfo `json:"players"`