Advertisement
BigSHinyToys

telnet client

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