Advertisement
DOGGYWOOF

Network user server

Feb 2nd, 2024 (edited)
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. -- Server program
  2.  
  3. local function registerDomain(domain)
  4. local file = fs.open("Domain", "w")
  5. file.writeLine("Domain Name: " .. domain)
  6. file.writeLine("Server ID: " .. os.computerID())
  7. file.close()
  8. print("Domain registered successfully.")
  9. shell.run("server")
  10. end
  11.  
  12. local function createUser(username, password)
  13. local userDir = "/disk/users/" .. username
  14. fs.makeDir(userDir)
  15.  
  16. local passwordFile = fs.open(userDir .. "/password.txt", "w")
  17. passwordFile.write(password)
  18. passwordFile.close()
  19.  
  20. print("User created successfully.")
  21. shell.run("server")
  22. end
  23.  
  24. local function deleteUser(username)
  25. local userDir = "/disk/users/" .. username
  26. fs.delete(userDir)
  27. print("User deleted successfully.")
  28. shell.run("server")
  29. end
  30.  
  31. -- Main program
  32. while true do
  33. print("1. Register Domain")
  34. print("2. Create User")
  35. print("3. Delete User")
  36. print("4. Run Server (press Enter to go back to menu)")
  37.  
  38. local option = tonumber(read())
  39.  
  40. if option == 1 then
  41. print("Enter Domain Name:")
  42. local domain = read()
  43. registerDomain(domain)
  44.  
  45. elseif option == 2 then
  46. print("Enter Username:")
  47. local username = read()
  48. print("Enter Password:")
  49. local password = read("*")
  50. createUser(username, password)
  51.  
  52. elseif option == 3 then
  53. print("Enter Username to Delete:")
  54. local username = read()
  55. deleteUser(username)
  56.  
  57. elseif option == 4 then
  58. shell.run("server")
  59. end
  60. end
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement