diff --git a/comm/const.go b/comm/const.go index 3bd829b21..d7e616b27 100644 --- a/comm/const.go +++ b/comm/const.go @@ -435,6 +435,8 @@ const ( //Rpc Rpc_ModuleStoneBossSettlement core.Rpc_Key = "Rpc_ModuleStoneBossSettlement" Rpc_Activity core.Rpc_Key = "Rpc_Activity" + + Rpc_ActivityOver core.Rpc_Key = "Rpc_ActivityOver" //活动结束 ) // 事件类型定义处 diff --git a/modules/activity/module.go b/modules/activity/module.go index c96eaf30b..51b729adb 100644 --- a/modules/activity/module.go +++ b/modules/activity/module.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/event" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" @@ -109,6 +110,8 @@ func (this *Activity) Start() (err error) { } } } + this.service.RegisterFunctionName(string(comm.Rpc_ActivityOver), this.Rpc_ActivityOver) + return } func (this *Activity) OnInstallComp() { @@ -436,3 +439,17 @@ func (this *Activity) Rpc_Activity(ctx context.Context, args string) (err error) this.modelhdList.LoadActivityData() return } + +// 活动结束通知 +func (this *Activity) Rpc_ActivityOver(ctx context.Context, args *pb.RPCGeneralReqB1, reply *pb.EmptyResp) (err error) { + this.Debug("Rpc_ActivityOver", + log.Field{Key: "args", Value: args.String()}, + ) + var ( + szOverActivity []string + ) + szOverActivity = args.Param2 + + this.Debug("szOverActivity", log.Field{Key: "args", Value: szOverActivity}) + return +} diff --git a/modules/mainline/comp_configure.go b/modules/mainline/comp_configure.go index 20aabcbfd..ded272fa8 100644 --- a/modules/mainline/comp_configure.go +++ b/modules/mainline/comp_configure.go @@ -42,8 +42,6 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp configure.RegisterConfigure(game_mainstage, cfg.NewGameMainStage, this.updateMlineStage) configure.RegisterConfigure(game_mainstarreward, cfg.NewGameMainStarreward, this.updateMlineReward) configure.RegisterConfigure(game_mainachievement, cfg.NewGameMainAchievement, this.GameMainAchievement) - - this.gettasks() return } diff --git a/modules/timer/activity.go b/modules/timer/activity.go new file mode 100644 index 000000000..d492717ae --- /dev/null +++ b/modules/timer/activity.go @@ -0,0 +1,111 @@ +package timer + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/lego/base" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/core/cbase" + "go_dreamfactory/lego/sys/timewheel" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + "go_dreamfactory/sys/db" + "sync" + "time" + + "go.mongodb.org/mongo-driver/bson" +) + +// 此组件废弃 +type Activity struct { + cbase.ModuleBase + modules.MCompModel + service base.IRPCXService + module *Timer + cTimerObj *timewheel.Task + closeSignal chan struct{} + hlock sync.RWMutex + activity map[pb.HdType]*pb.DBHuodong +} + +//组件初始化接口 +func (this *Activity) 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) + + return +} +func (this *Activity) Stop() (err error) { + this.closeSignal <- struct{}{} + return +} +func (this *Activity) Start() (err error) { + if db.IsCross() { + return + } + err = this.MCompModel.Start() + timer := time.NewTicker(time.Second * 1) + + go func() { + locp: + for { + select { + case <-this.closeSignal: + break locp + case <-timer.C: + this.CheckActivityData() + } + } + timer.Stop() + }() + //cron.AddFunc("0 0 0 ? * MON", this.TimerSeason) + return +} + +func (this *Activity) LoadActivityData() { + if c, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}); err != nil { + return + } else { + this.hlock.Lock() + defer this.hlock.Unlock() + this.activity = make(map[pb.HdType]*pb.DBHuodong) + for c.Next(context.Background()) { + hd := &pb.DBHuodong{} + if err = c.Decode(hd); err != nil { + this.module.Errorf("err:%v", err) + continue + } + this.activity[hd.Itype] = hd + } + } +} + +func (this *Activity) CheckActivityData() { + var ( + szEnd []string + ) + this.module.Debugf("ticker:%d", configure.Now().Unix()) + for _, v := range this.activity { + if v.Etime > configure.Now().Unix() { // 有活动结束 + szEnd = append(szEnd, v.Id) + } + } + if len(szEnd) > 0 { + if err := this.service.RpcCall( + context.Background(), + comm.Service_Worker, + string(comm.Rpc_ActivityOver), + pb.RPCGeneralReqB1{ + Param1: "endActivity", + Param2: szEnd, + }, + nil, + ); err != nil { + this.module.Errorln(err) + } + } +} diff --git a/modules/timer/module.go b/modules/timer/module.go index 171dc8ea5..292b7793d 100644 --- a/modules/timer/module.go +++ b/modules/timer/module.go @@ -27,11 +27,12 @@ type Timer struct { service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口 chat *ChatComp //俩天系统定时任务 //season *SeasonPagoda - forum *ForumComp - arena *ArenaComp - sociaty *SociatyComp - parkour *ParkourComp - caravan *CaravanRank + forum *ForumComp + arena *ArenaComp + sociaty *SociatyComp + parkour *ParkourComp + caravan *CaravanRank + activity *Activity } // 模块名 @@ -66,6 +67,7 @@ func (this *Timer) OnInstallComp() { 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) } // 跨服对象获取数据操作对象 @@ -90,6 +92,11 @@ func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, er return } +// 重新加载活动数据 +func (this *Timer) ReloadActivityData() { + this.activity.LoadActivityData() +} + // 日志 func (this *Timer) Enabled(lvl log.Loglevel) bool { return this.options.GetLog().Enabled(lvl) diff --git a/modules/web/api_activitynotify.go b/modules/web/api_activitynotify.go index b79011c4d..e1e6f24ab 100644 --- a/modules/web/api_activitynotify.go +++ b/modules/web/api_activitynotify.go @@ -44,4 +44,6 @@ func (this *Api_Comp) ActivityNotify(c *engine.Context) { Code: pb.ErrorCode_Success, Title: pb.ErrorCode_Success.ToString(), } + // 通知更新活动 + this.module.modelweb.ReloadActivityData() } diff --git a/modules/web/module.go b/modules/web/module.go index 6df3e2576..f99d00fa4 100644 --- a/modules/web/module.go +++ b/modules/web/module.go @@ -2,11 +2,11 @@ package web import ( "go_dreamfactory/comm" - "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules/timer" ) /* @@ -28,6 +28,7 @@ type Web struct { modelNotify *modelNotifyComp modelMail *modelMailComp configure *configureComp + modelweb *timer.Timer } //模块名 @@ -46,6 +47,15 @@ func (this *Web) Init(service core.IService, module core.IModule, options core.I this.options = options.(*Options) return } +func (this *Web) Star() (err error) { + this.ModuleBase.Start() + var module core.IModule + if module, err = this.service.GetModule(comm.ModuleTimer); err != nil { + return + } + this.modelweb = module.(*timer.Timer) + return +} func (this *Web) OnInstallComp() { this.ModuleBase.OnInstallComp()