private static void HandleClientCommunication(User userObj, string userInput) { UserInput CurrentInput = new UserInput(userObj, userInput); if (userInput.StartsWith(".")) { if (userInput.Trim().Length == 1) { userObj.LastCommand.Run(userObj.LastInput); return; } //TODO: need to check partial input as well ICommand CurrentCommand = Server.CommandList.Find(x => x.Name.Equals(CurrentInput.Args [0].ToLower())); if (CurrentCommand != null) { userObj.LastCommand = CurrentCommand; userObj.LastInput = CurrentInput; CurrentCommand.Run(CurrentInput); } else { userObj.WriteLine("Unknown command."); } } else { //TODO: setup default command thing.. Server.DefaultCommand.Run(CurrentInput); } }
private static void HandleClientCommunication(object client) { //NOTE since each communication is its own thread it is ok to block for a single user //althrough async would be the future plans even for a single user. //this server wouldn't need to be multi threaded if we used async stuff. MONO 3.0! User userObj = (User)client; NetworkStream clientStream = userObj.Stream; byte[] message = new byte[4096]; int bytesRead; while (true) { bytesRead = 0; try { bytesRead = clientStream.Read(message, 0, 4096); } catch { break; } UTF8Encoding encoder = new UTF8Encoding(); string userInput = encoder.GetString(message, 0, bytesRead).Trim(); UserInput CurrentInput = new UserInput(userObj, userInput); if (userInput.StartsWith(".")) { if (userInput.Trim().Length == 1) { userObj.LastCommand.Run(userObj.LastInput); continue; } //TODO: need to check partial input as well ICommand CurrentCommand = Server.CommandList.Find(x => x.Name.Equals(CurrentInput.Args[0].ToLower())); if (CurrentCommand != null) { userObj.LastCommand = CurrentCommand; userObj.LastInput = CurrentInput; CurrentCommand.Run(CurrentInput); } else { userObj.WriteLine("Unknown command."); } } else { //TODO: setup default command thing.. Server.DefaultCommand.Run(CurrentInput); } } }