feat: remove game (WIP)

This commit is contained in:
Settel 2022-12-15 15:20:15 +01:00
parent 13ff778bc8
commit 9821353cfb
2 changed files with 6 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package application
import (
"errors"
"fmt"
"net/http"
"os"
@ -58,14 +59,16 @@ func (app *Application) removeGame(gm *game.Game) error {
log.Info("game %s: removing state file", gm.GetId())
stateFilename := path.Join(gameBaseDir, "state.json")
if err := os.Remove(stateFilename); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return err
}
}
if err := gm.RemoveGame(); err != nil {
return err
}
log.Info("game %s: removing game dir", gm.GetId())
log.Info("game %s: removing game dir\n", gm.GetId())
if err := os.Remove(gameBaseDir); err != nil {
return err
}

View File

@ -44,7 +44,7 @@ func (app *Application) RemovePlayer(usr *user.User, w http.ResponseWriter, r *h
func (app *Application) removePlayerById(id string, gm *game.Game) error {
userToRemove := app.users[id]
if userToRemove.GetId() != id || userToRemove.GetGameId() != gm.GetId() {
return fmt.Errorf("couldn't find player %s in game %s\n", id, gm.GetId())
return fmt.Errorf("couldn't find player %s in game %s", id, gm.GetId())
}
if err := userToRemove.RemovePlayer(); err != nil {