diff --git a/client/src/components/final.vue b/client/src/components/Final.vue similarity index 100% rename from client/src/components/final.vue rename to client/src/components/Final.vue diff --git a/client/src/components/GameControls.vue b/client/src/components/GameControls.vue index 3892a71..0998537 100644 --- a/client/src/components/GameControls.vue +++ b/client/src/components/GameControls.vue @@ -1,8 +1,9 @@ @@ -27,6 +28,9 @@ export default { continueGame() { this.$engine.continueGame() }, + finishGame() { + this.$engine.finishGame() + }, }, } diff --git a/client/src/plugins/engine/finishGame.js b/client/src/plugins/engine/finishGame.js new file mode 100644 index 0000000..f29ca8b --- /dev/null +++ b/client/src/plugins/engine/finishGame.js @@ -0,0 +1,7 @@ +export default async function() { + const { store } = this.context + + await this.callApi('/api/finishGame', { + g: store.state.engine.user?.game, + }) +} diff --git a/client/src/plugins/engine/index.js b/client/src/plugins/engine/index.js index e3c8354..d610042 100644 --- a/client/src/plugins/engine/index.js +++ b/client/src/plugins/engine/index.js @@ -6,6 +6,7 @@ import fetchUserInfo from './fetchUserInfo' import startGame from './startGame' import resetGame from './resetGame' import continueGame from './continueGame' +import finishGame from './finishGame' import parseSyncData from './parseSyncData' import saveSelection from './saveSelection' @@ -24,6 +25,7 @@ export default (context, inject) => { startGame, resetGame, continueGame, + finishGame, parseSyncData, saveSelection, } diff --git a/server/src/application/finishGame.go b/server/src/application/finishGame.go new file mode 100644 index 0000000..151edad --- /dev/null +++ b/server/src/application/finishGame.go @@ -0,0 +1,29 @@ +package application + +import ( + "fmt" + "net/http" + "sirlab.de/go/knyt/user" +) + +func (app *Application) FinishGame(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 + } + + if err := app.saveGame(gm); err != nil { + fmt.Println(err) + } + + gm.FinishGame() +} diff --git a/server/src/game/finishGame.go b/server/src/game/finishGame.go new file mode 100644 index 0000000..8d012b7 --- /dev/null +++ b/server/src/game/finishGame.go @@ -0,0 +1,15 @@ +package game + +import ( + "fmt" +) + +func (gm *Game) FinishGame() { + state, _ := gm.GetState() + if state != STATE_PLAY { + fmt.Printf("invalid state, can't continue game in %s state\n", state) + return + } + + gm.runFinal() +} diff --git a/server/src/game/startGame.go b/server/src/game/startGame.go index 8473238..9b74659 100644 --- a/server/src/game/startGame.go +++ b/server/src/game/startGame.go @@ -6,8 +6,7 @@ import ( func (gm *Game) StartGame() { // go gm.runCountdown() - // go gm.runRound() - go gm.runFinal() + go gm.runRound() } func (gm *Game) ResetGame() { diff --git a/server/src/knyt.go b/server/src/knyt.go index 66dcd2d..365ac16 100644 --- a/server/src/knyt.go +++ b/server/src/knyt.go @@ -26,6 +26,7 @@ func main() { mux.PrivateHandleFunc("/api/startGame", app.StartGame) mux.PrivateHandleFunc("/api/resetGame", app.ResetGame) mux.PrivateHandleFunc("/api/continueGame", app.ContinueGame) + mux.PrivateHandleFunc("/api/finishGame", app.FinishGame) mux.PrivateHandleFunc("/api/saveSelection", app.SaveSelection) // default handler