If someone could help me out that'd be great
Server
Client
Cheers, MistaMadd001
--bankServer V: 0.2.1
local id = os.getComputerID()
if fs.exists("server/id") then
local time = os.time()
local date = os.day()
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Server started\n")
rednet.open("left")
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): RedNet activated\n")
file.close()
shell.run("clear")
print("Opening listening ports")
os.loadAPI("crypt")
sleep(2)
shell.run("clear")
print("Ports open, System online")
while true do
local id,msg = rednet.receive()
local data = textutils.unserialize(msg)
local cmd = data[1]
local acc = data[2]
local pwd = data[3]
local amt = data[4]
local toA = data[5]
local mayor = mistamadd001
if cmd == "install" then -- [[When a new computer in the system is started, this code saves their id as a file (sorta setting up a security system, once all the clients are installed i will be removing this code entirely, effectively locking the server to only the computers I select]]
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Attempting client install\n")
file.close()
print("("..id.."): Attempting Client Install")
if fs.exists("clients/")then
if fs.exists ("clients/"..id) then
rednet.send(id, " Client already installed")
local file = fs.open("backups/serverlog","a")
file.write(date..","..time..":"..id.."): Client already installed\n")
file.close()
print("("..id.."): Client already installed")
else
local file = fs.open("clients/"..id,"w")
file.close()
local file = fs.open("server/id", "r")
local sId = file.readall()
rednet.send(id, textutils.serialize({"confirm", sId})
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Client installed\n")
file.close()
print("("..id.."): Client installed")
end
else
fs.makeDir("clients")
local file = fs.open("clients/"..id,"w")
file.close()
rednet.send(id, " Client installed")
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Client installed\n")
file.close()
print("("..id.."): Client installed")
end
elseif cmd == "create" then -- [[ this is the 'new user' creation command]]
if fs.exists("clients/"..id) then
if fs.exists("users/" ..acc)then
rednet.send(id, "used")
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Account "..acc.." already created\n")
file.close()
print("("..id.."): Account "..acc.." already created")
else
local file = fs.open("users/"..acc, "w")
file.write(textutils.serialize({name = acc, pass = pwd, bal = 1000}))
file.close()
rednet.send(id, "created")
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Account "..acc.." created\n")
file.close()
print("("..id.."): Account "..acc.." created")
end
elseif cmd == "login" then -- [[******this is where i'm having the problem, this is the code that should be triggered when the ATM sends its first message******]]
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): User: "..acc.." login\n")
file.close()
print("("..id.."): User "..acc.." authentication attempted")
if fs.exists("clients/"..id) then
if fs.exists("users/"..acc) then
local file = fs.open("users/"..acc, "r")
local info = file.readall()
file.close()
cData = textutils.unserialize(info)
local cAcc = cData[name]
local cPwd = cData[pass]
local cBal = cData[bal]
if cPwd == pwd then
rednet.send(id, textutils.serialize({"confirm", cAcc, cBal}))
local id,msg = rednet.receive()
local data = textutils.unserialize(msg)
if cmd == "withdraw" then -- [[ these options are pretty self explanatory, theyre all triggered by subsequent messages from the ATM]]
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." Withdraw attempt\n")
file.close()
print("("..id.."): User "..acc.." Withdrawal attempted")
newBal = math.floor(cBal-amt)
local file = fs.open("users/"..acc, "w")
file.write(textutils.serialize({name = cAcc, pass = cPwd, bal = newBal}))
file.close()
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." Withdrew "..amt"\n")
file.close()
rednet.send(id, textutils.serialize({"confirm", acc, newBal}))
elseif cmd == "deposit" then
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." Deposit attempt\n")
file.close()
print("("..id.."): User "..acc.." Deposit attempted")
newBal = math.floor(cBal+amt)
local file = fs.open("users/"..acc, "w")
file.write(textutils.serialize({name = cAcc, pass = cPwd, bal = newBal}))
file.close()
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." Deposited "..amt"\n")
file.close()
rednet.send(id, textutils.serialize({"confirm", acc, newBal}))
elseif cmd == "transfer" then
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." transfer attempt\n")
file.close()
print("("..id.."): User "..acc.." Transfer attempted")
newBal = math.floor(cBal-amt)
local file = fs.open("users/"..acc, "w")
file.write(textutils.serialize({name = cAcc, pass = cPwd, bal = newBal}))
file.close()
rednet.send(id, textutils.serialize({"confirm", acc, bal = newBal}))
local file = fs.open("users/"..toA, "r")
local cData = file.readall()
file.close()
newBal = math.floor(cBal+amt)
local file = fs.open("users/"..toA, "w")
file.write(textutils.serialize({name = cAcc, pass = cPwd, bal = newBal}))
file.close()
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." transferred $"..amt.." to: "..toA"\n")
file.close()
print("("..id.."): User "..acc.." transferred $"..amt.." to: "..toA)
else
rednet.send(id, textutils.serialize({"declined"}))
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Unknown command "..cmd.." entered\n")
file.close()
print("("..id.."): Unknown command "..cmd.." entered")
end
else
rednet.send(id, textutils.serialize({"declined"}))
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." Password incorrect\n")
file.close()
print("("..id.."): User "..acc.." entered an incorrect password")
end
else
rednet.send(id, textutils.serialize({"declined"}))
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): User "..acc.." doesn't exist\n")
file.close()
print("("..id.."): User "..acc.." doesn't exist")
end
else
rednet.send(id, textutils.serialize({"declined"}))
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."):Unrecognised client\n")
file.close()
print("("..id.."): Unrecognised client, access denied")
end
elseif cmd == "eCharge" then -- [[ this is the start of my utilities charging system]]
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." transfer attempt\n")
file.close()
print("("..id.."): User "..acc.." Transfer attempted")
local file = fs.open("users/"..acc, "r")
local info = file.readall()
file.close()
cData = textutils.unserialize(info)
local cAcc = cData[name]
local cPwd = cData[pass]
local cBal = cData[bal]
local amt = 0.5
newBal = math.floor(cBal-amt)
local file = fs.open("users/"..acc, "w")
file.write(textutils.serialize({name = acc, pass = pwd, bal = newBal}))
file.close()
rednet.send(id, textutils.serialize({"confirm", acc, bal = newBal}))
local file = fs.open("users/"..toA, "r")
local info = file.readall()
file.close()
cData = textutils.unserialize(info)
local cAcc = cData[name]
local cPwd = cData[pass]
local cBal = cData[bal]
newBal = math.floor(cBal+amt)
local file = fs.open("users/"..toA, "w")
file.write(textutils.serialize({name = cAcc, pass = cPwd, bal = newBal}))
file.close()
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." transferred $"..amt.." to: "..toA"\n")
file.close()
print("("..id.."): User "..acc.." transferred $"..amt.." to: "..toA)
elseif cmd == "check" then -- [[this is part of my house rental system]]
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." house "..amt.." access attempt\n")
file.close()
print("("..id.."): User: "..acc.." attempting house "..amt.." access")
local file = fs.open("users/"..acc, "r")
local info = file.readall()
file.close()
cData = textutils.unserialize(info)
local cAcc = cData[name]
local cPwd = cData[pass]
local cBal = cData[bal]
if cPwd == pwd then
if cBal > 1500 or cBal == 1500 then
newBal = math.floor(cBal-1500)
local file = fs.open("users/"..acc, "w")
file.write(textutils.serialize({name = cAcc, pass = cPwd, bal = newBal}))
file.close()
local file = fs.open("users/"..mayor, "r")
local info = file.readall()
file.close()
mData = textutils.unserialize(info)
local mAcc = mData[name]
local mPwd = mData[pass]
local mBal = mData[bal]
newBal = math.floor(mBal + 1500)
rednet.send(id, textutils.serialize({"confirm", cAcc, cPwd, newBal}))
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." house "..amt.." access granted\n")
file.close()
print("("..id.."): User: "..acc.." house "..amt.." access granted")
elseif cBal < 1500 then
rednet.send(id, textutils.serialize({"declined"}))
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." house "..amt.." access denied, insufficient funds\n")
file.close()
print("("..id.."): User: "..acc.." house "..amt.." access denied, insufficient funds")
end
else if cPwd ~= pwd then
rednet.send(id, textutils.serialize({"declined"}))
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): "..acc.." house "..amt.." access denied, incorrect password\n")
file.close()
print("("..id.."): User: "..acc.." house "..amt.." access denied, incorrect password")
end
else rednet.send(id, textutils.serialize({"declined"}))
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Unknown command "..cmd.." entered\n")
file.close()
print("("..id.."): Unknown command "..cmd.." entered")
end
end
end
else
local id = os.getComputerID() -- [[this simply creates a new 'server' directory and creates a file with the 'server' computers ID, this hooks into the "install" command for clients, sending them the serverID for all future messages]]
fs.makeDir("server")
local file = fs.open("server/id","w")
file.write(id)
file.close()
local file = fs.open("backups/serverlog","a")
file.write(date..","..time.."("..id.."): Server Created\n")
file.close()
print("This Server's ID is "..id)
sleep(5)
end
os.pullEvent = os.pullEventRaw
rednet.open("left") --Modem side
os.loadAPI("crypt")
local cbl = peripheral.wrap("top") --Command Block side
if fs.exists("server/id") == false then --[[this creates a file that holds the serverID for future messages and sends the server the client ID for future authentication]]
rednet.broadcast(textutils.serialize({"install"})
local id,msg = rednet.receive()
local info = textutils.unserialize(msg)
local cmd = info[1]
local sId = info[2]
fs.makeDir("server")
local file = fs.open("server/id", "w")
file.write(sId)
file.close()
end
while true do
local file = fs.open("server/id", "r")
local sId = file.readall()
file.close()
shell.run("clear")
if disk.hasData("bottom") == false then --[[ this is pretty self explanatory, checks to see if there is a floppy disk inserted]]
while true do
print("Please insert bank card")
if os.pullEvent("disk") then
break
end
end
elseif disk.hasData("bottom") == true then --[[if there is a floppy inserted the program continues]]
local acc = disk.getLabel("bottom")
shell.run("clear")
print("Welcome "..acc)
print("Please enter your P.I.N.:")
pwd = read("*")
rednet.send(sId, textutils.serialize({"login", acc, crypt.hashPassword(pwd)}))
print("pwd sent") --[[*******this is where the program hangs, it sends the message and prints that its sent, then waits for the reply*******]]
id,msg = rednet.receive()
print("reply received") --[[ this is just for debugging]]
local data = textutils.unserialize(msg)
local cmd = data[1]
local acc = data[name]
local bal = data[bal]
if cmd == "confirm" then --[[ all password verification is done at the server, this denies any negative consequences]]
shell.run("clear")
print("Password accepted")
sleep(2)
while true do --[[ these are the options for account/balance manipulation]]
shell.run("clear")
local opts = {}
local opts1 = "Balance Enquiry"
local opts2 = "Withdraw"
local opts3 = "Deposit"
local opts4 = "Transfer"
print("What would you like to do")
print("")
for a,b in ipairs(opts) do
print(tostring(a)..") "..tostring(B)/>)
end
local cmd = read()
if cmd == 1 or "Balance" or "balance" then
shell.run("clear")
print("Balance:")
print("$"..bal)
elseif cmd == 2 or "Withdraw" or "withdraw" then
shell.run("clear")
write("How much do you want to withdraw: $")
local amt = read()
print("Processing")
sleep(5)
if amt == bal or amt < bal then
shell.run("clear")
print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
print("Y/N")
local cmd = read()
if cmd == "Y" or "y" then
rednet.send(sId, textutils.serialize({"withdraw", acc, crypt.hashPassword(pwd), amt}))
local id, msg = rednet.receive()
local data = textutils.unserialize(msg)
if cmd == "confirm" then
cbl.setCommand("eco give @p amt")
cbl.runCommand()
shell.run("clear")
print("New balance:")
print("$"..bal)
sleep(5)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("Withdrawal cancelled")
sleep(3)
end
else
print("You do not have enough funds to complete this transaction")
sleep(3)
end
elseif cmd == 3 or "Deposit" or "deposit" then
shell.run("clear")
write("How much do you want to deposit: $")
local amt = read()
print("Processing")
sleep(5)
shell.run("clear")
print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
print("Y/N")
local cmd = read()
if cmd == "Y" or "y" then
rednet.send(sId, textutils.serialize({"deposit", acc, crypt.hashPassword(pwd), amt}))
local id, msg = rednet.receive()
local data = textutils.unserialize(msg)
if cmd == "confirm" then
shell.run("clear")
print("Deposited $"..amt.." into "..acc.."'s account")
cbl.setCommand("eco take @p amt")
cbl.runCommand()
sleep(3)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("Transaction cancelled")
sleep(3)
end
elseif cmd == 4 or "Transfer" or "transfer" then
shell.run("clear")
write("Type the account name you would like to transfer funds to: ")
local toAcc = read()
shell.run("clear")
write("Please enter the amount you wish to transfer: $")
local amt = read()
shell.run("clear")
print("Please confirm, you wish to transfer $"..amt.." from "..acc.." to "..toA.." Y/N")
local cmd = read()
shell.run("clear")
print("Processing")
sleep(3)
if cmd == "Y" or "y" then
if amt == bal or amt < bal then
rednet.send(sId, textutils.serialize({"transfer", acc, crypt.hashPassword(pwd), amt, toA}))
local id,msg = rednet.receive()
local data = textutils.unserialize(msg)
if cmd == "confirm" then
shell.run("clear")
print("$"..amt.." transferred to "..toA)
sleep(3)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("You do not have enough funds to complete this transaction")
sleep(3)
end
else
shell.run("clear")
print("Transaction cancelled")
sleep(3)
end
else -- [[ this will auto stop the program if a selection isnt made in 20 seconds]]
sleep(20)
print("Took too long to make a selection, cancelling transaction")
sleep(3)
disk.eject("bottom")
break
end
end
else
print("Incorrect Password, Try Again")
sleep(5)
end
end
end
Line 94 and 95 of the server is simply receiving the message, then userializing it. You don't appear to do anything with it afterwards.
The thing is, on install and create, you only use the variable cmd once. Whereas with login, you receive it once, the if statement goes through, you send and receive another set, then do nothing with it. The loop will run again from the start, and it will receive another set of messages, and we're back to where we started.
The thing is, on install and create, you only use the variable cmd once. Whereas with login, you receive it once, the if statement goes through, you send and receive another set, then do nothing with it. The loop will run again from the start, and it will receive another set of messages, and we're back to where we started.
OK I fixed that now a more basic problem, apparently on line 86 which is a file.readall() its not getting any info, the readall() command doesnt seem to work
rednet.open("left") --Modem side
os.loadAPI("crypt")
local cbl = peripheral.wrap("top") --Command Block side
if fs.exists("server/id") == false then --[[this creates a file that holds the serverID for future messages and sends the server the client ID for future authentication]]
rednet.broadcast(textutils.serialize({"install"}))
sleep(0.1)
local id = rednet.receive()
print("this is the Server ID: "..id)
fs.makeDir("server")
local file = fs.open("server/id", "w")
file.write(id)
file.close()
end
while true do
local file = fs.open("server/id", "r")
local sId = tonumber(file.readAll())
file.close()
shell.run("clear")
if disk.hasData("bottom") == false then --[[ this is pretty self explanatory, checks to see if there is a floppy disk inserted]]
while true do
print("Please insert bank card")
if os.pullEvent("disk") then
break
end
end
elseif disk.hasData("bottom") == true then --[[if there is a floppy inserted the program continues]]
local acc = disk.getLabel("bottom")
shell.run("clear")
print("Welcome "..acc)
print("Please enter your P.I.N.:")
pwd = read("*")
rednet.send(sId, textutils.serialize({"login", acc, pwd}))
print("pwd sent") --[[*******this is where the program hangs, it sends the message and prints that its sent, then waits for the reply*******]]
id,msg = rednet.receive()
print("reply received") --[[ this is just for debugging]]
local data = textutils.unserialize(msg)
local cmd = data[1]
local acc = data[2]
local bal = data[3]
if cmd == "confirm" then --[[ all password verification is done at the server, this denies any negative consequences]]
shell.run("clear")
print("Password accepted")
sleep(2)
while true do --[[ these are the options for account/balance manipulation]]
shell.run("clear")
local file = fs.open("options", "r")
local tInfo = file.readAll()
file.close()
local opts = textutils.unserialize(tInfo)
print("What would you like to do")
print("")
for a,b in ipairs(opts) do
print(tostring(a)..") "..tostring(B)/>)
end
print(" ")
local cmd = read()
if cmd == 1 or "Balance" or "balance" then
shell.run("clear")
print("Balance:")
print("$"..bal)
sleep(10)
elseif cmd == 2 or "Withdraw" or "withdraw" then
shell.run("clear")
write("How much do you want to withdraw: $")
local amt = read()
print("Processing")
sleep(5)
if amt == bal or amt < bal then
shell.run("clear")
print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
print("Y/N")
local cmd = read()
if cmd == "Y" or "y" then
rednet.send(sId, textutils.serialize({"withdraw", acc, "blank", amt}))
local id, msg = rednet.receive()
local data = textutils.unserialize(msg)
if cmd == "confirm" then
cbl.setCommand("eco give @p amt")
cbl.runCommand()
shell.run("clear")
print("New balance:")
print("$"..bal)
sleep(5)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("Withdrawal cancelled")
sleep(3)
end
else
print("You do not have enough funds to complete this transaction")
sleep(3)
end
elseif cmd == 3 or "Deposit" or "deposit" then
shell.run("clear")
write("How much do you want to deposit: $")
local amt = read()
print("Processing")
sleep(5)
shell.run("clear")
print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
print("Y/N")
local cmd = read()
if cmd == "Y" or "y" then
rednet.send(sId, textutils.serialize({"deposit", acc, "blank", amt}))
local id, msg = rednet.receive()
local data = textutils.unserialize(msg)
if cmd == "confirm" then
shell.run("clear")
print("Deposited $"..amt.." into "..acc.."'s account")
cbl.setCommand("eco take @p amt")
cbl.runCommand()
sleep(3)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("Transaction cancelled")
sleep(3)
end
elseif cmd == 4 or "Transfer" or "transfer" then
shell.run("clear")
write("Type the account name you would like to transfer funds to: ")
local toAcc = read()
shell.run("clear")
write("Please enter the amount you wish to transfer: $")
local amt = read()
shell.run("clear")
print("Please confirm, you wish to transfer $"..amt.." from "..acc.." to "..toA.." Y/N")
local cmd = read()
shell.run("clear")
print("Processing")
sleep(3)
if cmd == "Y" or "y" then
if amt == bal or amt < bal then
rednet.send(sId, textutils.serialize({"transfer", acc, "blank", amt, toA}))
local id,msg = rednet.receive()
local data = textutils.unserialize(msg)
if cmd == "confirm" then
shell.run("clear")
print("$"..amt.." transferred to "..toA)
sleep(3)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("You do not have enough funds to complete this transaction")
sleep(3)
end
else
shell.run("clear")
print("Transaction cancelled")
sleep(3)
end
elseif cmd == 4 or "quit" or "Quit" then
disk.eject("bottom")
break
else -- [[ this will auto stop the program if a selection isnt made in 20 seconds]]
sleep(20)
print("Took too long to make a selection, cancelling transaction")
sleep(3)
disk.eject("bottom")
break
end
end
else
print("Incorrect Password, Try Again")
sleep(5)
end
end
end
if cmd == 2 or "Withdraw" or "withdraw" then
if cmd == "2" or cmd == "Withdraw" or cmd == "withdraw" then
if tonumber(cmd) == 2 or cmd:lower() == "withdraw" then
local newCmd
parallel.waitForAny(function() newCmd = read() end, function() os.pullEvent("disk_eject") end)
if not newCmd then
... disk was ejected
else
... disk remains, command was typed.
end
Well, there's the parallel API. Something like:local newCmd parallel.waitForAny(function() newCmd = read() end, function() os.pullEvent("disk_eject") end) if not newCmd then ... disk was ejected else ... disk remains, command was typed. end
while true do --[[ these are the options for account/balance manipulation]]
shell.run("clear")
local file = fs.open("options", "r")
local tInfo = file.readAll()
file.close()
local opts = textutils.unserialize(tInfo)
print("What would you like to do")
print("")
for a,b in ipairs(opts) do
print(tostring(a)..") "..tostring(B)/>)
end
print(" ")
local cmd = read()
if cmd:lower() == "balance" or tonumber(cmd) == 1 then
if disk.isPresent("bottom") then
shell.run("clear")
print("Balance:")
print("$"..bal)
sleep(10)
else
rednet.send(sId, textutils.serialize({"quit"}))
break
end
elseif cmd:lower() == "withdraw" or tonumber(cmd) == 2 then
if disk.isPresent("bottom")
shell.run("clear")
write("How much do you want to withdraw: $")
local amt = read()
shell.run("clear")
print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
print("Y/N")
local cmd = read()
if cmd:lower() == "y" then
if amt > tostring(bal) or amt == tostring(bal) then
rednet.send(sId, textutils.serialize({"withdraw", acc, "blank", amt}))
local id, msg = rednet.receive()
local data = textutils.unserialize(msg)
local cmd = data[1]
local acc = data[2]
local bal = data[3]
if cmd == "confirm" then
cbl.setCommand("eco give @p amt")
cbl.runCommand()
shell.run("clear")
print("New balance:")
print("$"..bal)
sleep(5)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
elseif amt > tostring(bal) then
print("You do not have enough funds to complete this transaction")
sleep(3)
end
end
else
rednet.send(sId, textutils.serialize({"quit"}))
break
end
elseif cmd:lower() == "deposit" or tonumber(cmd) == 3 then
if disk.isPresent("bottom")
shell.run("clear")
write("How much do you want to deposit: $")
local amt = read()
shell.run("clear")
print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
print("Y/N")
local cmd = read()
if cmd:lower() == "y" then
print("Processing")
sleep(2)
rednet.send(sId, textutils.serialize({"deposit", acc, "blank", amt}))
local id, msg = rednet.receive()
local data = textutils.unserialize(msg)
local cmd = data[1]
if cmd == "confirm" then
shell.run("clear")
print("Deposited $"..amt.." into "..acc.."'s account")
cbl.setCommand("eco take @p amt")
cbl.runCommand()
sleep(3)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("Transaction cancelled")
sleep(3)
end
else
rednet.send(sId, textutils.serialize({"quit"}))
break
end
elseif cmd:lower() == "transfer" or tonumber(cmd) == 4 then
if disk.isPresent("bottom")
shell.run("clear")
write("Type the account name you would like to transfer funds to: ")
local toA = read()
shell.run("clear")
print("Please enter the amount you wish to transfer:")
write("$")
local amt = read()
shell.run("clear")
print("Please confirm, you wish to transfer $"..amt.." from "..acc.." to "..toA.." Y/N")
local cmd = read()
shell.run("clear")
if cmd:lower() == "y" then
print("Processing")
sleep(3)
if amt < tostring(bal) or amt == tostring(bal) then
rednet.send(sId, textutils.serialize({"transfer", acc, "blank", amt, toA}))
local id,msg = rednet.receive()
local data = textutils.unserialize(msg)
local cmd = data[1]
if cmd == "confirm" then
shell.run("clear")
print("$"..amt.." transferred to "..toA)
sleep(3)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("You do not have enough funds to complete this transaction")
sleep(3)
end
else
shell.run("clear")
print("Transaction cancelled")
sleep(3)
end
else
rednet.send(sId, textutils.serialize({"quit"}))
break
end
elseif cmd:lower() == "quit" or tonumber(cmd) == 5 then
disk.eject("bottom")
sleep(0.5)
rednet.send(sId, textutils.serialize({"quit"}))
break
end
end
I just want the program to stop if the user pulls their card, otherwise someone else could mess with other peoples accounts
Well, there's the parallel API. Something like:local newCmd parallel.waitForAny(function() newCmd = read() end, function() os.pullEvent("disk_eject") end) if not newCmd then ... disk was ejected else ... disk remains, command was typed. end
Forgot the Parallel API lolWell, there's the parallel API. Something like:local newCmd parallel.waitForAny(function() newCmd = read() end, function() os.pullEvent("disk_eject") end) if not newCmd then ... disk was ejected else ... disk remains, command was typed. end
so how would I introduce that to thiswhile true do --[[ these are the options for account/balance manipulation]] shell.run("clear") local file = fs.open("options", "r") local tInfo = file.readAll() file.close() local opts = textutils.unserialize(tInfo) print("What would you like to do") print("") for a,b in ipairs(opts) do print(tostring(a)..") "..tostring(B)/>/>) end print(" ") local cmd = read() if cmd:lower() == "balance" or tonumber(cmd) == 1 then if disk.isPresent("bottom") then shell.run("clear") print("Balance:") print("$"..bal) sleep(10) else rednet.send(sId, textutils.serialize({"quit"})) break end elseif cmd:lower() == "withdraw" or tonumber(cmd) == 2 then if disk.isPresent("bottom") shell.run("clear") write("How much do you want to withdraw: $") local amt = read() shell.run("clear") print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?") print("Y/N") local cmd = read() if cmd:lower() == "y" then if amt > tostring(bal) or amt == tostring(bal) then rednet.send(sId, textutils.serialize({"withdraw", acc, "blank", amt})) local id, msg = rednet.receive() local data = textutils.unserialize(msg) local cmd = data[1] local acc = data[2] local bal = data[3] if cmd == "confirm" then cbl.setCommand("eco give @p amt") cbl.runCommand() shell.run("clear") print("New balance:") print("$"..bal) sleep(5) else shell.run("clear") print("We were unable to process this transaction please try again") sleep(3) end elseif amt > tostring(bal) then print("You do not have enough funds to complete this transaction") sleep(3) end end else rednet.send(sId, textutils.serialize({"quit"})) break end elseif cmd:lower() == "deposit" or tonumber(cmd) == 3 then if disk.isPresent("bottom") shell.run("clear") write("How much do you want to deposit: $") local amt = read() shell.run("clear") print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?") print("Y/N") local cmd = read() if cmd:lower() == "y" then print("Processing") sleep(2) rednet.send(sId, textutils.serialize({"deposit", acc, "blank", amt})) local id, msg = rednet.receive() local data = textutils.unserialize(msg) local cmd = data[1] if cmd == "confirm" then shell.run("clear") print("Deposited $"..amt.." into "..acc.."'s account") cbl.setCommand("eco take @p amt") cbl.runCommand() sleep(3) else shell.run("clear") print("We were unable to process this transaction please try again") sleep(3) end else shell.run("clear") print("Transaction cancelled") sleep(3) end else rednet.send(sId, textutils.serialize({"quit"})) break end elseif cmd:lower() == "transfer" or tonumber(cmd) == 4 then if disk.isPresent("bottom") shell.run("clear") write("Type the account name you would like to transfer funds to: ") local toA = read() shell.run("clear") print("Please enter the amount you wish to transfer:") write("$") local amt = read() shell.run("clear") print("Please confirm, you wish to transfer $"..amt.." from "..acc.." to "..toA.." Y/N") local cmd = read() shell.run("clear") if cmd:lower() == "y" then print("Processing") sleep(3) if amt < tostring(bal) or amt == tostring(bal) then rednet.send(sId, textutils.serialize({"transfer", acc, "blank", amt, toA})) local id,msg = rednet.receive() local data = textutils.unserialize(msg) local cmd = data[1] if cmd == "confirm" then shell.run("clear") print("$"..amt.." transferred to "..toA) sleep(3) else shell.run("clear") print("We were unable to process this transaction please try again") sleep(3) end else shell.run("clear") print("You do not have enough funds to complete this transaction") sleep(3) end else shell.run("clear") print("Transaction cancelled") sleep(3) end else rednet.send(sId, textutils.serialize({"quit"})) break end elseif cmd:lower() == "quit" or tonumber(cmd) == 5 then disk.eject("bottom") sleep(0.5) rednet.send(sId, textutils.serialize({"quit"})) break end end
sorry to be dumb, I'm just struggling to understand parallels
local function newFunc()
-- Insert massive block of code here.
end
while true do
-- Do login stuff (eg wait for a new disk) or whatever here.
parallel.waitForAny(newFunc, function() os.pullEvent("disk_eject") end)
-- Disk has been removed, say goodbye or whatever.
end
rednet.open("left") --Modem side
os.loadAPI("crypt")
local cbl = peripheral.wrap("top") --Command Block side
if fs.exists("server/id") == false then --[[this creates a file that holds the serverID for future messages and sends the server the client ID for future authentication]]
rednet.broadcast(textutils.serialize({"install"}))
sleep(0.1)
local id = rednet.receive()
print("this is the Server ID: "..id)
fs.makeDir("server")
local file = fs.open("server/id", "w")
file.write(id)
file.close()
end
local function options()
if cmd == "confirm" then --[[ all password verification is done at the server, this denies any negative consequences]]
shell.run("clear")
print("Password accepted")
sleep(2)
while true do --[[ these are the options for account/balance manipulation]]
shell.run("clear")
local file = fs.open("options", "r")
local tInfo = file.readAll()
file.close()
local opts = textutils.unserialize(tInfo)
print("What would you like to do")
print("")
for a,b in ipairs(opts) do
print(tostring(a)..") "..tostring(B)/>)
end
print(" ")
local cmd = read()
if cmd:lower() == "balance" or tonumber(cmd) == 1 then
shell.run("clear")
print("Balance:")
print("$"..bal)
sleep(10)
elseif cmd:lower() == "withdraw" or tonumber(cmd) == 2 then
shell.run("clear")
write("How much do you want to withdraw: $")
local amt = read()
shell.run("clear")
print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
print("Y/N")
local cmd = read()
if cmd:lower() == "y" then
if amt > tostring(bal) or amt == tostring(bal) then
rednet.send(sId, textutils.serialize({"withdraw", acc, "blank", amt}))
local id, msg = rednet.receive()
local data = textutils.unserialize(msg)
local cmd = data[1]
local acc = data[2]
local bal = data[3]
if cmd == "confirm" then
cbl.setCommand("eco give @p amt")
cbl.runCommand()
shell.run("clear")
print("New balance:")
print("$"..bal)
sleep(5)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
elseif amt > tostring(bal) then
print("You do not have enough funds to complete this transaction")
sleep(3)
end
end
elseif cmd:lower() == "deposit" or tonumber(cmd) == 3 then
shell.run("clear")
write("How much do you want to deposit: $")
local amt = read()
shell.run("clear")
print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
print("Y/N")
local cmd = read()
if cmd:lower() == "y" then
print("Processing")
sleep(2)
rednet.send(sId, textutils.serialize({"deposit", acc, "blank", amt}))
local id, msg = rednet.receive()
local data = textutils.unserialize(msg)
local cmd = data[1]
if cmd == "confirm" then
shell.run("clear")
print("Deposited $"..amt.." into "..acc.."'s account")
cbl.setCommand("eco take @p amt")
cbl.runCommand()
sleep(3)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("Transaction cancelled")
sleep(3)
end
elseif cmd:lower() == "transfer" or tonumber(cmd) == 4 then
shell.run("clear")
write("Type the account name you would like to transfer funds to: ")
local toA = read()
shell.run("clear")
print("Please enter the amount you wish to transfer:")
write("$")
local amt = read()
shell.run("clear")
print("Please confirm, you wish to transfer $"..amt.." from "..acc.." to "..toA.." Y/N")
local cmd = read()
shell.run("clear")
if cmd:lower() == "y" then
print("Processing")
sleep(3)
if amt < tostring(bal) or amt == tostring(bal) then
rednet.send(sId, textutils.serialize({"transfer", acc, "blank", amt, toA}))
local id,msg = rednet.receive()
local data = textutils.unserialize(msg)
local cmd = data[1]
if cmd == "confirm" then
shell.run("clear")
print("$"..amt.." transferred to "..toA)
sleep(3)
else
shell.run("clear")
print("We were unable to process this transaction please try again")
sleep(3)
end
else
shell.run("clear")
print("You do not have enough funds to complete this transaction")
sleep(3)
end
else
shell.run("clear")
print("Transaction cancelled")
sleep(3)
end
elseif cmd:lower() == "quit" or tonumber(cmd) == 5 then
disk.eject("bottom")
sleep(0.5)
rednet.send(sId, textutils.serialize({"quit"}))
break
end
end
elseif cmd == "declined" then
print("Incorrect Password, Try Again")
sleep(5)
end
end
local function diskRemove()
os.pullEvent("disk_eject")
end
while true do
local file = fs.open("server/id", "r")
local sId = tonumber(file.readAll())
file.close()
shell.run("clear")
if disk.hasData("bottom") == false then --[[ this is pretty self explanatory, checks to see if there is a floppy disk inserted]]
while true do
print("Please insert bank card")
if os.pullEvent("disk") then
break
end
end
elseif disk.hasData("bottom") == true then --[[if there is a floppy inserted the program continues]]
local acc = disk.getLabel("bottom")
shell.run("clear")
print("Welcome "..acc)
print("Please enter your P.I.N.:")
pwd = read("*")
rednet.send(sId, textutils.serialize({"login", acc, pwd}))
print("pwd sent") --[[*******this is where the program hangs, it sends the message and prints that its sent, then waits for the reply*******]]
id,msg = rednet.receive()
print("reply received") --[[ this is just for debugging]]
local data = textutils.unserialize(msg)
local cmd = data[1]
local acc = data[2]
local bal = data[3]
while true do
parallel.waitForAny(options, diskRemove)
if not options then
rednet.send(sId, textutils.serialize({"quit"}))
break
end
end
end
end