|
@@ -2,7 +2,7 @@
|
|
|
package main
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "battlecamp-go-server/board"
|
|
|
|
|
|
|
+ "encoding/json"
|
|
|
"battlecamp-go-server/games"
|
|
"battlecamp-go-server/games"
|
|
|
"log"
|
|
"log"
|
|
|
"net/http"
|
|
"net/http"
|
|
@@ -47,7 +47,9 @@ func proxyHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func listGames(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
func listGames(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
- http.Error(w, "listGames not implemented", http.StatusNotImplemented)
|
|
|
|
|
|
|
+ w.Header().Set("Content-Type", "text/plain;charset=utf-8")
|
|
|
|
|
+ e := json.NewEncoder(w)
|
|
|
|
|
+ e.Encode(currentGames.ListGames())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func createGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
func createGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
@@ -64,6 +66,7 @@ func createGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
currentGames.AddGame(game)
|
|
currentGames.AddGame(game)
|
|
|
|
|
+ w.WriteHeader(http.StatusCreated)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func joinGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
func joinGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
@@ -71,6 +74,9 @@ func joinGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func showGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
func showGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
|
|
+
|
|
|
|
|
+ w.Header().Set("Content-Type", "text/plain;charset=utf-8")
|
|
|
|
|
+
|
|
|
http.Error(w, "showGame not implemented", http.StatusNotImplemented)
|
|
http.Error(w, "showGame not implemented", http.StatusNotImplemented)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -88,7 +94,4 @@ func showBoard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
|
|
//y, _ := strconv.Atoi(req.FormValue("y"))
|
|
//y, _ := strconv.Atoi(req.FormValue("y"))
|
|
|
//rows, _ := strconv.Atoi(req.FormValue("rows"))
|
|
//rows, _ := strconv.Atoi(req.FormValue("rows"))
|
|
|
//cols, _ := strconv.Atoi(req.FormValue("cols"))
|
|
//cols, _ := strconv.Atoi(req.FormValue("cols"))
|
|
|
- b := board.New(56, 35)
|
|
|
|
|
- w.Header().Set("Content-Type", "text/plain;charset=utf-8")
|
|
|
|
|
- b.WriteJSON(w)
|
|
|
|
|
}
|
|
}
|