Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1.  
  2. --[[
  3. Remote Terminal Client
  4. by BigShinyToys
  5. OPEN SOURCE CODE (no rights reserved)
  6. ]]--
  7. local SeverID = nil
  8. local asa = 1 -- test mode
  9. local function runner()
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. while true do
  13. local e1,e2,e3,e4,e5 = os.pullEvent()
  14. if e1 == "rednet_message" then -- and e2 == SeverID
  15. local sTest = string.sub(e3,1,3)
  16. if sTest == "WRT" then
  17. write(string.sub(e3,4,#e3))
  18. elseif sTest == "CLR" then
  19. term.clear()
  20. elseif sTest == "CLL" then
  21. term.clearLine()
  22. elseif sTest == "SCB" then
  23. local boolin = string.sub(e3,4,#e3)
  24. if boolin == "true" then
  25. term.setCursorBlink(true)
  26. elseif boolin == "false" then
  27. term.setCursorBlink(false)
  28. end
  29. elseif sTest == "SCP" then
  30. local curP = textutils.unserialize(string.sub(e3,4,#e3))
  31. term.setCursorPos(curP[1],curP[2])
  32. elseif sTest == "GSZ" then -- work on this
  33. rednet.send(SeverID,"SIZ"..textutils.serialize({term.getSize()}))
  34. elseif sTest == "GCP" then
  35. rednet.send(SeverID,"POS"..textutils.serialize({term.getCursorPos()}))
  36. elseif sTest == "SCR" then
  37. term.scroll(tonumber(string.sub(e3,4,#e3)))
  38. end
  39. elseif e1 == "key" then
  40. rednet.send(SeverID,"key"..tostring(e2))
  41. rednet.send(asa,"key"..tostring(e2))
  42. elseif e1 == "char" then
  43. rednet.send(SeverID,"cha"..e2)
  44. rednet.send(asa,"cha"..e2)
  45. end
  46. end
  47. end
  48.  
  49. local function openRednet()
  50. local listOfSides = rs.getSides()
  51. for i = 1,6 do
  52. if peripheral.isPresent(listOfSides[i]) and peripheral.getType(listOfSides[i]) == "modem" then
  53. rednet.open(listOfSides[i])
  54. return listOfSides[i]
  55. end
  56. end
  57. end
  58. modemOn = openRednet()
  59. if not modemOn then
  60. print("No WIFI ModemnPress any key to return to exit")
  61. os.pullEvent("key")
  62. return
  63. end
  64. term.clear()
  65. term.setCursorPos(1,1)
  66. print("Welcom to remote terminal")
  67. print("Sever ID")
  68. SeverID = tonumber(read())
  69. print("User Name :")
  70. local UserName = read()
  71. print("Password")
  72. local UserPass = read("*")
  73. print("authenticating")
  74. rednet.send(SeverID,"RMTLOGINREQ:"..textutils.serialize({UserName,UserPass}))
  75. while true do
  76. local e1,e2,e3,e4,e5 = os.pullEvent()
  77. if e1 == "rednet_message" then
  78. if e2 == SeverID then
  79. if e3 == "Request Accepted" then
  80. runner()
  81. end
  82. end
  83. end
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement