public void ParseInput(string input) //Handle console commands { if (input.Length > 0) { if (input[0] != '/') { Player.GlobalMessage("[Console]: &f" + input); Logger.Log(input, LogType.GlobalChat); } else { input = input.Substring(1).Trim(); string cmd; string[] splitInput; string msg; string output = ""; splitInput = input.Split(' '); cmd = splitInput[0]; if (splitInput.Length > 1) { msg = input.Substring(input.IndexOf(' ')).Trim(); } else { msg = ""; } try { switch (cmd) { case "help": output = "Commands that the console can use: \n"; try { foreach (Command command in Command.all.All()) { if (command.ConsoleSupport) { output += "/" + command.Name + ", "; } } Logger.Log(output, LogType.ConsoleOutput); } catch (Exception e) { Logger.Log(e.Message, LogType.ErrorMessage); } output = output.Remove(output.Length - 2); break; default: Command runCmd = Command.all.Find(cmd); if (runCmd != null) { if (runCmd.ConsoleSupport) { Logger.Log("/" + input, LogType.ConsoleOutput); runCmd.Use(msg); } else { Logger.Log("This command is not supported by the console!", LogType.ConsoleOutput); } } else { Logger.Log("No such command!", LogType.ConsoleOutput); } break; } } catch (Exception e) { Logger.Log(e.Message, LogType.ErrorMessage); } //Thread.Sleep(10); } } }
/// <summary> /// This function parses input from the server console. In reality the server console should handle the wait for input /// and call a function within the library to parse a specific command. /// </summary> public void ParseInput() //Handle console commands { string cmd; string msg; string output; while (running) { string input = Console.ReadLine(); if (input == null) { continue; } cmd = input.Split(' ')[0]; if (input.Split(' ').Length > 1) { msg = input.Substring(input.IndexOf(' ')).Trim(); } else { msg = ""; } try { switch (cmd) { case "help": output = "Commands that the console can use: \n"; try { foreach (Command command in Command.all.All()) { if (command.ConsoleSupport) { output += command.Name + ", "; } } } catch (Exception e) { Console.WriteLine(e.Message); } output = output.Remove(output.Length - 2); Console.WriteLine(output); break; default: Command runCmd = Command.all.Find(cmd); if (runCmd != null) { if (runCmd.ConsoleSupport) { runCmd.Use(msg); } else { Console.WriteLine("This command is not supported by the console!"); } } else { Console.WriteLine("No such command!"); } break; } } catch (Exception e) { Logger.Log(e.Message, LogType.ErrorMessage); } //Thread.Sleep(10); } }