1
0
forked from MTSR/mapserver

logging & fixes

This commit is contained in:
Thomas Rudin 2019-02-06 18:28:24 +01:00
parent 18fb3240d5
commit 8256a47851
5 changed files with 53 additions and 10 deletions

View File

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

View File

@ -5,6 +5,8 @@ import (
"mapserver/eventbus"
"mapserver/mapblockparser"
"mapserver/mapobjectdb"
"github.com/sirupsen/logrus"
)
type MapObjectListener interface {
@ -44,6 +46,16 @@ func (this *Listener) OnEvent(eventtype string, o interface{}) {
for z := 0; z < 16; z++ {
nodeid := block.GetNodeId(x, y, z)
if nodeid == id {
fields := logrus.Fields{
"mbpos": block.Pos,
"x": x,
"y": y,
"z": z,
"type": name,
"nodeid": nodeid,
}
log.WithFields(fields).Debug("OnEvent()")
obj := v.onMapObject(x, y, z, block)
if obj != nil {

View File

@ -3,6 +3,8 @@ package mapobjectdb
import (
"mapserver/coords"
"time"
"github.com/sirupsen/logrus"
)
/*
@ -33,9 +35,14 @@ type MapObject struct {
func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject {
if x > 16 || y > 16 || z > 16 {
panic("Out of range3!") //XXX
fields := logrus.Fields{
"mbpos": MBPos,
"x": x,
"y": y,
"z": z,
"type": _type,
}
log.WithFields(fields).Debug("NewMapObject")
o := MapObject{
MBPos: MBPos,
@ -54,7 +61,7 @@ type SearchQuery struct {
//mapblock position
Pos1 *coords.MapBlockCoords `json:"pos1"`
Pos2 *coords.MapBlockCoords `json:"pos2"`
Type string `json:"type"`
Type string `json:"type"`
}
type DBAccessor interface {

View File

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

View File

@ -5,7 +5,6 @@ import (
"mapserver/mapobjectdb"
)
func (db *Sqlite3Accessor) GetMapData(q mapobjectdb.SearchQuery) ([]*mapobjectdb.MapObject, error) {
rows, err := db.db.Query(getMapDataPosQuery,
q.Type,
@ -42,11 +41,15 @@ func (db *Sqlite3Accessor) GetMapData(q mapobjectdb.SearchQuery) ([]*mapobjectdb
if currentId == nil || *currentId != id {
pos := coords.NewMapBlockCoords(posx, posy, posz)
mo := mapobjectdb.NewMapObject(
pos,
x, y, z,
Type,
)
mo := &mapobjectdb.MapObject{
MBPos: pos,
Type: Type,
X: x,
Y: y,
Z: z,
Mtime: mtime,
Attributes: make(map[string]string),
}
currentObj = mo
currentId = &id
@ -66,7 +69,6 @@ func (db *Sqlite3Accessor) RemoveMapData(pos *coords.MapBlockCoords) error {
return err
}
func (db *Sqlite3Accessor) AddMapData(data *mapobjectdb.MapObject) error {
res, err := db.db.Exec(addMapDataQuery,
data.X, data.Y, data.Z,