BeastmodeJD

CPCheck-Server

Dec 26th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.68 KB | None | 0 0
  1. --startup actions and declorations
  2.  
  3. monitor = peripheral.wrap("right")
  4. serverMon = peripheral.wrap("monitor_0")
  5. rednet.open("top")
  6.  
  7. -- create functions
  8.  
  9. function setAllGood()
  10.     monitor.clear()
  11.     monitor.setCursorPos(1,1)
  12.     monitor.setTextColor(colors.white)
  13.     monitor.write("Buildings on Network - CFW")
  14.     monitor.setCursorPos(1,3)
  15.     monitor.write("Bldg Ab: ")
  16.     monitor.setTextColor(colors.green)
  17.     monitor.setCursorPos(10,3)
  18.     monitor.write("Good")
  19.     monitor.setTextColor(colors.white)
  20.     monitor.setCursorPos(15,3)
  21.     monitor.write(" - ")
  22.     monitor.setTextColor(colors.green)
  23.     monitor.setCursorPos(19,3)
  24.     monitor.write("Locked")
  25. end
  26.  
  27. function setOneOrMoreError(b1, b1Why)
  28.     if (b1) then
  29.         if (b1Why == "No Response") then
  30.             monitor.setCursorPos(1,3)
  31.             monitor.clearLine()
  32.             monitor.setTextColor(colors.white)
  33.             monitor.write("Bldg Ab: ")
  34.             monitor.setTextColor(colors.red)
  35.             monitor.setCursorPos(10,3)
  36.             monitor.write("ERROR - No Response")
  37.         end
  38.         if (b1Why == "Wrong CPID") then
  39.             monitor.setCursorPos(1,3)
  40.             monitor.clearLine()
  41.             monitor.setTextColor(colors.white)
  42.             monitor.write("Bldg Ab: ")
  43.             monitor.setTextColor(colors.red)
  44.             monitor.setCursorPos(10,3)
  45.             monitor.write("ERROR - Wrong CP-ID")
  46.         end
  47.         if (b1Why == "Wrong Code") then
  48.             monitor.setCursorPos(1,3)
  49.             monitor.clearLine()
  50.             monitor.setTextColor(colors.white)
  51.             monitor.write("Bldg Ab: ")
  52.             monitor.setTextColor(colors.red)
  53.             monitor.setCursorPos(10,3)
  54.             monitor.write("ERROR - Wrong Code")
  55.         end
  56.     end
  57. end
  58.  
  59. function setOneOrMoreOnRequest(b1)
  60.     if (b1) then
  61.         monitor.setCursorPos(1,3)
  62.         monitor.clearLine()
  63.         monitor.setTextColor(colors.white)
  64.         monitor.write("Bldg Ab: ")
  65.         monitor.setTextColor(colors.green)
  66.         monitor.setCursorPos(10,3)
  67.         monitor.write("Good")
  68.         monitor.setTextColor(colors.white)
  69.         monitor.setCursorPos(15,3)
  70.         monitor.write(" - ")
  71.         monitor.setCursorPos(19,3)
  72.         monitor.setTextColor(colors.yellow)
  73.         monitor.write("Request")
  74.     end
  75. end
  76.  
  77. local function testBuildings()
  78.   isBad = false
  79.   message = nil
  80.   rednet.send(73, "C^Y|cE5krz")
  81.   sender, message, disT = rednet.receive(5)
  82.   if not (sender == 73) then
  83.     term.setCursorPos(1,3)
  84.     term.write(sender or "No Sender")
  85.     setOneOrMoreError(true, "Wrong CPID")
  86.     isBad = true
  87.   elseif not (message == "Vy;vR;F6jrC,k!n") then
  88.     setOneOrMoreError(true, "Wrong Code")
  89.     isBad = true
  90.   elseif (message == nil) then
  91.     setOneOrMoreError(true, "No Response")
  92.     isBad = true
  93.   end
  94.   if (isBad) then
  95.     return false
  96.   else
  97.     return true
  98.   end
  99. end
  100.  
  101. local function timerEnd()
  102.     event, timerID = os.pullEvent("timer")
  103. end
  104.  
  105. local function readPassword()
  106.     password = read("*")
  107. end
  108.  
  109. --Main Code
  110.  
  111. term.clear()
  112. term.setCursorPos(1,1)
  113. print("Version 1.0")
  114. print("Running...")
  115. setAllGood()
  116. if not (testBuildings()) then
  117.     --term.clear()
  118.     term.setCursorPos(1,10)
  119.     print("Error! to reset hit any key")
  120.     os.pullEvent("key")
  121.     os.reboot()
  122. end
  123. print("")
  124. print("Enter Password to set a building to 'request'")
  125. while (true) do
  126.     timer = os.startTimer(300)
  127.     parallel.waitForAny(readPassword, os.pullEvent("timer"))
  128.     if (password == "BeastmdoeJD24") then
  129.         term.clear()
  130.         term.setCursorPos(1,1)
  131.         print("what of the following buildings would you like to set to request?")
  132.         bldg = read()
  133.         if (bldg == "Ab") then
  134.             setOneOrMoreOnRequest(true)
  135.             sender, message, disT = rednet.receive(180)
  136.             if (sender == 73 and message == "vLctbt8LLG7shFoNDKw7") then
  137.                 rednet.send(73, "3Zu1eCzbkQsvCmCoRw9R")
  138.             else
  139.                 os.reboot()
  140.             end
  141.         else
  142.             print("That is not a vaild building")
  143.             sleep(3)
  144.             os.reboot()
  145.         end
  146.     else
  147.         term.clear()
  148.         term.setCursorPos(1,1)
  149.         print("Invaild Password")
  150.         sleep(3)
  151.         os.reboot()
  152.     end
  153. end
Advertisement
Add Comment
Please, Sign In to add comment