BigSHinyToys

Remote terminal Client mk2

May 11th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. --[[
  2.         reciver client mk2
  3.         by BigSHinyToys
  4. ]]--
  5.  
  6. local oldError = error
  7. error = function(...)
  8.     local data = {...}
  9.     local file = fs.open("log","a")
  10.     if file then
  11.         for i = 1,#data do
  12.             file.write(tostring(data[i]).." ")
  13.         end
  14.         file.write("\n")
  15.         file.close()
  16.     end
  17.     oldError(unpack(data))
  18. end
  19.  
  20. local function findDevice(sType)
  21.     for _,sSide in pairs(rs.getSides()) do
  22.         if peripheral.isPresent(sSide) and peripheral.getType(sSide) == sType then
  23.             return sSide,peripheral.wrap(sSide)
  24.         end
  25.     end
  26. end
  27.  
  28. local modemSide,modem = findDevice("modem")
  29. local freq = 0
  30.  
  31. local function main()
  32.     while true do
  33.        
  34.         local event = {os.pullEvent()}
  35.         if event[1] == "modem_message" then
  36.             local test,tInput = pcall(textutils.unserialize,event[5])
  37.             for i = 1,#tInput do
  38.                 pcall(
  39.                     function()
  40.                         local this = textutils.unserialize(tInput[i])
  41.                         local sFunk = this[1]
  42.                         table.remove(this,1)
  43.                         term[sFunk](unpack(this))
  44.                     end
  45.                 )
  46.             end
  47.         else
  48.             table.insert(event,1,"INS")
  49.             modem.transmit(freq,freq,textutils.serialize(event))
  50.         end
  51.        
  52.     end
  53. end
  54.  
  55. if modemSide then
  56.     print(" --- Remote access client --- ")
  57.     while true do
  58.         write("Choose Freq : ")
  59.         local temp = read()
  60.         if string.lower(temp) == "exit" then
  61.             print(" --- Exiting program --- ")
  62.             return
  63.         end
  64.         temp = tonumber(temp)
  65.         if type(temp) == "number" and temp >= 0 and temp <= 65535 then
  66.             freq = temp
  67.             break
  68.         end
  69.         print("ERROR : Range 0 - 65535 or Exit")
  70.     end
  71.     write("User : ")
  72.     local user = read()
  73.     write("Password : ")
  74.     local pass = read("*")
  75.     print("Opening modem : "..modemSide.." Freq : "..tostring(freq))
  76.     modem.open(freq)
  77.     modem.transmit(freq,freq,textutils.serialize({user = user,password = pass}))
  78.     os.pullEvent()
  79.     local width,hight = term.getSize()
  80.     modem.transmit(freq,freq,textutils.serialize({cmd = "REPLY-SCP",test = term.isColor(),w = width,h = hight}))
  81.     term.clear()
  82.     term.setCursorPos(1,1)
  83.     main()
  84. else
  85.     print("ERROR : Failed to find modem ")
  86. end
Advertisement
Add Comment
Please, Sign In to add comment