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)
|
||||
end
|
||||
|
||||
print(minetest.write_json(data)) --XXX
|
||||
|
||||
http.fetch({
|
||||
url = url .. "/api/minetest",
|
||||
extra_headers = { "Content-Type: application/json", "Authorization: " .. key },
|
||||
|
@ -25,7 +25,7 @@ WebSocketChannel.prototype.connect = function(){
|
||||
|
||||
var listeners = self.listenerMap[event.type];
|
||||
if (listeners){
|
||||
self.listeners.forEach(function(listener){
|
||||
listeners.forEach(function(listener){
|
||||
listener(event.data);
|
||||
});
|
||||
}
|
||||
|
@ -5,6 +5,10 @@ api.getConfig().then(function(cfg){
|
||||
var wsChannel = new WebSocketChannel();
|
||||
wsChannel.connect();
|
||||
|
||||
wsChannel.addListener("minetest-info", function(e){
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
var rtTiles = new RealtimeTileLayer(wsChannel);
|
||||
|
||||
var initialZoom = 11;
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"mapserver/app"
|
||||
"net/http"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type PlayerPos struct {
|
||||
@ -33,19 +31,25 @@ type Minetest struct {
|
||||
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")
|
||||
data := &MinetestInfo{}
|
||||
|
||||
err := json.NewDecoder(req.Body).Decode(data)
|
||||
logrus.Info(data)
|
||||
|
||||
if err != nil {
|
||||
resp.WriteHeader(500)
|
||||
resp.Write([]byte(err.Error()))
|
||||
logrus.Warn(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.ctx.WebEventbus.Emit("minetest-info", data)
|
||||
|
||||
json.NewEncoder(resp).Encode("stub")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user