// Looped Function that handles chat input and output public static void HandleChat(NetworkStream stream, User user, ConsoleColor ComplementaryColour, ConsoleColor OriginalColor) { string OutputMessage, InputMessage; while (true) { ConsoleKeyInfo KeyPressed; // Checks for key press if (Console.KeyAvailable) { KeyPressed = Console.ReadKey(); if (KeyPressed.Key == ConsoleKey.I) { Console.Write(">> "); InputMessage = Console.ReadLine(); user.SendMessage(InputMessage, stream); if (InputMessage.ToLower() == "quit") { user.Close(); } } } else { // Checks for data stream input OutputMessage = user.RecieveMessage(stream); if (OutputMessage.ToLower() != "quit" && OutputMessage != "") { // Changes console text color Console.ForegroundColor = ComplementaryColour; Console.WriteLine(OutputMessage); Console.ForegroundColor = OriginalColor; } // Handles closing if (OutputMessage.ToLower() == "quit") { user.Close(); } } } }