177 posts
Location
Spain
Posted 23 November 2014 - 01:17 PM
Hello guys! I'm having a trouble with my bank program.
First:
I don't know how can I save money amount (if I use variables, when I close the program the money clears and I don't want to use HTTP for security reasons.
Second:
Pay command. It uses RedNet. The account's ID is the ID of a Floppy Disk. I'm thinking about using a max account number Lenght and send in the msg the sender's ID and money (using string.sub())
EDIT: I solved this (I save accounts data in a Disk and I use string.sub()). You can close This.
Edited on 23 November 2014 - 03:44 PM
570 posts
Posted 23 November 2014 - 01:35 PM
First:
I don't know how can I save money amount (if I use variables, when I close the program the money clears and I don't want to use HTTP for security reasons.
Use the
fs API. Here's an example:
--# Saving the variable...
local myReallyNeatVariable = 22 --# The variable to be saved.
local file = fs.open("disk/myReallyNeatFile", "w") --# The first parameter is the file to write to, the second is the mode. "w" means write, "r" means read. You can combine these like "wr".
--# fs.open will give you a table that contains functions that allow you to perform operations on the file.
file.writeLine(myReallyNeatVariable) --# Write the variable to the file and add a new line at the end. It's not really necessary here, so you can just use file.write if you want.
file.close() --# We're done, close the file handle.
--# Loading it...
local file = fs.open("disk/myReallyNeatFile", "r")
local myReallyNeatVariable = tonumber(file.readLine()) --# readLine, as expected, reads a line. Since lines are strings, we need to convert it to a number. Luckily, tonumber does this.
file.close()
Second:
Pay command. It uses RedNet. The account's ID is the ID of a Floppy Disk. I'm thinking about using a max account number Lenght and send in the msg the sender's ID and money (using string.sub())
The problem with floppy disks is that you can easily edit the file that stores the money. Unless you've made sure that the disks can't be modified, there is no secure way to do this.
177 posts
Location
Spain
Posted 23 November 2014 - 03:03 PM
The problem with floppy disks is that you can easily edit the file that stores the money. Unless you've made sure that the disks can't be modified, there is no secure way to do this.
I store the money with FS but in a disk connected to the server. I will post my code because I'm having a trouble. Thanks!
177 posts
Location
Spain
Posted 23 November 2014 - 04:42 PM
I'm making a Bank porgram. The server gives responses to clients and save money amount. It works in RedNet. Cards are Floppy Disks.
When I try to pay, it says this:
server:39: attempt to index ? (a nil value)Server Code and
Client Code
1080 posts
Location
In the Matrix
Posted 23 November 2014 - 04:56 PM
It couldn't open. Instead of hardcoding disk/ try using getmountpath
file1 = fs.open(disk.getMountPath(dr)..from,"r")
Not sure if that'll work exactly, otherwise use fs.combine with the getMountPath
file1 = fs.open(fs.combine(disk.getMountPath(dr),from),"r")
Also make sure that the file actually exists by using fs.exists()
Edited on 23 November 2014 - 03:57 PM
8543 posts
Posted 23 November 2014 - 09:09 PM
Threads merged.