Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Remove Accounts File
- Written by TheShadow989
- ]]--
- os.pullEvent = os.pullEventRaw
- local verNumber = "Alpha 1.24"
- local nOption = 1
- userfinal = {}
- userlenght = {}
- usernamearray = {}
- rRead = fs.open("xos/.usertable", "r")
- users = textutils.unserialize(rRead.readAll())
- rRead.close()
- cu = tonumber(users[1])
- cs = tonumber(users[cu+1])
- cp = tonumber(users[cu+2])
- usernamearray[1] = users[2]
- if users[5] == nil then
- usernamearray[2] = "Empty"
- else
- usernamearray[2] = users[5]
- end
- if users[8] == nil then
- usernamearray[3] = "Empty"
- else
- usernamearray[3] = users[8]
- end
- if users[11] == nil then
- usernamearray[4] = "Empty"
- else
- usernamearray[4] = users[11]
- end
- userlenght[1] = string.len(usernamearray[1])
- userlenght[2] = string.len(usernamearray[2])
- userlenght[3] = string.len(usernamearray[3])
- userlenght[4] = string.len(usernamearray[4])
- for i=1, 4 do
- if userlenght[i] == 9 then
- userfinal[i] = ""..usernamearray[i]..""
- elseif userlenght[i] == 8 then
- userfinal[i] = ""..usernamearray[i].." "
- elseif userlenght[i] == 7 then
- userfinal[i] = " "..usernamearray[i].." "
- elseif userlenght[i] == 6 then
- userfinal[i] = " "..usernamearray[i].." "
- elseif userlenght[i] == 5 then
- userfinal[i] = " "..usernamearray[i].." "
- elseif userlenght[i] == 4 then
- userfinal[i] = " "..usernamearray[i].." "
- elseif userlenght[i] == 3 then
- userfinal[i] = " "..usernamearray[i].." "
- elseif userlenght[i] == 2 then
- userfinal[i] = " "..usernamearray[i].." "
- elseif userlenght[i] == 1 then
- userfinal[i] = " "..usernamearray[i].." "
- end
- end
- local w,h = term.getSize()
- local function drawMenu()
- local time = os.time()
- local formattedTime = textutils.formatTime(time, false)
- term.clear()
- term.setCursorPos(1,1)
- term.write("Logged in as: ")
- term.setTextColor( colors.red )
- term.write(""..users[cu].."")
- term.setTextColor( colors.white )
- term.setCursorPos(1,2)
- write(formattedTime)
- term.setCursorPos(1,19)
- term.write("xOS "..verNumber.." by TheShadow989")
- term.setCursorPos(w-11,1)
- if nOption == 1 then
- term.write(""..usernamearray[1].."")
- elseif nOption == 2 then
- term.write(""..usernamearray[2].."")
- elseif nOption == 3 then
- term.write(""..usernamearray[3].."")
- elseif nOption == 4 then
- term.write(""..usernamearray[4].."")
- elseif nOption == 5 then
- term.write("Back")
- end
- end
- function printCentered(y,s)
- local x = math.floor((w - string.len(s)) / 2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write( s )
- end
- term.clear()
- local function drawFrontend()
- printCentered( math.floor(h/2) - 4, "")
- printCentered( math.floor(h/2) - 3, "Select an account to delete." )
- printCentered( math.floor(h/2) - 2, "")
- printCentered( math.floor(h/2) - 1, ((nOption == 1) and "["..userfinal[1].."]") or userfinal[1] )
- printCentered( math.floor(h/2) + 0, ((nOption == 2) and "["..userfinal[2].."]") or userfinal[2] )
- printCentered( math.floor(h/2) + 1, ((nOption == 3) and "["..userfinal[3].."]") or userfinal[3] )
- printCentered( math.floor(h/2) + 2, ((nOption == 4) and "["..userfinal[4].."]") or userfinal[4] )
- printCentered( math.floor(h/2) + 3, "")
- printCentered( math.floor(h/2) + 4, ((nOption == 5) and "[ Back ]") or " Back " )
- end
- local function errormsg()
- local time = os.time()
- local formattedTime = textutils.formatTime(time, false)
- term.setCursorPos(1,1)
- term.write("Logged in as: ")
- term.setTextColor( colors.red )
- term.write(""..users[cu].."")
- term.setTextColor( colors.white )
- term.setCursorPos(1,2)
- write(formattedTime)
- term.setCursorPos(1,19)
- term.write("xOS "..verNumber.." by TheShadow989")
- term.setCursorPos(w-11,1)
- if nOption == 1 then
- term.write(""..usernamearray[1].."")
- elseif nOption == 2 then
- term.write(""..usernamearray[2].."")
- elseif nOption == 3 then
- term.write(""..usernamearray[3].."")
- elseif nOption == 4 then
- term.write(""..usernamearray[4].."")
- end
- term.setCursorPos(11,8)
- end
- local function save()
- wWrite = fs.open("xos/.usertable", "w")
- wWrite.write(textutils.serialize(users))
- wWrite.close()
- errormsg()
- term.setCursorPos(11,8)
- term.setTextColor(colors.green)
- term.write("Account Successfully Deleted!")
- term.setTextColor(colors.white)
- sleep(3)
- shell.run("xos/.accounts")
- end
- drawMenu()
- drawFrontend()
- while true do
- local e,p = os.pullEvent()
- if e == "key" then
- local key = p
- if key == 17 or key == 200 then
- if nOption > 1 then
- nOption = nOption - 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 31 or key == 208 then
- if nOption < 5 then
- nOption = nOption + 1
- drawMenu()
- drawFrontend()
- end
- elseif key == 28 then
- break
- end
- end
- end
- term.clear()
- if nOption == 1 then
- errormsg()
- term.setTextColor( colors.red )
- write("Cannot edit or delete Admin!")
- term.setTextColor( colors.white )
- sleep(2)
- shell.run("xos/.removeaccounts")
- elseif nOption == 2 then
- if usernamearray[2] == "Empty" then
- errormsg()
- term.setTextColor( colors.red )
- write("Cannot delete an empty slot!")
- term.setTextColor( colors.white )
- sleep(2)
- shell.run("xos/.removeaccounts")
- else
- if cu >= 5 then
- cu = cu - 3
- users[1] = cu
- end
- table.remove(users, 5)
- table.remove(users, 5)
- table.remove(users, 5)
- save()
- end
- elseif nOption == 3 then
- if usernamearray[3] == "Empty" then
- errormsg()
- term.setTextColor( colors.red )
- write("Cannot delete an empty slot!")
- term.setTextColor( colors.white )
- sleep(2)
- shell.run("xos/.removeaccounts")
- else
- if cu >= 8 then
- cu = cu - 3
- users[1] = cu
- end
- table.remove(users, 8)
- table.remove(users, 8)
- table.remove(users, 8)
- save()
- end
- elseif nOption == 4 then
- if usernamearray[4] == "Empty" then
- errormsg()
- term.setTextColor( colors.red )
- write("Cannot delete an empty slot!")
- term.setTextColor( colors.white )
- sleep(2)
- shell.run("xos/.removeaccounts")
- else
- if cu >= 11 then
- cu = cu - 3
- users[1] = cu
- end
- table.remove(users, 11)
- table.remove(users, 11)
- table.remove(users, 11)
- save()
- end
- elseif nOption == 5 then
- shell.run("xos/.accounts")
- end
Add Comment
Please, Sign In to add comment