Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local monitor = nil
- -- Determine where monitor is.
- monitorSide = nil
- if peripheral.isPresent("left") and peripheral.getType("left")=="monitor" then
- monitorSide = "left"
- elseif peripheral.isPresent("right") and peripheral.getType("right")=="monitor" then
- monitorSide = "right"
- elseif peripheral.isPresent("top") and peripheral.getType("top")=="monitor" then
- monitorSide = "top"
- elseif peripheral.isPresent("back") and peripheral.getType("back")=="monitor" then
- monitorSide = "back"
- elseif peripheral.isPresent("bottom") and peripheral.getType("bottom")=="monitor" then
- monitorSide = "bottom"
- end
- if monitorSide ~= nil then
- monitor = peripheral.wrap(monitorSide)
- print("Monitor found on "..monitorSide)
- monitor.setTextScale(.7)
- else
- monitor = nil
- end
- local players = {}
- local stayInLoop = true
- local delay = 0
- local adminLogin = 0
- function fileSave()
- file = fs.open("players","w")
- file.writeLine(textutils.serialize(players))
- file.close()
- end
- function player_new(name,job)
- table.insert(players,{name,job})
- fileSave()
- return true
- end
- function player_job(name,newJob)
- for i=1,#players do
- if players[i][1] == name then
- players[i][2] = newJob
- fileSave()
- return true
- end
- end
- return false
- end
- function player_remove(name)
- for i=1,#players do
- if players[i][1] == name then
- table.remove(players,i)
- fileSave()
- return true
- end
- end
- return false
- end
- function commands_help()
- print("Available options are: ")
- print("'new' - Adds a new player to the console.")
- print("'job' - Changes the job for an existing player.")
- print("'rename' - Renames an existing player")
- print("'delete' - Deletes and existing players from the console.")
- print("'list' - Shows a list of players in the system.")
- print("'logout' - Logs out of this system.")
- print("NOTE: Please logout after every command to prevent any unwanted changes!")
- end
- function after_command()
- print("")
- print("press 'Enter' to continue...")
- read()
- term.clear()
- term.setCursorPos(1,1)
- end
- print("Monitor Activated!")
- if (fs.exists("players") == true) then
- print("Reading data...")
- file = fs.open("players","r")
- data = file.readLine()
- file.close()
- players = textutils.unserialize(data)
- end
- while stayInLoop do
- local cmdIssued = 0
- sleep(0.1)
- delay = delay + 0.1
- --Auto reboot to prevent computer shutdown.
- if (delay > 600) then
- os.reboot()
- end
- --Reset monitor.
- monitor.clear()
- --Header.
- monitor.setCursorPos(9,1)
- monitor.write("Current Duties:")
- monitor.setCursorPos(9,2)
- monitor.write("===============")
- --Loop through all players.
- local line = 3
- for i=1,#players do
- monitor.setCursorPos(1,line)
- monitor.write(">>"..players[i][1]..":")
- line = line + 1
- monitor.setCursorPos(1,line)
- monitor.write("Job:> "..players[i][2])
- line = line + 2
- end
- if adminLogin == 0 then
- write("Enter admin password for commands: ")
- local pass = read("0")
- if pass == "master" then
- adminLogin = 1
- end
- end
- if adminLogin == 1 then
- --Wait for commands and execute them.
- commands_help()
- write("Command: ")
- local cmd = read()
- if cmd == "new" then
- print("New player adding. Write 'q' to quit.")
- write("Name: ")
- local name = read()
- if not (name=="q") then
- print("New Job: ")
- local job= read()
- if (player_new(name,job)==true) then
- print("Player "..name.." added successfully")
- end
- after_command()
- end
- end
- if cmd == "job" then
- print("Change job for player. Write 'q' to quit.")
- write("Name: ")
- local name = read()
- if not (name=="q") then
- print ("New Job: ")
- local job = read()
- if (player_job(name,job)==true) then
- print("Player "..name.." edited successfully")
- else
- print("Player "..name.." not found!")
- end
- after_command()
- end
- end
- if cmd == "rename" then
- print("Change name for and existing player. Write 'q' to quit")
- write("Name: ")
- local name = read()
- if not (name=="q") then
- write("New name: ")
- local new = read()
- if (player_rename(name,new)==true) then
- print("Player "..name.." renamed to "..new)
- else
- print("Player "..name.." not found!")
- end
- end
- end
- if cmd == "delete" then
- print(" Delete a player by name. Write 'q' to quit")
- write("Name: ")
- local name = read()
- if not (name=="q") then
- if (player_remove(name)==true) then
- print("Player "..name.." removed!")
- else
- print("Player "..name.." not found!")
- end
- after_command()
- end
- end
- if cmd == "list" then
- for i=1,#players do
- print(players[i][1])
- end
- after_command()
- end
- if cmd == "admin" then
- stayInLoop = false
- term.clear()
- term.setCursorPos(1,1)
- write("Maintenance Mode!")
- end
- if cmd == "logout" then
- os.reboot()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement