This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TwoDeeSee's profile picture

I am trying to make a login system that only lets you login once a day

Started by TwoDeeSee, 22 November 2015 - 05:09 AM
TwoDeeSee #1
Posted 22 November 2015 - 06:09 AM
I cannot figure out how to get this to work.
btw I am using the standard login with a few edits made by me


local opentime = 10
local side = "back"
local password = "dlk"
local don = "D125"
local don2 = "D12"
local res1 = "Dcal"
local res2 = "Dmac"
local res3 = "Dan"
local res4 = "Dale"

term.clear()
term.setCursorPos(1,1)
print("Type Your Username(Needed to teleport you) :")
local userName = read()
term.setCursorPos(1,2)
write("Type Your ID :")
local code = read("#")
if code == password then
fs.exit()
else
if code == don then
hate()
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
print("ID not found")
fs.makeDir("hdd01")
local file = fs.open("hdd00/"..code, "a")
file.writeLine("failed "..userName)
file.close()
sleep(15)
os.reboot()
end
end
function hate()
if fs.exists("hdd00/"..code.."check") then
term.setCursorPos(1,1)
print("Okay! heres your ticket for today! please stand still!")
fs.makeDir("hdd00")
local file = fs.open("hdd00/"..code, "a")
file.writeLine("Passed "..userName)
file.close()
local check = fs.open("hdd00/"..code.."check", "a")
check.writeLine("used 1 times today")
check.close()
rs.setOutput(side,true)
sleep(opentime)
rs.setOutput(side,false)
end
end

any ideas? thanks in advance!
KingofGamesYami #2
Posted 22 November 2015 - 03:13 PM
Once per minecraft day, or once per real day (24 hr)? If it's once per real day, I'd recommend finding an API on the forums which gets the real-world date/time (there are a couple) and using that.

To use that, I'd write down the date in a file, and if the date matches the current date, don't allow a login.
TwoDeeSee #3
Posted 23 November 2015 - 04:03 PM
Once per minecraft day, or once per real day (24 hr)? If it's once per real day, I'd recommend finding an API on the forums which gets the real-world date/time (there are a couple) and using that.

To use that, I'd write down the date in a file, and if the date matches the current date, don't allow a login.
once per server day, the server is set to reboot once per day and the computers are configured to delete the selected files after reboot.

which would work but Idk how to check if the file exists.
KingofGamesYami #4
Posted 23 November 2015 - 04:59 PM
fs.exists( "file name" )
Edited on 23 November 2015 - 04:40 PM
TwoDeeSee #5
Posted 24 November 2015 - 03:34 AM

if fs.exists("hdd00/"..code.."check") then
term.setCursorPos(1,1)
print("Okay! heres your ticket for today! please stand still!")
fs.makeDir("hdd00")

Please read the code…
Lyqyd #6
Posted 24 November 2015 - 05:39 AM
Don't get snarky with people trying to help you, especially when they link you to a way to check if a file exists right after you say you don't know how to check if a file exists:

which would work but Idk how to check if the file exists.