Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local Program_Run = true
- local MachineID = os.computerID()
- local Deposit_Box
- local Store_Box
- local Fee_Rate = 0.1
- local Min_FeeCharge = 30--minimum range till fees are charged
- local Accepts_Cards = false
- local User
- local Amount = 0
- local Admin_Pin = "0000"
- local Bank
- local Net_Mode = 0--0=none,1=slaved,2=master
- local Net = -1.0
- local Menu = "Home"
- local Currency = {{"createdeco:brass_coin",64},{"createdeco:iron_coin",16},{"createdeco:copper_coin",1}}
- function Boot()
- Deposit_Box = peripheral.wrap("top")
- Store_Box = peripheral.wrap("left")
- User = nil
- Pin = nil
- local file = fs.open("Banking.txt","r")
- file.readLine()
- Admin_Pin = file.readLine()
- file.readLine()
- Net = tonumber(file.readLine())
- file.readLine()
- Fee_Rate = tonumber(file.readLine())
- file.readLine()
- Bank = file.readLine()
- file.readLine()
- Min_FeeCharge = tonumber(file.readLine())
- file.readLine()
- Net_Mode = tonumber(file.readLine())
- file.readLine()
- Accepts_Cards = file.readLine()
- file.close()
- Explorer()
- end
- function Input(y)
- local n = 1
- local Text
- while true do
- term.setCursorPos(1,y)
- term.clearLine()
- if n == 1 then if Text ~= nil then term.write("> ["..Text.."]") else term.write("> [_]") end else if Text ~= nil then term.write("["..Text.."]") else term.write("[_]") end end
- term.setCursorPos(1,y+1)
- term.clearLine()
- if n == 2 then term.write("> -enter") else term.write("-enter") end
- term.setCursorPos(1,y+2)
- term.clearLine()
- term.write("use arrow keys")
- local event, a, b = os.pullEvent()
- if event == "key" and a ~= 265 and a ~= 264 and n == 1 then term.setCursorPos(1,y) term.clearLine() Text = read() end
- if event == "key" and (a == 265 or a == 264) then if n == 1 then n = 2 else n = 1 end end
- if n == 2 and a == keys.enter then break end
- end
- term.clear()
- return Text
- end
- function List(y,options)
- local n = 1
- while true do
- for i = 1, #options do
- term.setCursorPos(1,(i-1)+y)
- term.clearLine()
- if n == i then term.write("> -"..options[i]) else term.write("-"..options[i]) end
- end
- term.setCursorPos(1,y+#options)
- term.clearLine()
- term.write("W/S, Enter")
- local a, b, c = os.pullEvent("key")
- if b == keys.w or b == 265 then if n == 1 then n = #options else n = n - 1 end end
- if b == keys.s or b == 264 then if n == #options then n = 1 else n = n + 1 end end
- if b == keys.enter then break end
- end
- term.clear()
- return n
- end
- function CheckLog(Name)
- local Verified = false
- if fs.exists(fs.combine("Accounts",Name..".act")) then
- local file = fs.open(fs.combine("Accounts",Name..".act"),"r")
- local Data = textutils.unserialize(file.readAll())
- Verified = Data[2]
- if Data[5] == true then Vertified = false end
- file.close()
- end
- return Verified
- end
- function NetManage(a,b,c,d)
- local MSG
- if c == "request" then
- MSG = textutils.serialize(ReadAccount(b))
- elseif c == "update" then
- local file = fs.open(fs.combine("Accounts",b..".act"),"w")
- file.write(d)
- file.close()
- MSG = "accepted"
- elseif c == "charge" then
- end
- return MSG
- end
- function NetGet(act)
- local ReturnNet = math.random(88,99)
- local Modem = peripheral.wrap("back")
- Modem.open(ReturnNet)
- local MSG = textutils.serialize({Bank,act,"request"})
- Modem.transmit(Net,ReturnNet,MSG)
- local a, b, c, d, e, f = os.pullEvent("modem_message")
- local file = fs.open(fs.combine("Accounts",act..".act"),"w")
- file.write(e)
- file.close()
- end
- function NetSend(act)
- local ReturnNet = math.random(88,99)
- local Modem = peripheral.wrap("back")
- Modem.open(ReturnNet)
- local file = fs.open(fs.combine("Accounts",act..".act"),"r")
- local DATA = file.readAll()
- file.close()
- local MSG = textutils.serialize({Bank,act,"update",DATA})
- Modem.transmit(Net,ReturnNet,MSG)
- end
- function CreateAccount(UserName,admin)
- if admin == nil then admin = false end
- local Data = {MachineID,true,0,0.01,admin,{}}--machineid,unlocked,balance,rate,admin
- local file = fs.open(fs.combine("Accounts",UserName..".act"),"w")
- file.write(textutils.serialize(Data))
- file.close()
- end
- function ReadAccount(D)
- local Data = {}
- local file = fs.open(fs.combine("Accounts",User..".act"),"r")
- Data = textutils.unserialize(file.readAll())
- file.close()
- return Data[D]
- end
- function UpdateAccount(U,A)
- local Data = {ReadAccount(1),ReadAccount(2),ReadAccount(3)+A,ReadAccount(4),ReadAccount(5),ReadAccount(6)}
- local file = fs.open(fs.combine("Accounts",U..".act"),"w")
- file.write(textutils.serialize(Data))
- file.close()
- end
- function EditCards(action,card,var)
- local Cards = ReadAccount(6)
- if action == "delete" then Cards[card] = nil elseif action == "new" then Cards[#Cards+1] = math.random(11111,99999) end
- error("need to finish")
- end
- function CreateTranLog(from,to,amount,reason)
- local file = fs.open(fs.combine("TLogs",from.."_"..os.day()..".txt"),"w")
- file.write(textutils.serialize({amount,reason,MachineID}))
- file.close()
- end
- function Transfer(amount)
- local Result
- local Fees = 0
- if amount < 0 then Result = Chests(Deposit_Box,Store_Box,amount) else Result = true amount = DrainStore() end
- if Result == true then if amount < 0 and amount*-1 >= Min_FeeCharge and ReadAccount(User,5) == false then Fees = math.floor((amount*Fee_Rate)+0.5) amount = amount + Fees end UpdateAccount(User,amount) if Net ~= -1.0 and Net_Mode == 1 then NetSend(User) end end
- if Fees > 0 then UpdateAccount("_Admin",Fees) end
- end
- function Charge(a,b,amount,reason)
- local Result = false
- local A_D = ReadAccount(a)
- local B_D = ReadAccount(b)
- if A_D[3]-amount >= 0 then
- UpdateAccount(a,amount*-1)
- UpdateAccount(b,amount)
- CreateTranLog(a,b,amount,reason)
- Result = true
- end
- return Result
- end
- function DrainStore()
- local E = 0
- for i = 1, Deposit_Box.size() do
- local Slot = Deposit_Box.getItemDetail(i)
- for M = 1, #Currency do
- if Slot ~= nil then if Slot.name == Currency[M][1] then E = E + (Currency[M][2] * Slot.count) Deposit_Box.pushItems(peripheral.getName(Store_Box),i,64,M*9-8) end end
- end
- end
- return E
- end
- function TransferMenu()
- local n = 1
- local C = {}
- for i = 1, #Currency do
- C[i] = 0
- end
- term.clear()
- while true do
- for i = 1, #Currency+1 do
- term.setCursorPos(1,i+3)
- term.clearLine()
- if n == i then if i <= #Currency then term.write("[>] "..Currency[i][1].." ["..C[i].."] | $"..(C[i]*Currency[i][2])) else term.write("[>] confirm") end else if i <= #Currency then term.write("[ ] "..Currency[i][1].." ["..C[i].."] | $"..(C[i]*Currency[i][2])) else term.write("[ ] confirm") end end
- end
- term.setCursorPos(1,#Currency+5)
- term.clearLine()
- term.write("W/S,A/D,/\ \/,< >, enter")
- local a, b, c = os.pullEvent("key")
- if b == 264 or b == keys.s then if n == #C + 1 then n = 1 else n = n + 1 end end
- if b == 265 or b == keys.w then if n == 1 then n = #C + 1 else n = n - 1 end end
- if b == 263 or b == keys.a then if n <= #C and C[n] > 0 then C[n] = C[n] - 1 end end
- if b == 262 or b == keys.d then if n <= #C then C[n] = C[n] + 1 end end
- if n == #C+1 and b == keys.enter then break end
- end
- local E = 0
- for i = 1, #C do
- E = E + (Currency[i][2]*C[i])
- end
- local Bal = ReadAccount(3)
- if E <= Bal then
- local CE = C
- for X = 1, #C do
- for i = X*9-8, 9*X do
- local Slot = Store_Box.getItemDetail(i)
- if Slot ~= nil and Slot.name == Currency[X][1] and CE[X] ~= 0 then local T = Slot.count Store_Box.pushItems(peripheral.getName(Deposit_Box),i,CE[X]) if CE[X] > T then CE[X] = CE[X] - T else CE[X] = 0 end end
- end
- end
- UpdateAccount(User,E*-1)
- return true
- else
- return false
- end
- end
- function Chests(A,B,amount)
- local ChestA = A
- local ChestB = B
- local E = 0
- local S = 0
- for i = 1, A.size() do
- local Slot = A.getItemDetail(i)
- for M = 1, #Currency do
- if Slot ~= nil then if Slot.name == Currency[M][1] then E = E + (Currency[M][2] * Slot.count) end end
- end
- end
- if E >= amount then
- E = 0
- repeat
- for i = 1, ChestA.size() do
- local Slot = ChestA.getItemDetail(i)
- for M = 1, #Currency do
- if Slot ~= nil then if Slot.name == Currency[M][1] and Currency[M][2] <=(amount-E) then local AM = math.floor((amount/Currency[M][2])+0.6) E = E + AM ChestA.pushItems(peripheral.getName(ChestB),i,AM) end end
- end
- end
- until E >= amount
- Amount = E
- return true
- else
- return false
- end
- end
- function UI()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- term.clear()
- term.setCursorPos(1,1)
- local Data = {}
- if Menu == "Home" then
- print("Banking OS")
- print("//WARNING//Expermental")
- local c = List(3,{"login/signup","policies"})
- if c == 1 then Data = {"Page","Login"} else Data = {"Page","Policies"} end
- elseif Menu == "Policies" then
- print("Policies:")
- print("-no refunds on Fees")
- print("press enter")
- local event, a = os.pullEvent("key")
- repeat until a == keys.enter
- Data = {"Page","Home"}
- elseif Menu == "Login" then
- print("enter Credentials")
- local Log = Input(3)
- if Log == Admin_Pin then Data = {"Page","Admin"} elseif CheckLog(Log) == true then User = Log Data = {"Page", "Account"} if Net ~= -1.0 and Net_Mode == 1 then NetGet(Log) end else local T = List(5,{"create account","cancel"}) if T == 1 then CreateAccount(Log) User = Log Data = {"Page","Account"} elseif T == 2 then Data = {"Page","Home"} end end
- elseif Menu == "Setup" then
- elseif Menu == "Account" then
- local BAL = ReadAccount(3)
- print("Welcome, "..User)
- print("Balance: "..BAL)
- print("====================")
- local n = List(4,{"Transaction","Card","logout"})
- if n == 1 then Data = {"Page","Transaction"} elseif n == 2 then print("coming soon") os.sleep(3) elseif n == 3 then User = nil Data = {"Page","Home"} end
- elseif Menu == "Admin" then
- print("ADMIN MENU")
- local n = List(3,{"stop program","open deposit","close deposit","admin account","logout"})
- if n == 1 then Program_Run = false elseif n == 2 then redstone.setOutput("bottom",true) elseif n == 3 then redstone.setOutput("bottom",false) elseif n == 4 then User = "_Admin" Data = {"Page","Account"} elseif n == 5 then Data = {"Page","Home"} end
- elseif Menu == "Transaction" then
- local n = List(3,{"withdraw","deposit"})
- if n == 1 then TransferMenu() else UpdateAccount(User,0+DrainStore()) end
- Data = {"Page","Account"}
- elseif Menu == "Cards" then
- Print("Cards on file")
- local Cards = ReadAccount(6)
- Cards[#Cards+1] = "new"
- Cards[#Cards+1] = "exit"
- local n = List(3,Cards)
- if n == #Cards then Menu = "Account" elseif n == #Cards - 1 then else local G = List(3,{"delete","return"}) if G == 1 then EditCards("delete",n) end end
- end
- return Data
- end
- function Explorer()
- while true do
- local a, b, c, d, e, f
- if Net_Mode == 2 then local modem = peripheral.wrap("back") modem.open(Net) a, b, c, d, e, f = os.pullEvent("modem_message") local msg = textutils.unserialize(e) if msg[1] == Bank then modem.transmit(d,Net,NetManage(msg)) end end
- local R = UI()
- if R[1] == "Page" then Menu = R[2] end
- os.queueEvent("pass")
- if Program_Run == false then break end
- end
- if Program_Run == true then os.reboot() end
- end
- function Setup()
- fs.makeDir("Accounts")
- fs.makeDir("TLogs")
- Menu = "Setup"
- Admin_Pin, Net, Fee_Rate, Bank = "0000", -1, 0.05, "State Bank"
- local file = fs.open("Banking.txt","w")
- file.writeLine("Admin Pin")
- file.writeLine(Admin_Pin)
- file.writeLine("Net")
- file.writeLine(Net)
- file.writeLine("Fee")
- file.writeLine(Fee_Rate)
- file.writeLine("Bank")
- file.writeLine(Bank)
- file.writeLine("minium amount for fee to apply")
- file.writeLine(Min_FeeCharge)
- file.writeLine("Net Mode")
- file.writeLine(Net_Mode)
- file.writeLine("Accepts Cards")
- file.writeLine(Accepts_Cards)
- file.close()
- CreateAccount("_Admin",true)
- end
- if fs.exists("Banking.txt") then Boot() else Setup() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement