Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- os.loadAPI("gui")
- local function readLines(sPath)
- local file = fs.open(sPath, "r")
- if file then
- local tLines = {}
- local sLine = file.readLine()
- while sLine do
- table.insert(tLines, sLine)
- sLine = file.readLine()
- end
- file.close()
- return tLines
- end
- return nil
- end
- function lerConfig(name, line)
- local tLines = readLines(name)
- if not tLines then
- return nil
- end
- return tLines[line]
- end
- -- Configs
- textStart = gui.textStart
- server = 359 --id do servidor
- modemSide = lerConfig("config.txt", 1)
- diskSide = lerConfig("config.txt", 2)
- sorterSide = lerConfig("config.txt", 3)
- chestSide = tonumber(lerConfig("config.txt", 4)) --lado do bau acessivel pelo player
- inputSide = tonumber(lerConfig("config.txt", 5)) --lado de entrada de itens DO sistema
- outputSide = tonumber(lerConfig("config.txt", 6)) -- lado de saida de itens PARA o sistema
- versao = "1.0_beta_R4"
- nconta = ""
- npin = ""
- -- Fim das Configs
- -- Funçoes da GUI
- local desenharMenu, desenharBotoes, desenharBotao, desenharErro, center = gui.drawHeader, gui.drawButtons, 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
- -- Funções
- local function limitRead(len, replaceChar)
- len = len or 10
- local input=""
- local key = 0
- term.setCursorBlink(true)
- repeat
- local e,p1 = os.pullEvent()
- if e=="char" then
- if #input < len then
- input = input .. p1
- term.write(replaceChar or p1)
- end
- elseif e=="key" and p1==keys.backspace and #input > 0 then
- input = input:sub(1,#input-1)
- local x,y = term.getCursorPos()
- term.setCursorPos(x-1,y)
- term.write(" ")
- term.setCursorPos(x-1,y)
- end
- until p1==keys.enter
- term.setCursorBlink(false)
- return input
- end
- function ler(name)
- local file = name
- file = fs.open(file,"r")
- if file then
- file = file.readAll()
- return file
- else
- print("Erro de leitura")
- end
- end
- function cartaoValido()
- if fs.exists("/disk/numero.txt") then
- return true
- else
- return false
- end
- end
- function netstat()
- rednet.send(server, "ping")
- recebi = false
- now = os.time()
- while os.time() < now + 0.05 or recebi == true do
- id, message = rednet.receive()
- if message == "pong" then
- recebi = true
- return true
- end
- end
- return false
- end
- function getQuantidade(side, item, obj)
- data = obj.list(side)
- local c = 0;
- for i, j in pairs(data) do
- if i == item then
- c = j
- end
- end
- return c
- end
- function valor()
- rednet.send(server, "valor")
- recebi = false
- while recebi == false do
- id, message = rednet.receive()
- if id == server then
- recebi = true
- return message
- end
- end
- end
- function otherAmount()
- local amount = ""
- term.clear() desenharMenu()
- term.setCursorPos(center(textStart, "Valor : B$ ") + 12, textStart)
- return limitRead(20)
- end
- function getUUID(id, meta)
- uuid = id + meta * 32768
- return uuid
- end
- function deposit(amount, from, to)
- sorter = peripheral.wrap(sorterSide)
- sorter.extract(from, getUUID(27527, 0), to, amount)
- end
- function valorM()
- term.clear() desenharMenu() desenharBotoes()
- center(textStart, "O valor atual da moeda e " ..valor())
- desenharBotao(8, "OK")
- while true do
- local button = waitForButton()
- if button == 8 then return end
- end
- end
- function mostrarSaldo()
- term.clear() desenharMenu() desenharBotoes()
- rednet.send(server, "saldo_"..nconta.."_"..npin)
- id, message = rednet.receive()
- recebi = false
- while recebi == false do
- if(id == server) then
- recebi = true
- center(textStart, "O saldo da sua conta e " ..message)
- end
- end
- desenharBotao(8, "OK")
- while true do
- local button = waitForButton()
- if button == 8 then return end
- end
- end
- function transferir()
- term.clear() desenharMenu() desenharBotoes()
- desenharBotao(1, "B$1")
- desenharBotao(2, "B$2")
- desenharBotao(3, "B$5")
- desenharBotao(5, "B$10")
- desenharBotao(6, "B$20")
- desenharBotao(7, "B$50")
- desenharBotao(4, "Cancelar")
- desenharBotao(8, "Outro Valor")
- local valorS = nil
- while true do
- local button = waitForButton()
- if button == 1 then valorS = "1" break
- elseif button == 2 then valorS = "2" break
- elseif button == 3 then valorS = "5" break
- elseif button == 5 then valorS = "10" break
- elseif button == 6 then valorS = "20" break
- elseif button == 7 then valorS = "50" break
- elseif button == 4 then return
- elseif button == 8 then valorS = otherAmount() break
- end
- end
- local valor = tonumber(valorS)
- term.clear() desenharMenu() desenharBotoes()
- term.setCursorPos(center(textStart, "Valor : B$ ") + 12, textStart)
- term.write(valorS)
- term.setCursorPos(center(textStart + 1, "Conta : ") + 10, textStart + 1)
- local to = limitRead(20)
- desenharBotao(4, "Cancelar")
- desenharBotao(8, "Confirmar")
- while true do
- local button = waitForButton()
- if button == 4 then return
- elseif button == 8 then break
- end
- end
- if valor == nil or to == nil then
- errou("Valor(es) incompativel(eis)")
- end
- term.clear() desenharMenu() desenharBotoes()
- rednet.send(server, "transferir_"..nconta.."_"..npin.."_"..valor.."_"..to)
- id, message = rednet.receive()
- recebi = false
- while recebi == false do
- if(id == server) then
- recebi = true
- if message == "Transferencia Aprovada" then
- center(textStart, "Transferencia Completa")
- os.sleep(2)
- if peripheral.isPresent("left") then
- imp = peripheral.wrap("left")
- imp.newPage()
- imp.setPageTitle("ATM-Transferencia")
- imp.write(" --- ATM ---")
- imp.setCursorPos(1,2)
- imp.write("Conta: "..nconta)
- imp.setCursorPos(1,3)
- imp.write("Valor: "..valor)
- imp.setCursorPos(1,4)
- imp.write("Para: "..to)
- imp.endPage()
- end
- else
- errou("Houve um erro na Transferencia")
- end
- end
- end
- desenharBotao(8, "OK")
- while true do
- local button = waitForButton()
- if button == 8 then return end
- end
- end
- function deposito()
- term.clear() desenharMenu() desenharBotoes()
- desenharBotao(1, "B$1")
- desenharBotao(2, "B$2")
- desenharBotao(3, "B$5")
- desenharBotao(5, "B$10")
- desenharBotao(6, "B$20")
- desenharBotao(7, "B$50")
- desenharBotao(4, "Cancelar")
- desenharBotao(8, "Outro Valor")
- local valorS = nil
- while true do
- local button = waitForButton()
- if button == 1 then valorS = "1" break
- elseif button == 2 then valorS = "2" break
- elseif button == 3 then valorS = "5" break
- elseif button == 5 then valorS = "10" break
- elseif button == 6 then valorS = "20" break
- elseif button == 7 then valorS = "50" break
- elseif button == 4 then return
- elseif button == 8 then valorS = otherAmount() break
- end
- end
- sorter = peripheral.wrap(sorterSide)
- local valor = tonumber(valorS)
- term.clear() desenharMenu() desenharBotoes()
- term.setCursorPos(center(textStart, "Valor : B$ ") + 12, textStart)
- term.write(valorS)
- desenharBotao(4, "Cancelar")
- desenharBotao(8, "Confirmar")
- while true do
- local button = waitForButton()
- if button == 4 then return
- elseif button == 8 then break
- end
- end
- if valor == nil then
- errou("Valor incompativel")
- end
- term.clear() desenharMenu() desenharBotoes()
- if getQuantidade(5, 27527, sorter) < valor then
- desenharErro("Voce colocou apenas "..getQuantidade(5, 27527, sorter))
- term.setCursorPos(20, textStart + 1)
- term.write(" e tentou depositar "..valor)
- os.sleep(2)
- disk.eject(diskSide)
- nconta = ""
- npin = ""
- init()
- end
- if valor > 64 then
- errou("Voce so pode depositar 64 de uma vez")
- end
- deposit(valor, chestSide, outputSide)
- rednet.send(server, "atsaldo_"..nconta.."_"..npin.."_1_"..valor)
- center(textStart, "Deposito concluido")
- if peripheral.isPresent("left") then
- imp = peripheral.wrap("left")
- imp.newPage()
- imp.setPageTitle("ATM-Deposito")
- imp.write(" --- ATM ---")
- imp.setCursorPos(1,2)
- imp.write("Conta: "..nconta)
- imp.setCursorPos(1,3)
- imp.write("Valor: "..valor)
- imp.endPage()
- end
- desenharBotao(8, "OK")
- while true do
- local button = waitForButton()
- if button == 8 then return end
- end
- end
- function saque()
- term.clear() desenharMenu() desenharBotoes()
- desenharBotao(1, "B$1")
- desenharBotao(2, "B$2")
- desenharBotao(3, "B$5")
- desenharBotao(5, "B$10")
- desenharBotao(6, "B$20")
- desenharBotao(7, "B$50")
- desenharBotao(4, "Cancelar")
- desenharBotao(8, "Outro Valor")
- local valorS = nil
- while true do
- local button = waitForButton()
- if button == 1 then valorS = "1" break
- elseif button == 2 then valorS = "2" break
- elseif button == 3 then valorS = "5" break
- elseif button == 5 then valorS = "10" break
- elseif button == 6 then valorS = "20" break
- elseif button == 7 then valorS = "50" break
- elseif button == 4 then return
- elseif button == 8 then valorS = otherAmount() break
- end
- end
- local valor = tonumber(valorS)
- term.clear() desenharMenu() desenharBotoes()
- term.setCursorPos(center(textStart, "Valor : B$ ") + 12, textStart)
- term.write(valorS)
- desenharBotao(4, "Cancelar")
- desenharBotao(8, "Confirmar")
- while true do
- local button = waitForButton()
- if button == 4 then return
- elseif button == 8 then break
- end
- end
- if valor == nil then
- errou("Valor incompativel")
- end
- if valor > 64 then
- errou("Voce so pode sacar 64 de uma vez")
- end
- rednet.send(server, "saldo_"..nconta.."_"..pin)
- id, message = rednet.receive()
- recebi = false
- while recebi == false do
- if(id == server) then
- recebi = true
- saldo = tonumber(message) or "erro"
- end
- end
- term.clear() desenharMenu() desenharBotoes()
- if valor > saldo then
- errou("Voce nao tem dinheiro suficiente")
- end
- rednet.send(server, "atsaldo_"..nconta.."_"..npin.."_0_"..valor)
- deposit(valor, inputSide, chestSide)
- center(textStart, "Saque concluido, retire o seu dinheiro")
- if peripheral.isPresent("left") then
- imp = peripheral.wrap("left")
- imp.newPage()
- imp.setPageTitle("ATM-Saque")
- imp.write(" --- ATM ---")
- imp.setCursorPos(1,2)
- imp.write("Conta: "..nconta)
- imp.setCursorPos(1,3)
- imp.write("Valor: "..valor)
- imp.endPage()
- end
- desenharBotao(8, "OK")
- while true do
- local button = waitForButton()
- if button == 8 then return end
- end
- end
- function begin()
- term.clear()
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.red)
- center(10, "TKATM versao "..versao)
- term.setBackgroundColor(colors.blue)
- term.setTextColor(colors.white)
- center(12, "Para criar uma conta fale com o Esquilo_Azul")
- os.sleep(3)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- rednet.open(modemSide)
- center(5, "Verificando Conexao com o servidor, aguarde...")
- if not netstat() == true then
- center(5, "Servidor nao disponivel, tente mais tarde!")
- os.sleep(5)
- os.shutdown()
- end
- init()
- end
- function errou(msg)
- term.clear() desenharMenu() desenharBotoes()
- desenharErro(msg)
- disk.eject(diskSide)
- nconta = ""
- npin = ""
- os.sleep(2)
- init()
- end
- function init()
- term.clear() desenharMenu()
- rednet.open(modemSide)
- center(textStart, "Insira seu cartao ou aperte ENTER")
- center(textStart + 1, "para usar o ATM sem cartao")
- parallel.waitForAny(waitForEnter, waitForDisk)
- term.clear() desenharMenu()
- term.setCursorPos(center(textStart, "No da Conta: ") + 13, textStart)
- if cartaoValido() == true then
- conta = ler("/disk/numero.txt")
- term.write(conta)
- else
- conta = limitRead(20)
- end
- term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1)
- pin = limitRead(20, "*")
- if conta == "StopCard99785" and pin == "90778547093114" and cartaoValido() == true then
- term.clear()
- term.setCursorPos(1,1)
- print("Cartao de Operador Reconhecido!")
- disk.eject(diskSide)
- error()
- end
- rednet.send(server, "auth_"..conta.."_"..pin)
- recebi = false
- while recebi == false do
- id, message = rednet.receive()
- if id == server then
- if message == "autorizado" then
- term.clear()
- nconta = conta
- npin = pin
- recebi = true
- end
- if message == "negado" then
- term.clear()
- recebi = true
- desenharErro("Conta e PIN incompativeis")
- disk.eject(diskSide)
- nconta = ""
- npin = ""
- os.sleep(2)
- init()
- end
- end
- end
- bank()
- term.clear() desenharMenu()
- disk.eject(diskSide)
- nconta = ""
- npin = ""
- center(textStart, "Obrigado por usar o TKBank")
- center(textStart + 1, "Pegue seu cartao")
- sleep(2)
- init()
- end
- function bank()
- while true do
- term.clear() desenharMenu() desenharBotoes()
- desenharBotao(1, "Valor da Moeda")
- desenharBotao(4, "Retornar Cartao")
- desenharBotao(5, "Saldo")
- desenharBotao(6, "Saque")
- desenharBotao(7, "Deposito")
- desenharBotao(8, "Transferencia")
- local button = waitForButton()
- if button == 1 then valorM()
- elseif button == 4 then return
- elseif button == 5 then mostrarSaldo()
- elseif button == 6 then saque()
- elseif button == 7 then deposito()
- elseif button == 8 then transferir()
- end
- end
- end
- while true do
- begin()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement