advtrains data
This commit is contained in:
parent
419844e4ec
commit
721a1d7c93
@ -27,9 +27,51 @@ function send_stats()
|
|||||||
players = {}
|
players = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--[[
|
||||||
|
"trains":[
|
||||||
|
{"id":"690096","off_track":false,"pos":{"x":-125,"y":6,"z":-46},"velocity":0},
|
||||||
|
{"id":"973462","off_track":false,"pos":{"x":-125,"y":5,"z":-64},"velocity":0}
|
||||||
|
],
|
||||||
|
"uptime":2.0000000298023224,
|
||||||
|
"wagons":[
|
||||||
|
{"id":"980189","pos_in_train":2,"train_id":"690096","type":"advtrains:subway_wagon"},
|
||||||
|
{"id":"243215","pos_in_train":2.5,"train_id":"973462","type":"advtrains:engine_japan"}
|
||||||
|
]}
|
||||||
|
|
||||||
|
--]]
|
||||||
|
|
||||||
if has_advtrains then
|
if has_advtrains then
|
||||||
-- send trains if 'advtrains' mod installed
|
-- send trains if 'advtrains' mod installed
|
||||||
data.trains = advtrains.trains
|
--print(dump(advtrains))--XXX
|
||||||
|
|
||||||
|
data.trains = {}
|
||||||
|
for _, train in pairs(advtrains.trains) do
|
||||||
|
--print(dump(train))--XXX
|
||||||
|
|
||||||
|
local t = {
|
||||||
|
pos = train.last_pos,
|
||||||
|
velocity = train.velocity,
|
||||||
|
off_track = train.off_track,
|
||||||
|
id = train.id
|
||||||
|
}
|
||||||
|
|
||||||
|
table.insert(data.trains, t)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
data.wagons = {}
|
||||||
|
for _, wagon in pairs(advtrains.wagons) do
|
||||||
|
--print(dump(wagon))--XXX
|
||||||
|
|
||||||
|
local w = {
|
||||||
|
train_id = wagon.train_id,
|
||||||
|
id = wagon.id,
|
||||||
|
type = wagon.type,
|
||||||
|
pos_in_train = wagon.pos_in_train,
|
||||||
|
}
|
||||||
|
|
||||||
|
table.insert(data.wagons, w)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
@ -44,11 +86,14 @@ function send_stats()
|
|||||||
table.insert(data.players, info)
|
table.insert(data.players, info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local json = minetest.write_json(data)
|
||||||
|
--print(json)--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 },
|
||||||
timeout = 1,
|
timeout = 1,
|
||||||
post_data = minetest.write_json(data)
|
post_data = json
|
||||||
}, function(res)
|
}, function(res)
|
||||||
-- TODO: error-handling
|
-- TODO: error-handling
|
||||||
minetest.after(2, send_stats)
|
minetest.after(2, send_stats)
|
||||||
|
Loading…
Reference in New Issue
Block a user