private void UpdateRecording()
        {
            uint size   = 0;
            var  result = (m_VoIP.GetAvailableVoice(out size));

            if (result == VoiceResult.OK)
            {
                result = m_VoIP.GetVoice(m_compressedVoiceBuffer, out size);
                Debug.Assert(result == VoiceResult.OK, "Get voice failed: " + result.ToString());

                if (MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
                {
                    ProcessBuffer(m_compressedVoiceBuffer, (int)size, Sync.MyId);
                }

                foreach (var player in Sync.Players.GetOnlinePlayers())
                {
                    if (player.Id.SerialId == 0 &&
                        player.Id.SteamId != MySession.Static.LocalHumanPlayer.Id.SteamId &&
                        IsCharacterValid(player.Character) &&
                        m_voiceChatLogic.ShouldSendVoice(player) &&
                        !MySandboxGame.Config.DontSendVoicePlayers.Contains(player.Id.SteamId))   // check if that user wants messages from this user
                    {
                        SendBuffer buffer = new SendBuffer {
                            CompressedVoiceBuffer = m_compressedVoiceBuffer,
                            NumElements           = (int)(size / sizeof(byte)),
                            SenderUserId          = (long)MySession.Static.LocalHumanPlayer.Id.SteamId
                        };

                        if (Sync.IsServer)
                        {
                            MyMultiplayer.RaiseStaticEvent(x => SendVoicePlayer, player.Id.SteamId, (BitReaderWriter)buffer, new EndpointId(player.Id.SteamId));
                        }
                        else
                        {
                            MyMultiplayer.RaiseStaticEvent(x => SendVoice, player.Id.SteamId, (BitReaderWriter)buffer);
                        }

                        if (MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
                        {
                            m_debugSentVoice[player.Id.SteamId] = true;
                        }
                    }
                    else
                    {
                        if (MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
                        {
                            m_debugSentVoice[player.Id.SteamId] = false;
                        }
                    }
                }
            }
            else if (result == VoiceResult.NotRecording)
            {
                m_recording = false;

                if (MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
                {
                    var localUser = Sync.MyId;
                    if (!m_voices.ContainsKey(localUser))
                    {
                        var player = Sync.Players.GetPlayerById(new MyPlayer.PlayerId(localUser));
                        m_voices[localUser] = new MyEntity3DSoundEmitter(player.Character);
                    }

                    var emitter = m_voices[localUser];
                    if (m_receivedVoiceData.ContainsKey(localUser))
                    {
                        var data = m_receivedVoiceData[localUser];
                        emitter.PlaySound(data.UncompressedBuffer.ToArray(), (int)data.UncompressedBuffer.Count, m_VoIP.SampleRate);
                        data.ClearData();
                        data.ClearSpeakerTimestamp();
                        m_receivedVoiceData[localUser] = data;
                    }
                }
            }
        }
Exemple #2
0
        private void UpdateRecording()
        {
            uint size   = 0;
            var  result = (m_VoIP.GetAvailableVoice(out size));

            if (result == VoiceResult.OK)
            {
                result = m_VoIP.GetVoice(m_compressedVoiceBuffer, out size);
                Debug.Assert(result == VoiceResult.OK, "Get voice failed: " + result.ToString());

                if (MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
                {
                    ProcessBuffer(m_compressedVoiceBuffer, (int)size, MySteam.UserId);
                }

                foreach (var player in Sync.Players.GetOnlinePlayers())
                {
                    if (player.Id.SerialId == 0 &&
                        player.Id.SteamId != MySession.LocalHumanPlayer.Id.SteamId &&
                        IsCharacterValid(player.Character) &&
                        m_voiceChatLogic.ShouldSendVoice(player))
                    {
                        SendVoice(player.Id.SteamId, m_compressedVoiceBuffer, size);
                        if (MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
                        {
                            m_debugSentVoice[player.Id.SteamId] = true;
                        }
                    }
                    else
                    {
                        if (MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
                        {
                            m_debugSentVoice[player.Id.SteamId] = false;
                        }
                    }
                }
            }
            else if (result == VoiceResult.NotRecording)
            {
                m_recording = false;

                if (MyFakes.ENABLE_VOICE_CHAT_DEBUGGING)
                {
                    var localUser = MySteam.UserId;
                    if (!m_voices.ContainsKey(localUser))
                    {
                        var player = Sync.Players.TryGetPlayerById(new MyPlayer.PlayerId(localUser));
                        m_voices[localUser] = new MyEntity3DSoundEmitter(player.Character);
                    }

                    var emitter = m_voices[localUser];
                    if (m_receivedVoiceData.ContainsKey(localUser))
                    {
                        var data = m_receivedVoiceData[localUser];
                        emitter.PlaySound(data.UncompressedBuffer.ToArray(), (int)data.UncompressedBuffer.Count, m_VoIP.SampleRate);
                        data.ClearData();
                        data.ClearSpeakerTimestamp();
                        m_receivedVoiceData[localUser] = data;
                    }
                }
            }
        }