Harry de Boer 10 vuotta sitten
vanhempi
commit
5aac0f8c5e
1 muutettua tiedostoa jossa 7 lisäystä ja 18 poistoa
  1. 7 18
      battlecamp-go-gameserver/gameserver/urlrouter.go

+ 7 - 18
battlecamp-go-gameserver/gameserver/urlrouter.go

@@ -15,21 +15,23 @@ import (
 
 var gameServer *GameServer
 
+// api is documented at: https://wiki.summercamp.local/display/PIN/Pinguin+server+API
 func newUrlRouter(gs *GameServer) *httprouter.Router {
 	gameServer = gs
 
 	router := httprouter.New()
 	router.GET("/", showIndex)
 	router.GET("/games", listGames)
+	router.GET("/games/:gameid", showGame)
+	router.GET("/games/:gameid/board", showBoard)
+	router.GET("/games/:gameid/asciiboard", showAsciiBoard)
+	router.GET("/games/:gameid/players", listPlayers)
+	router.GET("/games/:gameid/players/:playerid", showPlayer)
 	router.PUT("/games", createGame)
 	router.PUT("/games/:rows/:cols", createGame)
-	router.POST("/games/:gameid/join", joinGame) // API says PUT... zuch.
-	router.GET("/games/:gameid", showGame)
-	router.GET("/games/:gameid/:boardid", proxyHandler)
-	router.GET("/games/:gameid/:boardid/:playerid", showPlayer)
+	router.POST("/games/:gameid/join", joinGame)
 	router.POST("/games/:gameid/move/:playerid/:direction", movePlayer)
 	router.GET("/debug/profiledump", profileDump)
-
 	return router
 }
 
@@ -38,19 +40,6 @@ func showIndex(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
 	w.Write([]byte("Go battlecamp!"))
 }
 
-func proxyHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
-
-	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)
-	} else {
-		listPlayers(w, r, ps)
-	}
-}
-
 func listGames(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
 	e := json.NewEncoder(w)
 	e.Encode(gameServer.ListGames())