feat: remove game (WIP)
This commit is contained in:
parent
13ff778bc8
commit
9821353cfb
@ -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 {
|
||||
return err
|
||||
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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user