Exemplo n.º 1
0
        private async Task InterceptOutgoingAsync(DataInterceptedEventArgs continuedFrom = null)
        {
            HPacket packet = await Local.ReceivePacketAsync().ConfigureAwait(false);

            if (packet != null)
            {
                var args = new DataInterceptedEventArgs(packet, ++_outSteps, true,
                                                        InterceptOutgoingAsync, ServerRelayer);

                try { OnDataOutgoing(args); }
                catch { args.Restore(); }

                if (!args.IsBlocked && !args.WasRelayed)
                {
                    await SendToServerAsync(args.Packet).ConfigureAwait(false);
                }
                if (!args.HasContinued)
                {
                    args.Continue();
                }
            }
            else
            {
                Disconnect();
            }
        }
Exemplo n.º 2
0
        private async Task InterceptIncomingAsync(DataInterceptedEventArgs continuedFrom = null)
        {
            HPacket packet = await Remote.ReceivePacketAsync().ConfigureAwait(false);

            if (packet != null)
            {
                var args = new DataInterceptedEventArgs(packet, ++_inSteps, false,
                                                        InterceptIncomingAsync, ClientRelayer);

                try { OnDataIncoming(args); }
                catch { args.Restore(); }

                if (!args.IsBlocked && !args.WasRelayed)
                {
                    await SendToClientAsync(args.Packet).ConfigureAwait(false);
                }
                if (!args.HasContinued)
                {
                    args.Continue();
                }
            }
            else
            {
                Disconnect();
            }
        }
Exemplo n.º 3
0
        private void CancelHandshake(DataInterceptedEventArgs e)
        {
            e.Restore();
            FinalizeHandshake();

            Local.Decrypter  = null;
            Remote.Encrypter = null;

            Local.Exchange.Dispose();
            Remote.Exchange.Dispose();
        }
Exemplo n.º 4
0
 public void HandleIncoming(DataInterceptedEventArgs e)
 {
     if (_safeModules.Length == 0)
     {
         return;
     }
     foreach (ModuleInfo module in _safeModules)
     {
         if (module.Instance != null)
         {
             try { module.Instance?.HandleIncoming(e); }
             catch
             {
                 // TODO: Display informative error to user with last read values/packet.
                 e.Restore();
             }
         }
     }
 }