From 15d1dca106cbc5ecf332bea4aeec4c4e2e6f1b67 Mon Sep 17 00:00:00 2001 From: Settel Date: Fri, 16 Dec 2022 15:48:10 +0100 Subject: [PATCH] feat: remove game --- client/src/components/admin/GameInfoTile.vue | 1 + server/src/application/removePlayer.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/client/src/components/admin/GameInfoTile.vue b/client/src/components/admin/GameInfoTile.vue index 8250599..257d9ef 100644 --- a/client/src/components/admin/GameInfoTile.vue +++ b/client/src/components/admin/GameInfoTile.vue @@ -132,6 +132,7 @@ const removeGame = async (): Promise => { if (confirm('remove game and wipe all of it\'s data?')) { console.log(1) await useEngine().removeGame() + document.location.reload() } } diff --git a/server/src/application/removePlayer.go b/server/src/application/removePlayer.go index 2907894..64923d1 100644 --- a/server/src/application/removePlayer.go +++ b/server/src/application/removePlayer.go @@ -3,6 +3,7 @@ package application import ( "fmt" "net/http" + "path" "sirlab.de/go/knowyt/game" "sirlab.de/go/knowyt/log" @@ -47,6 +48,17 @@ func (app *Application) removePlayerById(id string, gm *game.Game) error { return fmt.Errorf("couldn't find player %s in game %s", id, gm.GetId()) } + quotesInfo := gm.GetQuotesInfoByUser(userToRemove) + for _, quote := range quotesInfo.Quotes { + gameDirName := path.Join(app.config.DataDir, "games", gm.GetId()) + quoteFileNameShort := quote.Id + ".json" + quoteFileName := path.Join(gameDirName, "quotes", quoteFileNameShort) + + if err := gm.RemoveQuote(quoteFileName, userToRemove.GetId(), quote.Id); err != nil { + return err + } + } + if err := userToRemove.RemovePlayer(); err != nil { return err }