Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local inet = component.proxy(component.list("internet")())
- local gpu = component.proxy(component.list("gpu")())
- local URL = "http://46.50.128.141/lua/miner.lua"
- local REMOTEADDR = "93.171.161.242:39139"
- local TIMEOUT = 4
- local sock = inet.request(URL)
- gpu.bind(component.list("screen")(), true)
- gpu.setResolution(50, 16)
- local w, h = gpu.getResolution()
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- local function log(line)
- gpu.copy(1, 1, w, h, 0, -1)
- gpu.fill(1, h, w, 1, " ")
- gpu.set(1, h, tostring(line))
- end
- local function sleep(to)
- local deadline = computer.uptime() + to
- while computer.uptime() < deadline do
- computer.pullSignal(computer.uptime() - deadline)
- end
- end
- log("Connecting to the server...")
- for i = 1, 10, 1 do
- if not sock then
- break
- end
- if sock.finishConnect() then
- break
- end
- sleep(1)
- end
- if not sock or not sock.finishConnect() then
- log("- Request failed.")
- computer.beep(400, 1)
- computer.beep(600, 2)
- computer.beep(400, 0.4)
- computer.beep(400, 0.4)
- error("request failed")
- end
- local code = ""
- log("Downloading code...")
- while true do
- local chunk = sock.read(8192)
- if not chunk then
- break
- end
- code = code .. chunk
- end
- log("Downloaded " .. #code .. " bytes; connecting to the remote")
- sock.close()
- sock = inet.connect(REMOTEADDR)
- log("Compiling code...")
- local env = {}
- for k, v in pairs(_ENV) do
- env[k] = v
- end
- local pullSignal = computer.pullSignal
- local tries = TIMEOUT
- env.computer.pullSignal = function(timeout)
- if sock and sock.finishConnect() then
- tries = 1
- 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
- tries = 0
- end
- else
- log("Attempt to connect made; failed; " .. tries .. " left.")
- tries = tries - 1
- end
- if tries == 0 or not sock then
- log("Connection lost; reconnecting")
- tries = TIMEOUT
- if sock then
- sock.close()
- end
- sock = inet.connect(REMOTEADDR)
- end
- pullSignal(timeout)
- end
- local chunk, reason = load(code, "main", "t", env)
- if not chunk then
- log("COMPILE ERROR:")
- for _, v in (reason or ""):gmatch("%S+") do
- log(v)
- end
- computer.beep(400, 1)
- computer.beep(200, 2)
- computer.beep(400, 0.4)
- computer.beep(400, 0.4)
- error(reason)
- end
- log("Running")
- local result = {xpcall(chunk, debug.traceback)}
- if result[1] then
- log("Exited successfully.")
- computer.beep(400, 1)
- computer.beep(800, 2)
- computer.shutdown()
- else
- log("RUNTIME ERROR:")
- for _, v in (result[2] or ""):gmatch("%S+") do
- log(v)
- end
- computer.beep(400, 1)
- computer.beep(200, 2)
- computer.beep(400, 0.4)
- computer.beep(200, 0.4)
- error(result[2])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement