活动通知

This commit is contained in:
meixiongfeng 2023-08-24 19:23:23 +08:00
parent 2690497519
commit 3ef9eb20eb
7 changed files with 155 additions and 8 deletions

View File

@ -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" //活动结束
)
// 事件类型定义处

View File

@ -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
}

View File

@ -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
}

111
modules/timer/activity.go Normal file
View File

@ -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)
}
}
}

View File

@ -32,6 +32,7 @@ type Timer struct {
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)

View File

@ -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()
}

View File

@ -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()