Пример #1
0
        /// <summary>
        /// Send a packet directly to a set of peers. Override this to implement p2p sending in network integrations. The base implementation sends the packet using server relay.
        /// </summary>
        /// <param name="destinations"></param>
        /// <param name="packet"></param>
        protected virtual void SendReliableP2P([NotNull] List <ClientInfo <TPeer?> > destinations, ArraySegment <byte> packet)
        {
            //Since we're calling the base implementation of send P2P we'll just relay this packet by the server

            if (destinations.Count > 0)
            {
                //We're going to server relay, so update server counter
                SentServerTraffic.Update(packet.Count);

                //Get a buffer to write the relay packet into
                var buffer = _sendQueue.GetSendBuffer();
                {
                    //Write relay packet
                    var writer = new PacketWriter(buffer);
                    writer.WriteRelay(_serverNegotiator.SessionId, destinations, packet, true);

                    //Send relay packet
                    ((IClient <TPeer>) this).SendReliable(writer.Written);
                }
                //Recycle relay buffer
                _sendQueue.RecycleSendBuffer(buffer);
            }
        }