package timer import ( "context" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/sys/db" "go_dreamfactory/utils" ) // 此组件废弃 type CaravanRank struct { cbase.ModuleBase modules.MCompModel service base.IRPCXService module *Timer cTimerObj *timewheel.Task } const ( game_global = "game_global.json" //全局配置表 ) //组件初始化接口 func (this *CaravanRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.TableName = comm.TableCaravan this.MCompModel.Init(service, module, comp, options) this.module = module.(*Timer) this.service = service.(base.IRPCXService) err = this.LoadConfigure(game_global, cfg.NewGameGlobal) return } func (this *CaravanRank) LoadConfigure(name string, fn interface{}) (err error) { return configure.RegisterConfigure(name, fn, nil) } //读取配置数据 func (this *CaravanRank) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } //全局配置 func (this *CaravanRank) GetGlobalConf() *cfg.GameGlobalData { var ( configure *cfg.GameGlobal ok bool ) if v, err := this.GetConfigure(game_global); err != nil { log.Errorf("get global conf err:%v", err) return nil } else { if configure, ok = v.(*cfg.GameGlobal); !ok { log.Errorf("%T no is *cfg.Game_global", v) return nil } } return configure.GetDataList()[0] // 返回对象信息 } func (this *CaravanRank) Start() (err error) { if db.IsCross() { return } err = this.MCompModel.Start() opentime := this.service.GetOpentime().Unix() if configure.Now().Unix() < opentime { // 开服时间是未来可能存在问题 return } // 0 0 0 ? * MON // 每周一零点 cron.AddFunc("0 0 0 ? * MON", this.TimerSeason) return } func (this *CaravanRank) TimerSeason() { endTime := utils.WeekIntervalTime() this.module.Debugf("TimerSeason end: %d,cur time:%d", endTime, configure.Now().Unix()) if err := this.service.RpcCall( context.Background(), comm.Service_Worker, string(comm.Rpc_ModuleCaravanSettlement), pb.EmptyReq{}, nil, ); err != nil { this.module.Errorln(err) } }