Advertisement
Tigo_middelkoop

CC Roaming users server

Nov 28th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. print("Initializing...")
  2. local validSender = false
  3. valid = false
  4. tserved, vserved, dserved = 0
  5.  
  6. print("Loading startup settings...")
  7. count = true -- If you dont want the server to count request statics, set the value of this variable to "false" without qoutes.
  8. modemSide = "left" -- change to the side of the computer your modem is on
  9. whitelist = true -- If you dont want to use a whitelist, change the value to "false" without quotes. This is not recommended on Multiplayer, but it does not make any difference on a Singleplayer World.
  10.  
  11. print("Loading user database...")
  12. users = {"username1", "username2" } -- Change this to the names for the users you want to have. Make sure the usernames are in the same order as in the password table. Changing the order is fine, but you must maintain the same order in both the users and passwords tables. Incorrect orders WILL cause 2 or more users not being able to log in!
  13. passwords = {"password1", "password2" } -- Change this to the passwords for the users defined in the variable above. Again, make sure the passwords for users are in the same order as the usernames.
  14. senders = { 1, 2, 3, 4 } -- change this to the ID's of the all computers you want to accept requests from if you use a whitelist. If you do not use a whitelist, DO NOT REMOVE THIS LINE! Doing so will cause the program to crash everytime it is run, even though the variable is not used.
  15.  
  16. print("Loading core functions...")
  17. function clear()
  18. term.clear()
  19. term.setCursorPos(1, 1)
  20. print("CCLS Server 1.0 for CC 1.53")
  21. print("There is no user interaction here. Please contact your system administrator for assistance regarding the system.")
  22. if count == true then
  23. print(tserved.." total requests received this session.")
  24. print(vserved.." requests completed this session.")
  25. print(dserved.." requests denied this session.")
  26. elseif count == false then
  27. print("Request statics have been disabled.")
  28. else
  29. rednet.close(modemSide)
  30. term.clear()
  31. term.setCursorPos(1, 1)
  32. print("Error: Counter setting is not boolean and the server can not continue.")
  33. print("The server program will exit automatically in 10 minutes. Or you can hold down Ctrl+T for 1 second.")
  34. print("After that, please set the variable \"count\" in the source code to either \"true\" or \"false\" WITHOUT QUOTATION MARKS. Doing this with quotation marks will cause the same error.")
  35. sleep(600)
  36. shell.exit()
  37. end
  38.  
  39. print("Starting up...")
  40. rednet.open("back") -- Opens the modem to wait for incoming login requests
  41.  
  42. clear()
  43.  
  44. while true do
  45. validSender = false
  46. senderId, message, distance = rednet.receive()
  47. for i,v in ipairs(senders) do
  48. tserved = tserved + 1
  49. if v == senderId then
  50. validSender = true
  51. break
  52. else
  53. rednet.send(senderId, "301", true) -- Send response code 301 - which means Not Whitelisted.
  54. dserved = dserved + 1
  55. clear()
  56. end
  57. end
  58. if validSender then
  59. for i,v in ipairs(users) do
  60. if message == v then
  61. password = passwords[i]
  62. rednet.send(senderId, password, true)
  63. vserved = vserved + 1
  64. clear()
  65. break
  66. else
  67. rednet.send(senderId, "300", true) -- Send response code 300 - which means Bad Auth.
  68. dserved = dserved + 1
  69. clear()
  70. end
  71. end
  72. end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement