forked from MTSR/mapserver
bridge wip
This commit is contained in:
parent
c87027931c
commit
40c9386fdd
@ -23,7 +23,7 @@ function send_stats()
|
|||||||
local data = {
|
local data = {
|
||||||
time = minetest.get_timeofday() * 24000,
|
time = minetest.get_timeofday() * 24000,
|
||||||
uptime = minetest.get_server_uptime(),
|
uptime = minetest.get_server_uptime(),
|
||||||
max_lag = get_max_lag(),
|
max_lag = tonumber(get_max_lag()),
|
||||||
players = {}
|
players = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,11 +36,13 @@ function send_stats()
|
|||||||
velocity = player:get_player_velocity()
|
velocity = player:get_player_velocity()
|
||||||
}
|
}
|
||||||
|
|
||||||
table.insert(data.players, player)
|
table.insert(data.players, info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print(minetest.write_json(data)) --XXX
|
||||||
|
|
||||||
http.fetch({
|
http.fetch({
|
||||||
url = url,
|
url = url .. "/api/minetest",
|
||||||
extra_headers = { "Content-Type: application/json", "Authorization: " .. key },
|
extra_headers = { "Content-Type: application/json", "Authorization: " .. key },
|
||||||
timeout = 1,
|
timeout = 1,
|
||||||
post_data = minetest.write_json(data)
|
post_data = minetest.write_json(data)
|
||||||
|
@ -4,14 +4,48 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"mapserver/app"
|
"mapserver/app"
|
||||||
"net/http"
|
"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 {
|
type Minetest struct {
|
||||||
ctx *app.App
|
ctx *app.App
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Minetest) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
func (t *Minetest) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
resp.Header().Add("content-type", "application/json")
|
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")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user