Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("back")
- while true do
- id,request = rednet.receive()
- if request == "balance" then
- id,name = rednet.receive(.5)
- id,pass = rednet.receive(.5)
- --#if pass ~= nil or name ~= nil then
- if pass ~= nil and name ~= nil then
- --#check if exist
- if not fs.exists('Accounts/'..name) then return; end
- local account = fs.open("Accounts/"..name,"r")
- local accountInfo = {}
- for line in account.readLine do
- accountInfo[#accountInfo+1] = line
- end
- account.close()
- if accountInfo[1] == pass then
- rednet.send(id,accountInfo[2])
- end
- end
- elseif request == "transfer" then
- --#got rid of id cause its not being used
- _,name = rednet.receive(.5)
- _,pass = rednet.receive(.5)
- _,to = rednet.receive(.5)
- _,ammount = rednet.receive(.5)
- --#if name ~= nil or pass ~= nil or to ~= nil or ammount ~= nil then
- if name ~= nil and pass ~= nil and to ~= nil and ammount ~= nil then
- --#check if exist
- if not fs.exists('Accounts/'..name) then return; end
- if not fs.exists('Accounts/'..to) then return; end
- local account = fs.open("Accounts/"..name,"r")
- local accountInfo = {}
- for line in account.readLine do
- print(line)
- --#accountInfo[#accountInfo+1] = line --this one is just preference
- table.insert(accountInfo,line)
- end
- account.close()
- if pass == accountInfo[1] then
- if fs.exists("Accounts/"..to) == true then
- local tmpPerson = fs.open("Accounts/"..to,"r")
- local personInfo = {}
- for line in tmpPerson.readLine do
- --#personInfo[#personInfo+1] = line --this one is just preference
- table.insert(personInfo,line)
- end
- tmpPerson.close()
- if tonumber(accountInfo[2]) >= ammount then
- personInfo[2] = tonumber(personInfo[2])+ammount
- print('added '..personInfo[2])
- local person = fs.open("Accounts/"..to,"w")
- --#for i=0, #personInfo do --mainly causing the java error i believe
- for i=1, #personInfo do
- person.writeLine(personInfo[i])
- end
- person.close()
- local account = fs.open("Accounts/"..name,"w")
- accountInfo[2] = tonumber(accountInfo[2])-ammount
- --#for i=0, #accountInfo do --mainly causing the java error i believe
- for i=1, #accountInfo do
- --#person.writeLine(accountInfo[i])
- account.writeLine(accountInfo[i])
- end
- account.close()
- --#person.close() moved higher up
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment