Пример #1
0
        private async Task RunConnection(TcpClient client)
        {
            IChannel internalChannel = null;

            try
            {
                client.NoDelay = true;

                var stream = client.GetStream();
                await ReadCookie(stream);

                await stream.WriteObjectAsync(_universe.ModData);

                using (internalChannel = _universe.ConnectPlayer())
                {
                    internalChannel.OnGameEventAsync += e => SendGameEventAsync(stream, e);

                    while (true)
                    {
                        var playerEvent = await stream.ReadObjectAsync <PlayerEvent>();

                        await internalChannel.SendPlayerEventAsync(playerEvent);
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                client.Close();
            }
        }