Advertisement
ivan52

Doob_Kopalka

Jan 31st, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. local inet = component.proxy(component.list("internet")())
  2. local gpu = component.proxy(component.list("gpu")())
  3.  
  4. local URL = "http://46.50.128.141/lua/miner.lua"
  5. local REMOTEADDR = "93.171.161.242:39139"
  6. local TIMEOUT = 4
  7.  
  8. local sock = inet.request(URL)
  9.  
  10. gpu.bind(component.list("screen")(), true)
  11.  
  12. gpu.setResolution(50, 16)
  13.  
  14. local w, h = gpu.getResolution()
  15. gpu.setBackground(0x000000)
  16. gpu.setForeground(0xFFFFFF)
  17.  
  18. local function log(line)
  19.   gpu.copy(1, 1, w, h, 0, -1)
  20.   gpu.fill(1, h, w, 1, " ")
  21.   gpu.set(1, h, tostring(line))
  22. end
  23.  
  24. local function sleep(to)
  25.   local deadline = computer.uptime() + to
  26.   while computer.uptime() < deadline do
  27.     computer.pullSignal(computer.uptime() - deadline)
  28.   end
  29. end
  30.  
  31. log("Connecting to the server...")
  32.  
  33. for i = 1, 10, 1 do
  34.   if not sock then
  35.     break
  36.   end
  37.   if sock.finishConnect() then
  38.     break
  39.   end
  40.   sleep(1)
  41. end
  42.  
  43. if not sock or not sock.finishConnect() then
  44.   log("- Request failed.")
  45.   computer.beep(400, 1)
  46.   computer.beep(600, 2)
  47.   computer.beep(400, 0.4)
  48.   computer.beep(400, 0.4)
  49.   error("request failed")
  50. end
  51.  
  52. local code = ""
  53. log("Downloading code...")
  54. while true do
  55.   local chunk = sock.read(8192)
  56.   if not chunk then
  57.     break
  58.   end
  59.   code = code .. chunk
  60. end
  61.  
  62. log("Downloaded " .. #code .. " bytes; connecting to the remote")
  63.  
  64. sock.close()
  65. sock = inet.connect(REMOTEADDR)
  66.  
  67. log("Compiling code...")
  68.  
  69. local env = {}
  70. for k, v in pairs(_ENV) do
  71.   env[k] = v
  72. end
  73.  
  74. local pullSignal = computer.pullSignal
  75.  
  76. local tries = TIMEOUT
  77. env.computer.pullSignal = function(timeout)
  78.   if sock and sock.finishConnect() then
  79.     tries = 1
  80.     if not sock.write("STATUS DATA [" .. os.date("%Y-%m-%d %H:%M:%S") .. "]\n\t" .. (env.status and (env.status() or "none") or "none") .. "\n") then
  81.       tries = 0
  82.     end
  83.   else
  84.     log("Attempt to connect made; failed; " .. tries .. " left.")
  85.     tries = tries - 1
  86.   end
  87.   if tries == 0 or not sock then
  88.     log("Connection lost; reconnecting")
  89.     tries = TIMEOUT
  90.     if sock then
  91.       sock.close()
  92.     end
  93.     sock = inet.connect(REMOTEADDR)
  94.   end
  95.   pullSignal(timeout)
  96. end
  97.  
  98. local chunk, reason = load(code, "main", "t", env)
  99. if not chunk then
  100.   log("COMPILE ERROR:")
  101.   for _, v in (reason or ""):gmatch("%S+") do
  102.     log(v)
  103.   end
  104.   computer.beep(400, 1)
  105.   computer.beep(200, 2)
  106.   computer.beep(400, 0.4)
  107.   computer.beep(400, 0.4)
  108.   error(reason)
  109. end
  110.  
  111. log("Running")
  112. local result = {xpcall(chunk, debug.traceback)}
  113. if result[1] then
  114.   log("Exited successfully.")
  115.   computer.beep(400, 1)
  116.   computer.beep(800, 2)
  117.   computer.shutdown()
  118. else
  119.   log("RUNTIME ERROR:")
  120.   for _, v in (result[2] or ""):gmatch("%S+") do
  121.     log(v)
  122.   end
  123.   computer.beep(400, 1)
  124.   computer.beep(200, 2)
  125.   computer.beep(400, 0.4)
  126.   computer.beep(200, 0.4)
  127.   error(result[2])
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement