route mt updates to frontend
This commit is contained in:
parent
40c9386fdd
commit
4231be5e12
@ -39,8 +39,6 @@ function send_stats()
|
|||||||
table.insert(data.players, info)
|
table.insert(data.players, info)
|
||||||
end
|
end
|
||||||
|
|
||||||
print(minetest.write_json(data)) --XXX
|
|
||||||
|
|
||||||
http.fetch({
|
http.fetch({
|
||||||
url = url .. "/api/minetest",
|
url = url .. "/api/minetest",
|
||||||
extra_headers = { "Content-Type: application/json", "Authorization: " .. key },
|
extra_headers = { "Content-Type: application/json", "Authorization: " .. key },
|
||||||
|
@ -25,7 +25,7 @@ WebSocketChannel.prototype.connect = function(){
|
|||||||
|
|
||||||
var listeners = self.listenerMap[event.type];
|
var listeners = self.listenerMap[event.type];
|
||||||
if (listeners){
|
if (listeners){
|
||||||
self.listeners.forEach(function(listener){
|
listeners.forEach(function(listener){
|
||||||
listener(event.data);
|
listener(event.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@ api.getConfig().then(function(cfg){
|
|||||||
var wsChannel = new WebSocketChannel();
|
var wsChannel = new WebSocketChannel();
|
||||||
wsChannel.connect();
|
wsChannel.connect();
|
||||||
|
|
||||||
|
wsChannel.addListener("minetest-info", function(e){
|
||||||
|
console.log(e);
|
||||||
|
});
|
||||||
|
|
||||||
var rtTiles = new RealtimeTileLayer(wsChannel);
|
var rtTiles = new RealtimeTileLayer(wsChannel);
|
||||||
|
|
||||||
var initialZoom = 11;
|
var initialZoom = 11;
|
||||||
|
@ -4,8 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"mapserver/app"
|
"mapserver/app"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PlayerPos struct {
|
type PlayerPos struct {
|
||||||
@ -33,19 +31,25 @@ type Minetest struct {
|
|||||||
ctx *app.App
|
ctx *app.App
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Minetest) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
func (this *Minetest) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
if req.Header.Get("Authorization") != this.ctx.Config.WebApi.SecretKey {
|
||||||
|
resp.WriteHeader(403)
|
||||||
|
resp.Write([]byte("invalid key!"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
resp.Header().Add("content-type", "application/json")
|
resp.Header().Add("content-type", "application/json")
|
||||||
data := &MinetestInfo{}
|
data := &MinetestInfo{}
|
||||||
|
|
||||||
err := json.NewDecoder(req.Body).Decode(data)
|
err := json.NewDecoder(req.Body).Decode(data)
|
||||||
logrus.Info(data)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.WriteHeader(500)
|
resp.WriteHeader(500)
|
||||||
resp.Write([]byte(err.Error()))
|
resp.Write([]byte(err.Error()))
|
||||||
logrus.Warn(err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.ctx.WebEventbus.Emit("minetest-info", data)
|
||||||
|
|
||||||
json.NewEncoder(resp).Encode("stub")
|
json.NewEncoder(resp).Encode("stub")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user