Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load API
- os.loadAPI("sha256")
- os.loadAPI("gui")
- mesData = {}
- local textStart = gui.textStart
- local diskSide = "bottom"
- local serverId = 3
- local withdrawId = 14
- local version = "GAB-0.1"
- local url = "http://infaknox.space/main.php"
- local all = "0123456789abcdefghijklmnopqrstuvwxyz"
- local e = ""
- -- Import GUI functions
- local drawHeader, drawButton, drawError, center = gui.drawHeader, gui.drawButton, gui.drawError, gui.center
- local waitForMouse, waitForButton, waitForChar, waitForKey, waitForEnter =
- gui.waitForMouse,
- gui.waitForButton,
- gui.waitForChar,
- gui.waitForKey,
- gui.waitForEnter
- local waitForDisk = gui.waitForDisk
- -- Withdrawal Amount
- function otherAmount()
- local amount = ""
- term.clear()
- drawHeader()
- term.setCursorPos(center(textStart, "Amount : $ ") + 12, textStart)
- return read()
- end
- -- MessageBoard
- function message(acc, pin)
- while true do
- term.clear()
- drawHeader()
- drawButton(4, "Post Message")
- drawButton(8, "Return")
- local methods = {}
- for i = 1, 10 do
- table.insert(methods,i)
- end
- local scrollBuffer = {}
- local maxY = "10" --# setting max area size
- pos = 5
- --for k, v in pairs(methods) do
- local a = http.get("http://infaknox.space/messages")
- for line in a.readLine do
- local location = (line:find(":", 1))
- if location then
- usr = line:sub(1, location - 1)
- msg = line:sub(location + 1)
- pos = pos + 2
- term.setCursorPos(3, pos)
- term.write("Message: " .. usr)
- term.setCursorPos(3, pos + 1)
- term.write("By: " .. msg)
- table.insert(scrollBuffer,"Message: "..usr.." \n ".."By: "..msg) --# storing all of the things printed to the screen into a table
- end
- end
- local y = #scrollBuffer
- while true do
- local _, direction = os.pullEvent("mouse_scroll") --# listening for mouse_scroll events
- if direction == 1 then --# direction 1 is when you scroll the wheel one way
- if y < #scrollBuffer-maxY then --# don't want to be able to scroll outside of the range of the table
- y=y+1
- end
- term.clear() --# clearing screen so we can print the new scrolled version
- term.setCursorPos(3,10) --# setting to 1,1
- for i = 1, maxY-1 do --# looping through the screen coords
- if not scrollBuffer[i+y] then break end --# making sure the table location isnt nil
- print(scrollBuffer[i+y]) --# printing the table entry, i+y is the table entry
- end
- term.write(scrollBuffer[maxY+y])
- elseif direction == -1 then --# -1 is the only direction
- if y~=0 then --# not going to explain anymore, as it all repeats from here
- y=y-1
- end
- term.clear()
- term.setCursorPos(3,10)
- for i = 1, maxY-1 do
- if not scrollBuffer[i+y] then break end
- print(scrollBuffer[i+y])
- end
- term.write(scrollBuffer[maxY+y])
- end
- end
- local button = waitForButton()
- if button == 4 then
- post(acc, pin)
- elseif button == 8 then
- return
- end
- end
- end
- -- Balance
- function balance(acc, pin)
- term.clear()
- drawHeader()
- drawButton(4, "Cancel")
- drawButton(5, "Galleon Dollars")
- local mult = nil
- while true do
- local button = waitForButton()
- if button == 4 then
- return
- elseif button == 5 then
- mult = 1
- break
- end
- end
- request =
- http.post(
- url,
- "command=" ..
- textutils.urlEncode(tostring("balance")) .. "&" .. "username=" .. textutils.urlEncode(tostring(acc))
- )
- --.."&".."password="..textutils.urlEncode(tostring(crypt.hashPassword(pin))))
- response = request.readAll()
- term.clear()
- drawHeader()
- drawButton(8, "OK")
- if response ~= "-" then
- local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
- center(textStart, "Balance: $" .. displayBalance .. " Galleons.")
- else
- drawError("Transaction Error")
- end
- while true do
- local button = waitForButton()
- if button == 8 then
- return
- end
- end
- end
- -- Registration
- function register()
- local accname, accpin
- term.clear()
- drawHeader()
- center(textStart, "Insert keycard or press ENTER")
- center(textStart + 1, "to transact without a keycard")
- parallel.waitForAny(waitForEnter, waitForDisk)
- term.clear()
- drawHeader()
- for i = 1, 10 do
- r = math.random(#all)
- e = e .. string.sub(all, r, r)
- end
- term.setCursorPos(center(textStart, "Account No : " .. e .. "") + 13, textStart)
- accname = e
- if disk.hasData(diskSide) then
- disk.setLabel(diskSide, accname)
- else
- end
- term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1)
- accpin = read("*")
- request =
- http.post(
- url,
- "command=" ..
- textutils.urlEncode(tostring("register")) ..
- "&" ..
- "username=" ..
- textutils.urlEncode(tostring(e)) ..
- "&" .. "password=" .. textutils.urlEncode(tostring(sha256.sha256(accpin)))
- )
- response = request.readAll()
- term.clear()
- drawHeader()
- drawButton(8, "OK")
- if response == "Saved!" then
- center(textStart, "Added User: " .. accname .. "")
- sleep(3)
- disk.eject(diskSide)
- os.reboot()
- else
- drawError("ERROR")
- end
- while true do
- local button = waitForButton()
- if button == 8 then
- return
- end
- end
- end
- -- Deposit System
- function deposit(acc, pin)
- term.clear()
- drawHeader()
- drawButton(4, "Cancel")
- local mult = nil
- request =
- http.post(
- url,
- "command=" ..
- textutils.urlEncode(tostring("deposit")) .. "&" .. "username=" .. textutils.urlEncode(tostring(acc))
- )
- response = request.readAll()
- term.clear()
- drawHeader()
- drawButton(8, "OK")
- redstone.setOutput("back", true)
- center(textStart, "Now Accepting:")
- center(textStart + 1, "Gold Blocks, Ingots, Nuggets ")
- center(textStart + 2, "Please Close Terminal.")
- center(textStart + 3, "Then drop stacks of items ONLY")
- sleep(10)
- -- if response ~= "-" then
- -- local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
- --center(textStart, "Balance: $" .. displayBalance .. " Galleons.")
- -- else
- -- drawError("Transaction Error")
- -- end
- while true do
- local button = waitForButton()
- if button == 8 then
- redstone.setOutput("back", false)
- return
- end
- end
- end
- -- Money Transfer
- function transfer(acc, pin)
- term.clear()
- drawHeader()
- drawButton(1, "$100")
- drawButton(2, "$200")
- drawButton(3, "$500")
- drawButton(5, "$1000")
- drawButton(6, "$2000")
- drawButton(7, "$5000")
- drawButton(4, "Cancel")
- drawButton(8, "Other Amount")
- local amountS = nil
- while true do
- local button = waitForButton()
- if button == 1 then
- amountS = "100"
- break
- elseif button == 2 then
- amountS = "200"
- break
- elseif button == 3 then
- amountS = "500"
- break
- elseif button == 5 then
- amountS = "1000"
- break
- elseif button == 6 then
- amountS = "2000"
- break
- elseif button == 7 then
- amountS = "5000"
- break
- elseif button == 4 then
- return
- elseif button == 8 then
- amountS = otherAmount()
- break
- end
- end
- term.clear()
- drawHeader()
- local amount = tonumber(amountS)
- if amount ~= nil and (amount % 1) == 0 then
- term.clear()
- drawHeader()
- term.setCursorPos(center(textStart, "Amount : $ ") + 12, textStart)
- term.write(amountS)
- term.setCursorPos(center(textStart + 1, "Account : ") + 10, textStart + 1)
- local account = read()
- drawButton(4, "Cancel")
- drawButton(8, "Confirm")
- while true do
- local button = waitForButton()
- if button == 4 then
- return
- elseif button == 8 then
- break
- end
- end
- request =
- http.post(
- url,
- "command=" ..
- textutils.urlEncode(tostring("trans")) ..
- "&" ..
- "username=" ..
- textutils.urlEncode(tostring(acc)) ..
- "&" ..
- "account=" ..
- textutils.urlEncode(tostring(account)) ..
- "&" ..
- "amount=" ..
- textutils.urlEncode(tostring(amount)) ..
- "&" ..
- "password=" ..
- textutils.urlEncode(tostring(sha256.sha256(pin)))
- )
- term.clear()
- drawHeader()
- response = request.readAll()
- if response == "sendok" then
- center(textStart, "Transfer Successful")
- else
- drawError("Transaction Error")
- end
- else
- term.clear()
- drawHeader()
- drawError("Invalid Amount")
- end
- drawButton(8, "OK")
- while true do
- local button = waitForButton()
- if button == 8 then
- return
- end
- end
- end
- -- Withdrawal
- function withdraw(acc, pin)
- term.clear()
- drawHeader()
- drawButton(1, "$100")
- drawButton(2, "$200")
- drawButton(3, "$500")
- drawButton(5, "$1000")
- drawButton(6, "$2000")
- drawButton(7, "$5000")
- drawButton(4, "Cancel")
- drawButton(8, "Other Amount")
- local amountS = nil
- while true do
- local button = waitForButton()
- if button == 1 then
- amountS = "100"
- break
- elseif button == 2 then
- amountS = "200"
- break
- elseif button == 3 then
- amountS = "500"
- break
- elseif button == 5 then
- amountS = "1000"
- break
- elseif button == 6 then
- amountS = "2000"
- break
- elseif button == 7 then
- amountS = "5000"
- break
- elseif button == 4 then
- return
- elseif button == 8 then
- amountS = otherAmount()
- break
- end
- end
- term.clear()
- drawHeader()
- local amount = tonumber(amountS)
- if amount ~= nil and (amount % 100) == 0 then
- term.clear()
- drawHeader()
- term.setCursorPos(center(textStart, "Amount : MC$ ") + 12, textStart)
- term.write(amountS)
- drawButton(4, "Cancel")
- drawButton(8, "Confirm")
- while true do
- local button = waitForButton()
- if button == 4 then
- return
- elseif button == 8 then
- break
- end
- end
- local senderId, response = nil, nil
- rednet.open(modemSide)
- rednet.send(serverId, version .. textutils.serialize({"WITHDRAW", acc, crypt.hashPassword(pin), amountS}))
- while true do
- senderId, response = rednet.receive(5)
- if senderId == serverId then
- break
- end
- end
- rednet.close(modemSide)
- term.clear()
- drawHeader()
- if response ~= "-" then
- center(textStart, "Withdrawing " .. (amount) .. " MC$")
- rednet.open(modemSide)
- rednet.send(withdrawId, version .. textutils.serialize({"WITHDRAW", (amount) .. ""}))
- while true do
- senderId, response = rednet.receive(5)
- if senderId == withdrawId then
- break
- end
- end
- rednet.close(modemSide)
- term.clear()
- drawHeader()
- if response ~= "-" then
- center(textStart, "Please take your cash")
- sleep(2)
- return
- else
- drawError("Withdrawal Error")
- end
- else
- drawError("Transaction Error")
- end
- else
- term.clear()
- drawHeader()
- drawError("Invalid Amount")
- end
- drawButton(8, "OK")
- while true do
- local button = waitForButton()
- if button == 8 then
- return
- end
- end
- end
- -- Main Menu
- function bank(acc, pin)
- while true do
- term.clear()
- drawHeader()
- drawButton(1, "Market")
- drawButton(2, "Bounty")
- drawButton(3, "Message Board")
- drawButton(4, "Return Card")
- drawButton(5, "Balance Check")
- drawButton(6, "Withdrawal")
- drawButton(7, "Deposit")
- drawButton(8, "Transfer")
- local button = waitForButton()
- if button == 1 then
- market(acc, pin)
- elseif button == 2 then
- bounty(acc, pin)
- elseif button == 3 then
- message(acc, pin)
- elseif button == 4 then
- return
- elseif button == 5 then
- balance(acc, pin)
- elseif button == 6 then
- withdraw(acc, pin)
- elseif button == 7 then
- deposit(acc, pin)
- elseif button == 8 then
- transfer(acc, pin)
- end
- end
- end
- -- Login/Register Menu
- function begin()
- local acc, pin
- term.clear()
- drawHeader()
- drawButton(4, "Login")
- drawButton(8, "Open Account")
- while true do
- local button = waitForButton()
- if button == 4 then
- break
- elseif button == 8 then
- register()
- end
- end
- center(textStart, "Insert keycard or press ENTER")
- center(textStart + 1, "to transact without a keycard")
- parallel.waitForAny(waitForEnter, waitForDisk)
- term.clear()
- drawHeader()
- term.setCursorPos(center(textStart, "Account No : ") + 13, textStart)
- if disk.hasData(diskSide) then
- acc = disk.getLabel(diskSide)
- term.write(acc)
- else
- acc = read()
- end
- term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1)
- pin = read("*")
- sleep(1)
- request =
- http.post(
- url,
- "command=" ..
- textutils.urlEncode(tostring("login")) ..
- "&" ..
- "username=" ..
- textutils.urlEncode(tostring(acc)) ..
- "&" .. "password=" .. textutils.urlEncode(tostring(sha256.sha256(pin)))
- )
- if request == nil then
- term.clear()
- drawHeader()
- drawError("Login Server Is DOWN!")
- sleep(6)
- os.reboot()
- else
- response = request.readAll()
- term.clear()
- drawHeader()
- if response == "true" then
- bank(acc, pin)
- term.clear()
- drawHeader()
- disk.eject(diskSide)
- center(textStart, "Thank you for choosing InfaKnox.")
- center(textStart + 1, "Please take your keycard")
- sleep(6)
- os.reboot()
- else
- drawError("Login Error")
- sleep(4)
- os.reboot()
- end
- end
- while true do
- local button = waitForButton()
- if button == 8 then
- return
- end
- end
- end
- while true do
- begin()
- end
Add Comment
Please, Sign In to add comment