etelan

sendIdentification.lua

Dec 12th, 2021 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Components
  2. local component = require("component")
  3. local modem = component.modem
  4. local controller = component.inventory_controller
  5. local gpu = component.gpu
  6.  
  7. -- Other Libraries
  8. local io = require("io")
  9. local event = require("event")
  10. local colours = require("colors")
  11. local os = require("os")
  12.  
  13. -- port
  14. local sendPort = 6969
  15.  
  16. -- The file to go to
  17. local arguments_as_a_table = {...}
  18. local gameFile = arguments_as_a_table[1]
  19.  
  20. gpu.setResolution(40, 20)
  21. gpu.setForeground(colours.black, true)
  22. gpu.setBackground(colours.yellow, true)
  23.  
  24. -- Ask to put in chest
  25. function awaitKeyInput ()
  26.  
  27.   while true do
  28.     os.sleep(0.5)
  29.     local block = controller.getStackInSlot(1,1)
  30.     if block ~= nil then
  31.       if block.name == "opencomputers:print" then
  32.         break
  33.       end
  34.     end
  35.     -- Display, awaiting input
  36.     gpu.setForeground(colours.black, true)
  37.     gpu.setBackground(colours.yellow, true)    
  38.     gpu.fill(1, 1, 40, 20, " ")
  39.     gpu.set(10,10, "Insert Key Into Chest")
  40.   end
  41. end
  42.  
  43. -- Send Check
  44. function sendIdentificationPacket(address, port)
  45.  
  46.   local labelPacket = tostring(controller.getStackInSlot(1,1).label)
  47.   print("\n Key Name: " .. labelPacket)
  48.   modem.send(address, port, labelPacket)
  49. end  
  50.  
  51. -- Recieve Check
  52. function recieveIdentificationPacket()
  53.   print("Waiting for response")
  54.   modem.open(420)
  55.   local _, _, _, _, _, message = event.pull("modem_message")
  56.   if message == "Authorized" then
  57.     gpu.setBackground(colours.green, true)
  58.     gpu.fill(1, 1, 40, 20, " ")
  59.     print("Success")
  60.   else
  61.     gpu.setForeground(colours.black, true)
  62.     while true do
  63.  
  64.       gpu.setBackground(colours.red, true)
  65.       gpu.fill(1, 1, 40, 20, " ")
  66.       gpu.set(10,10, "Alert: Hacking attempted")
  67.       os.sleep(1)
  68.  
  69.       gpu.setBackground(colours.yellow, true)
  70.       gpu.fill(1, 1, 40, 20, " ")
  71.       gpu.set(10,10,"Alert: Locking Computer")
  72.       os.sleep(1)
  73.     end
  74.   end
  75. end
  76.  
  77. awaitKeyInput()
  78. sendIdentificationPacket("003d7717-ce37-46f3-aea8-a7d247da4b48", sendPort)
  79. recieveIdentificationPacket()
  80.  
  81. os.execute("mockGame.lua")
Add Comment
Please, Sign In to add comment