public static async Task Run(SessionContextPool pool, TcpClient client, ProxyServerConfig proxyConfig)
        {
            var    result = LastPipeState.GameStart;
            string contextId;

            using (var context = new SessionContext(client, proxyConfig))
            {
                contextId = context.Id;
                pool.ContextContainer.TryAdd(contextId, context);
                do
                {
                    try
                    {
                        var processor = Handlers[result];
                        //Console.WriteLine($"[{context.Id}] {result} → {processor.GetType()} ↓");
                        result = await processor.Run(proxyConfig.Handler, context);
                    }
                    catch (Exception)
                    {
                        result = LastPipeState.GameOver;
                    }
                } while (result != LastPipeState.GameOver);

                //Console.WriteLine($"[{context.Id}] {result} ⬆");
            }

            pool.ContextContainer.TryRemove(contextId, out _);
        }
Beispiel #2
0
 public ProxyListener(SessionContextPool pool, IPEndPoint endPoint,
                      Action <SessionContextPool, TcpClient, CancellationToken> handleClient)
 {
     Pool = pool;
     InternalTcpListener = new TcpListener(endPoint);
     _source             = new CancellationTokenSource();
     InternalTcpListener.Start();
     AcceptClients(InternalTcpListener, handleClient, _source.Token);
 }