This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Editing computercraft program through another program
Started by dexter9, 22 February 2013 - 07:00 AMPosted 22 February 2013 - 08:00 AM
Basically, I have a remote password server. Instead of having to go into the code all the time can i make a program where you type, username,id,password into and it makes an account? is there a program like this out there and is it compatible with many other programs?
Posted 22 February 2013 - 08:17 AM
If I good understand this should be this what you want :)/>/>
local tArgs = {...}
local databaseFile = fs.open(".database", "a")
if #tArgs >= 4 or #tArgs < 3 then
error(..shell.getRunningProgram()": 3 args expected - username, id, password")
end
databaseFile.writeLine(tArgs[1]..","..tArgs[2]..","..tArgs[3])
databaseFile.close()
if term.isColor() then
term.setTextColor(colors.lime)
print("Sucess!")
else
print("Sucess!")
end
Posted 22 February 2013 - 08:19 AM
Ok how can i get this to work with a program which currently has the database in it. Can i get the current program to look in the database?
Posted 22 February 2013 - 09:21 AM
What do you mean by that?Ok how can i get this to work with a program which currently has the database in it?
BTW I think a serialized table stored in a text file is the best database solution…
Posted 22 February 2013 - 09:37 AM
Ok basically the passwords are saved inside the program which decides whether the password entered is correct or not..
Posted 22 February 2013 - 09:59 AM
Umm… So you want to write a program… That… Actually… Rewrites the main program… Honestly? NO. THAT'S a terrible idea. Use config files or something like those instead. Do you need an example?
Posted 23 February 2013 - 07:50 AM
Please. I dont know much about this as you can see. I could do another program with a database if needed?
Posted 23 February 2013 - 08:04 AM
Ok. First of all, you have to learn how to actually create a database (or something like that). I've posted a tutorial about this. Reply when you're done with that.
BTW Are you familiar with tables inside tables? Because those are exactly what you might want to use.
BTW Are you familiar with tables inside tables? Because those are exactly what you might want to use.
Posted 24 February 2013 - 11:16 AM
Im not familar with any of that at all :L
Posted 24 February 2013 - 11:49 PM
It doesnt seem towork for me…..
Posted 25 February 2013 - 12:15 AM
If I good understand this should be this what you want :)/>/>/&gt;local tArgs = {...} local databaseFile = fs.open(".database", "a") if #tArgs >= 4 or #tArgs < 3 then error(..shell.getRunningProgram()": 3 args expected - username, id, password") end databaseFile.writeLine(tArgs[1]..","..tArgs[2]..","..tArgs[3]) databaseFile.close() if term.isColor() then term.setTextColor(colors.lime) print("Sucess!") else print("Sucess!") end
This would error out with line 4, ')' expected or something :P/>
Posted 25 February 2013 - 12:31 AM
I dont understand how to make a database file though…..
Posted 25 February 2013 - 12:40 AM
I dont understand how to make a database file though…..
local yourDatabase = {
["somename"] = "somepass",
["somename2"] = "somepass",
}
local function saveDatabase()
local handle = fs.open(".database", "w")
handle.write( textutils.serialize( yourDatabase ) )
handle.close()
end
local function loadDatabase()
local handle = fs.open(".database", "w")
local contents = handle.readAll()
handle.close()
yourDatabase = textutils.unserialize( contents or "{}" )
end
Posted 25 February 2013 - 12:45 AM
Ok thanks. How do i integrate it into my program. Do i include it in my program?
Posted 25 February 2013 - 02:30 AM
Ok got that bit working. Now how do i get my info updated into the database?
Posted 25 February 2013 - 02:36 AM
thats where integration with the other program comes in. I would say have like some special rednet message that can do it, then have these functions
local function addToDatabase(user, pass)
if yourDatabase[user] then
print("This user exists")
else
yourDatabase[user] = pass
end
end
local function removeFromDatabase(user, pass)
if not yourDatabase[user] then
print("This user does not exist")
else
yourDatabase[user] = nil
end
end