|
@@ -1,14 +1,15 @@
|
|
|
package main
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "log"
|
|
|
|
|
"battlecamp-go-server/games"
|
|
"battlecamp-go-server/games"
|
|
|
"battlecamp-go-server/player"
|
|
"battlecamp-go-server/player"
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "log"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
+ "github.com/go-stomp/stomp"
|
|
|
"github.com/julienschmidt/httprouter"
|
|
"github.com/julienschmidt/httprouter"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -85,6 +86,10 @@ 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)
|
|
|
|
|
+
|
|
|
log.Printf("Player %v joined game %v", p.Id, game.Id)
|
|
log.Printf("Player %v joined game %v", p.Id, game.Id)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -121,14 +126,13 @@ func movePlayer(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
p := g.GetPlayer(playerId)
|
|
p := g.GetPlayer(playerId)
|
|
|
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, stompConnection)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if !result {
|
|
if !result {
|
|
|
http.Error(w, "Bad request", http.StatusBadRequest)
|
|
http.Error(w, "Bad request", http.StatusBadRequest)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
e := json.NewEncoder(w)
|
|
e := json.NewEncoder(w)
|
|
|
e.Encode(p.Pos)
|
|
e.Encode(p.Pos)
|
|
|
log.Printf("Player %v moved in direction %v\n", p.Id, direction)
|
|
log.Printf("Player %v moved in direction %v\n", p.Id, direction)
|