diff --git a/comm/imodule.go b/comm/imodule.go index 5820e358e..11cf85e31 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -20,7 +20,7 @@ type ( } //功能开启通知 IOpenCmdNotice interface { - OpenCmdNotice(uid string, keys ...string) + OpenCmdNotice(session IUserSession, keys ...string) } // 活动通知 IActivityNotice interface { @@ -583,6 +583,7 @@ type ( } //每日任务 IDailytask interface { + IOpenCmdNotice IGetReddot //任务组完成 TaskGroupComplete(session IUserSession, group int32) diff --git a/modules/dailytask/module.go b/modules/dailytask/module.go index 8abe429f2..a46fa8df9 100644 --- a/modules/dailytask/module.go +++ b/modules/dailytask/module.go @@ -46,7 +46,7 @@ func (this *Dailytask) Start() (err error) { return } this.wtask = module.(comm.IWtask) - event.RegisterGO(comm.EventUserLogin, this.EventUserLogin) + event.Register(comm.EventUserLogin, this.EventUserLogin) return } @@ -61,56 +61,19 @@ func (this *Dailytask) OnInstallComp() { // 用户登录 func (this *Dailytask) EventUserLogin(session comm.IUserSession) { var ( - dtask *pb.DBDailytask - user *pb.DBUser errdata *pb.ErrorData - key int32 - group []int32 - tasks map[int32][]int32 - err error + isopen bool ) if db.IsCross() { //跨服不支持 return } - if dtask, err = this.modelDailytask.getUserDTasks(session.GetUserId()); err != nil { - this.Errorln(err) + if isopen, errdata = this.ModuleSys.CheckOpenCondCfgById(session.GetUserId(), "annulartask"); isopen { + this.Errorln(errdata) return } - - if !utils.IsToday(dtask.Rtime) { //不是同一天 重置 - if user, err = this.ModuleUser.GetUser(session.GetUserId()); err != nil { - this.Error("no found user", log.Field{Key: "uid", Value: session.GetUserId()}) - return - } - if key, group, err = this.modelDailytask.resetUserDTasks(user.Lv); err != nil { - this.Errorln(err) - return - } - if tasks, errdata = this.wtask.ResetDailytaskTask(session.Clone(), key, group...); errdata != nil { - this.Errorln(errdata) - return - } - dtask.Key = key - dtask.Groups = make([]*pb.DBDailytaskGroup, 0) - for k, v := range tasks { - dtask.Groups = append(dtask.Groups, &pb.DBDailytaskGroup{ - Group: k, - Tasks: v, - }) - } - dtask.Rtime = configure.Now().Unix() - if err = this.modelDailytask.Change(session.GetUserId(), map[string]interface{}{ - "key": dtask.Key, - "groups": dtask.Groups, - "rtime": dtask.Rtime, - }); err != nil { - this.Errorln(err) - return - } - } - + this.refreshtask(session) } // 任务组完成 @@ -137,6 +100,15 @@ func (this *Dailytask) TaskGroupComplete(session comm.IUserSession, group int32) } } +// 功能是否开启 +func (this *Dailytask) OpenCmdNotice(session comm.IUserSession, keys ...string) { + for _, v := range keys { + if v == "annulartask" { //日常功能开启 + this.refreshtask(session) + } + } +} + // 查询每日红点信息 func (this *Dailytask) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) { var ( @@ -168,3 +140,51 @@ func (this *Dailytask) Reddot(session comm.IUserSession, rid ...comm.ReddotType) } return } + +func (this *Dailytask) refreshtask(session comm.IUserSession) { + var ( + dtask *pb.DBDailytask + user *pb.DBUser + errdata *pb.ErrorData + key int32 + group []int32 + tasks map[int32][]int32 + err error + ) + if dtask, err = this.modelDailytask.getUserDTasks(session.GetUserId()); err != nil { + this.Errorln(err) + return + } + + if !utils.IsToday(dtask.Rtime) { //不是同一天 重置 + if user, err = this.ModuleUser.GetUser(session.GetUserId()); err != nil { + this.Error("no found user", log.Field{Key: "uid", Value: session.GetUserId()}) + return + } + if key, group, err = this.modelDailytask.resetUserDTasks(user.Lv); err != nil { + this.Errorln(err) + return + } + if tasks, errdata = this.wtask.ResetDailytaskTask(session, key, group...); errdata != nil { + this.Errorln(errdata) + return + } + dtask.Key = key + dtask.Groups = make([]*pb.DBDailytaskGroup, 0) + for k, v := range tasks { + dtask.Groups = append(dtask.Groups, &pb.DBDailytaskGroup{ + Group: k, + Tasks: v, + }) + } + dtask.Rtime = configure.Now().Unix() + if err = this.modelDailytask.Change(session.GetUserId(), map[string]interface{}{ + "key": dtask.Key, + "groups": dtask.Groups, + "rtime": dtask.Rtime, + }); err != nil { + this.Errorln(err) + return + } + } +} diff --git a/modules/practice/module.go b/modules/practice/module.go index 9ff4e1430..996384827 100644 --- a/modules/practice/module.go +++ b/modules/practice/module.go @@ -210,9 +210,9 @@ func (this *Practice) TaskComplete(session comm.IUserSession, taskid ...int32) { ) } -func (this *Practice) OpenCmdNotice(uid string, keys ...string) { +func (this *Practice) OpenCmdNotice(session comm.IUserSession, keys ...string) { this.Debug("OpenCmdNotice", - log.Field{Key: "session", Value: uid}, + log.Field{Key: "session", Value: session.GetUserId()}, log.Field{Key: "key", Value: keys}, ) if !this.IsCross() { @@ -220,7 +220,7 @@ func (this *Practice) OpenCmdNotice(uid string, keys ...string) { if v == "practice_ pillar1" || v == "practice_ pillar2" || v == "practice_ pillar3" { err := this.service.AcrossClusterRpcCall(context.Background(), this.GetCrossTag(), comm.Service_Worker, string(comm.RPC_ModulePracticeUnLockPillar), - &pb.RPCGeneralReqA2{Param1: uid, Param2: v}, &pb.EmptyResp{}) + &pb.RPCGeneralReqA2{Param1: session.GetUserId(), Param2: v}, &pb.EmptyResp{}) if err != nil { this.Errorln(err) return @@ -231,7 +231,7 @@ func (this *Practice) OpenCmdNotice(uid string, keys ...string) { } else { for _, v := range keys { if v == "practice_ pillar1" || v == "practice_ pillar2" || v == "practice_ pillar3" { - this.RPC_ModulePracticeUnLockPillar(context.Background(), &pb.RPCGeneralReqA2{Param1: uid, Param2: v}, &pb.EmptyResp{}) + this.RPC_ModulePracticeUnLockPillar(context.Background(), &pb.RPCGeneralReqA2{Param1: session.GetUserId(), Param2: v}, &pb.EmptyResp{}) } } } diff --git a/modules/sys/api_funcactivate.go b/modules/sys/api_funcactivate.go index db1f7b28d..7fe82dff8 100644 --- a/modules/sys/api_funcactivate.go +++ b/modules/sys/api_funcactivate.go @@ -65,18 +65,21 @@ func (this *apiComp) FuncActivate(session comm.IUserSession, req *pb.SysFuncActi return } - go this.module.wtask.OpenCmdNotice(session.GetUserId(), req.Cid) - //手动激活通知模块 - for _, m := range opencfg.Notify { - i, err := this.service.GetModule(core.M_Modules(m)) - if err != nil { - this.module.Errorln(err) - continue - } + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.wtask.OpenCmdNotice(session, req.Cid) + //手动激活通知模块 + for _, m := range opencfg.Notify { + i, err := this.service.GetModule(core.M_Modules(m)) + if err != nil { + this.module.Errorln(err) + continue + } - if ic, ok := i.(comm.IOpenCmdNotice); ok { - go ic.OpenCmdNotice(session.GetUserId(), req.Cid) + if ic, ok := i.(comm.IOpenCmdNotice); ok { + ic.OpenCmdNotice(session, req.Cid) + } } - } + }) + return } diff --git a/modules/sys/api_funcgetList.go b/modules/sys/api_funcgetList.go index 5d1c254e6..7a16fb903 100644 --- a/modules/sys/api_funcgetList.go +++ b/modules/sys/api_funcgetList.go @@ -76,9 +76,13 @@ func (this *apiComp) FuncGetList(session comm.IUserSession, req *pb.SysFuncGetLi "cond": list.Cond, }) } - if len(change) > 0 { - go this.module.wtask.OpenCmdNotice(session.GetUserId(), change...) - } session.SendMsg(string(this.module.GetType()), "funcgetlist", rsp) + + if len(change) > 0 { + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.wtask.OpenCmdNotice(session, change...) + }) + + } return } diff --git a/modules/turntable/module.go b/modules/turntable/module.go index 6d6422b03..48161b8ae 100644 --- a/modules/turntable/module.go +++ b/modules/turntable/module.go @@ -48,7 +48,7 @@ func (this *Turntable) Start() (err error) { if module, err = this.service.GetModule(comm.ModuleWarorder); err != nil { return } - event.RegisterGO(comm.EventUserLogin, this.EventUserLogin) + event.Register(comm.EventUserLogin, this.EventUserLogin) return } diff --git a/modules/wtask/module.go b/modules/wtask/module.go index ad4d2e4a6..6389489f9 100644 --- a/modules/wtask/module.go +++ b/modules/wtask/module.go @@ -154,7 +154,7 @@ func (this *WTask) BuriedsNotify(session comm.IUserSession, condis []*pb.ConIPro } // 功能开启 -func (this *WTask) OpenCmdNotice(uid string, keys ...string) { +func (this *WTask) OpenCmdNotice(session comm.IUserSession, keys ...string) { var ( opencmdTask map[string][]*cfg.GameWorldTaskData user *pb.DBUser @@ -169,21 +169,16 @@ func (this *WTask) OpenCmdNotice(uid string, keys ...string) { break } } - if user, err = this.ModuleUser.GetUser(uid); err != nil { - this.Error("获取用户信息失败!", log.Field{Key: "uid", Value: uid}) + if user, err = this.ModuleUser.GetUser(session.GetUserId()); err != nil { + this.Error("获取用户信息失败!", log.Field{Key: "uid", Value: session.GetUserId()}) return } - if wtask, err = this.modelwtask.getUserWTasks(uid); err != nil { - this.Error("获取世界任务数据 失败!", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()}) + if wtask, err = this.modelwtask.getUserWTasks(session.GetUserId()); err != nil { + this.Error("获取世界任务数据 失败!", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "err", Value: err.Error()}) return } - session, _ := this.GetUserSession(uid) - defer func() { - session.Push() - this.PutUserSession(session) - }() this.inquireActivations(session, wtask, user.Lv, keys, true) } @@ -277,11 +272,6 @@ func (this *WTask) ResetDailytaskTask(session comm.IUserSession, dailytaskid int boxchange bool ) - defer func() { - session.Push() - this.PutUserSession(session) - }() - results = make(map[int32][]int32) for _, v := range this.configure.getdesTask(1) { alltasks[v.Key] = v