Guest User

Untitled

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