Advertisement
osmarks

Potato Farm

Sep 29th, 2018
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. local a=http.get"https://pastebin.com/raw/Frv3xkB9"local b=fs.open("yafss.lua","w")b.write(a.readAll())a.close()b.close()
  2.  
  3. local yafss = require "./yafss"
  4.  
  5. local funcs = {}
  6.  
  7. local h = http.get "https://pastebin.com/raw/hvy03JuM"
  8. local vanilla_BIOS = h.readAll()
  9. h.close()
  10.  
  11. local instances = tonumber(...) or tonumber(settings.get "farm.instances") or 4
  12. local root = settings.get "farm.root" or "farm"
  13. fs.makeDir(root)
  14.  
  15. local function randbytes(len)
  16.     local out = ""
  17.     for i = 1, len do
  18.         out = out .. string.char(math.random(0, 255))
  19.     end
  20.     return out
  21. end
  22.  
  23. local ws_cache = {}
  24.  
  25. local function APIs(iID)
  26.     local httpwebsocket = http.websocket
  27.     local ID = math.random(0, 65534)
  28.     local label = randbytes(math.random(0, 256))
  29.     return {
  30.         os = {
  31.             getComputerID = function()
  32.                 return ID
  33.             end,
  34.             getComputerLabel = function()
  35.                 return label
  36.             end,
  37.             setComputerLabel = function()
  38.                 return "no."
  39.             end
  40.         },
  41.         _HOST = "Potato Farm on " .. _HOST,
  42.         potatOS = potatOS,
  43.         iID = iID,
  44.         http = {
  45.             websocket = function(URL)
  46.                 if ws_cache[URL] then return ws_cache[URL]
  47.                 else
  48.                     local ws = httpwebsocket(URL)
  49.                     ws_cache[URL] = ws
  50.                     return ws
  51.                 end
  52.             end
  53.         }
  54.     }
  55. end
  56.  
  57. local function instance_startup()
  58.     return [[
  59. shell.run "pastebin run RM13UGFa"
  60.     ]]
  61. end
  62.  
  63. for i = 1, instances do
  64.     local dir = fs.combine(root, tostring(i))
  65.     fs.makeDir(dir)
  66.     local startup = fs.combine(dir, "startup")
  67.  
  68.     if not fs.exists(startup) then
  69.         local f = fs.open(startup, "w")
  70.         f.write(instance_startup(i))
  71.         f.close()
  72.     end
  73.  
  74.     table.insert(funcs, function()
  75.         yafss(
  76.             dir,
  77.             {},
  78.             APIs(i),
  79.             vanilla_BIOS
  80.         )
  81.     end)
  82. end
  83.  
  84. if _G.process then
  85.     for ix, f in pairs(funcs) do
  86.         process.spawn(f, string.format("field-%x", ix))
  87.     end
  88. else
  89.     parallel.waitForAll(unpack(funcs))
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement