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

program hanging waiting for reply from server computer

Started by mistamadd001, 06 May 2014 - 01:15 AM
mistamadd001 #1
Posted 06 May 2014 - 03:15 AM
I am trying to create a banking system for my server. I've been able to create accounts and 'credit cards' for them, however now that I am trying to access an 'ATM' system I get to the point where the ATM sends its first lot of data (checking the users credentials) it hangs. The ATM 'supposedly' sends the message but the server never receives it (I have the server writing a log of all access requests(messages)). Neither the client or the server throws errors.

If someone could help me out that'd be great

Server
Client

Cheers, MistaMadd001
awsmazinggenius #2
Posted 06 May 2014 - 04:06 AM
Is it out of range? A little more info?
mistamadd001 #3
Posted 06 May 2014 - 04:16 AM
I have tested the range (this is just testing and as such is all within about 10-20 blocks) using the lua prompt, and the server received the message then, yet when I run the server program it does NOTHING. Therefore my guess is that I've used the wrong command in said server program, please have a look at the program and help me out.

If you need any more info please ask, I'm not sure what else you may need though
awsmazinggenius #4
Posted 06 May 2014 - 05:08 AM
It often helps to comment your code a little more excessively then you normally would when in Ask A Pro, so that someone can take one glance at it and know exactly what you are trying to accomplish.
CometWolf #5
Posted 06 May 2014 - 05:29 AM
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.
Edited on 06 May 2014 - 03:30 AM
mistamadd001 #6
Posted 06 May 2014 - 05:39 AM
OK I've gone through and annotated everything (even the stuff you don't need to look at) look for the *****


--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

The Client

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.

that is handled earlier in the code, data is used to define what cmd is check lines 21-26
CometWolf #7
Posted 06 May 2014 - 07:38 AM
That dosen't really make much sense though… To even get to that point, cmd would have to be "login". You then try to compare it to "transfer", "deposit", or "withdraw"
Edited on 06 May 2014 - 06:46 AM
mistamadd001 #8
Posted 06 May 2014 - 10:26 AM
The problem occurs even before getting to the deposit/withdraw/transfer commands as the client (upon receiving a message stating the password matches that of the users file) WOULD THEN ask for user input regarding which function they wish to perform.

It works for install and create though, I wouldn't think it would be any different for login, each time I step down further into a sequence I am re-iterating what each variable is. eg: I have stated that cmd = data[1] at the beginning of the main while loop, therefore each time I do rednet.receive() I am getting a serialized table, so my next line is always data = textutils.unserialize(msg) effectively resetting the cmd,acc,pwd,etc. variables to match the new table.

If this is incorrect I will change it, it just looks tidier to me the way I have it. Besides, the problem I'm having actually happens just after (I would assume) the login message is unserialized, as the server isn't logging what the message command was, and (as per my earlier testing) the server is definitely receiving the message, therefore my belief is that there is something happening during or just after unserializing, HOWEVER, because the install and create commands both work (I can install clients and I can create new users) that would lead me to believe that unserializing the login command is working.
CometWolf #9
Posted 06 May 2014 - 10:55 AM
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.
mistamadd001 #10
Posted 06 May 2014 - 11:25 AM
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
mistamadd001 #11
Posted 06 May 2014 - 11:35 AM
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

never mind i realised its readAll not readall

now one more quicky, how do I trim the decimal off of the os.getComputerID, I'm unable to use it to send messages to the server
mistamadd001 #12
Posted 06 May 2014 - 12:00 PM
using someone else's crypt program is becoming a pita, I've got the system working to the point that I am comparing the input from the client against the system created hash, but its not giving me the right answer
mistamadd001 #13
Posted 06 May 2014 - 12:48 PM
I have got the system to a point where it is communicating between client and server, however more problems have arisen.

Whenever I type an option it only ever gives me the balance, I have tried entering the number that corresponds to the option, I have tried typing the name of the option eg:transfer, but no change.


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
Bomb Bloke #14
Posted 06 May 2014 - 12:52 PM
These sorts of lines:

if cmd == 2 or "Withdraw" or "withdraw" then

… should be like:

if cmd == "2" or cmd == "Withdraw" or cmd == "withdraw" then

… or like:

if tonumber(cmd) == 2 or cmd:lower() == "withdraw" then
mistamadd001 #15
Posted 07 May 2014 - 01:21 AM
I've got to a point where its working to a point, but now I am trying to find a way to stop the options loop if the disk is removed instead of an option being chosen. Any ideas
cptdeath58 #16
Posted 07 May 2014 - 01:28 AM
There is no way to check if the disk was removed before the command but there is a way after.
mistamadd001 #17
Posted 07 May 2014 - 01:42 AM
I just want the program to stop if the user pulls their card, otherwise someone else could mess with other peoples accounts
Bomb Bloke #18
Posted 07 May 2014 - 01:44 AM
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
mistamadd001 #19
Posted 07 May 2014 - 02:06 AM
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

so how would I introduce that to this


	  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

sorry to be dumb, I'm just struggling to understand parallels
cptdeath58 #20
Posted 07 May 2014 - 02:11 AM
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
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

so how would I introduce that to this


	  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

sorry to be dumb, I'm just struggling to understand parallels
Forgot the Parallel API lol
Bomb Bloke #21
Posted 07 May 2014 - 02:13 AM
I suppose it'd be easier to take that entire huge block you just quoted, stick THAT in a function, then use parallel.waitForAny on that.

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

To understand what this is doing, you first need to understand events.
Edited on 07 May 2014 - 12:14 AM
mistamadd001 #22
Posted 07 May 2014 - 02:18 AM
I'll have a play and see how it goes

thanks for the help so far guys
mistamadd001 #23
Posted 07 May 2014 - 03:24 AM
I followed your instructions and came up with this, however after sending the password and receiving the reply all it does is turn off the computer. Dunno what I've done but here's the code


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
Bomb Bloke #24
Posted 07 May 2014 - 04:05 AM
At a quick glance I see two major problems (there may be others):

One is variable scope. You declare "cmd" as local to while/if block down the bottom of your code, so the "options" function can't see it. Stick a line that says "local cmd, acc, bal" up the top of your script (before "options" is defined), and get rid of the associated "local" tags down the bottom.

The other is that your "if not options then" check works along the lines of "if the options function doesn't exist then". Since that function never pops out of existence, that condition won't be achieved. A way around this might be to set a boolean (call it "running" or something) to true when the script starts, set it to false if the user attempts to quit, and check its state instead.
mistamadd001 #25
Posted 07 May 2014 - 05:32 AM
fml, now I cant get the login to work, I send the password and it gets denied everytime
mistamadd001 #26
Posted 07 May 2014 - 05:42 AM
maybe ill do it the messy way and just run it in sequence and write a disk check into each command