/// <summary> /// 房间内消息广播 /// </summary> /// <param name="clientPeer"></param> /// <param name="roomId"></param> public void BroadcastMessageByRoomId(int roomId, SocketMessage message) { byte[] dataValueBytes = EncodeHelper.EncodeMessage(message); //第一次打包消息 byte[] sendMessageDataBytes = EncodeHelper.EncodeMessage(dataValueBytes); //第二次打包消息 foreach (RoomInfo roomItem in this._roomIdRooms.Values) //遍历所有房间 直到找到要广播消息的房间 { if (roomItem.Id == roomId) { List <ClientPeer> clientPeers = this._roomClientDict[roomItem]; for (int clientIndex = 0; clientIndex < clientPeers.Count; clientIndex++) { ClientPeer tmpClientPeer = clientPeers[clientIndex]; tmpClientPeer.SendMessage(sendMessageDataBytes); } } } }