Advertisement
AssortedBrunoz

homepc

Dec 19th, 2024 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. local allChars = {}
  2. local id = os.getComputerID()
  3. local version = 1
  4. if tonumber(http.get("https://pastebin.com/raw/wEHXZmdN").readAll()) ~= version then
  5.     fs.delete(shell.getRunningProgram())
  6.     shell.run("pastebin get epFS33Px startup.lua")
  7.     print("rebooting, update successful")
  8.     shell.run("reboot")
  9. end
  10. local temp
  11. if not fs.exists("./storage.json") then
  12.     temp = fs.open("./storage.json", "w")
  13.     temp.write(textutils.serialiseJSON({
  14.         raws = {},
  15.         keys = {}
  16.     }))
  17.     temp.close()
  18. end
  19. local storageJson = fs.open("./storage.json", "r")
  20. local storage = textutils.unserialiseJSON(storageJson.readAll())
  21. local function saveStorage()
  22.     temp = fs.open("storage.json", "w")
  23.     temp.write(textutils.serialiseJSON(storage))
  24.     temp.close()
  25. end
  26.  
  27.  
  28. require("stringtools")()
  29. for i = 0, 255 do
  30.     allChars[i] = string.char(i)
  31. end
  32. local function encrypt(message)
  33.     message = string.fracture(textutils.serialise(message))
  34.     local new = ""
  35.     for _, char in pairs(message) do
  36.         for _idx, _char in ipairs(allChars) do
  37.             if char == _char then
  38.                 new = new..allChars[(_idx+id)%#allChars]
  39.             end
  40.         end
  41.     end
  42.     return new.."_"..id
  43. end
  44.  
  45. local function decrypt(message)
  46.     message = string.fracture(message)
  47.     local unlockId = ""
  48.     for i = #message, 1, -1 do
  49.         if message[i] ~= "_" then
  50.             unlockId = unlockId..message[i]
  51.         else
  52.             for j = i, #message do
  53.                 message[j] = nil
  54.             end
  55.             break
  56.         end
  57.     end
  58. ---@diagnostic disable-next-line: cast-local-type
  59.     unlockId = tonumber(string.reverse(unlockId))
  60.     local new = ""
  61.     for _, char in pairs(message) do
  62.         for _idx, _char in ipairs(allChars) do
  63.             if char == _char then
  64.                 new = new..allChars[(_idx-unlockId)%#allChars]
  65.             end
  66.         end
  67.     end
  68.     return textutils.unserialise(new)
  69. end
  70.  
  71. local function awaitMessage(channel, timeOut, condition)
  72.     local toReturn = {}
  73.     parallel.waitForAny(function()
  74.         repeat
  75.             os.sleep(1)
  76.             timeOut = timeOut - 1
  77.         until timeOut <= 0
  78.         toReturn = {false}
  79.     end, function()
  80.         while next(toReturn) == nil do
  81.             local received = table.pack(os.pullEvent("modem_message"))
  82.             if received[3] == channel then
  83.                 received[5] = decrypt(received[5])
  84.                 if condition(received[5]) then
  85.                     toReturn = {true, received}
  86.                 else
  87.                     toReturn = {false}
  88.                 end
  89.             end
  90.         end
  91.     end)
  92.     return table.unpack(toReturn)
  93. end
  94. local modem = peripheral.find("modem")
  95. modem.open(48184)
  96.  
  97. while true do
  98.     local _, _, channel, replyChannel, message, _ = os.pullEvent("modem_message")
  99.     message = decrypt(message)
  100.     if message.lookingFor == "home" and message.operation == "connect" and message.connector == "phone" then
  101.         modem.transmit(48084, 48184, encrypt({
  102.             name = "home",
  103.             operation = "connect",
  104.             status = true
  105.         }))
  106.     end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement