コード例 #1
0
        public static async Task SendPacketsAsync(this IBroadcastable channelGroup, IEnumerable <IPacket> packets,
                                                  IChannelMatcher?matcher)
        {
            var packetDefinitions = (packets as IPacket[] ?? packets).Where(c => c != null).ToArray();

            if (packetDefinitions.Any())
            {
                Parallel.ForEach(packets, packet => channelGroup.LastPackets.Enqueue(packet));
                Parallel.For(0, channelGroup.LastPackets.Count - channelGroup.MaxPacketsBuffer, (_, __) => channelGroup.LastPackets.TryDequeue(out var ___));
                if (channelGroup.Sessions == null)
                {
                    return;
                }

                await channelGroup.Sessions.WriteAndFlushAsync(packetDefinitions).ConfigureAwait(false);

                if (matcher == null)
                {
                    await channelGroup.Sessions.WriteAndFlushAsync(packetDefinitions).ConfigureAwait(false);
                }
                else
                {
                    await channelGroup.Sessions.WriteAndFlushAsync(packetDefinitions, matcher).ConfigureAwait(false);
                }
            }
        }
コード例 #2
0
        public static void SendPackets(this IBroadcastable channelGroup, IEnumerable <IPacket> packets,
                                       IChannelMatcher matcher)
        {
            var packetDefinitions = (packets as IPacket[] ?? packets.ToArray()).Where(c => c != null);

            if (packetDefinitions.Any())
            {
                Parallel.ForEach(packets, packet => channelGroup.LastPackets.Enqueue(packet));
                Parallel.For(0, channelGroup.LastPackets.Count - maxPacketsBuffer, (_, __) => channelGroup.LastPackets.TryDequeue(out var ___));
                channelGroup.Sessions?.WriteAndFlushAsync(packetDefinitions);
                if (matcher == null)
                {
                    channelGroup.Sessions?.WriteAndFlushAsync(packetDefinitions);
                }
                else
                {
                    channelGroup.Sessions?.WriteAndFlushAsync(packetDefinitions, matcher);
                }
            }
        }
コード例 #3
0
        private void Start()
        {
            allLogsRequestion        = GetComponent <ICallbackRequestable <IReadOnlyList <PieceMoveData> > >();
            retransmissionRequestion = GetComponent <ICallbackRequestable <PieceMoveData> >();
            pieceMoveDataBroadcaster = GetComponent <IBroadcastable <PieceMoveData> >();

            if (isServer)
            {
                allLogsRequestion.InitializeOnServer(serverContainer);
                retransmissionRequestion.InitializeOnServer(serverContainer);
            }

            if (isClient)
            {
                clientId = serverContainer.ResisterClient(netIdentity);
                allLogsRequestion.InitializeOnClient(clientId);
                retransmissionRequestion.InitializeOnClient(clientId);
                pieceMoveDataBroadcaster.OnRecieved.TakeUntilDestroy(this).Subscribe(onRecievedMoveData);
            }
        }
コード例 #4
0
 public static void SendPackets(this IBroadcastable channelGroup, IEnumerable <IPacket> packets)
 {
     channelGroup.SendPackets(packets, null);
 }
コード例 #5
0
 public static void SendPacket(this IBroadcastable channelGroup, IPacket packet, IChannelMatcher matcher)
 {
     channelGroup.SendPackets(new[] { packet }, matcher);
 }
コード例 #6
0
 public static void SendPacket(this IBroadcastable channelGroup, IPacket packet)
 {
     channelGroup.SendPackets(new[] { packet });
 }
コード例 #7
0
 public static Task SendPacketsAsync(this IBroadcastable channelGroup, IEnumerable <IPacket> packets)
 {
     return(channelGroup.SendPacketsAsync(packets, null));
 }
コード例 #8
0
 public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket packet, IChannelMatcher matcher)
 {
     return(channelGroup.SendPacketsAsync(new[] { packet }, matcher));
 }
コード例 #9
0
 public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket packet)
 {
     return(channelGroup.SendPacketsAsync(new[] { packet }));
 }