knowyt/server/src/application/continueGame.go

30 lines
577 B
Go

package application
import (
"fmt"
"net/http"
"sirlab.de/go/knowyt/user"
)
func (app *Application) ContinueGame(usr *user.User, w http.ResponseWriter, r *http.Request) {
gameRef := r.URL.Query().Get("g")
gm, err := app.GetGameById(gameRef)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "game not found")
return
}
if usr.GetGameId() != gameRef || !usr.IsGamemaster() {
w.WriteHeader(http.StatusForbidden)
fmt.Fprintf(w, "forbidden")
return
}
gm.ContinueGame()
if err := app.saveGameState(gm); err != nil {
fmt.Println(err)
}
}