Exemplo n.º 1
0
        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(); });
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        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...");
            }
        }