-
-
-
-
-
-
-
-
-
The maximum of users you can have is 3. That's why I programmed in an error which shuts down the PC when you try to add an fourth user. The only problem is, that I always get the error message, even if no users are registered! I really hope for a quick answer.Here's the code (And yes, I know, it's not very organized):
---- Preparations ----
term.clear()
---- Draw Login Screen ----
--- Background ---
paintutils.drawFilledBox(1,1,51,19,colors.cyan)
--- User Boxes ---
paintutils.drawBox(6,2,15,11,colors.blue)
paintutils.drawBox(22,2,31,11,colors.blue)
paintutils.drawBox(38,2,47,11,colors.blue)
--- New User Button ---
paintutils.drawLine(3,16,3,18,colors.white)
paintutils.drawLine(2,17,4,17,colors.white)
--- Shutdown Button ---
paintutils.drawFilledBox(48,16,50,18,colors.red)
paintutils.drawLine(49,16,50,17,colors.white)
paintutils.drawLine(48,17,49,18,colors.white)
--- WinOS Text ---
-- W --
paintutils.drawLine(16,15,16,18,colors.white)
paintutils.drawLine(17,19,17,19,colors.white)
paintutils.drawLine(18,17,18,18,colors.white)
paintutils.drawLine(19,19,19,19,colors.white)
paintutils.drawLine(20,15,20,18,colors.white)
-- i --
paintutils.drawLine(22,17,22,19,colors.white)
paintutils.drawLine(22,15,22,15,colors.white)
-- n --
paintutils.drawLine(24,17,24,19,colors.white)
paintutils.drawLine(24,17,26,17,colors.white)
paintutils.drawLine(27,18,27,19,colors.white)
-- O --
paintutils.drawLine(29,16,29,18,colors.white)
paintutils.drawLine(30,15,31,15,colors.white)
paintutils.drawLine(30,19,31,19,colors.white)
paintutils.drawLine(32,16,32,18,colors.white)
-- S --
paintutils.drawLine(35,15,36,15,colors.white)
paintutils.drawLine(34,16,36,18,colors.white)
paintutils.drawLine(34,19,35,19,colors.white)
---- Userbox Filling ----
--- Perparations ---
local userdata = fs.open("%userdata", "r")
local firstUDLine = userdata.readLine()
if firstUDLine == "" then
userdata.close()
local userdata = fs.open("%userdata", "w")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.close()
local userdata = fs.open("%userdata", "r")
end
--- Actual Filling ---
-- User 1 --
userdata.readLine()
if userdata.readLine() == "red" then
paintutils.drawFilledBox(7,3,14,10,colors.red)
elseif userdata.readLine() == "blue" then
paintutils.drawFilledBox(7,3,14,10,colors.blue)
elseif userdata.readLine() == "green" then
paintutils.drawFilledBox(7,3,14,10,colors.green)
else
paintutils.drawFilledBox(7,3,14,10,colors.white)
end
-- User 2 --
userdata.readLine()
if userdata.readLine() == "red" then
paintutils.drawFilledBox(23,3,30,10,colors.red)
elseif userdata.readLine() == "blue" then
paintutils.drawFilledBox(23,3,30,10,colors.blue)
elseif userdata.readLine() == "green" then
paintutils.drawFilledBox(23,3,30,10,colors.green)
else
paintutils.drawFilledBox(23,3,30,10,colors.white)
end
-- User 3 --
userdata.readLine()
if userdata.readLine() == "red" then
paintutils.drawFilledBox(39,3,46,10,colors.red)
elseif userdata.readLine() == "blue" then
paintutils.drawFilledBox(39,3,46,10,colors.blue)
elseif userdata.readLine() == "green" then
paintutils.drawFilledBox(39,3,46,10,colors.green)
else
paintutils.drawFilledBox(39,3,46,10,colors.white)
end
while true do
local event, button, x, y = os.pullEvent("mouse_click")
if button == 1 then
if x > 47 and x < 51 and y > 15 and y < 19 then
term.clear()
paintutils.drawFilledBox(1,1,51,19,colors.cyan)
term.setCursorPos(19,10)
term.write("Shutting down |")
term.setCursorBlink(false)
term.setCursorPos(33,10)
sleep(0.1)
term.write("/")
term.setCursorPos(33,10)
sleep(0.1)
term.write("-")
term.setCursorPos(33,10)
sleep(0.1)
term.write("\\")
term.setCursorPos(33,10)
sleep(0.1)
term.write("|")
term.setCursorPos(33,10)
sleep(0.1)
term.write("/")
term.setCursorPos(33,10)
sleep(0.1)
term.write("-")
term.setCursorPos(33,10)
sleep(0.1)
term.write("\\")
term.setCursorPos(33,10)
sleep(0.1)
term.write("|")
term.setCursorPos(33,10)
sleep(0.1)
term.write("/")
term.setCursorPos(33,10)
sleep(0.1)
os.shutdown()
elseif x > 1 and x < 5 and y > 15 and y < 19 then
while true do
term.clear()
paintutils.drawFilledBox(1,1,51,19,colors.cyan)
term.setCursorPos(19,4)
term.write("Add a new User:")
term.setCursorPos(13,7)
term.write("Username")
term.setCursorPos(13,9)
term.write("Password")
paintutils.drawFilledBox(2,14,8,16,colors.red)
term.setCursorPos(3,15)
term.write("Abort")
paintutils.drawFilledBox(43,14,50,16,colors.green)
term.setCursorPos(45,15)
term.write("Done")
term.setCursorPos(2,18)
term.write("Restart required after every action in this menu!")
term.setCursorPos(22,7)
local newUsername = read()
term.setCursorPos(22,9)
local newPassword = read("*")
term.setCursorPos(0,0)
if newUsername == "-" or newPassword == "-" then
term.setCursorBlink(true)
term.setTextColor(colors.red)
term.setBackgroundColor(colors.cyan)
term.setCursorPos(22,11)
term.write("Invalid Password or Username!")
sleep(5)
else
break
end
end
local userdata = fs.open("%userdata", "r")
if userdata.readLine == "-" then
userdata.close()
local userdata = fs.open("%userdata", "w")
userdata.writeLine(newUsername)
userdata.writeLine(newPassword)
userdata.writeLine("red")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.writeLine("-")
userdata.close()
else
userdata.readLine()
userdata.readLine()
if userdata.readLine == "-" then
userdata.close()
local userdata = fs.open("%userdata", "r")
local Line1 = userdata.readLine()
local Line2 = userdata.readLine()
local Line3 = userdata.readLine()
userdata.close()
local userdata = fs.open("%userdata", "w")
userdata.writeLine(Line1)
userdata.writeLine(Line2)
userdata.writeLine(Line3)
userdata.writeLine(newUsername)
userdata.writeLine(newPassword)
userdata.writeLine("green")
userdata.close()
else
userdata.readLine()
userdata.readLine()
if userdata.readLine == "-" then
userdata.close()
local userdata = fs.open("%userdata", "r")
local Line1 = userdata.readLine()
local Line2 = userdata.readLine()
local Line3 = userdata.readLine()
local Line4 = userdata.readLine()
local Line5 = userdata.readLine()
local Line6 = userdata.readLine()
userdata.close()
local userdata = fs.open("%userdata", "w")
userdata.writeLine(Line1)
userdata.writeLine(Line2)
userdata.writeLine(Line3)
userdata.writeLine(Line4)
userdata.writeLine(Line5)
userdata.writeLine(Line6)
userdata.writeLine(newUsername)
userdata.writeLine(newPassword)
userdata.writeLine("blue")
userdata.close()
else
term.setCursorBlink(true)
term.setTextColor(colors.red)
term.setBackgroundColor(colors.cyan)
term.setCursorPos(12,15)
term.write("Error! Computer restarting...")
term.setCursorBlink(false)
sleep(3)
os.shutdown()
end
end
end
end
end
end