2021-08-04 23:42:21 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2021-08-05 13:35:39 +00:00
|
|
|
"sirlab.de/go/knyt/user"
|
2021-08-04 23:42:21 +00:00
|
|
|
)
|
|
|
|
|
2021-08-05 13:35:39 +00:00
|
|
|
func (app *Application) SyncHandler(usr *user.User, w http.ResponseWriter, r *http.Request) {
|
2021-08-04 23:42:21 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-08-08 19:48:15 +00:00
|
|
|
if usr.GetGameId() != gameRef && !usr.IsAdmin() {
|
2021-08-05 14:36:39 +00:00
|
|
|
w.WriteHeader(http.StatusForbidden)
|
|
|
|
fmt.Fprintf(w, "forbidden")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:24:27 +00:00
|
|
|
app.updatePlayerIsConnected(usr)
|
2021-08-04 23:42:21 +00:00
|
|
|
eng := gm.GetEngine()
|
|
|
|
eng.SyncHandler(w, r)
|
2021-08-09 14:24:27 +00:00
|
|
|
app.updatePlayerIsDisconnected(usr)
|
2021-08-04 23:42:21 +00:00
|
|
|
}
|