daanh432

Untitled

Dec 24th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. --[[
  2.   Remote Terminal
  3.   by BigShinyToys
  4.   OPEN SOURCE CODE (no rights reserved)
  5. ]]--
  6. tArgs = {...}
  7. if #tArgs == 0 then
  8. elseif tArgs[1] == "reboot" then
  9. os.reboot()
  10. elseif tArgs[1] == "shutdown" then
  11. os.shutdown()
  12. elseif tArgs[1] == "restore" then
  13. function os.pullEventRaw( _sFilter )
  14.   return coroutine.yield( _sFilter )
  15. end
  16. term.restore()
  17. print("Closed Sestion")
  18. return
  19. elseif tArgs[1] == "logoff" then
  20. function os.pullEventRaw( _sFilter )
  21.   return coroutine.yield( _sFilter )
  22. end
  23. term.restore()
  24. print("Closed Sestion")
  25. end
  26. UserID = -1
  27. -- user names tha have access
  28. local Authenticate = {
  29. ted = "hello",
  30. harry = "hello2"
  31. }
  32. local function openRednet()
  33. local listOfSides = rs.getSides()
  34. for i = 1,6 do
  35.   if peripheral.isPresent(listOfSides[i]) and peripheral.getType(listOfSides[i]) == "modem" then
  36.    rednet.open(listOfSides[i])
  37.    return listOfSides[i]
  38.   end
  39. end
  40. end
  41. modemOn = openRednet()
  42. if not modemOn then
  43. print("No WIFI ModemnPress any key to return to exit")
  44. os.pullEvent("key")
  45. return
  46. end
  47. function os.pullEventRaw(...)
  48. local e1,e2,e3,e4,e5 = coroutine.yield(...)
  49. if e1 == "rednet_message" and e2 == UserID then
  50.    local a = string.sub(e3,1,3)
  51.   if a == "key" then
  52.    return "key",tonumber(string.sub(e3,4,string.len(e3)))
  53.   elseif a == "cha" then
  54.    return "char",string.sub(e3,4,4)
  55.   end
  56. end
  57. return e1,e2,e3,e4,e5
  58. end
  59. remote = {}
  60. function remote.write(s)
  61. rednet.send(UserID,"WRT"..s)
  62. end
  63. function remote.clear()
  64. rednet.send(UserID,"CLR")
  65. end
  66. function remote.clearLine()
  67. rednet.send(UserID,"CLL")
  68. end
  69. function remote.setCursorBlink(s)
  70. rednet.send(UserID,"SCB"..tostring(s))
  71. end
  72. function remote.setCursorPos(x,y)
  73. rednet.send(UserID,"SCP"..textutils.serialize({x,y}))
  74. end
  75. function remote.getSize()
  76. rednet.send(UserID,"GSZ")
  77. while true do
  78.   local w1,w2,w3 = os.pullEvent("rednet_message")
  79.   if string.sub(w3,1,3) == "SIZ" then
  80.    local a = textutils.unserialize(string.sub(w3,4,string.len(w3)))
  81.    return a[1],a[2]
  82.   end
  83. end
  84. end
  85. function remote.getCursorPos()
  86. rednet.send(UserID,"GCP")
  87. while true do
  88.   local w1,w2,w3 = os.pullEvent("rednet_message")
  89.   if string.sub(w3,1,3) == "POS" then
  90.    local a = textutils.unserialize(string.sub(w3,4,string.len(w3)))
  91.    return a[1],a[2]
  92.   end
  93. end
  94. end
  95. function remote.scroll(nLines)
  96. rednet.send(UserID,"SCR"..tostring(nLines))
  97. end
  98. term.clear()
  99. term.setCursorPos(1,1)
  100. print("Remote Terminal Started")
  101. while true do
  102. local q1,q2,q3,q4,q5 = os.pullEvent()
  103. print(tostring(q1).." "..tostring(q2))
  104. if q1 == "rednet_message" then
  105.   local test = string.sub(q3,1,12)
  106.   if test == "RMTLOGINREQ:" then
  107.    local uDAT =  textutils.unserialize(string.sub(q3,13,string.len(q3)))
  108.    if Authenticate[uDAT[1]] == uDAT[2] then
  109.         term.clear()
  110.         term.setCursorPos(1,1)
  111.         print("User "..tostring(uDAT[1]).." Online")
  112.         rednet.send(q2,"Request Accepted")
  113.         sleep(1)
  114.         UserID = q2
  115.         term.redirect(remote)
  116.         term.clear()
  117.         term.setCursorPos(1,1)
  118.         break
  119.    end
  120.   end
  121. end
  122. end
  123. print("Open Connection")
Add Comment
Please, Sign In to add comment