168 lines
4.2 KiB
Go
168 lines
4.2 KiB
Go
package buried
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
game_buriedtype = "game_buriedtype.json"
|
|
game_buriedcondi = "game_buriedcondi.json"
|
|
)
|
|
|
|
// 配置管理组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Buried
|
|
lock sync.RWMutex
|
|
group map[int32][]*cfg.GameBuriedCondiData //安排点类型 分组
|
|
}
|
|
|
|
// 组件初始化接口
|
|
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.MCompConfigure.Init(service, module, comp, options)
|
|
this.module = module.(*Buried)
|
|
this.LoadConfigure(game_buriedtype, cfg.NewGameBuriedType)
|
|
this.LoadConfigure(game_buriedcondi, cfg.NewGameBuriedCondi)
|
|
configure.RegisterConfigure(game_buriedcondi, cfg.NewGameBuriedCondi, this.updateconfigure)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) Start() (err error) {
|
|
err = this.MCompConfigure.Start()
|
|
err = this.checkconfig()
|
|
return
|
|
}
|
|
|
|
// 校验配置异常
|
|
func (this *configureComp) checkconfig() (err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
vtype *cfg.GameBuriedType
|
|
vt *cfg.GameBuriedTypeData
|
|
)
|
|
if v, err = this.GetConfigure(game_buriedtype); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
vtype = v.(*cfg.GameBuriedType)
|
|
for k, conids := range this.group {
|
|
if vt, ok = vtype.GetDataMap()[int32(k)]; ok {
|
|
for _, cond := range conids {
|
|
if len(vt.Filter) != len(cond.Filter) {
|
|
this.module.Error("埋点中心配置错误!",
|
|
log.Field{Key: "vtype", Value: int32(k)},
|
|
log.Field{Key: "cond", Value: cond.Id},
|
|
log.Field{Key: "vtype_filter", Value: vt.Filter},
|
|
log.Field{Key: "cond_filter", Value: cond.Filter},
|
|
)
|
|
}
|
|
}
|
|
} else {
|
|
for _, cond := range conids {
|
|
this.module.Error("未配置埋点类型!",
|
|
log.Field{Key: "vtype", Value: int32(k)},
|
|
log.Field{Key: "cond", Value: cond.Id},
|
|
)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 读取埋点配置数据
|
|
func (this *configureComp) getburiedtypedata(tt int32) (result *cfg.GameBuriedTypeData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_buriedtype); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameBuriedType).GetDataMap()[tt]; !ok {
|
|
err = comm.NewNotFoundConfErr(moduleName, game_buriedtype, tt)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 读取条件任务id配置
|
|
func (this *configureComp) getburiedcondidata(cid int32) (result *cfg.GameBuriedCondiData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_buriedcondi); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameBuriedCondi).GetDataMap()[cid]; !ok {
|
|
err = comm.NewNotFoundConfErr(moduleName, game_buriedcondi, cid)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 动态更新配置
|
|
func (this *configureComp) updateconfigure() {
|
|
if v, err := this.GetConfigure(game_buriedcondi); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok := v.(*cfg.GameBuriedCondi); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameBuriedCondi", v)
|
|
return
|
|
} else {
|
|
group := map[int32][]*cfg.GameBuriedCondiData{}
|
|
for _, v := range data.GetDataList() {
|
|
if _, ok = group[v.Type]; !ok {
|
|
group[v.Type] = make([]*cfg.GameBuriedCondiData, 0)
|
|
}
|
|
group[v.Type] = append(group[v.Type], v)
|
|
}
|
|
this.lock.Lock()
|
|
this.group = group
|
|
this.lock.Unlock()
|
|
}
|
|
}
|
|
}
|
|
|
|
// 读取埋点条件配置
|
|
func (this *configureComp) getCondiDatas(tt int32) (result []*cfg.GameBuriedCondiData) {
|
|
result = make([]*cfg.GameBuriedCondiData, 0)
|
|
this.lock.RLock()
|
|
if _, ok := this.group[tt]; ok {
|
|
result = this.group[tt]
|
|
}
|
|
this.lock.RUnlock()
|
|
return
|
|
}
|
|
|
|
// 读取埋点条件配置
|
|
func (this *configureComp) getCondiData(id int32) (result *cfg.GameBuriedCondiData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_buriedcondi); err != nil {
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameBuriedCondi).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(moduleName, game_buriedcondi, id)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|