Example #1
0
func deregisterPlayer(w http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	name := req.FormValue("id")
	if name == "" {
		http.Error(w, `{"error": "No id provided!"}`, http.StatusBadRequest)
		return
	}
	id, err := room.IdFromString(name)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	sim.RemovePlayer(id)
}
Example #2
0
func collidePlayer(w http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	id := req.FormValue("id")
	if id == "" {
		http.Error(w, `{"error": "No id provided!"}`, http.StatusBadRequest)
		return
	}

	var c room.Collision
	c.Id, err = room.IdFromString(id)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	data := req.FormValue("data")
	if data != "" {
		err := unwrap(data, &c.Collision)
		if err != nil {
			http.Error(w, `{"error": "Bad data!"}`, http.StatusBadRequest)
		}
	}

	c.ServerTime = time.Now()

	r, hit, err := sim.Collision(c)
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}

	fmt.Fprintf(w, `{"role": "%s", "hit": "%s"}`, r, hit)
}