diff --git a/comm/const.go b/comm/const.go index a5788349d..9da21a8ce 100644 --- a/comm/const.go +++ b/comm/const.go @@ -402,34 +402,49 @@ const ( Diamond int32 = 2 //钻石 ) -// 门票 +//定时通知类型 +type NotifyType int32 + const ( -// ArenaTicket string = "100004" //竞技场入场券 -// MoonFantasyTicket string = "100003" //梦境场入场券 -// PhysicalMedicament string = "10017" //体力药剂 -// UnifiedTicket string = "100100" //统一门票 + Notify1001 NotifyType = 1001 //铁匠铺炉温达到满值 ) // 红点枚举 type ReddotType int32 const ( - Reddot1 ReddotType = 10001 //任务----日常任务奖励红点 - Reddot2 ReddotType = 10002 //任务----周常任务奖励红点 - Reddot3 ReddotType = 10003 //公会----签到红点 - Reddot4 ReddotType = 10004 //任务----成就任务奖励红点 - Reddot5 ReddotType = 10005 //主线关卡----可挑战红点 + //任务 + Reddot10101 ReddotType = 10101 //任务----日常活跃宝箱红点 + Reddot10102 ReddotType = 10102 //任务----周活跃宝箱红点 + Reddot10103 ReddotType = 10103 //任务----成就任务奖励红点 + Reddot10201 ReddotType = 10201 //任务----日常活跃奖励红点 + Reddot10301 ReddotType = 10301 //任务----周常活跃奖励红点 + + //邮件 + Reddot12101 ReddotType = 12101 //邮件-----附件红点 + Reddot12102 ReddotType = 12102 //邮件-----未读邮件红点 + //维京 + Reddot13102 ReddotType = 13102 //维京远征 有挑战次数 + //狩猎 + Reddot14102 ReddotType = 14102 //狩猎 有挑战次数 + + //英雄 + Reddot20102 ReddotType = 20102 //英雄----升级红点 前端处理 + Reddot20201 ReddotType = 20201 //英雄----觉醒红点 前端处理 + Reddot10 ReddotType = 10010 //英雄----共鸣红点 前端处理 + Reddot20301 ReddotType = 20301 //英雄----升星红点 前端处理 + //公会 + Reddot15102 ReddotType = 15102 //公会----签到红点 + Reddot15201 ReddotType = 15201 //公会----申请红点 + //主线关卡 + Reddot11100 ReddotType = 11100 //主线关卡----可挑战红点 + // 铁匠铺 + Reddot17102 ReddotType = 17102 // 铁匠铺手册台 + Reddot17106 ReddotType = 17106 // 铁匠铺手册台收藏家奖励上 + Reddot17107 ReddotType = 17107 // 铁匠铺手册台收藏家奖励按钮上 + Reddot6 ReddotType = 10006 //爬塔----可挑战红点 Reddot7 ReddotType = 10007 //爬塔----奖励红点 - Reddot8 ReddotType = 10008 //英雄----升级红点 前端处理 - Reddot9 ReddotType = 10009 //英雄----觉醒红点 前端处理 - Reddot10 ReddotType = 10010 //英雄----共鸣红点 前端处理 - Reddot11 ReddotType = 10011 //英雄----升星红点 前端处理 - Reddot12 ReddotType = 10012 //装备----可穿戴红点 前端处理 - Reddot13 ReddotType = 10013 //装备----可替换红点 前端处理 - Reddot14 ReddotType = 10014 //装备----可强化红点 前端处理 - Reddot15 ReddotType = 10015 //装备----可附魔红点 前端处理 - Reddot16 ReddotType = 10016 //装备----可洗炼红点 前端处理 Reddot17 ReddotType = 10017 //星座图----红点 Reddot18 ReddotType = 10018 //英雄招募----红点 // 前端处理 Reddot19 ReddotType = 10019 //竞技场----挑战红点 @@ -439,13 +454,6 @@ const ( Reddot23 ReddotType = 10023 //熊猫武馆----可挂机红点 Reddot24 ReddotType = 10024 //熊猫武馆----可升级红点 Reddot25 ReddotType = 10025 //熊猫武馆----可领取奖励红点 - Reddot26 ReddotType = 10026 //邮件-----附件红点 - Reddot27 ReddotType = 10027 //任务----日常活跃奖励红点 - Reddot28 ReddotType = 10028 //任务----周常活跃奖励红点 - Reddot29 ReddotType = 10029 //公会----申请红点 - Reddot30 ReddotType = 10030 //邮件-----未读邮件红点 - Reddot31 ReddotType = 10031 //维京远征 有挑战次数 - Reddot32 ReddotType = 10032 //狩猎 有挑战次数 Reddot33 ReddotType = 10033 //附魔副本 有挑战次数 ) diff --git a/comm/imodule.go b/comm/imodule.go index 969eb1c49..28fc5da37 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -234,23 +234,7 @@ type ( IReddot } - // 随机任务 - IRtask interface { - // 条件校验 - CheckCondi(uid string, condiId int32, p ...int32) (errdata *pb.ErrorData) - // 多条件校验 - CheckCondis(uid string, condiIds ...int32) (condIds []int32) - // 远程任务条件校验 - RemoteCheckCondi(uid string, condiId int32, rsp *pb.DBRtaskRecord) error - // 删除任务条件数据 - RemoveCondi(uid string, condiId int32) error - // 更新任务条件数据 - ChangeCondi(uid string, data map[int32]*pb.RtaskData) error - //任务批量触发 - TriggerTask(uid string, taskParams ...*TaskParam) - // 获取任务条件记录 - GetCondiData(uid string) *pb.DBRtaskRecord - } + //好友 IFriend interface { diff --git a/comm/pool.go b/comm/pool.go index 0d514f6e7..f14642792 100644 --- a/comm/pool.go +++ b/comm/pool.go @@ -5,25 +5,6 @@ import ( "sync" ) -var taskParamPool = &sync.Pool{ - New: func() interface{} { - return &TaskParam{} - }, -} - -//GetBuriedParam -func GetTaskParam(t TaskType, p ...int32) *TaskParam { - task := taskParamPool.Get().(*TaskParam) - task.TT = t - task.Params = append(task.Params, p...) - return task -} - -func PuttaskParam(r *TaskParam) { - r.Params = r.Params[:0] - taskParamPool.Put(r) -} - var buriedParamPool = &sync.Pool{ New: func() interface{} { return &pb.BuriedParam{ diff --git a/lego/sys/timewheel/timewheel.go b/lego/sys/timewheel/timewheel.go index ff0bda215..4dd421394 100644 --- a/lego/sys/timewheel/timewheel.go +++ b/lego/sys/timewheel/timewheel.go @@ -2,6 +2,8 @@ package timewheel import ( "context" + "go_dreamfactory/lego/sys/log" + "runtime" "sync" "sync/atomic" "time" @@ -117,8 +119,7 @@ func (this *TimeWheel) Stop() { this.stopC <- struct{}{} } - -//此处写法 为监控时间轮是否正常执行 +//此处写法 为监控时间轮是否正常执行 func (this *TimeWheel) tickGenerator() { if this.tickQueue == nil { return @@ -184,10 +185,10 @@ func (this *TimeWheel) handleTick() { } if task.async { - go task.callback(task, task.args...) + go this.calltask(task, task.args...) } else { // optimize gopool - task.callback(task, task.args...) + this.calltask(task, task.args...) } // circle @@ -209,6 +210,18 @@ func (this *TimeWheel) handleTick() { this.currentIndex++ } +//执行时间轮事件 捕捉异常错误 防止程序崩溃 +func (this *TimeWheel) calltask(task *Task, args ...interface{}) { + defer func() { //程序异常 收集异常信息传递给前端显示 + if r := recover(); r != nil { + buf := make([]byte, 4096) + l := runtime.Stack(buf, false) + log.Errorf("timewheel err:%s", string(buf[0:l])) + } + }() + task.callback(task, task.args...) +} + func (this *TimeWheel) addAny(delay time.Duration, circle, async bool, callback func(*Task, ...interface{}), agr ...interface{}) *Task { if delay <= 0 { delay = this.tick diff --git a/modules/hunting/module.go b/modules/hunting/module.go index 8216ba121..d29081b5d 100644 --- a/modules/hunting/module.go +++ b/modules/hunting/module.go @@ -172,8 +172,8 @@ func (this *Hunting) Reddot(session comm.IUserSession, rid ...comm.ReddotType) ( reddot = make(map[comm.ReddotType]bool) for _, v := range rid { switch v { - case comm.Reddot32: - reddot[comm.Reddot32] = this.modelHunting.checkReddot32(session) + case comm.Reddot14102: + reddot[comm.Reddot14102] = this.modelHunting.checkReddot32(session) break } } diff --git a/modules/mail/module.go b/modules/mail/module.go index acfedc136..58d9d527c 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -106,18 +106,18 @@ func (this *Mail) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (red reddot = make(map[comm.ReddotType]bool) for _, v := range rid { switch v { - case comm.Reddot26: + case comm.Reddot12101: if isredot := this.modelMail.checkReddot26(session.GetUserId()); isredot { - reddot[comm.Reddot26] = true + reddot[comm.Reddot12101] = true } else { - reddot[comm.Reddot26] = false + reddot[comm.Reddot12101] = false } break - case comm.Reddot30: + case comm.Reddot12102: if isredot := this.modelMail.checkReddot30(session.GetUserId()); isredot { - reddot[comm.Reddot30] = true + reddot[comm.Reddot12102] = true } else { - reddot[comm.Reddot30] = false + reddot[comm.Reddot12102] = false } break } diff --git a/modules/mline/module.go b/modules/mline/module.go index f01d80d1d..701beedda 100644 --- a/modules/mline/module.go +++ b/modules/mline/module.go @@ -53,8 +53,8 @@ func (this *Mline) Start() (err error) { func (this *Mline) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) { reddot = make(map[comm.ReddotType]bool) for _, v := range rid { - if v == comm.Reddot5 { - reddot[comm.Reddot5] = this.CheckPoint(session.GetUserId()) + if v == comm.Reddot11100 { + reddot[comm.Reddot11100] = this.CheckPoint(session.GetUserId()) break } } diff --git a/modules/notify/core.go b/modules/notify/core.go index a3131f139..8df44855e 100644 --- a/modules/notify/core.go +++ b/modules/notify/core.go @@ -1 +1,8 @@ package notify + +import "go_dreamfactory/lego/sys/timewheel" + +//定时通知 +type timernotify struct { + rtask *timewheel.Task +} diff --git a/modules/notify/module.go b/modules/notify/module.go index 9368783d1..6a61a2a45 100644 --- a/modules/notify/module.go +++ b/modules/notify/module.go @@ -4,6 +4,8 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" + "go_dreamfactory/pb" + "time" ) /* @@ -40,3 +42,9 @@ func (this *Notify) OnInstallComp() { this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp) this.modelNotify = this.RegisterComp(new(modelNotifyComp)).(*modelNotifyComp) } + +//添加定时通知消息 +func (this *Notify) AddTimerNotify(uid string, ntype comm.NotifyType, delay time.Duration) (errdata *pb.ErrorData) { + + return +} diff --git a/modules/notify/notify_timer.go b/modules/notify/notify_timer.go new file mode 100644 index 000000000..145947161 --- /dev/null +++ b/modules/notify/notify_timer.go @@ -0,0 +1,73 @@ +package notify + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/core/cbase" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/sys/timewheel" + "go_dreamfactory/pb" + "time" +) + +///定时通知组件 +type notifyTimer struct { + cbase.ModuleCompBase + module *Notify + timers map[string]map[comm.NotifyType]*timernotify +} + +//组件初始化接口 +func (this *notifyTimer) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { + this.ModuleCompBase.Init(service, module, comp, opt) + this.timers = make(map[string]map[comm.NotifyType]*timernotify) + return +} + +func (this *notifyTimer) addTimerNotify(uid string, ntype comm.NotifyType, delay time.Duration) (errdata *pb.ErrorData) { + var ( + utimers map[comm.NotifyType]*timernotify + timer *timernotify + ok bool + ) + if utimers, ok = this.timers[uid]; !ok { + this.timers[uid] = make(map[comm.NotifyType]*timernotify) + utimers = this.timers[uid] + } + if timer, ok = utimers[ntype]; !ok { //还没有定时任务 + utimers[ntype] = &timernotify{} + utimers[ntype].rtask = timewheel.Add(delay, this.timerNotify, uid, ntype) + } else { + timewheel.Remove(utimers[ntype].rtask) + timer.rtask = timewheel.Add(delay, this.timerNotify, uid, ntype) + } + return +} + +func (this *notifyTimer) timerNotify(task *timewheel.Task, args ...interface{}) { + if len(args) != 2 { + this.module.Error("异常定时通知消息", log.Field{Key: "args", Value: args}) + return + } + var ( + uid string + ntype comm.NotifyType + utimers map[comm.NotifyType]*timernotify + ok bool + ) + uid = args[0].(string) + ntype = args[1].(comm.NotifyType) + if utimers, ok = this.timers[uid]; !ok { + return + } + if _, ok = utimers[ntype]; !ok { //还没有定时任务 + return + } + delete(utimers, ntype) + + switch ntype { + case comm.Notify1001: + break + } + +} diff --git a/modules/reddot/api_get.go b/modules/reddot/api_get.go index 17c898325..b7fa1b12a 100644 --- a/modules/reddot/api_get.go +++ b/modules/reddot/api_get.go @@ -23,19 +23,19 @@ func (this *apiComp) Get(session comm.IUserSession, req *pb.ReddotGetReq) (errda // reddot[v] = false _rid := comm.ReddotType(rid) switch _rid { - case comm.Reddot1: + case comm.Reddot10101: for k, v := range this.module.ModuleTask.Reddot(session, _rid) { reddot[int32(k)] = v } - case comm.Reddot2: + case comm.Reddot10102: for k, v := range this.module.ModuleTask.Reddot(session, _rid) { reddot[int32(k)] = v } - case comm.Reddot3: + case comm.Reddot15102: for k, v := range this.module.ModuleSociaty.Reddot(session, _rid) { reddot[int32(k)] = v } - case comm.Reddot4: + case comm.Reddot10103: for k, v := range this.module.ModuleTask.Reddot(session, _rid) { reddot[int32(k)] = v } @@ -55,16 +55,16 @@ func (this *apiComp) Get(session comm.IUserSession, req *pb.ReddotGetReq) (errda for k, v := range this.module.gourmet.Reddot(session, _rid) { reddot[int32(k)] = v } - case comm.Reddot26, comm.Reddot30: + case comm.Reddot12101, comm.Reddot12102: for k, v := range this.module.mail.Reddot(session, _rid) { reddot[int32(k)] = v } - case comm.Reddot31: + case comm.Reddot13102: for k, v := range this.module.viking.Reddot(session, _rid) { reddot[int32(k)] = v } - case comm.Reddot32: + case comm.Reddot14102: for k, v := range this.module.hunting.Reddot(session, _rid) { reddot[int32(k)] = v } diff --git a/modules/reddot/api_getall.go b/modules/reddot/api_getall.go index 64afa81f2..209cda992 100644 --- a/modules/reddot/api_getall.go +++ b/modules/reddot/api_getall.go @@ -19,11 +19,11 @@ func (this *apiComp) GetAll(session comm.IUserSession, req *pb.ReddotGetAllReq) if errdata = this.GetAllCheck(session, req); errdata != nil { return } - for k, v := range this.module.ModuleTask.Reddot(session, comm.Reddot1, comm.Reddot2, comm.Reddot4, comm.Reddot27, - comm.Reddot28) { + for k, v := range this.module.ModuleTask.Reddot(session, comm.Reddot10101, comm.Reddot10102, comm.Reddot10103, comm.Reddot10201, + comm.Reddot10301) { reddot[int32(k)] = v } - for k, v := range this.module.mline.Reddot(session, comm.Reddot5) { + for k, v := range this.module.mline.Reddot(session, comm.Reddot11100) { reddot[int32(k)] = v } for k, v := range this.module.pagoda.Reddot(session, comm.Reddot6) { @@ -42,17 +42,17 @@ func (this *apiComp) GetAll(session comm.IUserSession, req *pb.ReddotGetAllReq) reddot[int32(k)] = v } - for k, v := range this.module.sociaty.Reddot(session, comm.Reddot3, comm.Reddot29) { + for k, v := range this.module.sociaty.Reddot(session, comm.Reddot15102, comm.Reddot15201) { reddot[int32(k)] = v } - for k, v := range this.module.mail.Reddot(session, comm.Reddot26, comm.Reddot30) { + for k, v := range this.module.mail.Reddot(session, comm.Reddot12101, comm.Reddot12102) { reddot[int32(k)] = v } - for k, v := range this.module.viking.Reddot(session, comm.Reddot31) { + for k, v := range this.module.viking.Reddot(session, comm.Reddot13102) { reddot[int32(k)] = v } - for k, v := range this.module.hunting.Reddot(session, comm.Reddot32) { + for k, v := range this.module.hunting.Reddot(session, comm.Reddot14102) { reddot[int32(k)] = v } diff --git a/modules/sociaty/module.go b/modules/sociaty/module.go index 560db1f5a..ba2493ae5 100644 --- a/modules/sociaty/module.go +++ b/modules/sociaty/module.go @@ -154,11 +154,11 @@ func (this *Sociaty) Reddot(session comm.IUserSession, rid ...comm.ReddotType) ( } for _, v := range rid { switch v { - case comm.Reddot3: + case comm.Reddot15102: tf := this.modelSociaty.IsSign(session.GetUserId(), sociaty) - reddot[comm.Reddot3] = !tf - case comm.Reddot29: - reddot[comm.Reddot29] = applyReddot + reddot[comm.Reddot15102] = !tf + case comm.Reddot15201: + reddot[comm.Reddot15201] = applyReddot } } } diff --git a/modules/task/module.go b/modules/task/module.go index c305084da..001ebd43d 100644 --- a/modules/task/module.go +++ b/modules/task/module.go @@ -143,22 +143,22 @@ func (this *ModuleTask) Reddot(session comm.IUserSession, rid ...comm.ReddotType for _, v := range rid { switch v { - case comm.Reddot1: + case comm.Reddot10101: tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_DAILY) - reddot[comm.Reddot1] = tf - case comm.Reddot2: + reddot[comm.Reddot10101] = tf + case comm.Reddot10102: tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_WEEKLY) - reddot[comm.Reddot2] = tf + reddot[comm.Reddot10102] = tf - case comm.Reddot4: + case comm.Reddot10103: tf, _ := this.modelTask.noReceiveTask(session.GetUserId(), comm.TASK_ACHIEVE) - reddot[comm.Reddot4] = tf - case comm.Reddot27: + reddot[comm.Reddot10103] = tf + case comm.Reddot10201: tf, _ := this.modelTaskActive.noReceiveTaskActive(session.GetUserId(), comm.TASK_DAILY) - reddot[comm.Reddot27] = tf - case comm.Reddot28: + reddot[comm.Reddot10201] = tf + case comm.Reddot10301: tf, _ := this.modelTaskActive.noReceiveTaskActive(session.GetUserId(), comm.TASK_WEEKLY) - reddot[comm.Reddot28] = tf + reddot[comm.Reddot10301] = tf } } return diff --git a/modules/viking/module.go b/modules/viking/module.go index 7b65a55a9..d16ee5938 100644 --- a/modules/viking/module.go +++ b/modules/viking/module.go @@ -180,8 +180,8 @@ func (this *Viking) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (r reddot = make(map[comm.ReddotType]bool) for _, v := range rid { switch v { - case comm.Reddot31: - reddot[comm.Reddot31] = this.modelViking.checkReddot31(session) + case comm.Reddot13102: + reddot[comm.Reddot13102] = this.modelViking.checkReddot31(session) break }