private void Handler(string input) { if (input.Split(' ').Length == 0) { return; } string commandName = input.Split(' ')[0]; if (commandName == "Help") { int page = 0; int i = 0; if (input.Split(' ').Length > 1 && !int.TryParse(input.Split(' ')[1], out page)) { var cmd = input.Split(' ')[1]; if (!Commands.ContainsKey(cmd)) { output.text += "\n" + string.Format(info, "The command \"" + cmd + "\" doesn't exists\nType \"Help\" to get a list of available commands"); return; } TTCommand commandHelp = Commands[cmd]; output.text += "\n" + string.Format(info, cmd + " : " + commandHelp.Description); if (commandHelp.ArgumentsDescriptions.Keys.Count != 0) { foreach (string argName in commandHelp.ArgumentsDescriptions.Keys) { Console.WriteLine(argName.ToString()); try { //Console.WriteLine(commandHelp.ArgumentsDescriptions[argName]); output.text += "\n" + argName + " : " + commandHelp.ArgumentsDescriptions[argName]; } catch (Exception ex) { Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } } } //Console.WriteLine(output.text); } else { if (page < 0) { page = 0; } if (page > 0) { page -= 1; } double pageCount = Math.Ceiling((double)Commands.Count / 5); if (page + 1 > pageCount) { page = 0; } output.text += "\n" + string.Format(info, "Help - Page " + (page + 1) + "/" + pageCount); output.text += "\n" + string.Format(info, "Command usage : CommandName Arg1:Value1 Arg2:Value2 ArgN:ValueN\nFor more informations about a command do \"Help CommandName\""); foreach (string commName in Commands.Keys) { if (page * 5 <= i && i < page * 5 + 5) { TTCommand commandHelp = Commands[commName]; output.text += "\n" + commName + " : " + commandHelp.Description; } i++; } } } else if (commandName == "Clear") { output.text = ""; last = ""; history.Clear(); historyIndex = 0; } else { if (!Commands.ContainsKey(commandName)) { output.text += "\n" + string.Format(info, "The command \"" + commandName + "\" doesn't exists\nType \"Help\" to get a list of available commands"); } else { Dictionary <string, string> args = new Dictionary <string, string>(); try { if (input.Split(' ').Length > 1) { for (var i = 1; i < input.Split(' ').Length; i++) { string[] arg = input.Split(' ')[i].Split(':'); args.Add(arg[0], arg[1]); } } } catch { output.text += string.Format(error, "\nBad syntax. Make sure to use \"name:value\""); } TTCommand command = Commands[commandName]; try { string commandOut = command.Call(args); if (commandOut != null) { output.text += "\n" + commandOut; } } catch (Exception ex) { output.text += "\n" + string.Format(error, "An error occured in the command " + commandName); Console.WriteLine(ex.ToString()); } } } }
private void Handler(string input) { if (input.Split(' ').Length == 0) { return; } string commandName = input.Split(' ')[0]; if (commandName == "Help") { int page = 0; int i = 0; if (input.Split(' ').Length > 1 && !int.TryParse(input.Split(' ')[1], out page)) { TTCommand commandHelp = Commands[input.Split(' ')[1]]; output.text += "\n" + string.Format(info, input.Split(' ')[1] + " : " + commandHelp.Description); if (commandHelp.ArgumentsDescriptions.Keys.Count != 0) { foreach (string argName in commandHelp.ArgumentsDescriptions.Keys) { Console.WriteLine(argName.ToString()); try { ///Console.WriteLine(commandHelp.ArgumentsDescriptions[argName]); output.text += "\n" + argName + " : " + commandHelp.ArgumentsDescriptions[argName]; } catch (Exception ex) { Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } } } //Console.WriteLine(output.text); } else { if (page < 0) { page = 0; } if (page > 0) { page -= 1; } double pageCount = Math.Ceiling((double)Commands.Count / 5); if (page + 1 > pageCount) { page = 0; } output.text += "\n" + string.Format(info, "Help - Page " + (page + 1) + "/" + pageCount); output.text += "\n" + string.Format(info, "Command usage : CommandName Arg1:Value1 Arg2:Value2 ArgN:ValueN\nFor more informations about a command do \"Help CommandName\""); foreach (string commName in Commands.Keys) { if (page * 5 <= i && i < page * 5 + 5) { TTCommand commandHelp = Commands[commName]; output.text += "\n" + commName + " : " + commandHelp.Description; } i++; } } } else if (commandName == "clear") { output.text = ""; last = ""; history.Clear(); historyIndex = 0; } /*else if (commandName == "s") * { * Tank temp = Singleton.Manager<ManSpawn>.inst.SpawnEmptyTechRef(Singleton.playerTank.Team, Singleton.playerPos + new Vector3(30, 0, 30), Quaternion.identity, true, false,"").visible.tank; * try * { * output.text += "\n"+ temp.blockman.blockTableSize + " " + temp.blockman.blockCentreBounds.ToString(); * var block = Singleton.Manager<ManSpawn>.inst.SpawnBlock(BlockTypes.GSOCockpit_111, new Vector3(0, 53, 0), Quaternion.identity); * temp.blockman.AddBlock(ref block, IntVector3.zero); * output.text += "\n" + temp.blockman.blockTableSize + " " + temp.blockman.blockCentreBounds.ToString(); * output.text += "\n" + temp.blockman.GetBlockAtPosition(IntVector3.zero).BlockType.ToString(); * } catch (Exception ex) * { * output.text += "\n" + string.Format(error, ex.Message + "\n" + ex.StackTrace); * } * }*/ else { if (!Commands.TryGetValue(commandName, out var a)) { output.text += "\n" + string.Format(info, "The command \"" + commandName + "\" doesn't exists\nType \"Help\" to get a list of available commands"); } else { Dictionary <string, string> args = new Dictionary <string, string>(); try { if (input.Split(' ').Length > 1) { for (var i = 1; i < input.Split(' ').Length; i++) { string[] arg = input.Split(' ')[i].Split(':'); args.Add(arg[0], arg[1]); } } } catch { output.text += string.Format(error, "\nBad syntax. Make sure to use \"name:value\""); } TTCommand command = Commands[commandName]; try { string commandOut = command.Call(args); if (commandOut != null) { output.text += "\n" + commandOut; } } catch (Exception ex) { output.text += "\n" + string.Format(error, "An error occured in the command " + commandName); Console.WriteLine(ex.Message + "\n" + ex.StackTrace); } } } }