Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local fs = require("filesystem")
- local sides = require("sides")
- local colors = require("colors")
- local modem = component.modem
- local computer = component.computer
- local card_reader = component.os_magreader
- local redstone = component.redstone
- local bundle = sides.right
- local cab100 = colors.orange
- local cab500 = colors.red
- local cab2000 = colors.yellow
- local cab10000 = colors.green
- vyber = true
- modem.open(443)
- function center(str, line)
- c = 1 + math.floor((80 - 0) / 2) - math.floor(#str / 2)
- term.setCursor(c, line)
- term.write(str)
- end
- function toHeader(balance, name)
- term.setCursor(1, 0)
- term.write(balance)
- p = 80 - (math.floor(#balance) + math.floor(#name))
- for i = p,0,-1 do
- term.write(" ")
- end
- term.write(name)
- end
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function loadC(price)
- a = io.open("/home/bankovky/"..price, "r")
- b = a:read("*all")
- a:close()
- return tonumber(b)
- end
- function writeC(val, price)
- a = io.open("/home/bankovky/"..price, "w")
- a:write(val)
- a:close()
- end
- while true do
- c100 = loadC(100)
- c500 = loadC(500)
- c2000 = loadC(2000)
- c10000 = loadC(10000)
- v100 = 0
- v500 = 0
- v2000 = 0
- v10000 = 0
- celkem_skladem = c100*100 + c500*500 + c2000*2000 + c10000*10000
- if c100 == 0 and c500 == 0 and c2000 == 0 and c10000 == 0 then
- vyber = false
- else
- vyber = true
- end
- term.clear()
- center("ATM Komerční banka", 7)
- center("Přiložte kartu", 8)
- ev, _, user, ucet, uuid = event.pull("magData")
- computer.beep(500, 0.5)
- term.clear()
- center("ATM Komerční banka", 7)
- center("Zadejte pin: ", 8)
- pin = term.read();
- term.clear()
- center("ATM Komerční banka", 7)
- center("Probíhá autorizace...", 8)
- modem.broadcast(443, "LOGIN#" .. ucet .. "#" .. pin)
- local _, _, from, port, _, msg = event.pull("modem_message")
- if msg == "UNKNOW_ACCOUNT" then
- else
- if msg == "BAD_PIN" then
- else
- logged = true
- while logged == true do
- cut = split(msg, "#")
- term.clear()
- toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
- center("ATM Komerční banka", 7)
- center("Výběr 1", 9)
- center("Odhlásit 0", 10)
- term.setCursor(39,11)
- volba = tonumber(term.read())
- if volba == 0 then
- logged = false
- elseif volba == 1 then
- term.clear()
- toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
- center("ATM Komerční banka", 7)
- center("Zadejte částku:", 9)
- term.setCursor(39,10)
- castka = tonumber(term.read())
- zbyva_vydat = castka
- if (tonumber(cut[1]) - castka) >= 0 then
- if celkem_skladem >= castka then
- term.clear()
- toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
- center("ATM Komerční banka", 7)
- center("Zpracovávání...", 9)
- center("Prosím počkejte!", 10)
- bankovky = 0
- while zbyva_vydat ~= 0 do
- if zbyva_vydat >= 10000 then
- numero = zbyva_vydat / 10000
- v10000 = math.floor(numero)
- if v10000 > c10000 then
- v10000 = c10000
- end
- zbyva_vydat = zbyva_vydat - (v10000 * 10000)
- bankovky = bankovky + v10000
- elseif zbyva_vydat >= 2000 then
- numero = zbyva_vydat / 2000
- v2000 = math.floor(numero)
- if v2000 > c2000 then
- v2000 = c2000
- end
- zbyva_vydat = zbyva_vydat - (v2000 * 2000)
- bankovky = bankovky + v2000
- elseif zbyva_vydat >= 500 then
- numero = zbyva_vydat / 500
- v500 = math.floor(numero)
- if v500 > c500 then
- v500 = c500
- end
- zbyva_vydat = zbyva_vydat - (v500 * 500)
- bankovky = bankovky + v500
- elseif zbyva_vydat >= 100 then
- numero = zbyva_vydat / 100
- v100 = math.floor(numero)
- if v100 > c100 then
- v100 = c100
- end
- zbyva_vydat = zbyva_vydat - (v100 * 100)
- bankovky = bankovky + v100
- else
- ignore = zbyva_vydat
- zbyva_vydat = 0
- end
- end--while
- term.clear()
- toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
- center("ATM Komerční banka", 7)
- center("Zpracovávání...", 9)
- center("Už jen dotaz na server!", 10)
- if ignore == nil then
- ignore = 0
- end
- celk = (castka - ignore) * -1
- modem.broadcast(443, "ATM#" .. ucet .. "#" .. celk)
- local _, _, from, port, _, msg = event.pull("modem_message")
- term.clear()
- toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
- center("ATM Komerční banka", 7)
- center("Zpracovávání...", 9)
- center("K výdeji: "..v10000.."x 10000, "..v2000.."x 2000, "..v500.."x 500,"..v100.."x 100.", 10)
- os.sleep(3)
- while bankovky ~= 0 do
- if v10000 ~= nil and v10000 ~= 0 then
- while v10000 ~= 0 do
- -- Výdej 10 000
- redstone.setBundledOutput(bundle, cab10000, 100)
- os.sleep(0.5)
- redstone.setBundledOutput(bundle, cab10000, 0)
- v10000 = v10000 - 1
- c10000 = c10000 - 1
- bankovky = bankovky - 1
- end
- elseif v2000 ~= nil and v2000 ~= 0 then
- while v2000 ~= 0 do
- -- Výdej 2 000
- redstone.setBundledOutput(bundle, cab2000, 100)
- os.sleep(0.5)
- redstone.setBundledOutput(bundle, cab2000, 0)
- v2000 = v2000 - 1
- c2000 = c2000 - 1
- bankovky = bankovky - 1
- end
- elseif v500 ~= nil and v500 ~= 0 then
- while v500 ~= 0 do
- -- Výdej 500
- redstone.setBundledOutput(bundle, cab500, 100)
- os.sleep(0.5)
- redstone.setBundledOutput(bundle, cab500, 0)
- v500 = v500 - 1
- c500 = c500 - 1
- bankovky = bankovky - 1
- end
- elseif v100 ~= nil and v100 ~= 0 then
- while v100 ~= 0 do
- -- Výdej 100
- redstone.setBundledOutput(bundle, cab100, 100)
- os.sleep(0.5)
- redstone.setBundledOutput(bundle, cab100, 0)
- v100 = v100 - 1
- c100 = c100 - 1
- bankovky = bankovky - 1
- end
- end
- end
- writeC(c10000, "10000")
- writeC(c2000, "2000")
- writeC(c500, "500")
- writeC(c100, "100")
- term.clear()
- toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
- center("ATM Komerční banka", 7)
- center("Bankovky byly vyslány, prosím počkejte", 9)
- center("než dorazí všechny.", 10)
- os.sleep(5)
- else
- term.clear()
- toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
- center("ATM Komerční banka", 7)
- center("Je nám líto, ale bankomat nemá dostatek financí.", 9)
- os.sleep(5)
- end--dostatekban
- else
- term.clear()
- toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
- center("ATM Komerční banka", 7)
- center("Je nám líto, ale nemáte dostatek financí na účtu.", 9)
- os.sleep(5)
- end--dostatekfin
- end--volba
- end--logged
- end --bad pin
- end --unknown acc
- end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement