karelvysinka

Modem Client 2022

Feb 5th, 2022 (edited)
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local version =
  2. 10
  3. -- Program pro >prijmani< zprav pres modem
  4. -- Pri zmene programu je treba na radku "2" zmenit verzi, aby se program automaticky aktualizoval
  5. -- "local code" je treba zmenit dle potreby
  6. -- Server:
  7. -- pastebin get NNbbTX6n startup
  8. -- Client:
  9. -- pastebin get yKvCXrCg startup
  10.  
  11. local code = "yKvCXrCg"
  12.  
  13. --kontrola verze
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. print("Program loading...")
  17. print("Current version: "..version)
  18. local updateSite= http.get("http://pastebin.com/raw.php?i="..code)
  19. updateSite.readLine()
  20. local newVersion = updateSite.readLine()
  21.     if tonumber(newVersion) > version then
  22.             print("Update required. Updating now...")
  23.             local updateSite = http.get("http://pastebin.com/raw.php?i="..code)
  24.             local siteFile = updateSite.readAll()
  25.             local writeFile = fs.open(shell.getRunningProgram(),"w")
  26.             writeFile.write(siteFile)
  27.             writeFile.close()
  28.             print("The program will now restart your computer.")
  29.             sleep(1)
  30.             os.reboot()
  31.     end
  32. print("Program OK...")
  33.  
  34. function start()
  35.     while true do
  36.  
  37. local modem = peripheral.wrap("right")
  38. modem.open(16384)  -- Otevri kanal a naslouchej na nem
  39. --print("Waiting message...")
  40. local event, modemSide, senderChannel,
  41.   replyChannel, message, senderDistance = os.pullEvent("modem_message")
  42.  
  43. --print("Prave jsem obdrzel zpravu na kanalu: "..senderChannel)
  44. --print("Mel bych na to odpovedet na kanalu: "..replyChannel)
  45. --print("Prijimajici modem je umisten na zarizeni: "..modemSide.." side")
  46. print(message)
  47. --print("Odesilatelem je: "..(senderDistance or "neznamy pocet").." bloku ode me.")
  48.  
  49.  
  50.     end
  51. end
  52.  
  53. function provedPrikaz(message)
  54.     if message == "test" then
  55.         print("Test")
  56.     end
  57.    
  58.     if message == "reboot" then
  59.     print("Rebootuji computer")
  60.     os.reboot()
  61.     end
  62. print("Konec provadeni prikazu")
  63. end
  64.  
  65. start()
Add Comment
Please, Sign In to add comment