feat: remove game (WIP)
This commit is contained in:
parent
13ff778bc8
commit
9821353cfb
@ -1,6 +1,7 @@
|
|||||||
package application
|
package application
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -58,14 +59,16 @@ func (app *Application) removeGame(gm *game.Game) error {
|
|||||||
log.Info("game %s: removing state file", gm.GetId())
|
log.Info("game %s: removing state file", gm.GetId())
|
||||||
stateFilename := path.Join(gameBaseDir, "state.json")
|
stateFilename := path.Join(gameBaseDir, "state.json")
|
||||||
if err := os.Remove(stateFilename); err != nil {
|
if err := os.Remove(stateFilename); err != nil {
|
||||||
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := gm.RemoveGame(); err != nil {
|
if err := gm.RemoveGame(); err != nil {
|
||||||
return err
|
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 {
|
if err := os.Remove(gameBaseDir); err != nil {
|
||||||
return err
|
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 {
|
func (app *Application) removePlayerById(id string, gm *game.Game) error {
|
||||||
userToRemove := app.users[id]
|
userToRemove := app.users[id]
|
||||||
if userToRemove.GetId() != id || userToRemove.GetGameId() != gm.GetId() {
|
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 {
|
if err := userToRemove.RemovePlayer(); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user