예제 #1
0
        private static void SendHangars(Data.ClientInfo clientInfo)//Отправка всех ангаров (после подключение клиента)
        {
            //Получение ангаров

            System.Collections.Generic.List <Data.InfoHangar> infos = database.GetAnyHangar();

            foreach (Data.InfoHangar info in infos)
            {
                Task.Delay(1000).Wait();
                clientInfo.TcpClient.Client.Send(Encoding.UTF8.GetBytes($"RUPDA:{info.IdHangar}:{info.NameHangar}:{info.CountPlane}:{info.Length}:{info.With}"));
            }
        }
예제 #2
0
        private static void ConnectingClient()//Ловить клиентов
        {
            while (true)
            {
                Task.Delay(10).Wait();
                TcpClient client = Data.Server.AcceptTcpClient();
                Functions.WriteLine("Новый клиент подключился!", ConsoleColor.Green);

                Data.ClientCheck statusClient = CheckClient(client);
                if (statusClient.IsDatabase)
                {
                    Data.ClientInfo clientInfo = new Data.ClientInfo(statusClient.ClientInfo.TypeClient, statusClient.ClientInfo.Name, client);
                    Thread          thread     = new Thread(new ParameterizedThreadStart(new ParameterizedThreadStart(ListenClient)));
                    thread.Start(clientInfo);
                }
            }
        }
예제 #3
0
        private static void ListenClient(object obj)//Сама прослушка клиента
        {
            Data.ClientInfo clientInfo = (Data.ClientInfo)obj;
            SendHangars(clientInfo);
            byte[] buffer = new byte[1024];

            while (true)
            {
                Task.Delay(10).Wait();
                int    messI  = clientInfo.TcpClient.Client.Receive(buffer);
                string answer = Encoding.UTF8.GetString(buffer, 0, messI);
                Console.WriteLine(answer);
                Functions.WriteLine($"Новое подключение от {clientInfo.TcpClient.Client.RemoteEndPoint}", ConsoleColor.Green);

                if (answer.Contains("ADDA"))//Добавление
                {
                    try
                    {
                        Match  regex  = Regex.Match(answer, "ADDA:(.*):(.*):(.*):(.*)");
                        string with   = regex.Groups[1].Value;
                        string height = regex.Groups[2].Value;
                        string length = regex.Groups[3].Value;
                        string name   = regex.Groups[4].Value;

                        database.AddHagar(with, height, length, name);
                        SendHangars(clientInfo);
                    }
                    catch (Exception ex)
                    {
                        Functions.WriteLine($"ERROR ADDA: {ex.Message}", ConsoleColor.Red);
                    }
                }
                else if (answer.Contains("RUPDP"))//Загрузка инфы о самолётах
                {
                    try
                    {
                        List <Data.InfoPlane> infos = database.GetInfoPlanes();
                        foreach (Data.InfoPlane i in infos)
                        {
                            //clientInfo.TcpClient.Client.Send(Encoding.UTF8.GetBytes($"UPDPOZ:{i.ID}:{i.X}:{i.Y}"));

                            //clientInfo.TcpClient.Client.Send(Encoding.UTF8.GetBytes($"UPDPOZ:{i.ID}:{i.X}:{i.Y}:{i.Height}:{i.Leugth}:{i.Money}:{i.Name}:{i.OneDayMoney}:{i.PlaneHeight}:" +
                            //    $"{i.StartTime}:{i.Time}:{i.With}:{i.ErrorMoney}:{i.FinishTime}"));

                            clientInfo.TcpClient.Client.Send(Encoding.UTF8.GetBytes($"RUPDP:{i.ID}:{i.Name}:{i.X}:{i.Y}:{i.StartTime.Date}:{i.FinishTime.Date}:" +
                                                                                    $"{i.Time.Date}:{i.Leugth}:{i.With}:{i.Money}:{i.OneDayMoney}:{i.ErrorMoney}"));
                        }

                        Functions.WriteLine($"RUPDP от {clientInfo.TcpClient.Client.RemoteEndPoint}", ConsoleColor.Green);
                    }
                    catch (Exception ex)
                    {
                        Functions.WriteLine($"ERROR RUPDP: {ex.Message}", ConsoleColor.Red);
                    }
                }
                else if (answer.Contains("UPDA"))//Получение всех ангаров
                {
                    try
                    {
                        SendHangars(clientInfo);
                        Functions.WriteLine($"UPDA от {clientInfo.TcpClient.Client.RemoteEndPoint}", ConsoleColor.Green);
                    }
                    catch (Exception ex)
                    {
                        Functions.WriteLine($"ERROR UPDA: {ex.Message}", ConsoleColor.Red);
                    }
                }
                else if (answer.Contains("UPDP"))//Получение данных о самолёте по id ангара
                {
                    try
                    {
                        List <Data.InfoPlane> planes = database.GetPlanes(int.Parse(answer.Substring(5)));//Лютая херня!!!

                        foreach (Data.InfoPlane plane in planes)
                        {
                            Task.Delay(800).Wait();
                            clientInfo.TcpClient.Client.Send(Encoding.UTF8.GetBytes($"RUPDP;{plane.ID};{plane.Name};{plane.X};{plane.Y};{plane.StartTime.Date};{plane.FinishTime.Date};" +
                                                                                    $"{plane.Time.Date};{plane.Leugth};{plane.With};{plane.Money};{plane.OneDayMoney};{plane.ErrorMoney}"));
                        }
                        Functions.WriteLine($"UPDP от {clientInfo.TcpClient.Client.RemoteEndPoint}", ConsoleColor.Green);
                    }
                    catch (Exception ex)
                    {
                        Functions.WriteLine($"ERROR UPDP: {ex.Message}", ConsoleColor.Red);
                    }
                }
            }
        }