Hayden_Almeida

Rodar Server.exe

May 10th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.42 KB | None | 0 0
  1. --[[
  2. ================================ CONFIGS ====================================
  3. CRIADO POR: HAYDEN ALMEIDA
  4. Canal no youTube: https://www.youtube.com/channel/UCUZCQ1q0ZOHpqABIvpxB32g
  5. local data = "08/05/2016 as 1709" data de atualizaçao
  6. Caso encontre um erro e quiser entrar em contato: haydenalmeida@hotmail.com
  7. Ou Skype: haydenalmeida
  8. --]]
  9. local ver = "1.1"  -- versao atual do programa
  10. local Tog_Debug = false -- if Tog_Debug == true then print("Debug 1") end -- DEBUG
  11. PC_ID = os.getComputerID()
  12. --======================== FIM DAS CONFIGS ===================================
  13. if fs.exists("configs") == true then
  14.     if fs.exists("configs/start") == true then
  15.         local file = fs.open("configs/start", "r")
  16.         local ler1 = file.readLine()
  17.         local ler2 = file.readLine()
  18.         file.close()
  19.         if peripheral.isPresent(ler1) == true and peripheral.isPresent(ler2) then
  20.             local diskDriveSide = tostring(ler1)
  21.             local NetSide = tostring(ler2)
  22.             rednet.open(NetSide)
  23.         end
  24.     end
  25. end
  26.  
  27. while true do
  28.     timenow = os.time()
  29.     timenow = textutils.formatTime(timenow, true)
  30.     dianow = os.day()
  31.     print(timenow)
  32.     local senderId, message, protocol = rednet.receive("HA Banking System",5)
  33.     if Tog_Debug == true then print("Debug 1") end -- DEBUG
  34.     if message == "Caixa Ligando" then
  35.         if Tog_Debug == true then print("Debug 2") end -- DEBUG
  36.         local passou_Caixa = false
  37.         local senderId = tostring(senderId)
  38.         local lines = {}
  39.         local hFile = fs.open("//configs/caixas_registrados", "r")
  40.         for lines in hFile.readLine do
  41.             if lines == senderId then passou_Caixa = true end
  42.             if Tog_Debug == true then print("Linhas: "..lines) print(senderId) end -- DEBUG
  43.         end
  44.         hFile.close()
  45.         if passou_Caixa == true then -- se o Caixa que entrou em contato faz parte da lista de caixas registrados.
  46.             if Tog_Debug == true then print("Debug 3") end -- DEBUG
  47.             senderId = tonumber(senderId)
  48.             write("  Caixa Logado: "..senderId.." ")
  49.             rednet.send(senderId,"ok","HA Banking System")
  50.         end
  51.  
  52.  
  53.     elseif message == "a32981-a38a2381-a389aa231-1939039" then
  54.         local Id, message, protocol = rednet.receive("HA Banking System",2)
  55.         if Id == senderId then
  56.             if Tog_Debug == true then print("Debug 4") end -- DEBUG
  57.             local table = textutils.unserialize(message)
  58.             if fs.exists("//usuarios/"..table.a1) == true then
  59.                 if Tog_Debug == true then print("Debug 5") end -- DEBUG
  60.                 local file = fs.open("//usuarios/"..table.a1.."/parametros", "r")
  61.                 local tContents = {}
  62.                 for line in file.readLine do -- Lendo todas as linhas do Arquivo
  63.                     tContents[ #tContents + 1 ] = line -- Coloca cada linha em Cada tContents[1], tContents[2], etc..
  64.                 end
  65.                 file.close()
  66.                 if Tog_Debug == true then print("Debug 6") end -- DEBUG
  67.  
  68.                 if tContents[1] == table.a1 then
  69.                     write("Usuario conectado ")
  70.                     if Tog_Debug == true then print("Debug 7") end -- DEBUG
  71.                     local Card_ID = tostring(tContents[3])
  72.                     local Dec = (table.a2..".0")
  73.                     if Card_ID == Dec then
  74.                         local table = {
  75.                         a1 = tContents[2],
  76.                         a2 = tContents[5]
  77.                         }
  78.                         local serial = textutils.serialize(table)
  79.                         rednet.send(Id, serial,"HA Banking System")
  80.                     end
  81.                 end
  82.             else
  83.                 print("usuario nao encontrado.")
  84.             end
  85.         end
  86.     elseif message == "b32981-a38a2381-a389aa231-19398" then
  87.         local Id, message, protocol = rednet.receive("HA Banking System",2)
  88.         if Id == senderId then
  89.             local table = textutils.unserialize(message)
  90.             if fs.exists("//usuarios/"..table.a1) == true then
  91.                 local file = fs.open("//usuarios/"..table.a1.."/parametros", "r")
  92.                 local tContents = {}
  93.                 for line in file.readLine do -- Lendo todas as linhas do Arquivo
  94.                     tContents[ #tContents + 1 ] = line -- Coloca cada linha em Cada tContents[1], tContents[2], etc..
  95.                 end
  96.                 file.close()
  97.  
  98.                 local table = {
  99.                 a1 = tContents[1],
  100.                 a2 = tContents[4]
  101.                 }
  102.                 local serial = textutils.serialize(table)
  103.                 rednet.send(Id, serial,"HA Banking System")
  104.             else
  105.                 rednet.send(Id, "Usuario nao encontrado!","HA Banking System")
  106.             end
  107.         end
  108.     elseif message == "b32981-a38a2381-a389aa231-19399" then
  109.         local Id, message, protocol = rednet.receive("HA Banking System",2)
  110.         if Id == senderId then
  111.             local tabela = textutils.unserialize(message)
  112.             print("tabela.a1: "..tabela.a1)
  113.             if fs.exists("//usuarios/"..tabela.a1) == true and fs.exists("//usuarios/"..tabela.a3) == true then
  114.                 -- ================ CONTA DO FAVORECIDO:
  115.                 local arq = fs.open("//usuarios/"..tabela.a1.."/parametros", "r")
  116.                 local tContents = {}
  117.                 for line in arq.readLine do -- Lendo todas as linhas do Arquivo
  118.                     tContents[ #tContents + 1 ] = line -- Coloca cada linha em Cada tContents[1], tContents[2], etc..
  119.                 end
  120.                 arq.close()            
  121.  
  122.                 local Dec = (tabela.a2..".0")
  123.                 local Dec_Num = tonumber(Dec)
  124.                 local Conta = (Dec_Num + tContents[5])
  125.                 table.remove(tContents, 5) -- removendo a linha 5
  126.                 table.insert(tContents, 5, Conta) -- adicionando a nova linha 5
  127.                 local arq = fs.open("//usuarios/"..tabela.a1.."/parametros", "w")
  128.                 for i, v in ipairs( tContents ) do
  129.                     arq.writeLine( v )
  130.                 end
  131.                 arq.close()
  132.                 -- ======================= CONTA DA PESSOA QUE TRANSFERIU ======
  133.                 local arq = fs.open("//usuarios/"..tabela.a3.."/parametros", "r")
  134.                 local tContents = {}
  135.                 for line in arq.readLine do -- Lendo todas as linhas do Arquivo
  136.                     tContents[ #tContents + 1 ] = line -- Coloca cada linha em Cada tContents[1], tContents[2], etc..
  137.                 end
  138.                 arq.close()            
  139.  
  140.                 local Conta = (tContents[5] - Dec_Num)
  141.                 table.remove(tContents, 5) -- removendo a linha 5
  142.                 table.insert(tContents, 5, Conta) -- adicionando a nova linha 5
  143.                 local arq = fs.open("//usuarios/"..tabela.a3.."/parametros", "w")
  144.                 for i, v in ipairs( tContents ) do
  145.                     arq.writeLine( v )
  146.                 end
  147.                 arq.close()
  148.                 local file = fs.open("configs/ultimas_transferencias", "r")
  149.                 ler1 = file.readLine()
  150.                 file.close()
  151.                 local Conta = (ler1 + 1)
  152.                 local file = fs.open("configs/ultimas_transferencias", "w")
  153.                 file.writeLine(Conta)
  154.                 file.close()
  155.                 -- ========== ARQUIVO DE LOGS:
  156.                 -- Log do Banco:
  157.                 local file2 = fs.open("//Logs/transferencias/"..ler1, "w")
  158.                 file2.writeLine("EXTRATO: "..ler1)
  159.                 file2.writeLine("Dia: "..dianow)
  160.                 file2.writeLine("Hora: "..timenow)
  161.                 file2.writeLine("Pelo Caixa ID: "..Id)
  162.                 file2.writeLine("Por: "..tabela.a3)
  163.                 file2.writeLine("Para: "..tabela.a1)
  164.                 file2.writeLine("VALOR: $"..tabela.a2)
  165.                 file2.close()
  166.                 -- Log do Cliente:
  167.                 local file3 = fs.open("//usuarios/"..tabela.a1.."/logs/Extrato_"..ler1, "w")
  168.                 file3.writeLine("EXTRATO: "..ler1)
  169.                 file3.writeLine("Dia: "..dianow)
  170.                 file3.writeLine("Hora: "..timenow)
  171.                 file3.writeLine("Pelo Caixa ID: "..Id)
  172.                 file3.writeLine("Por: "..tabela.a3)
  173.                 file3.writeLine("Para: "..tabela.a1)
  174.                 file3.writeLine("VALOR: $"..tabela.a2)
  175.                 file3.close()
  176.                 -- Log do Favorecido:
  177.                 local file4 = fs.open("//usuarios/"..tabela.a3.."/logs/Extrato_"..ler1, "w")
  178.                 file4.writeLine("EXTRATO: "..ler1)
  179.                 file4.writeLine("Dia: "..dianow)
  180.                 file4.writeLine("Hora: "..timenow)
  181.                 file4.writeLine("Pelo Caixa ID: "..Id)
  182.                 file4.writeLine("Por: "..tabela.a3)
  183.                 file4.writeLine("Para: "..tabela.a1)
  184.                 file4.writeLine("VALOR: $"..tabela.a2)
  185.                 file4.close()
  186.  
  187.                 rednet.send(Id, "kaoeuhai--1930a3","HA Banking System")
  188.                 sleep(1)
  189.                 rednet.send(Id, ler1,"HA Banking System")
  190.                 print("Transferencia efetuada ")
  191.             end
  192.         end
  193.     end
  194.     sleep(1)
  195. end
Add Comment
Please, Sign In to add comment