knowyt/server/src/application/syncHandler.go

29 lines
558 B
Go

package application
import (
"fmt"
"net/http"
"sirlab.de/go/knyt/user"
)
func (app *Application) SyncHandler(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.IsAdmin() {
w.WriteHeader(http.StatusForbidden)
fmt.Fprintf(w, "forbidden")
return
}
gm.UpdatePlayerTimestamp(usr)
eng := gm.GetEngine()
eng.SyncHandler(w, r)
}