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

User login recording (Lua Question) [SOLVED]

Started by Espiroth, 29 May 2012 - 08:33 PM
Espiroth #1
Posted 29 May 2012 - 10:33 PM
This following programs reads from a inserted disk to see if that person has a high enough clearance.

I wanted to know if i could have the program read from only a SPECIFIC line on the disk or a specific file on the disk so i can include additional data such as name or specific permissions. Then have the program write to its own rom, adding lines to a previous existing log.

Are there any commands that could help me do that?

Spoiler

while true do
event, param1, param2 = os.pullEvent()
if event == "disk" and param1 == "dside" or if disk.isPresent(dside) == true then
if fs.exists("disk/level") then
file = io.open("disk/level", "r")
passt = file:read()
if passt >= pass then
print("ACCESS GRANTED")
disk.eject(dside)
power(pside, colors.blue)
sleep(10)
power(pside, 0)
else
print ("ACCESS LEVEL NOT HIGH ENOUGH")
sleep(10)
disk.eject(dside)
os.reboot()
end
end
disk.eject(dside)
end
end

Credit for this program goes to coolblockj
http://mccraftcpl.pr...play&thread=163
Espiroth #2
Posted 30 May 2012 - 12:00 AM
I solved this problem by have the program write many files to the floppy, each holding the string of info I need




print ("Corsair Security Card Programming Suite")

HorzLoadBar(5, 45, "/")

print ("Insert blank card")
while true do
os.pullEvent()
if disk.isPresent(dside) then
print ("Card detected")
write ("Enter clearance level of card: >")
local clearance = read()
write ("Enter purpose of card: >")
local purpose = read()
write ("Enter ID# of card: >")
local id = read()
write ("Enter name of user: >")
local name = read()
disk.setLabel(dside, "Level "..clearance.." Access card")
file = io.open("disk/data/clearance", "w")
file:write(clearance)
file:close()
file = io.open("disk/data/purpose", "w")
file:write(purpose)
file:close()
file = io.open("disk/data/name", "w")
file:write(name)
file:close()
print ("Card has successfuly been programmed.")
sleep(2)
print ("Please remove the card")
sleep(2)
print ("Rebooting...")
sleep(1)
os.reboot()
end
end