Ver código fonte

url param validatie voor showAsciiBoard

Harry de Boer 10 anos atrás
pai
commit
bebaed0ef9
1 arquivos alterados com 17 adições e 1 exclusões
  1. 17 1
      battlecamp-go-gameserver/gameserver/urlrouter.go

+ 17 - 1
battlecamp-go-gameserver/gameserver/urlrouter.go

@@ -157,9 +157,25 @@ func showBoard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
 func showAsciiBoard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
 	w.Header().Set("Content-Type", "text/plain;charset=utf-8")
 
+	xString := req.FormValue("x")
+	yString := req.FormValue("y")
+	widthString := req.FormValue("cols")
+	heightString := req.FormValue("rows")
+
 	id, _ := strconv.ParseInt(ps.ByName("gameid"), 10, 64)
 	b := gameServer.GetGame(id).Board.String()
-	w.Write([]byte(b))
+	
+	if xString != "" && yString != "" && widthString != "" && heightString != "" {
+		x, _ := strconv.Atoi(xString)
+		y, _ := strconv.Atoi(yString)
+		width, _ := strconv.Atoi(widthString)
+		height, _ := strconv.Atoi(heightString)
+		log.Printf("showboard x %v y %v width %v height %v", x, y, width, height)
+	else if xString != "" || yString != "" || widthString != "" || heightString != "" {
+		http.Error(w, "Bad request", http.StatusBadRequest)
+	} else {
+		w.Write([]byte(b))
+	}
 }
 
 func profileDump(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {