Advertisement
NuAoA

recordMods

Jun 8th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. --Read Redstone
  2. --NuAoA
  3. local sig_names = {"White","Orange","Magenta","LightBlue","Yellow","Lime","Pink","Gray","LightGray","Cyan","Purple","Blue","Brown","Green","Red","Black"}
  4. local sig_values = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
  5. local on_array = {}
  6. os.pullEvent = os.pullEventRaw
  7. local mod_array = {
  8. "Anon232"; --White
  9. "USCCoder"; --Orange
  10. "Canilsen"; --Magenta
  11. "Cynterea"; --LightBlue
  12. "Daebat"; --Yellow
  13. "Drehmini"; --Lime
  14. "Brendan09"; --Pink
  15. "Sonolumin"; --Gray
  16. "Sega5"; --LightGray
  17. "Awade33"; --Cyan
  18. "k"; --Purple
  19. "k"; --Blue
  20. "k"; --Brown
  21. "k"; --Green
  22. "k"; --Red
  23. "k"; --Black
  24. }
  25.  
  26. for i=1,16 do
  27.     local temp_tab = {}
  28.     temp_tab["name"] = mod_array[i]
  29.     temp_tab["state"] = false
  30.     on_array[i] = temp_tab
  31. end
  32.  
  33. function deepcopy(orig)
  34.     local orig_type = type(orig)
  35.     local copy
  36.     if orig_type == 'table' then
  37.         copy = {}
  38.         for orig_key, orig_value in next, orig, nil do
  39.             copy[deepcopy(orig_key)] = deepcopy(orig_value)
  40.         end
  41.         setmetatable(copy, deepcopy(getmetatable(orig)))
  42.     else -- number, string, boolean, etc
  43.         copy = orig
  44.     end
  45.     return copy
  46. end    
  47.  
  48. function decode(value)
  49.     local tab = {}
  50.     for i=16,1,-1 do
  51.         if value>=sig_values[i] then
  52.             value = value - sig_values[i]
  53.             tab[i] = true
  54.         end
  55.     end
  56.     return tab
  57. end
  58.  
  59. function broadcast()   
  60.     rednet.open("front")
  61.     while true do
  62.         local event = os.pullEvent("sendTable")
  63.         local str = ""
  64.         for i=1,16 do
  65.             str = str..on_array[i]["name"]
  66.             if on_array[i]["state"] then
  67.                 str = str.."|on "
  68.             else
  69.                 str = str.."|off "
  70.             end        
  71.         end
  72.         rednet.broadcast(str)
  73.         print(str)
  74.     end
  75. end
  76.  
  77. function update()
  78.     while true do
  79.         local event = os.pullEvent("redstone")
  80.         local temp_tab = decode(rs.getBundledInput("right"))       
  81.         for i=1,16 do
  82.             on_array[i]["state"] = temp_tab[i]
  83.         end
  84.         os.queueEvent("sendTable")
  85.     end
  86. end
  87.  
  88. function antiHack()
  89.     print("[AntiHack] Enabled")
  90.     while true do
  91.         local event,side = os.pullEventRaw()       
  92.         if event == "peripheral" then
  93.             if peripheral.getType(side) == "drive" then
  94.                 -- we got someone putting a drive next to the terminal
  95.             elseif peripheral.getType(side) == "computer" then
  96.                
  97.             end
  98.         elseif event == "disk" then
  99.             if fs.exists("disk/startup") then
  100.                 fs.delete("disk/startup")
  101.                 disk.setLabel(side,"Broken Floppy")
  102.             end
  103.         elseif event == "terminate" then
  104.             os.queueEvent("password")
  105.         end
  106.     end    
  107. end
  108. function password()
  109.     while true do
  110.         local event = os.pullEvent("password")
  111.         sleep(0)
  112.         term.clear()
  113.         term.setCursorPos(1,1)
  114.         if string.lower(read("*")) == "recordmods" then        
  115.             shell.run("edit startup")
  116.             os.reboot()
  117.         end
  118.     end
  119. end
  120. parallel.waitForAll(update,broadcast,password,antiHack)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement