feat: remove game (WIP)
This commit is contained in:
parent
e152d33da0
commit
13ff778bc8
@ -37,11 +37,11 @@ func (app *Application) RemoveGame(usr *user.User, w http.ResponseWriter, r *htt
|
||||
}
|
||||
|
||||
func (app *Application) removeGame(gm *game.Game) error {
|
||||
log.Info("remove game %s\n", gm.GetId())
|
||||
log.Info("game %s: start removing\n", gm.GetId())
|
||||
|
||||
gameInfo := gm.GetGameInfo()
|
||||
for _, player := range gameInfo.Players {
|
||||
log.Info("remove player %s (%s)\n", player.Id, player.Name)
|
||||
log.Info("game %s: removing player %s (%s)\n", gm.GetId(), player.Id, player.Name)
|
||||
|
||||
if err := app.removePlayerById(player.Id, gm); err != nil {
|
||||
return err
|
||||
@ -49,6 +49,13 @@ func (app *Application) removeGame(gm *game.Game) error {
|
||||
}
|
||||
|
||||
gameBaseDir := path.Join(app.config.DataDir, "games", gm.GetId())
|
||||
log.Info("game %s: removing quotes dir\n", gm.GetId())
|
||||
quotesDir := path.Join(gameBaseDir, "quotes")
|
||||
if err := os.Remove(quotesDir); err != nil {
|
||||
log.Error("failed to remove quotes\n")
|
||||
return nil
|
||||
}
|
||||
log.Info("game %s: removing state file", gm.GetId())
|
||||
stateFilename := path.Join(gameBaseDir, "state.json")
|
||||
if err := os.Remove(stateFilename); err != nil {
|
||||
return err
|
||||
@ -58,11 +65,16 @@ func (app *Application) removeGame(gm *game.Game) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("game %s: removing game dir", gm.GetId())
|
||||
if err := os.Remove(gameBaseDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
app.mu.Lock()
|
||||
delete(app.games, gm.GetId())
|
||||
app.mu.Unlock()
|
||||
|
||||
log.Info("game %s done\n", gm.GetId())
|
||||
log.Info("game %s removed\n", gm.GetId())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user