1
0
forked from MTSR/mapserver

bridge wip

This commit is contained in:
Thomas Rudin 2019-02-03 13:08:57 +01:00
parent c87027931c
commit 40c9386fdd
2 changed files with 40 additions and 4 deletions

View File

@ -23,7 +23,7 @@ function send_stats()
local data = {
time = minetest.get_timeofday() * 24000,
uptime = minetest.get_server_uptime(),
max_lag = get_max_lag(),
max_lag = tonumber(get_max_lag()),
players = {}
}
@ -36,11 +36,13 @@ function send_stats()
velocity = player:get_player_velocity()
}
table.insert(data.players, player)
table.insert(data.players, info)
end
print(minetest.write_json(data)) --XXX
http.fetch({
url = url,
url = url .. "/api/minetest",
extra_headers = { "Content-Type: application/json", "Authorization: " .. key },
timeout = 1,
post_data = minetest.write_json(data)

View File

@ -4,14 +4,48 @@ import (
"encoding/json"
"mapserver/app"
"net/http"
"github.com/sirupsen/logrus"
)
type PlayerPos struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Z float64 `json:"z"`
}
type Player struct {
Pos PlayerPos `json:"pos"`
Name string `json:"name"`
HP int `json:"hp"`
Breath int `json:"breath"`
//TODO: stamina, skin, etc
}
type MinetestInfo struct {
MaxLag float64 `json:"max_lag"`
Players []Player `json:"players"`
Time float64 `json:"time"`
Uptime float64 `json:"uptime"`
}
type Minetest struct {
ctx *app.App
}
func (t *Minetest) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
resp.Header().Add("content-type", "application/json")
json.NewEncoder(resp).Encode("stub")
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
}
json.NewEncoder(resp).Encode("stub")
}