|
|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
import (
|
|
|
"battlecamp-go-server/games"
|
|
|
+ "battlecamp-go-server/player"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"net/http"
|
|
|
@@ -70,7 +71,16 @@ func createGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
}
|
|
|
|
|
|
func joinGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
- http.Error(w, "joinGame not implemented", http.StatusNotImplemented)
|
|
|
+ w.Header().Set("Content-Type", "application/json")
|
|
|
+ idString := ps.ByName("gameid")
|
|
|
+ gameId, _ := strconv.ParseInt(idString, 10, 64)
|
|
|
+ var player player.Player
|
|
|
+ d := json.NewDecoder(r.Body)
|
|
|
+ d.Decode(&player)
|
|
|
+ game := currentGames.GetGame(gameId)
|
|
|
+ game.Join(&player)
|
|
|
+ e := json.NewEncoder(w)
|
|
|
+ e.Encode(&player)
|
|
|
}
|
|
|
|
|
|
func showGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
@@ -81,7 +91,11 @@ func showGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
}
|
|
|
|
|
|
func listPlayers(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
- http.Error(w, "listPlayers not implemented", http.StatusNotImplemented)
|
|
|
+ w.Header().Set("Content-Type", "application/json")
|
|
|
+ idString := ps.ByName("gameid")
|
|
|
+ gameId, _ := strconv.ParseInt(idString, 10, 64)
|
|
|
+ e := json.NewEncoder(w)
|
|
|
+ e.Encode(currentGames.GetGame(gameId).Players)
|
|
|
}
|
|
|
|
|
|
func showPlayer(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
@@ -89,7 +103,6 @@ func showPlayer(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
}
|
|
|
|
|
|
func movePlayer(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
-
|
|
|
http.Error(w, "movePlayer not implemented", http.StatusNotImplemented)
|
|
|
}
|
|
|
|