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

Editing computercraft program through another program

Started by dexter9, 22 February 2013 - 07:00 AM
dexter9 #1
Posted 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?
mibac138 #2
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
dexter9 #3
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?
LBPHacker #4
Posted 22 February 2013 - 09:21 AM
Ok how can i get this to work with a program which currently has the database in it?
What do you mean by that?

BTW I think a serialized table stored in a text file is the best database solution…
dexter9 #5
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..
LBPHacker #6
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?
dexter9 #7
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?
LBPHacker #8
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.
dexter9 #9
Posted 24 February 2013 - 11:16 AM
Im not familar with any of that at all :L
dexter9 #10
Posted 24 February 2013 - 11:49 PM
It doesnt seem towork for me…..
remiX #11
Posted 25 February 2013 - 12:15 AM
If I good understand this should be this what you want :)/>/>/&amp;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/>
dexter9 #12
Posted 25 February 2013 - 12:31 AM
I dont understand how to make a database file though…..
theoriginalbit #13
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
dexter9 #14
Posted 25 February 2013 - 12:45 AM
Ok thanks. How do i integrate it into my program. Do i include it in my program?
dexter9 #15
Posted 25 February 2013 - 02:30 AM
Ok got that bit working. Now how do i get my info updated into the database?
theoriginalbit #16
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