Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- serverID = os.getComputerID
- userIDs = {}
- userIDsN = 0
- function manageUsers()
- local menu = "\nManaging users:\n"
- menu = menu .. "0. Back\n"
- menu = menu .. "1. Show users\n"
- menu = menu .. "2. Add users\n"
- menu = menu .. "3. Remove users\n\n"
- menu = menu .. "Your choice: "
- io.write(menu)
- choice = io.read("*l");
- while choice ~= "0" do
- if choice == "0" then
- break
- elseif choice == "1" then
- showUsers()
- elseif choice == "2" then
- addUsers()
- elseif choice == "3" then
- removeUsers()
- end
- io.write(menu)
- choice = io.read("*l");
- end
- end
- function showUsers()
- io.write("\n")
- for i,v in ipairs(userIDs) do
- io.write("userID[" .. i .. "]: " .. v .. "\n")
- end
- end
- function addUsers()
- local input = io.read("*l")
- while input ~= "." do
- local id = tonumber(input)
- userIDsN = userIDsN + 1
- userIDs[userIDsN] = id
- input = io.read("*l")
- end
- updateUserIDsfile()
- end
- function removeUsers()
- local input = io.read("*l")
- while input ~= "." do
- local id = tonumber(id)
- for i = id, userIDsN - 1 do
- userIDs[i] = userIDs[i + 1]
- end
- userIDs[userIDsN] = nil
- userIDsN = userIDsN - 1
- input = io.read("*l")
- end
- updateUserIDsfile()
- end
- function writeToFile(path,data)
- local file = fs.open(path,"w")
- file.write(textutils.serialise(data))
- file.close()
- end
- function readFromFile(path)
- local file = fs.open(path,"r")
- data = textutils.unserialise(file.readAll())
- file.close()
- return data
- end
- function updateUserIDsfile()
- writeToFile("data/userIDs",userIDs)
- end
- function updateUserIDs()
- if fs.exists("data/userIDs") then
- userIDs = readFromFile("data/userIDs")
- userIDsN = table.getn(userIDs)
- end
- end
- function init()
- updateUserIDs()
- end
- function loop()
- init()
- local menu = "\nMenu:\n"
- menu = menu .. "0. Close\n"
- menu = menu .. "1. Manage users\n\n"
- menu = menu .. "Your choice: "
- io.write(menu)
- choice = io.read("*l");
- while choice ~= "0" do
- if choice == "0" then
- break
- elseif choice == "1" then
- manageUsers()
- elseif choice == "2" then
- showUsers()
- end
- io.write(menu)
- choice = io.read("*l");
- end
- end
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement