|
@@ -3,12 +3,12 @@ package main
|
|
|
import (
|
|
import (
|
|
|
"battlecamp-go-server/games"
|
|
"battlecamp-go-server/games"
|
|
|
"battlecamp-go-server/player"
|
|
"battlecamp-go-server/player"
|
|
|
|
|
+ "battlecamp-go-server/stomp"
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"log"
|
|
"log"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
-
|
|
|
|
|
- "github.com/go-stomp/stomp"
|
|
|
|
|
|
|
+
|
|
|
"github.com/julienschmidt/httprouter"
|
|
"github.com/julienschmidt/httprouter"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -65,9 +65,9 @@ func createGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
if xString != "" && yString != "" {
|
|
if xString != "" && yString != "" {
|
|
|
x, _ := strconv.Atoi(xString)
|
|
x, _ := strconv.Atoi(xString)
|
|
|
y, _ := strconv.Atoi(yString)
|
|
y, _ := strconv.Atoi(yString)
|
|
|
- game = currentGames.AddGame(x, y, stompConnection)
|
|
|
|
|
|
|
+ game = currentGames.AddGame(x, y)
|
|
|
} else {
|
|
} else {
|
|
|
- game = currentGames.AddGame(56, 35, stompConnection)
|
|
|
|
|
|
|
+ game = currentGames.AddGame(56, 35)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
w.WriteHeader(http.StatusCreated)
|
|
@@ -89,8 +89,7 @@ func joinGame(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
e := json.NewEncoder(w)
|
|
e := json.NewEncoder(w)
|
|
|
e.Encode(&p)
|
|
e.Encode(&p)
|
|
|
|
|
|
|
|
- b, _ := json.Marshal(p)
|
|
|
|
|
- stompConnection.Send("/topic/go-battlecamp.update", "application/json;charset=utf-8", b, stomp.SendOpt.NoContentLength)
|
|
|
|
|
|
|
+ stomp.SendJson("update", p)
|
|
|
|
|
|
|
|
log.Printf("Player %v joined game %v", p.Id, game.Id)
|
|
log.Printf("Player %v joined game %v", p.Id, game.Id)
|
|
|
}
|
|
}
|
|
@@ -129,7 +128,7 @@ func movePlayer(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
direction := ps.ByName("direction")
|
|
direction := ps.ByName("direction")
|
|
|
|
|
|
|
|
- result := g.Move(p, direction, stompConnection)
|
|
|
|
|
|
|
+ result := g.Move(p, direction)
|
|
|
|
|
|
|
|
if !result {
|
|
if !result {
|
|
|
http.Error(w, "Bad request", http.StatusBadRequest)
|
|
http.Error(w, "Bad request", http.StatusBadRequest)
|