From 714da99c0119bd0bfcb0359f17288b9c175d4a76 Mon Sep 17 00:00:00 2001 From: liwei Date: Mon, 19 Sep 2022 17:23:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=85=8D=E7=BD=AE=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E6=B2=A1=E6=9C=89=E5=AE=9A=E6=97=B6=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/stup.sh | 10 ++++++---- modules/gateway/agentmgr_comp.go | 5 ++++- modules/timer/chat.go | 21 +++++++++++---------- sys/configure/configure.go | 5 ++++- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/bin/stup.sh b/bin/stup.sh index 2cfde666f..b24bc4c4e 100755 --- a/bin/stup.sh +++ b/bin/stup.sh @@ -9,13 +9,14 @@ if [ $num -eq 0 ] then nohup $CMD > /dev/null 2>&1 & - # nohup $CMD >output.log 2>&1 & + #nohup $CMD > $SERVICE.log 2>&1 & if [ $? -ne 0 ] then echo "start failed, please check the log!" exit $? else - echo $! > $SERVICE.pid + + # echo $! > $SERVICE.pid echo "start success" fi else @@ -26,13 +27,14 @@ } stop(){ echo "stopping $SERVICE..." - kill -9 `cat $SERVICE.pid` + #kill -9 `cat $SERVICE.pid` + kill -9 `ps -ef | grep $SERVICE | grep conf | awk '{print $2}'` if [ $? -ne 0 ] then echo "stop failed, may be $SERVICE isn't running" exit $? else - rm -rf $SERVICE.pid + #rm -rf $SERVICE.pid echo "stop success" fi } diff --git a/modules/gateway/agentmgr_comp.go b/modules/gateway/agentmgr_comp.go index fe4960c80..cf2a15027 100644 --- a/modules/gateway/agentmgr_comp.go +++ b/modules/gateway/agentmgr_comp.go @@ -155,7 +155,10 @@ func (this *AgentMgrComp) SendMsgToAllAgent(ctx context.Context, args *pb.BroadC } this.module.Debugf("SendMsgToAllAgent: msg:%v", msg) this.agents.Range(func(key, value any) bool { - value.(IAgent).WriteMsg(msg) + agent := value.(IAgent) + if agent.UserId() != "" { //只发送登录用户 + agent.WriteMsg(msg) + } return true }) return nil diff --git a/modules/timer/chat.go b/modules/timer/chat.go index 7d3a29f38..0378db445 100644 --- a/modules/timer/chat.go +++ b/modules/timer/chat.go @@ -12,6 +12,7 @@ import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/cron" + "go_dreamfactory/lego/sys/log" "google.golang.org/protobuf/types/known/anypb" ) @@ -52,29 +53,28 @@ func (this *ChatComp) Start() (err error) { } else { var id cron.EntryID this.takes = make([]cron.EntryID, 0) - for _, v := range v.(*cfg.GameChatSystem).GetDataList() { - if v.Type == int32(comm.TimedNotice) { //处理定时任务 + confs := v.(*cfg.GameChatSystem) + + for k, v1 := range confs.GetDataMap() { + if v1.Type == int32(comm.TimedNotice) { //处理定时任务 weekStr := "" - for _, w := range v.Week { + for _, w := range v1.Week { weekStr += fmt.Sprintf("%d,", w) } - if len(weekStr) > 0 && len(weekStr) < 7 { + if len(v1.Week) > 0 && len(v1.Week) < 7 { weekStr = weekStr[0 : len(weekStr)-1] } else { weekStr = "*" } - cronStr := fmt.Sprintf("* %d %d * * %s", v.TimeM, v.TimeH, weekStr) - if id, err = cron.AddFunc(cronStr, this.chatNoticen(v)); err != nil { + cronStr := fmt.Sprintf("* %d %d * * %s", v1.TimeM, v1.TimeH, weekStr) + this.module.Debug("注册Chat广播公告消息", log.Field{Key: "cronStr", Value: cronStr}, log.Field{Key: "text", Value: v1.Text}) + if id, err = cron.AddFunc(cronStr, this.chatNoticen(confs.GetDataMap()[k])); err != nil { this.module.Errorf("cron.AddFunc:%s err:%v", cronStr, err) continue } this.takes = append(this.takes, id) } } - //测试代码 - // if id, err = cron.AddFunc("0 */1 * * * ?", this.chatNoticen(&cfg.GameChatSystemData{Text: "测试公告系统"})); err != nil { - // this.module.Errorf("cron.AddFunc:%s err:%v", "0 */1 * * * ?", err) - // } } }) return @@ -89,6 +89,7 @@ func (this *ChatComp) chatNoticen(n *cfg.GameChatSystemData) func() { Content: n.Text, } data, _ := anypb.New(&pb.ChatMessagePush{Chat: msg}) + this.module.Debug("广播公告消息", log.Field{Key: "chat", Value: msg}) if err := this.module.service.AcrossClusterBroadcast(context.Background(), msg.Stag, comm.Service_Gateway, string(comm.Rpc_GatewaySendRadioMsg), pb.UserMessage{ MainType: string(comm.ModuleChat), SubType: "message", diff --git a/sys/configure/configure.go b/sys/configure/configure.go index c9c833370..e569cce41 100644 --- a/sys/configure/configure.go +++ b/sys/configure/configure.go @@ -47,7 +47,6 @@ type Configure struct { func (this *Configure) Start() (err error) { timer := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval)) - defer timer.Stop() go func() { locp: for { @@ -58,6 +57,7 @@ func (this *Configure) Start() (err error) { this.checkConfigure() } } + timer.Stop() }() return @@ -177,6 +177,7 @@ func (this *Configure) loaderConfigure(name string, handle *configurehandle) (er //检查配置文件是否有更新 func (this *Configure) checkConfigure() { + log.Debug("Check Configure Update") if dir, err := ioutil.ReadDir(this.options.ConfigurePath); err != nil { log.Errorf("[Configure Sys] checkConfigure err:%v", err) } else { @@ -190,8 +191,10 @@ func (this *Configure) checkConfigure() { handle := this.configurehandles[v.Name] this.hlock.RUnlock() if err = this.loaderConfigure(v.Name, handle); err != nil { + log.Errorln(err) return } + log.Debug("UpDate Configure", log.Field{Key: "table", Value: v.Name}) for _, v := range handle.events { if v != nil { go func(f func()) {