Ejemplo n.º 1
0
        public void broadcast(string msg, ProtocolSICmdType cmd, string except = "") //Faz um broadcast para todos os jogadores
        {
            connection.WaitOne();                                                    //Adquire controle do networkStream
            byte[]        msgToSend;
            NetworkStream networkStream = tcpClient.GetStream();

            foreach (ClientHandler client in room.getClientList())
            {
                if (!client.nomeJogador.Equals(except))
                {
                    NetworkStream newNetworkStream = client.tcpClient.GetStream(); //Cria uma nova via de comunicação para o client

                    byte[] ack = protocolSI.Make(ProtocolSICmdType.ACK);
                    newNetworkStream.Write(ack, 0, ack.Length);

                    msgToSend = protocolSI.Make(cmd, client.security.CifrarTexto(msg));
                    newNetworkStream.Write(msgToSend, 0, msgToSend.Length);
                    esperaACK();
                }
            }
            connection.ReleaseMutex(); //Libera o networkStream
        }