Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ================================ CONFIGS ====================================
- CRIADO POR: HAYDEN ALMEIDA
- Canal no youTube: https://www.youtube.com/channel/UCUZCQ1q0ZOHpqABIvpxB32g
- local data = "08/05/2016 as 1709" data de atualizaçao
- Caso encontre um erro e quiser entrar em contato: haydenalmeida@hotmail.com
- Ou Skype: haydenalmeida
- --]]
- local ver = "1.1" -- versao atual do programa
- local Tog_Debug = false -- if Tog_Debug == true then print("Debug 1") end -- DEBUG
- PC_ID = os.getComputerID()
- --======================== FIM DAS CONFIGS ===================================
- if fs.exists("configs") == true then
- if fs.exists("configs/start") == true then
- local file = fs.open("configs/start", "r")
- local ler1 = file.readLine()
- local ler2 = file.readLine()
- file.close()
- if peripheral.isPresent(ler1) == true and peripheral.isPresent(ler2) then
- local diskDriveSide = tostring(ler1)
- local NetSide = tostring(ler2)
- rednet.open(NetSide)
- end
- end
- end
- while true do
- timenow = os.time()
- timenow = textutils.formatTime(timenow, true)
- dianow = os.day()
- print(timenow)
- local senderId, message, protocol = rednet.receive("HA Banking System",5)
- if Tog_Debug == true then print("Debug 1") end -- DEBUG
- if message == "Caixa Ligando" then
- if Tog_Debug == true then print("Debug 2") end -- DEBUG
- local passou_Caixa = false
- local senderId = tostring(senderId)
- local lines = {}
- local hFile = fs.open("//configs/caixas_registrados", "r")
- for lines in hFile.readLine do
- if lines == senderId then passou_Caixa = true end
- if Tog_Debug == true then print("Linhas: "..lines) print(senderId) end -- DEBUG
- end
- hFile.close()
- if passou_Caixa == true then -- se o Caixa que entrou em contato faz parte da lista de caixas registrados.
- if Tog_Debug == true then print("Debug 3") end -- DEBUG
- senderId = tonumber(senderId)
- write(" Caixa Logado: "..senderId.." ")
- rednet.send(senderId,"ok","HA Banking System")
- end
- elseif message == "a32981-a38a2381-a389aa231-1939039" then
- local Id, message, protocol = rednet.receive("HA Banking System",2)
- if Id == senderId then
- if Tog_Debug == true then print("Debug 4") end -- DEBUG
- local table = textutils.unserialize(message)
- if fs.exists("//usuarios/"..table.a1) == true then
- if Tog_Debug == true then print("Debug 5") end -- DEBUG
- local file = fs.open("//usuarios/"..table.a1.."/parametros", "r")
- local tContents = {}
- for line in file.readLine do -- Lendo todas as linhas do Arquivo
- tContents[ #tContents + 1 ] = line -- Coloca cada linha em Cada tContents[1], tContents[2], etc..
- end
- file.close()
- if Tog_Debug == true then print("Debug 6") end -- DEBUG
- if tContents[1] == table.a1 then
- write("Usuario conectado ")
- if Tog_Debug == true then print("Debug 7") end -- DEBUG
- local Card_ID = tostring(tContents[3])
- local Dec = (table.a2..".0")
- if Card_ID == Dec then
- local table = {
- a1 = tContents[2],
- a2 = tContents[5]
- }
- local serial = textutils.serialize(table)
- rednet.send(Id, serial,"HA Banking System")
- end
- end
- else
- print("usuario nao encontrado.")
- end
- end
- elseif message == "b32981-a38a2381-a389aa231-19398" then
- local Id, message, protocol = rednet.receive("HA Banking System",2)
- if Id == senderId then
- local table = textutils.unserialize(message)
- if fs.exists("//usuarios/"..table.a1) == true then
- local file = fs.open("//usuarios/"..table.a1.."/parametros", "r")
- local tContents = {}
- for line in file.readLine do -- Lendo todas as linhas do Arquivo
- tContents[ #tContents + 1 ] = line -- Coloca cada linha em Cada tContents[1], tContents[2], etc..
- end
- file.close()
- local table = {
- a1 = tContents[1],
- a2 = tContents[4]
- }
- local serial = textutils.serialize(table)
- rednet.send(Id, serial,"HA Banking System")
- else
- rednet.send(Id, "Usuario nao encontrado!","HA Banking System")
- end
- end
- elseif message == "b32981-a38a2381-a389aa231-19399" then
- local Id, message, protocol = rednet.receive("HA Banking System",2)
- if Id == senderId then
- local tabela = textutils.unserialize(message)
- print("tabela.a1: "..tabela.a1)
- if fs.exists("//usuarios/"..tabela.a1) == true and fs.exists("//usuarios/"..tabela.a3) == true then
- -- ================ CONTA DO FAVORECIDO:
- local arq = fs.open("//usuarios/"..tabela.a1.."/parametros", "r")
- local tContents = {}
- for line in arq.readLine do -- Lendo todas as linhas do Arquivo
- tContents[ #tContents + 1 ] = line -- Coloca cada linha em Cada tContents[1], tContents[2], etc..
- end
- arq.close()
- local Dec = (tabela.a2..".0")
- local Dec_Num = tonumber(Dec)
- local Conta = (Dec_Num + tContents[5])
- table.remove(tContents, 5) -- removendo a linha 5
- table.insert(tContents, 5, Conta) -- adicionando a nova linha 5
- local arq = fs.open("//usuarios/"..tabela.a1.."/parametros", "w")
- for i, v in ipairs( tContents ) do
- arq.writeLine( v )
- end
- arq.close()
- -- ======================= CONTA DA PESSOA QUE TRANSFERIU ======
- local arq = fs.open("//usuarios/"..tabela.a3.."/parametros", "r")
- local tContents = {}
- for line in arq.readLine do -- Lendo todas as linhas do Arquivo
- tContents[ #tContents + 1 ] = line -- Coloca cada linha em Cada tContents[1], tContents[2], etc..
- end
- arq.close()
- local Conta = (tContents[5] - Dec_Num)
- table.remove(tContents, 5) -- removendo a linha 5
- table.insert(tContents, 5, Conta) -- adicionando a nova linha 5
- local arq = fs.open("//usuarios/"..tabela.a3.."/parametros", "w")
- for i, v in ipairs( tContents ) do
- arq.writeLine( v )
- end
- arq.close()
- local file = fs.open("configs/ultimas_transferencias", "r")
- ler1 = file.readLine()
- file.close()
- local Conta = (ler1 + 1)
- local file = fs.open("configs/ultimas_transferencias", "w")
- file.writeLine(Conta)
- file.close()
- -- ========== ARQUIVO DE LOGS:
- -- Log do Banco:
- local file2 = fs.open("//Logs/transferencias/"..ler1, "w")
- file2.writeLine("EXTRATO: "..ler1)
- file2.writeLine("Dia: "..dianow)
- file2.writeLine("Hora: "..timenow)
- file2.writeLine("Pelo Caixa ID: "..Id)
- file2.writeLine("Por: "..tabela.a3)
- file2.writeLine("Para: "..tabela.a1)
- file2.writeLine("VALOR: $"..tabela.a2)
- file2.close()
- -- Log do Cliente:
- local file3 = fs.open("//usuarios/"..tabela.a1.."/logs/Extrato_"..ler1, "w")
- file3.writeLine("EXTRATO: "..ler1)
- file3.writeLine("Dia: "..dianow)
- file3.writeLine("Hora: "..timenow)
- file3.writeLine("Pelo Caixa ID: "..Id)
- file3.writeLine("Por: "..tabela.a3)
- file3.writeLine("Para: "..tabela.a1)
- file3.writeLine("VALOR: $"..tabela.a2)
- file3.close()
- -- Log do Favorecido:
- local file4 = fs.open("//usuarios/"..tabela.a3.."/logs/Extrato_"..ler1, "w")
- file4.writeLine("EXTRATO: "..ler1)
- file4.writeLine("Dia: "..dianow)
- file4.writeLine("Hora: "..timenow)
- file4.writeLine("Pelo Caixa ID: "..Id)
- file4.writeLine("Por: "..tabela.a3)
- file4.writeLine("Para: "..tabela.a1)
- file4.writeLine("VALOR: $"..tabela.a2)
- file4.close()
- rednet.send(Id, "kaoeuhai--1930a3","HA Banking System")
- sleep(1)
- rednet.send(Id, ler1,"HA Banking System")
- print("Transferencia efetuada ")
- end
- end
- end
- sleep(1)
- end
Add Comment
Please, Sign In to add comment