Cavious

databaseServer

Jun 18th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. --[[
  2. FILENAME: databaseServer.lua(Startup.lua)
  3. AUTHOR: Donald R. Valverde (Cavious)
  4. VERSION: 1.0-BETA
  5. --]]
  6.  
  7. rednet.open( "back" )
  8. rsDoor = --Needs computerNumber
  9.  
  10. function logData(text)
  11.     local nTime = os.time()
  12.     local file = fs.open(".db_log", "a")
  13.     file.writeLine(textutils.formatTime( nTime, false).."::"..text)
  14.     file.close()
  15. end
  16.  
  17. function pullDatabase(connectionID, password)
  18.     local file = fs.open(".db_passwords", "r")
  19.     local data = file.readAll()
  20.     file.close()
  21.  
  22.  
  23.     if (data:match(password)) then
  24.         rednet.send(connectionID, ".successful")
  25.         logData(connectionID..password.."SUCCESS")
  26.     else
  27.         rednet.send(connectionID, ".fail")
  28.         logData(connectionID..password.."FAILED")
  29.     end
  30. end
  31.  
  32. function redNetData()
  33.     while(true) do
  34.         local id, message, protocol = rednet.receive("password")
  35.        
  36.         pullDatabase(id, message)
  37.  
  38.     end
  39. end
  40.  
  41. function doorAccess()
  42.     while(true) do
  43.         term.clear()
  44.         term.setCursorPos(1,1)
  45.         term.setBackgroundColor(colors.gray)
  46.         term.setTextColor(colors.yellow)
  47.         term.write("DOOR(OPEN/CLOSE): ")
  48.         term.setTextColor(colors.lightBlue)
  49.        
  50.         input = io.read()
  51.         string.lower(input)
  52.        
  53.         if(input == "open") then
  54.             rednet.send(rsDoor, ".open")
  55.             logData("SERVER_COMMAND::OPEN")
  56.             term.setCursorPos(1,2)
  57.             term.write("DOOR OPEN!")
  58.             os.sleep(10)
  59.             rednet.send(rsDoor, ".close")
  60.             logData("SERVER_COMMAND::CLOSE_TIMEDELAY")
  61.         elseif(input == "close") then
  62.             rednet.send(rsDoor, ".close")
  63.             logData("SERVER_COMMAND::CLOSE")
  64.         end
  65.        
  66.     end
  67. end
  68.  
  69. term.clear()
  70.  
  71. while(true) do
  72.     parallel.waitForAny(redNetData, doorAccess)
  73. end
Advertisement
Add Comment
Please, Sign In to add comment