Guest User

Untitled

a guest
Oct 11th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. term.clear() --Clear any text
  2. term.setCursorPos(1,1) --Set cursor position to beginning
  3. write"This is not a user-accessible computer." -- User information
  4. write"Log in at one of the USER PCs." --User information
  5. print("")
  6. local firstCycle = true -- Used to determine whether to run bootUp function. Boolean variable
  7. local validSender = false --Used to determine whether valid information has been entered. Boolean variable
  8. local modemSide = "top" --Determines modem side. String variable
  9. local valid = false --Used to determine whether check is made as to whether to return password or not. Boolean variable
  10. local DeBug = true -- turns off prints so people cant see passwrds
  11. users = {{uname = "XenoG", pword = "pl455ey"},
  12. {uname = "Test", pword = "user"},
  13. {uname = "Xenogene", pword = "lolgasm"}
  14. } --Users table. Left is key, right is value. In effect Username-Password (Key-Value)
  15. senders = {18,20} --Table of all computer ID's that can access server.
  16. function bootUp() --New function "bootUp()"
  17. rednet.open(modemSide) --Sends message to rednet to make sure the modem is open
  18. end --End function
  19. local function printTEST(...) -- allows you to turn off prints of ueser name set local DeBug = true to local DeBug = false
  20. if DeBug then
  21. print(...)
  22. end
  23. end
  24. while true do --Main server loop
  25. validSender = false --set validSender to false. Needs to be done every loop round
  26. local user = nil
  27. local password = nil
  28.  
  29. if firstCycle then --If the this is the first cycle then
  30. bootUp() --Call the bootUp() function
  31. end --End IF statement
  32. senderId, message, distance = rednet.receive() --rednet.receive() function call. Loop waits here until a message is received
  33. for i,v in ipairs(senders) do --For index, value, search in the table senders, then execute next line
  34. if v == senderId then --If v is equal to a senderId (found in senders table) then
  35. validSender = true --Set validSender to true
  36. break --Break the loop
  37. end --End IF statement
  38. end --End FOR loop
  39. if validSender then --If validSender is true, execute next line
  40. printTEST("MES "..message)
  41. for k,v in pairs(users) do --For index, value, search in the table users, then execute next line
  42. printTEST(k..")U "..v.uname.." P "..v.pword)
  43. if message == v.uname then --If k is equal to message (found in users table) then
  44. valid = true --Set valid to true
  45. password = v.pword -- Set password to the value of v
  46. user = v.uname
  47. break -- this is needed so valid = false isnt called
  48. else --Otherwise
  49. valid = false --Set valid to false
  50. end --End IF statement
  51. end --End FOR loop
  52.  
  53. if valid then --If valid is true, execute next line
  54. rednet.send(senderId, password) -- Send the senderID and the password to rednet
  55. printTEST("Sent "..senderId.." "..password)
  56. print("User "..user.." Requested Login")
  57. else --Otherwise
  58. rednet.send(senderId, "Not Valid") --Send a Not Valid message to rednet
  59. printTEST("Sent "..senderId.." ".."Not Valid")
  60. print("Atempted Login Failed")
  61. end --End IF statement
  62. end --End IF statement
  63. end --End WHILE TRUE DO loop
Add Comment
Please, Sign In to add comment