Advertisement
pepeknamornik

server_elektromer

Sep 4th, 2020
4,666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. ModemPos = "top"
  2. MyID = os.getComputerID()
  3. modem = peripheral.wrap(ModemPos)
  4. modem.open(MyID)
  5.  
  6. function bar(styl, text)
  7.     if (styl == "OK") then                  -- Uspech
  8.         term.setTextColor(colors.green)
  9.     elseif (styl == "FAIL") then            -- Neuspesne
  10.         term.setTextColor(colors.red)
  11.     elseif (styl == "INFO") then            -- Informativni
  12.         term.setTextColor(colors.lightBlue)
  13.     elseif (styl == "def") then             -- defaultni
  14.         term.setTextColor(colors.white)
  15.     elseif (styl == "PRO") then             -- Progress
  16.         term.setTextColor(colors.yellow)
  17.     else
  18.         styl = "def"
  19.         term.setTextColor(colors.white)
  20.     end
  21.    
  22.     if not (styl == "def") then
  23.         zprava = ("["..textutils.formatTime(os.time(), true).."] ["..styl.."] "..text)
  24.         else
  25.         zprava = text
  26.     end
  27.    
  28.     if logs then
  29.     logy(zprava)
  30.     end
  31.     print (zprava)
  32. end
  33.  
  34.  
  35. function loop()
  36.  
  37. local function defaultHod()
  38. idComp = nil
  39. hodnota = nil
  40. bar("INFO", "Pripraveno pro novy zapis")       
  41.        
  42. end
  43.  
  44. local _, side, freq, rfreq, message = os.pullEvent('modem_message')
  45.  
  46. if (rfreq == 8080) then
  47.         idComp = message    --login to domain
  48.         bar("INFO", "Prijem informaci ze zarizeni "..idComp)
  49.     end
  50.  
  51. if (rfreq == 8081) then
  52.         hodnota = message
  53.         bar("PRO", "Nová hodnota: "..hodnota)
  54.        
  55.         if tonumber(idComp) > 0 then
  56.         local zapis = fs.open("/database/"..idComp..".txt", "w")
  57.         zapis.writeLine(hodnota)
  58.         bar("OK", "Prepsano")
  59.         zapis.close()
  60.         defaultHod()
  61.         end
  62. end
  63.  
  64. loop()
  65. end
  66.  
  67. bar("INFO", "Pripraveno k pouziti")
  68. loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement