Przeglądaj źródła

Added http://localhost:8080/games/asciiboard/boardid

Ronald Peterson 10 lat temu
rodzic
commit
9dcb6a8ea5
1 zmienionych plików z 11 dodań i 1 usunięć
  1. 11 1
      main.go

+ 11 - 1
main.go

@@ -37,7 +37,9 @@ func showIndex(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
 
 func proxyHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
 
-	if ps.ByName("gameid") == "board" {
+	if ps.ByName("gameid") == "asciiboard" {
+		showAsciiBoard(w, r, ps)
+	} else if ps.ByName("gameid") == "board" {
 		showBoard(w, r, ps)
 	} else if ps.ByName("boardid") == "join" {
 		joinGame(w, r, ps)
@@ -113,3 +115,11 @@ func showBoard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
 	//rows, _ := strconv.Atoi(req.FormValue("rows"))
 	//cols, _ := strconv.Atoi(req.FormValue("cols"))
 }
+
+func showAsciiBoard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
+	w.Header().Set("Content-Type", "text/plain;charset=utf-8")
+
+	id, _ := strconv.ParseInt(ps.ByName("boardid"), 10, 64)
+	b := currentGames.GetGame(id).Board.String()
+	w.Write([]byte(b))
+}