package timer import ( "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/log" "go_dreamfactory/sys/db" "time" ) /* 模块名:定时任务 描述:处理区服集群下需要做的一些定时任务 开发:李伟 */ func NewModule() core.IModule { m := new(Timer) return m } type Timer struct { cbase.ModuleBase options *Options service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口 chat *ChatComp //俩天系统定时任务 //season *SeasonPagoda forum *ForumComp arena *ArenaComp sociaty *SociatyComp parkour *ParkourComp caravan *CaravanRank activity *Activity stone *StoneComp } // 模块名 func (this *Timer) GetType() core.M_Modules { return comm.ModuleTimer } // NewOptions 模块自定义参数 func (this *Timer) NewOptions() (options core.IModuleOptions) { return new(Options) } // 模块初始化接口 注册用户创建角色事件 func (this *Timer) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) this.options = options.(*Options) return } func (this *Timer) Start() (err error) { err = this.ModuleBase.Start() return } func (this *Timer) OnInstallComp() { this.ModuleBase.OnInstallComp() this.chat = this.RegisterComp(new(ChatComp)).(*ChatComp) //this.season = this.RegisterComp(new(SeasonPagoda)).(*SeasonPagoda) this.arena = this.RegisterComp(new(ArenaComp)).(*ArenaComp) this.sociaty = this.RegisterComp(new(SociatyComp)).(*SociatyComp) this.parkour = this.RegisterComp(new(ParkourComp)).(*ParkourComp) this.caravan = this.RegisterComp(new(CaravanRank)).(*CaravanRank) this.activity = this.RegisterComp(new(Activity)).(*Activity) this.stone = this.RegisterComp(new(StoneComp)).(*StoneComp) } // 跨服对象获取数据操作对象 func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, err error) { var ( stag string conn *db.DBConn ) if stag, err = comm.UidToSTag(uid); err != nil { return } if stag == this.service.GetTag() { if conn, err = db.Local(); err != nil { return } } else { if conn, err = db.ServerDBConn(stag); err != nil { return } } model = db.NewDBModel(tableName, time.Hour, conn) return } // 重新加载活动数据 func (this *Timer) ReloadActivityData() { this.activity.LoadActivityData() } // 日志 func (this *Timer) Enabled(lvl log.Loglevel) bool { return this.options.GetLog().Enabled(lvl) } func (this *Timer) SetName(name string) { this.options.GetLog().SetName(name) } // 日志接口 func (this *Timer) Debug(msg string, args ...log.Field) { this.options.GetLog().Debug(msg, args...) } func (this *Timer) Info(msg string, args ...log.Field) { this.options.GetLog().Info(msg, args...) } func (this *Timer) Print(msg string, args ...log.Field) { this.options.GetLog().Print(msg, args...) } func (this *Timer) Warn(msg string, args ...log.Field) { this.options.GetLog().Warn(msg, args...) } func (this *Timer) Error(msg string, args ...log.Field) { this.options.GetLog().Error(msg, args...) } func (this *Timer) Panic(msg string, args ...log.Field) { this.options.GetLog().Panic(msg, args...) } func (this *Timer) Fatal(msg string, args ...log.Field) { this.options.GetLog().Fatal(msg, args...) } func (this *Timer) Debugf(format string, args ...interface{}) { this.options.GetLog().Debugf(format, args...) } func (this *Timer) Infof(format string, args ...interface{}) { this.options.GetLog().Infof(format, args...) } func (this *Timer) Printf(format string, args ...interface{}) { this.options.GetLog().Printf(format, args...) } func (this *Timer) Warnf(format string, args ...interface{}) { this.options.GetLog().Warnf(format, args...) } func (this *Timer) Errorf(format string, args ...interface{}) { this.options.GetLog().Errorf(format, args...) } func (this *Timer) Fatalf(format string, args ...interface{}) { this.options.GetLog().Fatalf(format, args...) } func (this *Timer) Panicf(format string, args ...interface{}) { this.options.GetLog().Panicf(format, args...) } func (this *Timer) Debugln(args ...interface{}) { this.options.GetLog().Debugln(args...) } func (this *Timer) Infoln(args ...interface{}) { this.options.GetLog().Infoln(args...) } func (this *Timer) Println(args ...interface{}) { this.options.GetLog().Println(args...) } func (this *Timer) Warnln(args ...interface{}) { this.options.GetLog().Warnln(args...) } func (this *Timer) Errorln(args ...interface{}) { this.options.GetLog().Errorln(args...) } func (this *Timer) Fatalln(args ...interface{}) { this.options.GetLog().Fatalln(args...) } func (this *Timer) Panicln(args ...interface{}) { this.options.GetLog().Panicln(args...) }