活动通知
This commit is contained in:
parent
2690497519
commit
3ef9eb20eb
@ -435,6 +435,8 @@ const ( //Rpc
|
|||||||
Rpc_ModuleStoneBossSettlement core.Rpc_Key = "Rpc_ModuleStoneBossSettlement"
|
Rpc_ModuleStoneBossSettlement core.Rpc_Key = "Rpc_ModuleStoneBossSettlement"
|
||||||
|
|
||||||
Rpc_Activity core.Rpc_Key = "Rpc_Activity"
|
Rpc_Activity core.Rpc_Key = "Rpc_Activity"
|
||||||
|
|
||||||
|
Rpc_ActivityOver core.Rpc_Key = "Rpc_ActivityOver" //活动结束
|
||||||
)
|
)
|
||||||
|
|
||||||
// 事件类型定义处
|
// 事件类型定义处
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"go_dreamfactory/lego/base"
|
"go_dreamfactory/lego/base"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/event"
|
"go_dreamfactory/lego/sys/event"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/configure"
|
"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
|
return
|
||||||
}
|
}
|
||||||
func (this *Activity) OnInstallComp() {
|
func (this *Activity) OnInstallComp() {
|
||||||
@ -436,3 +439,17 @@ func (this *Activity) Rpc_Activity(ctx context.Context, args string) (err error)
|
|||||||
this.modelhdList.LoadActivityData()
|
this.modelhdList.LoadActivityData()
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
@ -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_mainstage, cfg.NewGameMainStage, this.updateMlineStage)
|
||||||
configure.RegisterConfigure(game_mainstarreward, cfg.NewGameMainStarreward, this.updateMlineReward)
|
configure.RegisterConfigure(game_mainstarreward, cfg.NewGameMainStarreward, this.updateMlineReward)
|
||||||
configure.RegisterConfigure(game_mainachievement, cfg.NewGameMainAchievement, this.GameMainAchievement)
|
configure.RegisterConfigure(game_mainachievement, cfg.NewGameMainAchievement, this.GameMainAchievement)
|
||||||
|
|
||||||
this.gettasks()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
111
modules/timer/activity.go
Normal file
111
modules/timer/activity.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,11 +27,12 @@ type Timer struct {
|
|||||||
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
||||||
chat *ChatComp //俩天系统定时任务
|
chat *ChatComp //俩天系统定时任务
|
||||||
//season *SeasonPagoda
|
//season *SeasonPagoda
|
||||||
forum *ForumComp
|
forum *ForumComp
|
||||||
arena *ArenaComp
|
arena *ArenaComp
|
||||||
sociaty *SociatyComp
|
sociaty *SociatyComp
|
||||||
parkour *ParkourComp
|
parkour *ParkourComp
|
||||||
caravan *CaravanRank
|
caravan *CaravanRank
|
||||||
|
activity *Activity
|
||||||
}
|
}
|
||||||
|
|
||||||
// 模块名
|
// 模块名
|
||||||
@ -66,6 +67,7 @@ func (this *Timer) OnInstallComp() {
|
|||||||
this.sociaty = this.RegisterComp(new(SociatyComp)).(*SociatyComp)
|
this.sociaty = this.RegisterComp(new(SociatyComp)).(*SociatyComp)
|
||||||
this.parkour = this.RegisterComp(new(ParkourComp)).(*ParkourComp)
|
this.parkour = this.RegisterComp(new(ParkourComp)).(*ParkourComp)
|
||||||
this.caravan = this.RegisterComp(new(CaravanRank)).(*CaravanRank)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重新加载活动数据
|
||||||
|
func (this *Timer) ReloadActivityData() {
|
||||||
|
this.activity.LoadActivityData()
|
||||||
|
}
|
||||||
|
|
||||||
// 日志
|
// 日志
|
||||||
func (this *Timer) Enabled(lvl log.Loglevel) bool {
|
func (this *Timer) Enabled(lvl log.Loglevel) bool {
|
||||||
return this.options.GetLog().Enabled(lvl)
|
return this.options.GetLog().Enabled(lvl)
|
||||||
|
@ -44,4 +44,6 @@ func (this *Api_Comp) ActivityNotify(c *engine.Context) {
|
|||||||
Code: pb.ErrorCode_Success,
|
Code: pb.ErrorCode_Success,
|
||||||
Title: pb.ErrorCode_Success.ToString(),
|
Title: pb.ErrorCode_Success.ToString(),
|
||||||
}
|
}
|
||||||
|
// 通知更新活动
|
||||||
|
this.module.modelweb.ReloadActivityData()
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
|
|
||||||
"go_dreamfactory/lego/base"
|
"go_dreamfactory/lego/base"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/modules/timer"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -28,6 +28,7 @@ type Web struct {
|
|||||||
modelNotify *modelNotifyComp
|
modelNotify *modelNotifyComp
|
||||||
modelMail *modelMailComp
|
modelMail *modelMailComp
|
||||||
configure *configureComp
|
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)
|
this.options = options.(*Options)
|
||||||
return
|
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() {
|
func (this *Web) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
|
Loading…
Reference in New Issue
Block a user