Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.wrap("right")
- authSet = 3
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextScale(0.6)
- term.setBackgroundColor(colors.blue)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- print "Bank Server 3.1 Status:"
- print "--------------------------------------"
- term.setCursorPos(3,4)
- print("Current Auth Code > "..authSet)
- term.redirect(mon)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- print("Server Online.")
- function authF()
- authSet = authSet * 2 + 7
- end
- side = "top" -- Rednet Modem sidem (End of Setup)
- rednet.open(side)
- -- Functions
- function drawStart()
- id, message = rednet.receive()
- if type(message) == "string" then
- if message == "Login" then
- login()
- elseif message == "Balance" then
- balance()
- elseif message == "Transfer" then
- transfer()
- elseif message == "Create" then
- create()
- elseif message == "Delete" then
- delete()
- elseif message == "Rename" then
- rename()
- elseif message == "Passcode" then
- passcode()
- elseif message == "Add" then
- add()
- elseif message == "Auth" then
- auth()
- elseif message == "Withdraw" then
- withdraw()
- else
- rednet.send(id,"Command Not Found")
- drawStart()
- end
- else
- rednet.send(id,"Data is Not String")
- end
- end
- function login()
- id, user = rednet.receive()
- id, pass = rednet.receive()
- mon.write(user .. " is trying to login.")
- if type(pass) == "string" then
- if type(user) == "string" then
- if fs.exists("user/"..user) == true then
- h = fs.open("user/"..user, "r")
- passReal = h.readAll()
- h.close()
- if pass == passReal then
- rednet.send(id,"Login Successful")
- mon.write(user.." was logged in.")
- drawStart()
- else
- mon.write(user.." failed to login.")
- rednet.send(id,"Password Incorrect")
- drawStart()
- end
- else
- rednet.send(id,"Unknown User")
- drawStart()
- end
- else
- rednet.send(id,"User Is Not String")
- end
- else
- rednet.send(id,"Password Is Not String")
- end
- end
- function balance()
- id, user = rednet.receive()
- if type(user) == "string" then
- h = fs.open("$/"..user, "r")
- bal = h.readAll()
- h.close()
- rednet.send(id,bal)
- mon.write(user.." retrieved their balance.")
- drawStart()
- else
- rednet.send(id,"User is Not String")
- end
- end
- function transfer()
- id, user1 = rednet.receive()
- id, user2 = rednet.receive()
- id, am = rednet.receive()
- if type(user1) == "string" and type(user2) == "string" and type(am) == "string" then
- if fs.exists("user/"..user1) and fs.exists("user/"..user2)then
- h = fs.open("$/"..user1, "r")
- bal1 = h.readAll()
- h.close()
- if tonumber(bal1) >= tonumber(am) then
- h = fs.open("$/"..user2, "r")
- bal2 = h.readAll()
- h.close()
- bal1 = bal1 - am
- bal2 = bal2 + am
- h = fs.open("$/"..user1, "w")
- h.write(bal1)
- h.close()
- h = fs.open("$/"..user2, "w")
- h.write(bal2)
- h.close()
- rednet.send(id,"Funds Transfered")
- mon.write(user.. " transfered funds.")
- drawStart()
- elseif bal1 <= am then
- rednet.send(id,"Not Enough Funds")
- --term.setCursorPos(1,3)
- --print(user1)
- --print(user2)
- --print(bal1)
- --print(bal2)
- --print(am)
- drawStart()
- else
- rednet.send(id,"An Error Occurred")
- drawStart()
- end
- else
- rednet.send(id," User(s) Not Found")
- drawStart()
- end
- else
- rednet.send(id,"Data Is Not String")
- end
- end
- function create()
- id, user = rednet.receive()
- id, pass = rednet.receive()
- if type(user) == "string" and type(pass) then
- if fs.exists("user/"..user) then
- rednet.send(id,"User Exists")
- else
- h = fs.open("user/"..user,"w")
- h.write(pass)
- h.close()
- h = fs.open("$/"..user,"w")
- h.write("0")
- h.close()
- rednet.send(id,"Account Created")
- mon.write("Account created.")
- drawStart()
- end
- else
- rednet.send(id,"Data Is Not String")
- end
- drawStart()
- end
- function delete()
- end
- function rename()
- end
- function passcode()
- end
- function add()
- id, user = rednet.receive()
- id, amt = rednet.receive()
- id, auth1 = rednet.receive()
- if type(user) == "string" and type(amt) == "string" and type(auth1) == "string" then
- if tonumber(auth1) == authSet then
- if fs.exists("user/"..user) then
- h = fs.open("$/"..user, "r")
- bal = h.readAll()
- h.close()
- balNew = bal + amt
- h = fs.open("$/"..user, "w")
- h.write(balNew)
- h.close()
- rednet.send(id,"$"..amt.." Added to "..user)
- drawStart()
- else
- rednet.send(id,"No Such User")
- drawStart()
- end
- else
- rednet.send(id,"Authorization Code Not Accepted")
- drawStart()
- end
- else
- rednet.send(id,"Data Is Not String")
- end
- end
- function auth()
- authF()
- rednet.send(id,"New Auth Code Found")
- drawStart()
- end
- function withdraw()
- id, logU = rednet.receive()
- local a = fs.open("$/"..user, "r")
- rednet.send(id, "Need Amount")
- id, msg = rednet.receive()
- local actual = a.readAll()
- if actual < msg then
- rednet.send(id, "Not enough funds!")
- elseif actual >= msg then
- final = actual - msg
- a.close()
- local b = fs.open("$/"..user, "w")
- b.write(final)
- b.close()
- rednet.send(id, "Withdraw complete.")
- end
- end
- -- Program
- drawStart()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement