Cavious

serverData

Jun 13th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. --[[
  2. FILENAME: powerSystem.lua(Change to startup in game)
  3. CREATED BY: Cavious(Donald R. Valverde)
  4. VERSION: 1.0-ALPHA
  5. --]]
  6.  
  7. sideMain = ""
  8. sideDebug = ""
  9.  
  10. activeTab = "t1"
  11.  
  12. monMain = peripheral.wrap(sideMain)
  13. monDebug = peripheral.wrap(sideDebug)
  14. rednet.open( "bottom" )
  15.  
  16. function drawText(monitor, text, xPos, yPos, backgroundColor, fontColor)
  17.     monitor.setCursorPos(xPos, yPos)
  18.     monitor.setBackgroundColor(backgroundColor)
  19.     monitor.setTextColor(fontColor)
  20.     monitor.write(text)
  21. end
  22.  
  23. function drawImage(monitor, file, xPos, yPos)
  24.     term.redirect(monitor)
  25.     local image = paintutils.loadImage(file)
  26.     paintutils.drawImage(image, xPos, yPos)
  27.     term.native()
  28. end
  29.  
  30. function tabT1()
  31.     drawImage(monMain, ".backgroundT1", 2, 2)
  32.     --ADD BUTTON(MAX of THREE)
  33. end
  34.  
  35. function tabT2()
  36.     drawImage(monMain, ".backgroundT2", 2, 2)
  37.     --ADD BUTTON(MAX of THREE)
  38. end
  39.  
  40. function tabT3()
  41.     drawImage(monMain, ".backgroundT3", 2, 2)
  42.     --ADD BUTTON(MAX of THREE)
  43. end
  44.  
  45. function tabT4()
  46.     drawImage(monMain, ".backgroundT4", 2, 2)
  47.     --ADD BUTTON(MAX of THREE)
  48. end
  49.  
  50. function logData(text)
  51.     local file = fs.open(".db_log", "w")
  52.     file.writeLine(text)
  53.     file.close()
  54. end
  55.  
  56. function pullDatabase(connectionID, password)
  57.     local file = fs.open(".db_passwords", "r")
  58.     local data = file.readAll()
  59.     file.close()
  60.  
  61.  
  62.     if (data:match(password)) then
  63.         rednet.send(connectionID, ".successful")
  64.         logData(connectionID..password.."SUCCESS")
  65.         search = false;
  66.     else
  67.         rednet.send(connectionID, ".fail")
  68.         logData(connectionID..password.."FAILED")
  69.         search = false;
  70.     end
  71. end
  72.  
  73. monMain.clear()
  74. monMain.setTextScale(0.5)
  75.  
  76. drawImage(monMain, ".backgroundLeft", 1, 1)
  77. drawImage(monMain, ".backgroundRight", 20, 1)
  78.  
  79. drawText(monMain, "RESTART", 6, 8, colors.yellow, colors.black)
  80. drawText(monMain, "T1", 15, 2, colors.green, colors.white)
  81. drawText(monMain, "T2", 15, 3, colors.blue, colors.white)
  82. drawText(monMain, "T3", 15, 4, colors.red, colors.white)
  83. drawText(monMain, "T4", 15, 5, colors.orange, colors.white)
  84.  
  85. tabT1()
  86.  
  87. function touchScreen()
  88.     while(true) do
  89.         event, side, xPos, yPos = os.pullEvent("monitor_touch")
  90.        
  91.         if(yPos == 3 and xPos == 16 or yPos == 3 and xPos == 17) then
  92.             activeTab = "t1"
  93.             tabT1()
  94.         elseif(yPos == 4 and xPos == 16 or yPos == 4 and xPos == 17) then
  95.             activeTab = "t2"
  96.             tabT2()
  97.         elseif(yPos == 5 and xPos == 16 or yPos == 5 and xPos == 17) then
  98.             activeTab = "t3"
  99.             tabT3()
  100.         elseif(yPos == 6 and xPos == 16 or yPos == 6 and xPos == 17) then
  101.             activeTab = "t4"
  102.             tabT4()
  103.         elseif(yPos == 8 and xPos >= 6 and xPos < 14) then
  104.             drawText(monMain, "RESTART", 6, 8, colors.orange, colors.black)
  105.             os.sleep(1)
  106.             os.reboot()
  107.         end
  108.     end
  109. end
  110.  
  111. function redNetData()
  112.     while(true) do
  113.         local id, password, protocol = rednet.receive("password")
  114.        
  115.         pullDatabase(id, password)
  116.  
  117.     end
  118. end
  119.  
  120. while(true) do
  121.     parallel.waitForAny(touchScreen, redNetData)
  122. end
Advertisement
Add Comment
Please, Sign In to add comment