Exemplo n.º 1
0
        public void CreateMessageWindow(string username)
        {
            // Well, we got here, guess there hasn't been one yet
            // Let's create it
            wfMsg retMsg = new wfMsg(username, this);

            // Show the window now (we will do this again, but that's ok)
            retMsg.Show();
            retMsg.Select();
            retMsg.BringToFront();
            lock (msgForms)
            {
                msgForms.Add(retMsg);
            }
            // We need to know if a form is disposed
            retMsg.Disposed += new System.EventHandler(this.MessageWindowDisposed);
        }
Exemplo n.º 2
0
        private void DataReceived(object sender, ReceiveEventArgs e)
        {
            // We've received data, process it
            string username  = null;
            string chatmsg   = null;
            bool   friend    = false;
            wfMsg  msgWindow = null;

            MessageType msg = (MessageType)e.Message.ReceiveData.Read(typeof(MessageType));

            switch (msg)
            {
            case MessageType.LoginSuccess:                     // We've been logged in
                this.EnableLoggedInUi(true);
                this.UpdateText(MessengerShared.ApplicationName + " - (" + gUsername + ")");
                break;

            case MessageType.InvalidPassword:                     // Server says we entered the wrong password
                MessageBox.Show("The password you've entered is invalid.", "Invalid password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case MessageType.InvalidUser:
                MessageBox.Show("The username you've entered is invalid.", "Invalid user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case MessageType.UserAlreadyExists:
                MessageBox.Show("The username you've entered already exists.\nYou must choose a different user name.", "Invalid user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case MessageType.SendClientFriends:
                int numFriends = (int)e.Message.ReceiveData.Read(typeof(int));
                // Ok, we know how many friends are in the message, let's go through them all
                for (int i = 0; i < numFriends; i++)
                {
                    friend   = (bool)e.Message.ReceiveData.Read(typeof(bool));
                    username = e.Message.ReceiveData.ReadString();

                    object[] newParams = { offlineNode, username, friend };
                    // User our callback to add our friend to this node
                    this.BeginInvoke(new AddNodeCallback(this.AddNode), newParams);
                }
                break;

            case MessageType.FriendAdded:
                username = e.Message.ReceiveData.ReadString();
                object[] addParams = { offlineNode, username, true };
                // User our callback to add our friend to this node
                this.BeginInvoke(new AddNodeCallback(this.AddNode), addParams);
                MessageBox.Show(username + " added succesfully to your friends list.", "Added", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case MessageType.FriendDeleted:
                username = e.Message.ReceiveData.ReadString();
                object[] deleteParams = { username };
                // User our callback to add our friend to this node
                this.BeginInvoke(new RemoveNodeCallback(this.RemoveNode), deleteParams);
                break;

            case MessageType.FriendBlocked:
                username = e.Message.ReceiveData.ReadString();
                object[] blockParams = { offlineNode, username, false };
                // User our callback to add our friend to this node
                this.BeginInvoke(new AddNodeCallback(this.AddNode), blockParams);
                MessageBox.Show(username + " has been blocked succesfully.", "Blocked", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case MessageType.FriendDoesNotExist:
                MessageBox.Show("You cannot add this friend since they do not exist.", "Invalid user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case MessageType.BlockUserDoesNotExist:
                MessageBox.Show("You cannot block this user since they do not exist.", "Invalid user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case MessageType.FriendLogon:
                username = e.Message.ReceiveData.ReadString();
                object[] logonParams = { onlineNode, username };
                // User our callback to add our friend to this node
                this.BeginInvoke(new NodeLogonOffCallback(this.NodeLogonOff), logonParams);
                break;

            case MessageType.FriendLogoff:
                username = e.Message.ReceiveData.ReadString();
                object[] logoffParams = { offlineNode, username };
                // User our callback to add our friend to this node
                this.BeginInvoke(new NodeLogonOffCallback(this.NodeLogonOff), logoffParams);
                break;

            case MessageType.ReceiveMessage:
                username = e.Message.ReceiveData.ReadString();
                chatmsg  = e.Message.ReceiveData.ReadString();
                // We need to get a message window
                msgWindow = this.GetMessageWindow(username);

                // Show the window, and add the text
                msgWindow.BeginInvoke(new wfMsg.ShowWindowCallback(msgWindow.ShowWindow));

                object[] receiveMsg = { chatmsg, false, false };
                msgWindow.BeginInvoke(new wfMsg.AddChatMsgCallback(msgWindow.AddChatMessage), receiveMsg);

                break;

            case MessageType.UserBlocked:
                username  = e.Message.ReceiveData.ReadString();
                chatmsg   = "Your message to " + username + " could not be delivered because this user has you blocked.";
                msgWindow = this.GetMessageWindow(username);
                // Show the window, and add the text
                msgWindow.BeginInvoke(new wfMsg.ShowWindowCallback(msgWindow.ShowWindow));

                object[] blockMsg = { chatmsg, false, true };
                msgWindow.BeginInvoke(new wfMsg.AddChatMsgCallback(msgWindow.AddChatMessage), blockMsg);
                break;

            case MessageType.UserUnavailable:
                username  = e.Message.ReceiveData.ReadString();
                chatmsg   = e.Message.ReceiveData.ReadString();
                msgWindow = this.GetMessageWindow(username);
                // Show the window, and add the text
                msgWindow.BeginInvoke(new wfMsg.ShowWindowCallback(msgWindow.ShowWindow));

                object[] unavailableMsg = { "Your Message: \r\n" + chatmsg + "\r\nto " + username + " could not be delivered because the user is no longer available.", false, true };
                msgWindow.BeginInvoke(new wfMsg.AddChatMsgCallback(msgWindow.AddChatMessage), unavailableMsg);
                break;
            }
            e.Message.ReceiveData.Dispose();             // Don't need the data anymore
        }
Exemplo n.º 3
0
 private void mnuSend_Click(object sender, System.EventArgs e)
 {
     wfMsg msgWindow = this.GetMessageWindow(tvwItems.SelectedNode.Tag.ToString());
 }