예제 #1
0
        private void timerReceive_Tick(object sender, EventArgs e)
        {
            //If there's nothing in the queue just exit
            if (connection.receiveQueue.Count == 0)
            {
                return;
            }
            //There is a thing in the queue
            string message     = connection.receiveQueue.Take();
            int    splitPlace  = message.IndexOf('¶');
            int    splitPlace2 = message.IndexOf('¶', splitPlace + 1);

            string sendName = message.Substring(0, splitPlace);
            string opcode   = message.Substring(splitPlace + 1, splitPlace2 - (splitPlace + 1));
            string operand  = message.Substring(splitPlace2 + 1);

            switch (opcode)
            {
            case "sendMessage":
                //Create a message object, then send it to the server
                Message newMessage = new Message(sendName, operand);

                messageToUI(newMessage);

                break;

            case "messageList":
                //Get the message history from the server
                List <string> newMessagesString = operand.Split('¶').ToList();

                bulkAddMessages(newMessagesString);

                break;

            case "userList":
                //Get the list of users online, sending the server your nickname in the process
                if (operand != "")
                {
                    List <string> newPersonString = operand.Split('¶').ToList();

                    bulkAddPeople(newPersonString);
                }

                break;

            case "closeClient":
                //Close the program with an error
                Console.WriteLine(operand);
                FormError formError = new FormError(operand);
                formError.ShowDialog();
                Application.Exit();
                break;

            default:
                break;
            }
        }
예제 #2
0
 private void raiseError(string errorDescription)
 {
     if (errorShown == false)
     {
         errorShown = true;
         Console.WriteLine(errorDescription);
         FormError formError = new FormError(errorDescription);
         formError.ShowDialog();
         Application.Exit();
     }
 }