예제 #1
0
        private void HandleUserInput()
        {
            while (true)
            {
                var userInput = Console.ReadLine().Trim();
                if (String.IsNullOrEmpty(userInput))
                {
                    continue;
                }

                if (commandMaster.IsCommand(userInput))
                {
                    var commandMessage = commandMaster.FormCommand(userInput);
                    if (commandMessage != null)
                    {
                        MessageEntered?.Invoke(JObject.FromObject(commandMessage));
                    }
                    continue;
                }

                if (Convert.ToString(userInput.Take(2)) == "//")
                {
                    userInput = userInput.Remove(0, 1);
                }
                var message = new ChatMessageFromClient(userInput);
                MessageEntered?.Invoke(JObject.FromObject(message));
            }
        }
예제 #2
0
        void IConsoleDataHandler.CommonMessage(string message)
        {
            var chatMessageFromClient = new ChatMessageFromClient
            {
                MessageType = MessageType.ChatMessageFromClient
            };

            if (message.Length > 2 && message[0] == '@')
            {
                message = message.Remove(0, 1);
                var wordArray = message.Split(' ');
                chatMessageFromClient.Args["Recipient"] = wordArray[0];
                var recipient = wordArray[0].ToString().Length;
                message = string.Join(" ", wordArray);
                message = message.Remove(0, recipient + 1);
            }

            chatMessageFromClient.Message = message;

            sender.Launch(chatMessageFromClient);
        }