示例#1
0
        /// <summary>
        /// Check if the channel is one the local player is listening to
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="recipient"></param>
        /// <returns></returns>
        private RemoteChannel?IsChannelToLocalPlayer(ChannelBitField channel, ushort recipient)
        {
            var options = new PlaybackOptions(channel.IsPositional, channel.AmplitudeMultiplier, channel.Priority);

            if (channel.Type == ChannelType.Player)
            {
                //If the channel is not to the local player we don't care about it
                if (recipient != _localId)
                {
                    return(null);
                }

                return(new RemoteChannel(_localName, ChannelType.Player, options));
            }
            else if (channel.Type == ChannelType.Room)
            {
                //This only returns the name for rooms we're currently listening to
                var roomName = _localListeningRooms.Name(recipient);
                if (roomName == null)
                {
                    return(null);
                }

                return(new RemoteChannel(roomName, ChannelType.Room, options));
            }
            else
            {
                //ncrunch: no coverage start (Justification: Impossible branch)
                throw Log.CreatePossibleBugException(string.Format("Unknown ChannelType variant '{0}'", channel.Type), "1884B2CF-35AA-46BD-93C7-80F14D8D25D8");
                //ncrunch: no coverage end
            }
        }
示例#2
0
        public void ProcessVoiceData(TPeer source, ref PacketReader reader)
        {
            //Read the fixed size header
            byte   options;
            ushort senderId, sequenceNumber, numChannels;

            reader.ReadVoicePacketHeader(out options, out senderId, out sequenceNumber, out numChannels);

            //Read out the list of recipients for this voice packet
            _recipientsBuffer.Clear();
            for (var i = 0; i < numChannels; i++)
            {
                var channelBitfield  = reader.ReadByte();
                var channelRecipient = reader.ReadUInt16();

                var channel = new ChannelBitField(channelBitfield);

                //Populate the _recipientsBuffer with peers listening to the channel
                GetChannelPeers(channel.Type, channelRecipient);
            }

            //Remove source peer from recipients buffer (we don't want to send voice back to where it came from)
            _recipientsBuffer.Remove(source);

            for (var i = 0; i < _recipientsBuffer.Count; i++)
            {
                _server.SendUnreliable(_recipientsBuffer[i], reader.All);
            }
        }
示例#3
0
        private bool ChannelAddressesUs(ChannelBitField channel, ushort recipient)
        {
            if (channel.Type == ChannelType.Player)
            {
                return(recipient == _client.LocalId);
            }

            return(_rooms.Contains(recipient));
        }
示例#4
0
        private void ReadChannelStates(ref PacketReader reader, ReceivingState state, ushort numChannels, out bool positional, out bool allClosing, out bool forceReset, out ChannelPriority priority)
        {
            positional = true;
            allClosing = true;
            int forcingReset = 0;

            priority = ChannelPriority.None;

            for (var i = 0; i < numChannels; i++)
            {
                byte   channelBitfield;
                ushort channelRecipient;
                reader.ReadVoicePacketChannel(out channelBitfield, out channelRecipient);
                var channel = new ChannelBitField(channelBitfield);

                var compositeId = (int)(channel.Type) | channelRecipient << 8;
                _tmpCompositeIdBuffer.Add(compositeId);

                int previousSession;
                if (state.ExpectedPerChannelSessions.TryGetValue(compositeId, out previousSession))
                {
                    if (previousSession != channel.SessionId)
                    {
                        forcingReset++;
                    }
                }
                state.ExpectedPerChannelSessions[compositeId] = channel.SessionId;

                if (ChannelAddressesUs(channel, channelRecipient))
                {
                    if (!channel.IsPositional)
                    {
                        positional = false;
                    }

                    if (!channel.IsClosing)
                    {
                        allClosing = false;
                    }

                    if (channel.Priority > priority)
                    {
                        priority = channel.Priority;
                    }
                }
            }

            forceReset = forcingReset == numChannels;
            state.ClearChannels(_tmpCompositeIdBuffer);
            _tmpCompositeIdBuffer.Clear();
        }