Guest User

Untitled

a guest
Jul 1st, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. local version = "Version 1.2"
  2. local description = "'SSH'-Client for connecting to a remote controlable PC/Turtle via Rednet"
  3.  
  4. old_commands = {}
  5.  
  6. running = true
  7. side = "left" --Side where the Modem is attached on
  8. w, h = term.getSize()
  9. Send_ID = 0
  10. send_to = 0
  11. nbr_com = 0
  12. commandSpec = ""
  13.  
  14. --Functions
  15.  
  16. local function printCentered(str, ypos)
  17. term.setCursorPos(w/2 - #str/2, ypos)
  18. term.write(str)
  19. end
  20.  
  21. local function printRight(str, ypos)
  22. term.setCursorPos(w - #str, ypos)
  23. term.write(str)
  24. end
  25.  
  26. local function printLeft(str, ypos)
  27. term.setCursorPos(1, ypos)
  28. term.write(str)
  29. end
  30.  
  31. function drawHeader()
  32. printCentered("SSH-System for Rednet.", 1)
  33. printCentered(string.rep("-", w), 2)
  34. printLeft(version, h)
  35. printRight("by Dean4Devil", h)
  36. end
  37.  
  38.  
  39. function ssh_send(msg)
  40. rednet.open(side)
  41. rednet.send(send_to, msg)
  42. id, answer, distance = rednet.receive(5)
  43. answer = tostring(answer)
  44. rednet.close(side)
  45. end
  46.  
  47. --Funktions END
  48. --Main
  49. term.clear()
  50. while running == true do
  51. term.clear()
  52. drawHeader()
  53. term.setCursorPos(1, 4)
  54. write( "> " )
  55. commandRaw = read()
  56. commandMain = tostring(commandRaw)
  57. table.insert(old_commands, commandMain)
  58. commandMainLower = string.lower(commandMain)
  59. commandSpec = string.sub(commandMain, 1, 1)
  60. if commandSpec == "/" then --lokales Kommando -> nicht versenden!
  61. if commandMainLower == "/exit" then
  62. running = false
  63. elseif commandMainLower == "/connect" then
  64. print("Give ID:")
  65. write("> ")
  66. send_to = tonumber(read())
  67. elseif commandMainLower == "/disconnect" then
  68. send_to = 0
  69. elseif commandMainLower == "/dito" then
  70. write("\n")
  71. write(old_commands[#old_commands-1])
  72. ssh_send(old_commands[#old_commands-1])
  73. else
  74. print("Unknown Command!")
  75. end
  76. elseif commandSpec == "#" then --Server-Präprozessor -> versenden
  77.  
  78. else --normale Kommandos -> versenden
  79. ssh_send(commandMain)
  80. print(answer)
  81. sleep(1)
  82. end
  83.  
  84. end
  85. term.clear()
  86. term.setCursorPos(1,1)
  87. --Main END
Add Comment
Please, Sign In to add comment