1
0
forked from MTSR/mapserver

trains in bridge

This commit is contained in:
Thomas Rudin 2019-02-15 18:37:16 +01:00
parent dabc52fbe8
commit 118762b19d
3 changed files with 24 additions and 5 deletions

View File

@ -38,6 +38,9 @@ function send_stats()
{"id":"243215","pos_in_train":2.5,"train_id":"973462","type":"advtrains:engine_japan"} {"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 if has_advtrains then
@ -45,6 +48,7 @@ function send_stats()
data.trains = {} data.trains = {}
for _, train in pairs(advtrains.trains) do for _, train in pairs(advtrains.trains) do
print(dump(train))--XXX
local t = { local t = {
pos = train.last_pos, pos = train.last_pos,

11
server/web/logger.go Normal file
View File

@ -0,0 +1,11 @@
package web
import (
"github.com/sirupsen/logrus"
)
var log *logrus.Entry
func init() {
log = logrus.WithFields(logrus.Fields{"prefix": "mapobjectdb"})
}

View File

@ -4,6 +4,8 @@ import (
"encoding/json" "encoding/json"
"mapserver/app" "mapserver/app"
"net/http" "net/http"
"github.com/sirupsen/logrus"
) )
type GenericPos struct { type GenericPos struct {
@ -13,17 +15,17 @@ type GenericPos struct {
} }
type Wagon struct { type Wagon struct {
Id int `json:"id"` Id string `json:"id"`
PosInTrain int `json:"pos_in_train"` PosInTrain float64 `json:"pos_in_train"`
Type string `json:"type"` Type string `json:"type"`
} }
type Train struct { type Train struct {
Pos GenericPos `json:"pos"` Pos GenericPos `json:"pos"`
Id int `json:"id"` Id string `json:"id"`
Wagons []*Wagon `json:"wagons"` Wagons []*Wagon `json:"wagons"`
OffTrack bool `json:"off_track"` OffTrack bool `json:"off_track"`
Velocity int `json:"velocity"` Velocity float64 `json:"velocity"`
} }
type Player struct { type Player struct {
@ -62,6 +64,8 @@ func (this *Minetest) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
if err != nil { if err != nil {
resp.WriteHeader(500) resp.WriteHeader(500)
resp.Write([]byte(err.Error())) resp.Write([]byte(err.Error()))
log.WithFields(logrus.Fields{"error": err}).Error("Json unmarshal")
return return
} }