void Receive() { lock (receivedMessageLock) { while (true) { try { byte[] receivedMessage = new byte[256]; serverStream.Read(receivedMessage, 0, receivedMessage.Length); string receivedMessageString = Encoding.ASCII.GetString(receivedMessage); ChatTextBox.BeginInvoke((System.Windows.Forms.MethodInvoker) delegate() { ChatTextBox.AppendText(receivedMessageString); }); ResetForm(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } }
private void HandleSendChatMessage() { if (_account.Character.Status == CharacterStatus.Disconnected) { return; } if (string.IsNullOrWhiteSpace(ChatTextBox.Text)) { Logger.Default.Log("Vous ne pouvez pas envoyer un texte vide.", LogMessageType.Public); } else { if (ChatTextBox.Text.Length > 2 && ChatTextBox.Text[0] == '.') { var txt = ChatTextBox.Text.Substring(1); try { CommandManager.ParseAndCall(_account, txt); } catch (Exception e) { Logger.Default.Log(e.Message); Logger.Default.Log("Commande Incorrecte ou qui a échouée.", LogMessageType.Public); } ChatTextBox.BeginInvoke(new Action(() => ChatTextBox.Text = "")); return; } if (ChatTextBox.Text.Length < 2) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_GLOBAL, ChatTextBox.Text)); } else { var txt = ChatTextBox.Text.Substring(0, 2); var chattxt = ChatTextBox.Text.Replace(txt, ""); switch (txt) { case "/g": if (string.IsNullOrWhiteSpace(chattxt)) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_GUILD, chattxt)); } break; case "/s": if (string.IsNullOrWhiteSpace(chattxt)) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_GLOBAL, chattxt)); } break; case "/t": if (string.IsNullOrWhiteSpace(chattxt)) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_TEAM, chattxt)); } break; case "/a": if (string.IsNullOrWhiteSpace(chattxt)) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_ALLIANCE, chattxt)); } break; case "/p": if (string.IsNullOrWhiteSpace(chattxt)) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_PARTY, chattxt)); } break; case "/k": if (string.IsNullOrWhiteSpace(chattxt)) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_ARENA, chattxt)); } break; case "/b": if (string.IsNullOrWhiteSpace(chattxt)) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_SALES, chattxt)); } break; case "/r": if (string.IsNullOrWhiteSpace(chattxt)) { _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_SEEK, chattxt)); } break; default: _account.Network.SendToServer(new ChatClientMultiMessage( (byte)ChatChannelsMultiEnum.CHANNEL_GLOBAL, ChatTextBox.Text)); break; } ChatTextBox.BeginInvoke(new Action(() => ChatTextBox.Text = "")); } } }
private void HandleSendChatMessage() { if (_account.Character.Status == CharacterStatus.Disconnected) { return; } if (string.IsNullOrWhiteSpace(ChatTextBox.Text)) { Logger.Default.Log("Vous ne pouvez pas envoyer un texte vide.", LogMessageType.Public); } else { _chatHistory.Add(ChatTextBox.Text); Logger.Default.Log(ChatTextBox.Text, LogMessageType.Command); if (ChatTextBox.Text.Length > 2 && ChatTextBox.Text[0] == '.') { var txt = ChatTextBox.Text.Substring(1); try { CommandManager.ParseAndCall(_account, txt); } catch (Exception e) { Logger.Default.Log(e.Message); Logger.Default.Log("Commande Incorrecte ou qui a échouée.", LogMessageType.Public); } ChatTextBox.BeginInvoke(new Action(() => ChatTextBox.Text = "")); return; } if (ChatTextBox.Text.Length < 2) { var ccmm = new ChatClientMultiMessage { Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_GLOBAL, Content = ChatTextBox.Text }; _account.Network.SendToServer(ccmm); } else { var txt = ChatTextBox.Text.Substring(0, 2); var chattxt = ChatTextBox.Text.Replace(txt, ""); if (txt == "/w") { string[] receiver = chattxt.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); var messagePacket = new ChatClientPrivateMessage(receiver[0]) { Content = receiver[1] }; _account.Network.SendToServer(messagePacket); } else { var ccmm = new ChatClientMultiMessage { Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_GLOBAL, Content = chattxt }; switch (txt) { case "/g": if (string.IsNullOrWhiteSpace(chattxt)) { ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_GUILD; } break; case "/s": if (string.IsNullOrWhiteSpace(chattxt)) { ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_GLOBAL; } break; case "/t": if (string.IsNullOrWhiteSpace(chattxt)) { ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_TEAM; } break; case "/a": if (string.IsNullOrWhiteSpace(chattxt)) { ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_ALLIANCE; } break; case "/p": if (string.IsNullOrWhiteSpace(chattxt)) { ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_PARTY; } break; case "/k": if (string.IsNullOrWhiteSpace(chattxt)) { ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_ARENA; } break; case "/b": if (string.IsNullOrWhiteSpace(chattxt)) { ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_SALES; } break; case "/r": if (string.IsNullOrWhiteSpace(chattxt)) { ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_SEEK; } break; default: ccmm.Channel = (sbyte)ChatChannelsMultiEnum.CHANNEL_GLOBAL; ccmm.Content = txt + chattxt; break; } _account.Network.SendToServer(ccmm); ChatTextBox.BeginInvoke(new Action(() => ChatTextBox.Text = "")); } } } }