From 118762b19db866ab5220a7a51f8e9346f094dae3 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Fri, 15 Feb 2019 18:37:16 +0100 Subject: [PATCH] trains in bridge --- mapserver_mod/mapserver/bridge.lua | 4 ++++ server/web/logger.go | 11 +++++++++++ server/web/minetest.go | 14 +++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 server/web/logger.go diff --git a/mapserver_mod/mapserver/bridge.lua b/mapserver_mod/mapserver/bridge.lua index c06523c..1aa0299 100644 --- a/mapserver_mod/mapserver/bridge.lua +++ b/mapserver_mod/mapserver/bridge.lua @@ -38,6 +38,9 @@ function send_stats() {"id":"243215","pos_in_train":2.5,"train_id":"973462","type":"advtrains:engine_japan"} ]} + {"max_lag":0.38148100000000001,"players":[{"breath":11,"hp":20,"name":"BuckarooBanzai","pos":{"x":-114.66400146484375,"y":3.5,"z":-66.122001647949219},"velocity":{"x":0,"y":0,"z":0}}],"time":18530.00020980835,"trains":[{"id":"261557","off_track":true,"pos":{"x":-125,"y":5,"z":-56},"velocity":0,"wagons":[{"id":"423954","pos_in_train":6,"type":"advtrains:subway_wagon"},{"id":"635309","pos_in_train":10,"type":"advtrains:subway_wagon"},{"id":"253216","pos_in_train":2,"type":"advtrains:subway_wagon"}]},{"id":"690096","off_track":false,"pos":{"x":-125,"y":6,"z":-46},"velocity":0,"wagons":[{"id":"980189","pos_in_train":2,"type":"advtrains:subway_wagon"}]}],"uptime":235.100003503263} + + --]] if has_advtrains then @@ -45,6 +48,7 @@ function send_stats() data.trains = {} for _, train in pairs(advtrains.trains) do + print(dump(train))--XXX local t = { pos = train.last_pos, diff --git a/server/web/logger.go b/server/web/logger.go new file mode 100644 index 0000000..8b69b9b --- /dev/null +++ b/server/web/logger.go @@ -0,0 +1,11 @@ +package web + +import ( + "github.com/sirupsen/logrus" +) + +var log *logrus.Entry + +func init() { + log = logrus.WithFields(logrus.Fields{"prefix": "mapobjectdb"}) +} diff --git a/server/web/minetest.go b/server/web/minetest.go index 6d506d3..4b6a47d 100644 --- a/server/web/minetest.go +++ b/server/web/minetest.go @@ -4,6 +4,8 @@ import ( "encoding/json" "mapserver/app" "net/http" + + "github.com/sirupsen/logrus" ) type GenericPos struct { @@ -13,17 +15,17 @@ type GenericPos struct { } type Wagon struct { - Id int `json:"id"` - PosInTrain int `json:"pos_in_train"` - Type string `json:"type"` + Id string `json:"id"` + PosInTrain float64 `json:"pos_in_train"` + Type string `json:"type"` } type Train struct { Pos GenericPos `json:"pos"` - Id int `json:"id"` + Id string `json:"id"` Wagons []*Wagon `json:"wagons"` OffTrack bool `json:"off_track"` - Velocity int `json:"velocity"` + Velocity float64 `json:"velocity"` } type Player struct { @@ -62,6 +64,8 @@ func (this *Minetest) ServeHTTP(resp http.ResponseWriter, req *http.Request) { if err != nil { resp.WriteHeader(500) resp.Write([]byte(err.Error())) + log.WithFields(logrus.Fields{"error": err}).Error("Json unmarshal") + return }