private void AppendLog(string text)
 {
     if (this.Disposing || this.IsDisposed)
     {
         return;
     }
     if (LogTextBox.InvokeRequired)
     {
         LogTextBox.Invoke(new EventHandler((s, e) =>
         {
             lock (LogTextBox)
             {
                 LogTextBox.AppendText(text);
             }
             LogTextBox.ScrollToCaret();
         }), this, null);
     }
     else
     {
         lock (LogTextBox)
         {
             LogTextBox.AppendText(text);
         }
         LogTextBox.ScrollToCaret();
     }
 }
Beispiel #2
0
        // ----------------------------------------------------------------------------------------------------------------------------
        // WRITE LINE TO LOG TEXTBOX - THREADSAFE
        //
        private void LogWriteTextBox(DateTime dateTime, string messageString, string fileName = null)
        {
            try
            {
                if (LogTextBox.InvokeRequired)
                {
                    EventClass.EventHandler d = new EventClass.EventHandler(LogWriteTextBox);
                    LogTextBox.Invoke(d, new object[] { dateTime, messageString, fileName });
                    return;
                }

                // CLEAR SOME LINES FROM THE TOP OF THE LOG
                if (LogTextBox.Text.Length > 30000)
                {
                    LogTextBox.Text = LogTextBox.Text.Substring(10000);
                }

                // ADD LINE AND SCROLL TO END
                LogTextBox.AppendText(messageString + "\r\n");

                if (bScroll)
                {
                    //LogTextBox.CaretIndex = LogTextBox.Text.Length;
                    //LogTextBox.ScrollToEnd();
                }
            }

            catch (Exception ex)
            {
                //LogWriteTextBox(DateTime.Now, DateTime.Now.ToString("0:MM/dd/yy hh:mm:ss.fff tt") + "     EXCEPTION: " + ex.Message);
                LogWriteFile(DateTime.Now, DateTime.Now.ToString("0:MM/dd/yy hh:mm:ss.fff tt") + "     EXCEPTION: " + ex.Message);
            }
        }
Beispiel #3
0
        public void Recieve()
        {
            IPEndPoint from = new IPEndPoint(IPAddress.Any, 0);

            Thread.Sleep(1000); //Pozbycie się niewygodnych wyjątków

            while (true)
            {
                LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("RECIEVER> Waiting for data...\r\n")));

                try
                {
                    this.buffer = client_socket.Receive(ref from);
                }
                catch (Exception e)
                {
                    LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("RECIEVER> Socket error while recieving the message! " + e.ToString() + "\r\n")));
                }

                if (buffer.Length > 0)
                {
                    LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("SERVER> " + ByteToString(this.buffer) + "\r\n")));
                    ExecAndAck(); //Uzupełnienie pól klasy
                    LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("\n")));
                }
            }
        }
Beispiel #4
0
 public void WrongMessage()
 {
     LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("RECIEVER> Server has sent a bad message!\r\n")));
     TimeLeft.Invoke(new Action(() => TimeLeft.Text   = ""));
     SessionID.Invoke(new Action(() => SessionID.Text = ""));
     SetReadyToSend(false);
 }
Beispiel #5
0
 public void Log(string text)
 {
     if (LogTextBox.InvokeRequired)
     {
         SafeCallDelegate del = new SafeCallDelegate(Log);
         LogTextBox.Invoke(del, new object[] { text });
     }
     else
     {
         string currentTime = string.Format("[{0:HH}:{0:mm}:{0:ss}]", DateTime.Now);
         LogTextBox.Text          += currentTime + text + Environment.NewLine;
         toolStripStatusLabel.Text = text.StartsWith(">> ") ? text.Substring(3) : text;
         LogTextBox.SelectionStart = LogTextBox.TextLength;
         LogTextBox.ScrollToCaret();
         if (text == ">> state: Disconnected")
         {
             ServerTextBox.BackColor = Color.LightCoral;
             Icon = notifyIcon.Icon = Resource.RedIcon;
         }
         else if (text == ">> state: Connected")
         {
             ServerTextBox.BackColor = Color.LightGreen;
             Icon = notifyIcon.Icon = Resource.GreenIcon;
         }
         else if (text.StartsWith(">> error:"))
         {
             MessageBox.Show(text.Substring(3));
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// Prompts Message to be displayed in the Log window in the Addon form.
        /// Message is cleared after it has been displayed.
        /// </summary>
        public static void UpdateLogTextBox()
        {
            if (LogTextBox.InvokeRequired)
            {
                LogTextBox.Invoke(new Action(AddLogEntry));
                return;
            }

            AddLogEntry();
        }
Beispiel #7
0
 public void AddLogEntry(string text)
 {
     if (LogTextBox.InvokeRequired)
     {
         LogTextBox.Invoke(new LogEntryDelegate(AddLogEntry), text);
     }
     else
     {
         LogTextBox.AppendText(text);
     }
 }
        public void Log(string msg)
        {
            LogTextBox.Invoke(new Action(() => {
                if (LogTextBox.Text.Length + msg.Length > 4000)
                {
                    LogTextBox.Text = LogTextBox.Text.Substring(2000);
                }

                LogTextBox.AppendText(msg);
                LogTextBox.AppendText(Environment.NewLine);
            }));
        }
 private void AppendLog(string line)
 {
     if (LogTextBox.InvokeRequired)
     {
         LogTextBox.Invoke(new EventHandler((s, e) => {
             LogTextBox.AppendText(line);
             LogTextBox.ScrollToCaret();
         }), this, null);
     }
     else
     {
         LogTextBox.AppendText(line);
         LogTextBox.ScrollToCaret();
     }
 }
Beispiel #10
0
        public void AddLog(string text, string errorMessage, Color color)
        {
            int length = 0;

            LogTextBox.Invoke(new Action(() => length = LogTextBox.TextLength));
            //int length = LogTextBox.TextLength;
            string logMessage = text + errorMessage;

            LogTextBox.Invoke(new Action(() => LogTextBox.AppendText(text)));
            LogTextBox.Invoke(new Action(() => LogTextBox.SelectionStart  = length));
            LogTextBox.Invoke(new Action(() => LogTextBox.SelectionLength = text.Length));
            LogTextBox.Invoke(new Action(() => LogTextBox.SelectionColor  = color));

            LogTextBox.Invoke(new Action(() => length = LogTextBox.TextLength));
            LogTextBox.Invoke(new Action(() => LogTextBox.AppendText(errorMessage + "\n")));
            LogTextBox.Invoke(new Action(() => LogTextBox.SelectionStart  = length));
            LogTextBox.Invoke(new Action(() => LogTextBox.SelectionLength = errorMessage.Length));
            LogTextBox.Invoke(new Action(() => LogTextBox.SelectionColor  = Color.Black));
        }
Beispiel #11
0
        public void ExecAndAck()
        {
            FromByte(this.buffer);
            //Wybór co robimy na podstawie operacji:

            if (this.op == "HelloThere")        //Przydział ID
            {
                if (this.od == "GeneralKenobi") //Serwer przysłał nam nowe ID!
                {
                    SessionID.Invoke(new Action(() => SessionID.Text         = this.id));
                    SessionIDInfo.Invoke(new Action(() => SessionIDInfo.Text = "Otrzymano nowe ID od serwera!"));
                    SetReadyToSend(true);

                    //Potwierdzenie komunikatu

                    SetMessage(op, "RogerRoger", id, tm, lb);
                    SendMessageToServer(1);

                    //Sprzątanie

                    SetMessage("");
                    this.buffer = null;
                    return;
                }

                if (this.od == "NOK") //Serwer nie przysłał nam nowego ID!
                {
                    SessionID.Invoke(new Action(() => SessionIDInfo.Text = "Serwer odmówił przydziału ID!"));
                    SetReadyToSend(true);

                    //Potwierdzenie komunikatu

                    SetMessage(op, "RogerRoger", "", tm, lb);
                    SendMessageToServer(1);

                    //Sprzątanie

                    SetMessage("");
                    this.buffer = null;
                    return;
                }
            }

            if (this.op == "TR") //Pozostały czas
            {
                SetReadyToSend(true);
                GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "Czas ucieka!"));
                TimeLeft.Invoke(new Action(() => TimeLeft.Text = tm));

                //Potwierdzenie komunikatu

                SetMessage(op, "RogerRoger", id, tm, lb);
                SendMessageToServer(2);

                //Sprzątanie

                SetMessage("");
                this.buffer = null;
                return;
            }

            if (this.op == "GN")     //Zgadywanie liczby
            {
                if (this.od == "WN") //Nie zgadłeś
                {
                    GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "Zła liczba!"));
                    SetReadyToSend(true);

                    //Potwierdzenie komunikatu

                    SetMessage(op, "RogerRoger", id, tm, lb);
                    SendMessageToServer(2);

                    //Sprzątanie

                    SetMessage("");
                    this.buffer = null;
                    return;
                }

                if (this.od == "WIN")
                {
                    GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "Brawo! O tą liczbę mi chodziło!"));
                    Number.Invoke(new Action(() => Number.BackColor = Color.PaleGreen));
                    SetReadyToSend(true);

                    //Potwierdzenie komunikatu

                    SetMessage(op, "RogerRoger", id, tm, lb);
                    SendMessageToServer(1);

                    //Sprzątanie po wygranej!!!
                    LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("RECIEVER> User has won the game! Terminating connection...\r\n")));
                    TimeLeft.Invoke(new Action(() => TimeLeft.Text   = ""));
                    SessionID.Invoke(new Action(() => SessionID.Text = ""));
                    SetReadyToSend(false);

                    SetMessage("");
                    this.buffer = null;
                    return;
                }
            }

            if (this.op == "ItIsOverAnakin") //Koniec gry
            {
                LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("RECIEVER> It is over! Server has terminated the communication.\r\n")));
                TimeLeft.Invoke(new Action(() => TimeLeft.Text               = ""));
                SessionID.Invoke(new Action(() => SessionID.Text             = ""));
                GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "To koniec Anakinie, mam wysoką ziemię!"));
                SetReadyToSend(false);

                //?potfierdzenie?

                return;
            }

            //W przypadku, gdy nie trafiliśmy w żadnego ifa
            WrongMessage();
            return;
        }
Beispiel #12
0
 private void InsertLog(string text)
 {
     string[] output = LogTextBox.Text.Split('\n');
     output[0] = text;
     LogTextBox.Invoke(new Action(() => LogTextBox.Text = string.Join(Environment.NewLine, output)));
 }
Beispiel #13
0
        //---------------------------------------------------------//

        private void Log(string text) => LogTextBox.Invoke(new Action(() => LogTextBox.Text = text + Environment.NewLine + LogTextBox.Text));
Beispiel #14
0
        private void Logger_OnLog(string log, LogMessageType logType)
        {
            Console.WriteLine(log);

            void LogCallback()
            {
                LogTextBox.SelectionStart  = LogTextBox.Text.Length;
                LogTextBox.SelectionLength = 0;

                switch (logType)
                {
                case LogMessageType.Global:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E9E9E9");
                    break;

                case LogMessageType.Team:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF006C");
                    break;

                case LogMessageType.Guild:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#975FFF");
                    break;

                case LogMessageType.Alliance:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FFAD42");
                    break;

                case LogMessageType.Party:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#00E4FF");
                    break;

                case LogMessageType.Sales:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#B3783E");
                    break;

                case LogMessageType.Seek:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E4A0D5");
                    break;

                case LogMessageType.Noob:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#D3AA07");
                    break;

                case LogMessageType.Admin:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF00FF");
                    break;

                case LogMessageType.Private:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#7EC3FF");
                    break;

                case LogMessageType.Info:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#46A324");
                    break;

                case LogMessageType.FightLog:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#9DFF00");
                    break;

                case LogMessageType.Public:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#EF3A3E");
                    break;

                case LogMessageType.Arena:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#F16392");
                    break;

                case LogMessageType.Community:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#9EC79D");
                    break;

                case LogMessageType.Sender:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#1B96FF");
                    break;

                case LogMessageType.Default:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E8890D");
                    break;

                case LogMessageType.Divers:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#3498db");
                    break;

                case LogMessageType.Error:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF0033");
                    break;

                default:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E8890D");
                    break;
                }

                var text = $"[{DateTime.Now.ToLongTimeString()}] {log}";

                LogTextBox.SelectedText   = text + "\r\n";
                LogTextBox.SelectionColor = LogTextBox.ForeColor;
                LogTextBox.ScrollToCaret();
            }

            LogTextBox.Invoke((Action)LogCallback);
        }
Beispiel #15
0
 private void DeleteID_Click(object sender, EventArgs e)
 {
     SessionID.Invoke(new Action(() => SessionID.Text         = ""));
     SessionIDInfo.Invoke(new Action(() => SessionIDInfo.Text = "Użytkownik usunął ID sesji!"));
     LogTextBox.Invoke(new Action(() => LogTextBox.Text       = "RECIEVER> Waiting for data..."));
 } //DELET ID
Beispiel #16
0
        } //Metoda ustawiająca pole MessageToSend

        public void SendMessageToServer(int variant) //Metoda wysyłająca wiadomość do servera i ustawiająca flage answer na false
        {
            //Zmienna variant określa przypadki wysyłania wiadomości
            //0 - SendMessage wysyła tab z id sesji
            //1 - SendMessage wysyła tab ze zgadywaniem lub wątek reciever
            //2 - SendMessage ma pozostawić flagę ReadyToSend na true

            //Klika wyjątków do obsłużenia...
            if (variant == 0) //Zakładka Id sesji
            {
                if (MessageToSend == "")
                {
                    LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("CORE> User tried to send an empty message!\r\n")));
                    MessageToSend = "";
                    buffer        = null;
                    return;
                }
            }

            else if (variant == 1) //Zakładka Zgaduj Liczbę i wątek reciever
            {
                if (MessageToSend == "")
                {
                    LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("CORE> User tried to send an empty message!\r\n")));
                    MessageToSend = "";
                    buffer        = null;
                    return;
                }

                if (ReadyToSend.Checked == false)
                {
                    LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("CORE> Server has not acknoledged previous message!\r\n")));
                    GuessNumberInfo.Invoke(new Action(() => GuessNumberInfo.Text = "Nie możesz teraz zgadywać!"));
                    MessageToSend = "";
                    buffer        = null;
                    return;
                }
            }
            //Kilka wyjątków do obsłużenia...

            //Jeżeli wszystko jest OK...
            //Adres servera i jego port
            IPAddress server_addr = IPAddress.Parse(ServerIP.Text);
            int       server_port;

            Int32.TryParse(ServerPort.Text, out server_port);

            //Tworzenie endpointu i wypełnienie bufora
            IPEndPoint server = new IPEndPoint(server_addr, server_port);

            buffer = Encoding.ASCII.GetBytes(this.MessageToSend);

            //Wysyłanie wiadomości i ustawienie checkboxa ReadyToSend na False
            try
            {
                client_socket.Send(buffer, buffer.Length, server);
            }
            catch (Exception e)
            {
                LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("CORE> WinSock error ocurred while sending a message " + e.ToString() + "\r\n")));
                SetReadyToSend(false);
                MessageToSend = "";
                buffer        = null;
                return;
            }
            LogTextBox.Invoke(new Action(() => LogTextBox.AppendText("CORE> User sent message : " + MessageToSend + "\r\n")));

            //Czyszczenie wiadomości i bufora, oraz odznaczenie czekboksa
            if (variant != 2)
            {
                SetReadyToSend(false);
            }
            MessageToSend = "";
            buffer        = null;
        }
        public void Consumer()
        {
            int ackMode = Session.AUTO_ACKNOWLEDGE;

            TIBCO.EMS.Message msg = null;

            while (true)
            {
                try
                {
                    // receive the message
                    msg = msgConsumer.Receive();
                }
                catch (EMSException EMSex)
                {
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + EMSex.Message; });
                    logger.Error(EMSex.Message);
                }
                if (msg == null)
                {
                    break;
                }

                if (ackMode == Session.CLIENT_ACKNOWLEDGE ||
                    ackMode == Session.EXPLICIT_CLIENT_ACKNOWLEDGE ||
                    ackMode == Session.EXPLICIT_CLIENT_DUPS_OK_ACKNOWLEDGE)
                {
                    msg.Acknowledge();
                }

                LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\nReceived message: " + msg; });
                logger.Info("Received message: " + msg);

                if (msg is TextMessage)
                {
                    TextMessage tm = (TextMessage)msg;
                    //ReceveMsgTextBox.Text = tm.Text;
                    ReceveMsgTextBox.Invoke((MethodInvoker) delegate() { ReceveMsgTextBox.Text = tm.Text; });
                    logger.Info(tm.Text);
                }
                if (msg is BytesMessage)
                {
                    BytesMessage bm = (BytesMessage)msg;
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadBoolean(); });
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadChar(); });
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadShort(); });
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadInt(); });
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadLong(); });
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadFloat(); });
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + bm.ReadDouble(); });
                }

                if (msg is MapMessage)
                {
                    MapMessage mm       = (MapMessage)msg;
                    var        mapNames = mm.GetMapNames();
                    LogTextBox.Invoke((MethodInvoker) delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.ToString(); });

                    /*   foreach (String name in mapNames)
                     * {
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetBoolean(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetByte(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetBytes(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetChar(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetShort(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetInt(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetLong(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetFloat(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetDouble(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetString(name); });
                     *     LogTextBox.Invoke((MethodInvoker)delegate() { LogTextBox.Text = LogTextBox.Text + "\n" + mm.GetObject(name); });
                     * }*/
                }
            }
        }
Beispiel #18
0
        private void Logger_OnLog(string log, LogMessageType logType)
        {
            Console.WriteLine(log);

            void LogCallback()
            {
                LogTextBox.SelectionStart  = LogTextBox.Text.Length;
                LogTextBox.SelectionLength = 0;

                switch (logType)
                {
                case LogMessageType.Global:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E9E9E9");
                    break;

                case LogMessageType.Team:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF006C");
                    break;

                case LogMessageType.Guild:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#975FFF");
                    break;

                case LogMessageType.Alliance:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FFAD42");
                    break;

                case LogMessageType.Party:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#00E4FF");
                    break;

                case LogMessageType.Sales:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#B3783E");
                    break;

                case LogMessageType.Seek:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E4A0D5");
                    break;

                case LogMessageType.Noob:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#D3AA07");
                    break;

                case LogMessageType.Admin:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#FF00FF");
                    break;

                case LogMessageType.Private:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#7EC3FF");
                    break;

                case LogMessageType.Info:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#46A324");
                    break;

                case LogMessageType.FightLog:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#9DFF00");
                    break;

                case LogMessageType.Public:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#EF3A3E");
                    break;

                case LogMessageType.Arena:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#F16392");
                    break;

                case LogMessageType.Community:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#9EC79D");
                    break;

                case LogMessageType.Sender:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#1B96FF");
                    break;

                case LogMessageType.Default:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E8890D");
                    break;

                case LogMessageType.Divers:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#3498db");
                    break;

                default:
                    LogTextBox.SelectionColor = ColorTranslator.FromHtml("#E8890D");
                    break;
                }
                var valueOrig = string.Empty;

                if (log.Contains("Received:") || log.Contains("Send"))
                {
                    switch (log.Split(':')[0])
                    {
                    case "Received":
                        valueOrig = "Serveur";
                        break;

                    case "Send":
                        valueOrig = "Client";
                        break;
                    }
                    string[] row1         = { DateTime.Now.ToLongTimeString(), valueOrig, log.Split('(')[1].Split(')')[0], log.Split('-')[1].Replace(" ", "") };
                    var      listViewItem = new ListViewItem(row1);
                    PacketsListView.Items.Add(listViewItem);

                    if (log.Contains("Send"))
                    {
                        PacketsListView.Items[PacketsListView.Items.Count - 1].ForeColor = ColorTranslator.FromHtml("#F16392");
                    }
                    if (log.Contains("Received"))
                    {
                        PacketsListView.Items[PacketsListView.Items.Count - 1].ForeColor = ColorTranslator.FromHtml("#9EC79D");
                    }
                }
                else if (log.Contains("NO HANDLER"))
                {
                    NoHandlersListBox.Items.Add(log.Split(':')[1].Replace(" ", ""));
                }
                else
                {
                    var text = $"[{DateTime.Now.ToLongTimeString()}] {log}";
                    LogTextBox.SelectedText   = text + "\r\n";
                    LogTextBox.SelectionColor = LogTextBox.ForeColor;
                    LogTextBox.ScrollToCaret();
                }
            }

            LogTextBox.Invoke((Action)LogCallback);
        }