Marlingaming

Aperture Science OS System - Client Console 01

Sep 16th, 2021 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. --Client Console
  3. --this program allows the user to use console like commands while not being able to use system breaking commands on the default console
  4. --this program is for Minecraft 1.16.5, CC Tweaked
  5. term.clear()
  6. term.setCursorPos(1,1)
  7. local AllowedCommands = {"os.Details","os.delete","os.run","exit","","",""}
  8. local CommandOutput = {"custom","custom","shell.run(item)","custom","","",""}
  9. local AllowedOSPrograms = {"SecurityCheck"}
  10. local Line = 5
  11. print("CLIENT CONSOLE")
  12. print("Type Desired command then click enter to submit, or press left ctrl to exit")
  13. print("//warning this is a WIP feature, so it may be very buggy or things missing//")
  14. print("============================================================================")
  15.  
  16. function Console()
  17. term.setCursorPos(1,19+Line)
  18. local input = read()
  19. while true do
  20. local event, key = os.pullEvent("key")
  21. if key == keys.enter then
  22. break
  23. elseif input == "exit" then
  24. input = -1
  25. break
  26. else
  27. end
  28. term.write(input)
  29. end
  30. term.clearLine()
  31. if input == -1 then
  32. shell.run("ApertureOS_Base")
  33. else
  34. CheckCommand(input)
  35. end
  36.  
  37. end
  38.  
  39. function CheckCommand(command)
  40. local result = false
  41. command = command
  42. local Variable = nil
  43. local COMMAND = nil
  44. local COMMANDNum = 0
  45. local i = 1
  46. for i = 1, string.len(command) do
  47. if string.substring(command,i,i) == nil then
  48. COMMAND = string.substring(command,1,i-1)
  49. Variable = string.substring(command,i+1,#command)
  50. else
  51. i = i + 1
  52. end
  53. end
  54. for i = 1, #AllowedCommands do
  55. if COMMAND == AllowedCommands[i] then
  56. result = true
  57. COMMANDNum = i
  58. end
  59. end
  60. term.setCursorPos(1,Line)
  61. term.scroll(1)
  62. if result == false then
  63. term.writeLine("Couldnt find Command Called '"..command.."'")
  64. term.clear()
  65. Console()
  66. elseif result == true then
  67. term.writeLine(command.."(Sent!)")
  68. CheckOutput(COMMAND,COMMANDNum,Variable)
  69. end
  70. end
  71.  
  72. function CheckOutput(Command,CommandNum,Variable)
  73. local i = 1
  74. local result = false
  75. local Repeat = true
  76. for i = 1, #AllowedOSPrograms do
  77. if Variable == AllowedOSPrograms[i] then
  78. result = true
  79. end
  80. end
  81. if result == true then
  82. if CommandOutput[CommandNum] == "Custom" then
  83. if AllowedCommands[CommandNum] == "os.details" then
  84.  
  85. elseif AllowedCommands[CommandNum] == "os.delete" then
  86. Repeat = false
  87. shell.run("pastebin","run","tZnsW7FB") --os deletion handler
  88. elseif AllowedCommands[CommandNum] == "exit" then
  89. shell.run("ApertureOS_Base")
  90. end
  91. else
  92. if AllowedCommands[CommandNum] == "os.run" then
  93. Repeat = false
  94. shell.run(Variable)
  95. else
  96. end
  97. end
  98. elseif result == false then
  99. term.setCursorPos(1,Line)
  100. term.clearLine()
  101. term.writeLine("Command Was Successful, but "..Variable.." was either blacklisted variable or wasnt recongized")
  102. end
  103. if Repeat == true then
  104. Console()
  105. end
  106.  
  107. end
  108.  
  109.  
  110.  
  111.  
  112. Console()
Add Comment
Please, Sign In to add comment