コード例 #1
0
        /// <summary>
        /// Called when a client has had a connection assigned, meaning we can now communicate with them directly
        /// </summary>
        /// <param name="client"></param>
        protected virtual void OnMetClient([NotNull] ClientInfo <TPeer?> client)
        {
            //Sanity check we're really in a session
            if (Log.AssertAndLogError(IsConnected, "704E1AA4-1802-4FA6-B8BD-4CB780DD82F2", "Attempted to call IntroduceP2P before connected to Dissonance session"))
            {
                return;
            }
            if (Log.AssertAndLogError(_serverNegotiator.LocalId.HasValue, "9B611EAA-B2D9-4C96-A619-976B61F5A76B", "No LocalId assigned even though server negotiator is connected"))
            {
                return;
            }

            //Check that we can communicate directly with this peer
            if (client.Connection.HasValue)
            {
                //write a p2p handshake to introduce ourselves back to them
                var packet = new PacketWriter(_sendQueue.GetSendBuffer()).WriteHandshakeP2P(_serverNegotiator.SessionId, _serverNegotiator.LocalId.Value).Written;

                //Send the packet back directly
                //We allocate a list here but that's ok, this only happens once per remote client to connect.
                _sendQueue.EnqueueReliableP2P(
                    _serverNegotiator.LocalId.Value,
                    new List <ClientInfo <TPeer?> > {
                    client
                },
                    packet
                    );
            }
        }