public static void addMessage(ChatterDLL.Message msg) { string chatMessage = string.Empty; //Same user. if ((lastChatUser.username == msg.sender.username && lastChatUser.username != string.Empty && msg.data[0].ToString() != "/") || msg.sender.username.ToLower() == "server") { chatMessage = msg.sender.username + ": " + msg.data + "\n"; } //Different user. else if (msg.data[0].ToString() != "/") { chatMessage = "\n" + msg.sender.username + ": " + msg.data + "\n"; } else { return; } lastChatUser = msg.sender; frmMain.chatBox.Invoke((MethodInvoker) delegate() { frmMain.chatBox.Text += chatMessage; }); frmMain.chatBox.Invoke((MethodInvoker) delegate() { frmMain.chatBox.SelectionStart = frmMain.chatBox.Text.Length; }); frmMain.chatBox.Invoke((MethodInvoker) delegate() { frmMain.chatBox.ScrollToCaret(); }); }
private void btnSend_Click(object sender, EventArgs e) { string text = txtChat.Text.Trim(); if (text != string.Empty && receiver != string.Empty && isSignedIn) { User rec = new User() { username = receiver }; ChatterDLL.Message msg = new ChatterDLL.Message() { receiver = rec, data = text, type = ChatterDLL.msgType.chat }; ChatSender.sendMessage(msg); txtChat.Text = string.Empty; } }
public static void StartListener() { ServerConnect._serverSocket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallBack), ServerConnect._serverSocket); if (!frmMain.isSignedIn) { ChatterDLL.Message loginReq = new ChatterDLL.Message(); loginReq.type = msgType.login; loginReq.sender = Chat.localUser; loginReq.receiver = new User() { username = "******" }; ChatSender.sendMessage(loginReq); Chat.addText("Signing in..."); } }