Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --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
- 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()
- 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
- 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
- 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
- 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
- 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
- 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
- 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 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 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()
- 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
Add Comment
Please, Sign In to add comment