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/eventbus"
"mapserver/mapblockparser" "mapserver/mapblockparser"
"mapserver/mapobjectdb" "mapserver/mapobjectdb"
"github.com/sirupsen/logrus"
) )
type MapObjectListener interface { type MapObjectListener interface {
@ -44,6 +46,16 @@ func (this *Listener) OnEvent(eventtype string, o interface{}) {
for z := 0; z < 16; z++ { for z := 0; z < 16; z++ {
nodeid := block.GetNodeId(x, y, z) nodeid := block.GetNodeId(x, y, z)
if nodeid == id { 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) obj := v.onMapObject(x, y, z, block)
if obj != nil { if obj != nil {

View File

@ -3,6 +3,8 @@ package mapobjectdb
import ( import (
"mapserver/coords" "mapserver/coords"
"time" "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 { func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject {
if x > 16 || y > 16 || z > 16 { fields := logrus.Fields{
panic("Out of range3!") //XXX "mbpos": MBPos,
"x": x,
"y": y,
"z": z,
"type": _type,
} }
log.WithFields(fields).Debug("NewMapObject")
o := MapObject{ o := MapObject{
MBPos: MBPos, MBPos: MBPos,
@ -54,7 +61,7 @@ type SearchQuery struct {
//mapblock position //mapblock position
Pos1 *coords.MapBlockCoords `json:"pos1"` Pos1 *coords.MapBlockCoords `json:"pos1"`
Pos2 *coords.MapBlockCoords `json:"pos2"` Pos2 *coords.MapBlockCoords `json:"pos2"`
Type string `json:"type"` Type string `json:"type"`
} }
type DBAccessor interface { 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" "mapserver/mapobjectdb"
) )
func (db *Sqlite3Accessor) GetMapData(q mapobjectdb.SearchQuery) ([]*mapobjectdb.MapObject, error) { func (db *Sqlite3Accessor) GetMapData(q mapobjectdb.SearchQuery) ([]*mapobjectdb.MapObject, error) {
rows, err := db.db.Query(getMapDataPosQuery, rows, err := db.db.Query(getMapDataPosQuery,
q.Type, q.Type,
@ -42,11 +41,15 @@ func (db *Sqlite3Accessor) GetMapData(q mapobjectdb.SearchQuery) ([]*mapobjectdb
if currentId == nil || *currentId != id { if currentId == nil || *currentId != id {
pos := coords.NewMapBlockCoords(posx, posy, posz) pos := coords.NewMapBlockCoords(posx, posy, posz)
mo := mapobjectdb.NewMapObject( mo := &mapobjectdb.MapObject{
pos, MBPos: pos,
x, y, z, Type: Type,
Type, X: x,
) Y: y,
Z: z,
Mtime: mtime,
Attributes: make(map[string]string),
}
currentObj = mo currentObj = mo
currentId = &id currentId = &id
@ -66,7 +69,6 @@ func (db *Sqlite3Accessor) RemoveMapData(pos *coords.MapBlockCoords) error {
return err return err
} }
func (db *Sqlite3Accessor) AddMapData(data *mapobjectdb.MapObject) error { func (db *Sqlite3Accessor) AddMapData(data *mapobjectdb.MapObject) error {
res, err := db.db.Exec(addMapDataQuery, res, err := db.db.Exec(addMapDataQuery,
data.X, data.Y, data.Z, data.X, data.Y, data.Z,