csharp/AantCoder/OnlineCity/Source/ServerCore/SessionServer.cs

SessionServer.cs
using Model;
using OCUnion;
using ServerOnlineCity.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using Transfer;
using Util;

namespace ServerOnlineCity
{
    public clast SessionServer : IDisposable
    {
        public bool IsActive = true;
        private ConnectClient Client;
        private byte[] Key;
        private static Random Rnd = new Random();
        private static Encoding KeyEncoding = Encoding.GetEncoding(1252);
        private CryptoProvider cryptoHash = new CryptoProvider();
        private Service Worker;
        private DateTime ServiceCheckTime;


        public void Dispose()
        {
            IsActive = false;
            Client.Dispose();
        }

        public string GetNameWhoConnect()
        {
            try
            {
                return Worker?.Context?.Player?.Public?.Login ?? "";
            }
            catch
            {
                return "";
            }
        }
        public ServiceContext GetContext()
        {
            try
            {
                return Worker?.Context;
            }
            catch
            {
                return null;
            }
        }

        private void SetKey()
        {
            var rnd = new Random();
            var k = new byte[Rnd.Next(400, 600)];
            for (int i = 0; i < k.Length; i++)
            {
                k[i] = (byte)(Rnd.Next(0, 128) + rnd.Next(0, 128));
            }
            var k2 = KeyEncoding.GetBytes("089~`tgjРР·dfgорЫГ9♫7ПМпfghjp147&$#hf%#h^^gxчмиА▀ЫЮББЮю,>