示例#1
0
        public void Do(ConnectClient client)
        {
            Client = client;

            Loger.Log("Server ReceiveBytes1");

            ///установка условно защищенного соединения
            //Строго первый пакет: Передаем серверу КОткр
            var rc     = Client.ReceiveBytes();
            var crypto = new CryptoProvider();

            if (SessionClient.UseCryptoKeys)
            {
                crypto.OpenKey = Encoding.UTF8.GetString(rc);
            }

            //Строго первый ответ: Передаем клиенту КОткр(Сессия)
            SetKey();
            Loger.Log("Server SendMessage1");
            if (SessionClient.UseCryptoKeys)
            {
                Client.SendMessage(crypto.Encrypt(Key));
            }
            else
            {
                Client.SendMessage(Key);
            }

            //if (LogMessage != null) LogMessage("session Connected");

            Worker = new Service();

            ///рабочий цикл
            while (true)
            {
                //Loger.Log("Server Loop1");
                var rec = Client.ReceiveBytes();
                //Loger.Log("Server Loop2");
                var rec2 = CryptoProvider.SymmetricDecrypt(rec, Key);
                //Loger.Log("Server " + Loger.Bytes(rec2));
                //Loger.Log("Server Loop3");
                var recObj = (ModelContainer)GZip.UnzipObjByte(rec2); //Deserialize
                //Loger.Log("Server Loop4");

                var sendObj = Service(recObj);

                //Loger.Log("Server Loop5");
                var ob = GZip.ZipObjByte(sendObj); //Serialize
                //Loger.Log("Server Loop6");
                var send = CryptoProvider.SymmetricEncrypt(ob, Key);
                //Loger.Log("Server Loop7");
                Client.SendMessage(send);
            }
        }
示例#2
0
        /// <summary>
        /// Передаем и принимаем объект ModelContainer
        /// </summary>
        private ModelContainer Trans(ModelContainer sendObj)
        {
            lock (LockObj)
            {
                ErrorMessage = null;

                var time1 = DateTime.UtcNow;

                var ob   = GZip.ZipObjByte(sendObj); //Serialize
                var send = CryptoProvider.SymmetricEncrypt(ob, Key);

                if (send.Length > 1024 * 512)
                {
                    Loger.Log($"Client Network toS {send.Length} unzip {GZip.LastSizeObj} ");
                }
                var time2 = DateTime.UtcNow;

                Client.SendMessage(send);

                var time3 = DateTime.UtcNow;

                var rec = Client.ReceiveBytes();

                var time4 = DateTime.UtcNow;

                var rec2 = CryptoProvider.SymmetricDecrypt(rec, Key);

                var time5 = DateTime.UtcNow;

                var res = (ModelContainer)GZip.UnzipObjByte(rec2); //Deserialize

                var time6 = DateTime.UtcNow;
                if (rec.Length > 1024 * 512)
                {
                    Loger.Log($"Client Network fromS {rec.Length} unzip {GZip.LastSizeObj} ");
                }

                if ((time5 - time1).TotalMilliseconds > 900)
                {
                    Loger.Log($"Client Network timeSerialize {(time2 - time1).TotalMilliseconds}" +
                              $" timeSend {(time3 - time2).TotalMilliseconds}" +
                              $" timeReceive {(time4 - time3).TotalMilliseconds}" +
                              $" timeDecrypt {(time5 - time4).TotalMilliseconds}" +
                              $" timeDeserialize {(time6 - time5).TotalMilliseconds}");
                }

                return(res);
            }
        }
示例#3
0
 /// <summary>
 /// Передаем и принимаем объект ModelContainer
 /// </summary>
 private ModelContainer Trans(ModelContainer sendObj)
 {
     lock (LockObj)
     {
         //Loger.Log("Client T1");
         var ob = GZip.ZipObjByte(sendObj); //Serialize
         //Loger.Log("Client Push " + Loger.Bytes(ob));
         var send = CryptoProvider.SymmetricEncrypt(ob, Key);
         //Loger.Log("Client Send");
         Client.SendMessage(send);
         //Loger.Log("Client Receive");
         var rec = Client.ReceiveBytes();
         //Loger.Log("Client Received");
         var rec2 = CryptoProvider.SymmetricDecrypt(rec, Key);
         //Loger.Log("Client Pop " + Loger.Bytes(rec2));
         return((ModelContainer)GZip.UnzipObjByte(rec2)); //Deserialize
     }
 }
示例#4
0
        public void Do(ConnectClient client)
        {
            Client = client;

            Loger.Log("Server ReceiveBytes1");

            ///установка условно защищенного соединения
            //Строго первый пакет: Передаем серверу КОткр
            var rc     = Client.ReceiveBytes();
            var crypto = new CryptoProvider();

            if (SessionClient.UseCryptoKeys)
            {
                crypto.OpenKey = Encoding.UTF8.GetString(rc);
            }

            //Строго первый ответ: Передаем клиенту КОткр(Сессия)
            SetKey();
            Loger.Log("Server SendMessage1");
            if (SessionClient.UseCryptoKeys)
            {
                Client.SendMessage(crypto.Encrypt(Key));
            }
            else
            {
                Client.SendMessage(Key);
            }

            var context = new ServiceContext();

            Worker = new Service(context);

            ///рабочий цикл
            while (true)
            {
                var rec = Client.ReceiveBytes();

                if (context.Player != null)
                {
                    lock (context.Player)
                    {
                        context.Player.Public.LastOnlineTime = DateTime.UtcNow;
                    }
                }

                //отдельно обрабатываем пинг
                if (rec.Length == 1)
                {
                    if (rec[0] == 0x00)
                    {
                        Client.SendMessage(new byte[1] {
                            0x00
                        });
                    }
                    //отдельно обрабатываем запрос на обновление (ответ 0 - нет ничего, 1 - что-то есть)
                    else if (rec[0] == 0x01)
                    {
                        var exists = ServiceCheck();
                        Client.SendMessage(new byte[1] {
                            exists ? (byte)0x01 : (byte)0x00
                        });
                    }
                    continue;
                }

                var time1 = DateTime.UtcNow;

                var rec2   = CryptoProvider.SymmetricDecrypt(rec, Key);
                var recObj = (ModelContainer)GZip.UnzipObjByte(rec2); //Deserialize

                if (rec.Length > 1024 * 512)
                {
                    Loger.Log($"Server Network fromC {rec.Length} unzip {GZip.LastSizeObj} ");
                }
                var time2 = DateTime.UtcNow;

                ModelContainer sendObj;
                try
                {
                    sendObj = Worker.GetPackage(recObj);
                }
                catch (Exception ext)
                {
                    Loger.Log("Exception GetPackage: " + ext.ToString());
                    sendObj = new ModelContainer()
                    {
                        TypePacket = 0
                    };
                }

                var time3 = DateTime.UtcNow;

                var ob   = GZip.ZipObjByte(sendObj); //Serialize
                var send = CryptoProvider.SymmetricEncrypt(ob, Key);

                if (send.Length > 1024 * 512)
                {
                    Loger.Log($"Server Network toC {send.Length} unzip {GZip.LastSizeObj} ");
                }
                var time4 = DateTime.UtcNow;

                Client.SendMessage(send);

                var time5 = DateTime.UtcNow;

                if ((time5 - time1).TotalMilliseconds > 900)
                {
                    Loger.Log($"Server Network timeDeserialize {(time2 - time1).TotalMilliseconds}" +
                              $" timeWorker {(time3 - time2).TotalMilliseconds}" +
                              $" timeSerialize {(time4 - time3).TotalMilliseconds}" +
                              $" timeSend {(time5 - time4).TotalMilliseconds}");
                }

                if (context.Player != null)
                {
                    lock (context.Player)
                    {
                        context.Player.Public.LastOnlineTime = DateTime.UtcNow;
                        if (context.Player.ExitReason != OCUnion.Transfer.DisconnectReason.AllGood)
                        {
                            //context.Player.ExitReason = OCUnion.Transfer.DisconnectReason.AllGood;
                            Loger.Log("Disconnect  . . ." + context.Player.ExitReason.ToString());
                            break;
                        }
                    }
                }
            }
        }
示例#5
0
        public void Do(ConnectClient client)
        {
            Client = client;

            Loger.Log("Server ReceiveBytes1");

            ///установка условно защищенного соединения
            //Строго первый пакет: Передаем серверу КОткр
            var rc     = Client.ReceiveBytes();
            var crypto = new CryptoProvider();

            if (SessionClient.UseCryptoKeys)
            {
                crypto.OpenKey = Encoding.UTF8.GetString(rc);
            }

            //Строго первый ответ: Передаем клиенту КОткр(Сессия)
            SetKey();
            Loger.Log("Server SendMessage1");
            if (SessionClient.UseCryptoKeys)
            {
                Client.SendMessage(crypto.Encrypt(Key));
            }
            else
            {
                Client.SendMessage(Key);
            }

            //if (LogMessage != null) LogMessage("session Connected");

            Worker = new Service();

            ///рабочий цикл
            while (true)
            {
                //Loger.Log("Server Loop1");
                var rec = Client.ReceiveBytes();

                if (Worker.Player != null)
                {
                    Worker.Player.Public.LastOnlineTime = DateTime.UtcNow;
                }

                //отдельно обрабатываем пинг
                if (rec.Length == 1)
                {
                    if (rec[0] == 0x00)
                    {
                        Client.SendMessage(new byte[1] {
                            0x00
                        });
                    }
                    //отдельно обрабатываем запрос на обновление (ответ 0 - нет ничего, 1 - что-то есть)
                    else if (rec[0] == 0x01)
                    {
                        var exists = ServiceCheck();
                        Client.SendMessage(new byte[1] {
                            exists ? (byte)0x01 : (byte)0x00
                        });
                    }
                    continue;
                }

                //Loger.Log("Server Loop2");
                var rec2 = CryptoProvider.SymmetricDecrypt(rec, Key);
                //Loger.Log("Server " + Loger.Bytes(rec2));
                //Loger.Log("Server Loop3");
                var recObj = (ModelContainer)GZip.UnzipObjByte(rec2); //Deserialize
                //Loger.Log("Server Loop4");

                var sendObj = Service(recObj);

                //Loger.Log("Server Loop5");
                var ob = GZip.ZipObjByte(sendObj); //Serialize
                //Loger.Log("Server Loop6");
                var send = CryptoProvider.SymmetricEncrypt(ob, Key);
                //Loger.Log("Server Loop7");
                Client.SendMessage(send);
            }
        }