Пример #1
0
        //
        public void SendVoicesInfo(IEnumerable <LocalVoice> voices, int channelId, int targetPlayerId)
        {
            object content = voiceClient.buildVoicesInfo(voices, true);

            var sendOpt = new SendOptions()
            {
                Reliability = true,
                Channel     = (byte)channelId
            };

            var opt = new LoadBalancing.RaiseEventOptions();

            if (targetPlayerId != 0)
            {
                opt.TargetActors = new int[] { targetPlayerId };
            }
            lock (sendLock)
            {
                this.OpRaiseEvent(VoiceEventCode.GetCode(channelId), content, opt, sendOpt);
            }

            if (targetPlayerId == 0) // send debug echo infos to myself if broadcast requested
            {
                SendDebugEchoVoicesInfo(channelId);
            }
        }
        public void SendVoiceRemove(LocalVoice voice, int channelId, int targetPlayerId)
        {
            object content = voiceClient.buildVoiceRemoveMessage(voice);
            var    opt     = new LoadBalancing.RaiseEventOptions();

            opt.SequenceChannel = (byte)channelId;
            if (targetPlayerId != 0)
            {
                opt.TargetActors = new int[] { targetPlayerId };
            }
            lock (sendLock)
            {
                this.OpRaiseEvent(VoiceEventCode.GetCode(opt.SequenceChannel), content, true, opt);
            }
        }
        public void SendFrame(object content, int channelId, LocalVoice localVoice)
        {
            var opt = new LoadBalancing.RaiseEventOptions();

            opt.SequenceChannel = (byte)channelId;
            if (localVoice.DebugEchoMode)
            {
                opt.Receivers = LoadBalancing.ReceiverGroup.All;
            }
            opt.InterestGroup = localVoice.Group;
            lock (sendLock)
            {
                this.OpRaiseEvent((byte)VoiceEventCode.GetCode(opt.SequenceChannel), content, localVoice.Reliable, opt);
            }
            this.loadBalancingPeer.SendOutgoingCommands();
        }
        private void onEventActionVoiceClient(EventData ev)
        {
            byte channel;

            // check for voice event first
            if (VoiceEventCode.TryGetChannelID(ev.Code, this.loadBalancingPeer.ChannelCount, out channel))
            {
                // Payloads are arrays. If first array element is 0 than next is event subcode. Otherwise, the event is data frame with voiceId in 1st element.
                this.voiceClient.onVoiceEvent(ev[(byte)LoadBalancing.ParameterCode.CustomEventContent], channel, (int)ev[LoadBalancing.ParameterCode.ActorNr], this.LocalPlayer.ID);
            }
            else
            {
                int playerId;
                switch (ev.Code)
                {
                case (byte)LoadBalancing.EventCode.Join:
                    playerId = (int)ev[LoadBalancing.ParameterCode.ActorNr];
                    if (playerId == this.LocalPlayer.ID)
                    {
                    }
                    else
                    {
                        this.voiceClient.sendVoicesInfo(playerId);    // send to new joined only
                    }
                    break;

                case (byte)LoadBalancing.EventCode.Leave:
                {
                    playerId = (int)ev[LoadBalancing.ParameterCode.ActorNr];
                    if (playerId == this.LocalPlayer.ID)
                    {
                        this.voiceClient.clearRemoteVoices();
                    }
                    else
                    {
                        onPlayerLeave(playerId);
                    }
                }
                break;
                }
            }
            if (this.OnEventAction != null)
            {
                this.OnEventAction(ev);
            }
        }
        public void SendFrame(ArraySegment <byte> data, byte evNumber, byte voiceId, int channelId, LocalVoice localVoice)
        {
            object[] content = new object[] { voiceId, evNumber, data };

            var opt = new LoadBalancing.RaiseEventOptions();

            opt.SequenceChannel = (byte)channelId;
            if (localVoice.DebugEchoMode)
            {
                opt.Receivers = LoadBalancing.ReceiverGroup.All;
            }
            opt.InterestGroup = localVoice.Group;
            lock (sendLock)
            {
                this.OpRaiseEvent((byte)VoiceEventCode.GetCode(channelId), content, localVoice.Reliable, opt);
            }
            this.loadBalancingPeer.SendOutgoingCommands();
        }
Пример #6
0
        public void SendVoiceRemove(LocalVoice voice, int channelId, int targetPlayerId)
        {
            object content = voiceClient.buildVoiceRemoveMessage(voice);
            var    sendOpt = new SendOptions()
            {
                Reliability = true,
                Channel     = (byte)channelId
            };

            var opt = new LoadBalancing.RaiseEventOptions();

            if (targetPlayerId != 0)
            {
                opt.TargetActors = new int[] { targetPlayerId };
            }
            lock (sendLock)
            {
                if (voice.DebugEchoMode)
                {
                    opt.Receivers = ReceiverGroup.All;
                }
                this.OpRaiseEvent(VoiceEventCode.GetCode(channelId), content, opt, sendOpt);
            }
        }