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

Array Database

Started by augustas656, 27 April 2014 - 01:49 PM
augustas656 #1
Posted 27 April 2014 - 03:49 PM
I need help creating a system, you have wireless pocket computers and a wireless database computer, on the pocket computers you can create an account or join an account, so whatever you press you have to type in username and password. I've already done this part, now then you have your username and password. I need to rednet send this username and password the the recieving database computer. Then I need the database computer to open a file that contains an array with usernames and passwords, if you are joining an account, it uses a for loop to cycle through all entries and find an array inside the main array with the username as mentioned. Then it checks for the password, if the password is correct then the database sends info about that user and that the account login was correct, else the database computer makes the pocket computer say that the username or password is wrong and restarts. If the username isn't found, the username or password is wrong this being said again, and restarts. If you are creating an account, it will send the username and password to the database computer, first it will search for the same username as the new account, if they find one the pocket computers says an account with the username already exists, and restarts the pocket computer, else the database computer creates a new entry array inside the main array with the password and username as mentioned, the entry also creates a bunch of default new information, which is then later sent to the pocket computer after creation.

Anyone got a similar script or can help me with some parts of this? Thanks, all help is appreciated.
Regards
Augustas
KingofGamesYami #2
Posted 27 April 2014 - 04:28 PM
I would look at the modem API instead of rednet, and save the usernames and passwords like this

local pass = {} --#obviosly if your computer restarts, this variable will be lost.
pass[username] = password
To save the usernames and passwords to a file

local data = textutils.serialize(pass)
local file = fs.open("pass", "w")
file.writeLine(data)
file.close()
To load the password file

local file = fs.open("pass", "r")
local data = file.readAll()
pass = textutils.unserialize(data)
file.close()
If you want to store the account data all together, you could matrix it instead, changing pass[username] to userdata[username][pass] or something similar.
You would have to program two programs to be able to tell the pocket computer what to do, one on the pocket computer that interprets the messages, and one on the 'database' that sends the appropriate information, as well as receiving the messages from the pocket computer.
Edited on 27 April 2014 - 02:35 PM
augustas656 #3
Posted 27 April 2014 - 05:28 PM
Does modem api include wireless messages?
viluon #4
Posted 27 April 2014 - 05:55 PM
ofc yes first read then ask