From 3f30073a7d977b192d5997fb353aaa4debdad815 Mon Sep 17 00:00:00 2001 From: NorthLan <6995syu@163.com> Date: Mon, 16 May 2022 09:59:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E5=90=8C=E6=A0=B7=E7=BB=93=E6=9E=84=E5=AE=A2=E6=88=B7=E7=AB=AF?= =?UTF-8?q?=E5=8F=AA=E5=8F=91=E6=B6=88=E6=81=AF=E5=88=B0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/room/manager.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/game/room/manager.go b/game/room/manager.go index 07ca869..bca751f 100644 --- a/game/room/manager.go +++ b/game/room/manager.go @@ -15,7 +15,8 @@ import ( ) const ( - roomKey = "ROOM" + roomKey = "ROOM" + liveRoomIdKey = "LIVE_ROOM_ID" ) type ( @@ -74,12 +75,13 @@ func (m *Manager) Join(s *session.Session, msg *pbRoom.JoinRoomReq) error { room := m.RoomByGameType(msg.GameType) game.CacheGameType(msg.LiveRoomId, msg.GameType) - // uid - liveRoomId - err := s.Bind(msg.LiveRoomId) + // uid - uuid + err := s.Bind(uuid.NextId()) if err != nil { return err } s.Set(roomKey, room) + s.Set(liveRoomIdKey, msg.LiveRoomId) // members var resp = &pbRoom.JoinRoomResp{ @@ -136,14 +138,18 @@ func (m *Manager) Broadcast(route string, msg proto.Message) { // PushToLiveRoom 消息Push到直播间ID指定客户端 func (r *Room) PushToLiveRoom(liveRoomId int64, route string, msg proto.Message) { - sess, err := r.group.Member(liveRoomId) - if err != nil { - logger.SLog.Errorf("未找到直播间[%d]对应客户端", liveRoomId) - return - } - err = sess.Push(route, msg) - if err != nil { - logger.SLog.Errorf("推送消息到 直播间[%d] 失败, err:%+v", liveRoomId, err) + for _, sid := range r.group.Members() { + member, err := r.group.Member(sid) + if err != nil { + continue + } + lRId := member.Value(liveRoomIdKey).(int64) + if lRId == liveRoomId { + err = member.Push(route, msg) + if err != nil { + logger.SLog.Errorf("推送消息到 直播间[%d]客户端 失败, err:%+v", liveRoomId, err) + } + } } }