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) + } + } } }