Example #1
0
        void SendPendingPackets()
        {
            //_listener.Send(bytes, bytes.Length, ip);
            while (!_stop)
            {
                try
                {
                    OutgoingVoice udpPacket = null;
                    _outGoing.TryTake(out udpPacket, 100000, _pendingProcessingCancellationToken.Token);

                    if (udpPacket != null)
                    {
                        var bytes       = udpPacket.ReceivedPacket;
                        var bytesLength = bytes.Length;
                        foreach (var outgoingEndPoint in udpPacket.OutgoingEndPoints)
                        {
                            try
                            {
                                _listener.Send(bytes, bytesLength, outgoingEndPoint);
                            }
                            catch (Exception ex)
                            {
                                //dont log, slows down too much...
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Info("Error processing Sending Queue UDP Packet: " + ex.Message);
                }
            }
        }
        private OutgoingVoice GenerateOutgoingPacket(UDPVoicePacket udpVoice, PendingPacket pendingPacket,
                                                     SRClient fromClient)
        {
            var outgoingList  = new List <IPEndPoint>();
            var outgoingVoice = new OutgoingVoice
            {
                OutgoingEndPoints = outgoingList,
                ReceivedPacket    = pendingPacket.RawBytes
            };

            var coalitionSecurity =
                _serverSettings.ServerSetting[(int)ServerSettingType.COALITION_AUDIO_SECURITY];
            var guid = fromClient.ClientGuid;

            foreach (var client in _clientsList)
            {
                if (!client.Key.Equals(guid))
                {
                    var ip = client.Value.VoipPort;

                    // check that either coalition radio security is disabled OR the coalitions match
                    if ((ip != null) && (!coalitionSecurity || (client.Value.Coalition == fromClient.Coalition)))
                    {
                        var radioInfo = client.Value.RadioInfo;

                        if (radioInfo != null)
                        {
                            RadioReceivingState radioReceivingState = null;
                            var receivingRadio = radioInfo.CanHearTransmission(udpVoice.Frequency,
                                                                               (RadioInformation.Modulation)udpVoice.Modulation,
                                                                               udpVoice.UnitId, out radioReceivingState);

                            //only send if we can hear!
                            if (receivingRadio != null)
                            {
                                outgoingList.Add(ip);
                            }
                        }
                    }
                }
                else
                {
                    var ip = client.Value.VoipPort;

                    if (ip != null)
                    {
                        // outgoingList.Add(ip);
                    }
                }
            }

            return(outgoingList.Count > 0 ? outgoingVoice : null);
        }