From 9ade1bb5a5b3b6a63190ad9b2fef7326692b5428 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 11 Aug 2022 12:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=81=8A=E5=A4=A9=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=B6=88=E6=81=AF=E7=BE=A4=E5=8F=91=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/chat/api_send.go | 2 +- modules/chat/modelChat.go | 10 ++++++++-- modules/modulebase.go | 12 ++++++------ modules/options.go | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/chat/api_send.go b/modules/chat/api_send.go index 655c15879..cb0aca940 100644 --- a/modules/chat/api_send.go +++ b/modules/chat/api_send.go @@ -85,7 +85,7 @@ func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code return } msg.ChannelId = userexpand.Chatchannel //指定频道 - if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s:%d", crosschatkey, userexpand.Chatchannel), int64(max_chat), msg); err != nil { + if err = this.module.modelChat.addChatMsg(fmt.Sprintf("%s-%d", crosschatkey, userexpand.Chatchannel), int64(max_chat), msg); err != nil { code = pb.ErrorCode_DBError return } diff --git a/modules/chat/modelChat.go b/modules/chat/modelChat.go index d9d5c8672..87faa28d1 100644 --- a/modules/chat/modelChat.go +++ b/modules/chat/modelChat.go @@ -189,11 +189,17 @@ func (this *modelChatComp) ChanageChannel(session comm.IUserSession, channel int //读取跨服聊天频道下成员 func (this *modelChatComp) GetCrossChannelMember(channel int32) (result []*pb.CacheUser, err error) { key := fmt.Sprintf("%s-%d-member", crosschatkey, channel) - result = make([]*pb.CacheUser, 0) - if err = this.Redis.HGetAll(key, &result); err != nil { + temp := make(map[string]*pb.CacheUser, 0) + if err = this.Redis.HGetAll(key, &temp); err != nil { this.module.Errorf("err:%v", err) return } + n := 0 + result = make([]*pb.CacheUser, len(temp)) + for _, v := range temp { + result[n] = v + n++ + } return } diff --git a/modules/modulebase.go b/modules/modulebase.go index 992ec4b3a..47b41fc58 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -111,30 +111,30 @@ func (this *ModuleBase) SendMsgToUser(mainType, subType string, msg proto.Messag func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Message, user ...*pb.CacheUser) (err error) { var ( gateways map[string]map[string][]string = make(map[string]map[string][]string) - cluster map[string][]string + cluster map[string][]string = make(map[string][]string) gateway []string ok bool ) for _, v := range user { if cluster, ok = gateways[v.ServiceTag]; !ok { - gateways[v.ServiceTag] = make(map[string][]string) + cluster = make(map[string][]string) + gateways[v.ServiceTag] = cluster } if gateway, ok = cluster[v.GatewayServiceId]; !ok { gateway = make([]string, 0) cluster[v.GatewayServiceId] = gateway } - gateway = append(gateway, v.SessionId) + cluster[v.GatewayServiceId] = append(cluster[v.GatewayServiceId], v.SessionId) } - reply := &pb.RPCMessageReply{} data, _ := anypb.New(msg) for k, v := range gateways { for k1, v1 := range v { - if _, err = this.service.AcrossClusterRpcGo(context.Background(), k1, fmt.Sprintf("%s/%s", comm.Service_Gateway, k), string(comm.Rpc_GatewayAgentSendMsg), &pb.BatchMessageReq{ + if _, err = this.service.AcrossClusterRpcGo(context.Background(), k, fmt.Sprintf("%s/%s", comm.Service_Gateway, k1), string(comm.Rpc_GatewaySendBatchMsg), &pb.BatchMessageReq{ UserSessionIds: v1, MainType: mainType, SubType: subType, Data: data, - }, reply); err != nil { + }, nil); err != nil { log.Errorf("SendMsgToUsers:%s.%s->%s.%s err:%v", k1, k, mainType, subType, err) } } diff --git a/modules/options.go b/modules/options.go index 2922bb262..d0ef44696 100644 --- a/modules/options.go +++ b/modules/options.go @@ -33,7 +33,7 @@ func (this *Options) LoadConfig(settings map[string]interface{}) (err error) { err = mapstructure.Decode(settings, this) } - if this.Log = log.NewTurnlog(this.Debug, log.Clone("", 3)); this.Log == nil { + if this.Log = log.NewTurnlog(this.Debug, log.Clone("", 4)); this.Log == nil { err = errors.New("log is nil") } return