Also im trying to make an installer to get pastebin files, what is the best possible way to do this?
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
help please
Started by Ristyo, 24 March 2013 - 04:47 PMPosted 24 March 2013 - 05:47 PM
i am trying to make a program that can make people make a new account and login, but i am confused how to store the account information, can anybody help me?
Also im trying to make an installer to get pastebin files, what is the best possible way to do this?
Also im trying to make an installer to get pastebin files, what is the best possible way to do this?
Posted 24 March 2013 - 06:24 PM
Saving account information:
Loading account information:
-- example table of username and passwords
-- e.g. "Username = 'Password'"
accounts = {
SomePerson = 'SomePassword';
AnotherPerson = 'AnotherPassword';
}
-- make the table into a string
data = textutils.serialize(accounts)
-- save it to a file called "accounts"
file = fs.open('accounts', 'w') -- open "accounts" with writing mode
file.write(data) -- write the stringed table
file.close()
Loading account information:
file = fs.open('accounts', 'r') -- open "accounts" for reading
content = file.readAll() -- get what's in the file as a string to the variable "content"
file.close()
-- turn the file's text back into a table
accounts = textutils.unserialize(content)
print(accounts.SomePerson) --> SomePassword
Posted 24 March 2013 - 06:32 PM
the file.write(data)
the data is the accounts?
the data is the accounts?
Posted 24 March 2013 - 06:34 PM
Yes. It's the writeable version of the accounts table. You can't write a table directly to a file, so I used textutils.serialize() to turn it into a string.
Posted 24 March 2013 - 06:43 PM
thanks, the only reason im asking this cause im making an OS (well, everybody did) so thanks Kingdaro! ill put ur name there
Posted 24 March 2013 - 11:04 PM
One more, if you want to have the accounts get set by a variable (in this case x=read()) how to do it?
Posted 25 March 2013 - 12:16 AM
Well have it just insert into the table of accounts. Make sure you load all the accounts in the beggining and then ask register or login etc. And then if registeration is succesfull:
local user = read()
local password = read()
accounts[user] = password
Posted 25 March 2013 - 01:03 AM
For your installer thing, you could use shell.run("pastebin get pbincode programname").
I've made a rip-off that program, so it doesnt display the text it produces:
All credits go to the developers of ComputerCraft
I've made a rip-off that program, so it doesnt display the text it produces:
function getPastebin( code, path ) -- Credits to the devs of CC
local path = path or code
local response = http.get(
"http://pastebin.com/raw.php?i=" .. textutils.urlEncode( code )
)
if response then
local contents = response.readAll()
local file = fs.open( path, "w" )
file.write( contents )
file.close()
return true
else
return false
end
end
All credits go to the developers of ComputerCraft
Posted 25 March 2013 - 04:01 AM
Does this way work?
Stacking shell.run("pastebin get", pbin code, file name)
Its all stacked up to get each pastebin files
Will it work?
Example
shell.run("pastebin get", pbin code, file name1")
shell.run("pastebin get", pbin code, file name2")
Stacking shell.run("pastebin get", pbin code, file name)
Its all stacked up to get each pastebin files
Will it work?
Example
shell.run("pastebin get", pbin code, file name1")
shell.run("pastebin get", pbin code, file name2")