the_king_jaz

BANK

Feb 4th, 2016
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.59 KB | None | 0 0
  1. proto = "CCBZ_DATA_RETRIEVAL"
  2. side = "top"
  3. rednet.open(side,true)
  4. function clear()
  5.   term.clear()
  6.   term.setCursorPos(1,1)
  7. end
  8. while true do
  9.   sleep(.01)
  10.   clear()
  11.   print("Recieving Data")
  12.   senderID, opt = rednet.receive(proto)
  13.   sleep(.01)
  14.   if opt=="colorRequest" then
  15.     clear()
  16.     print("Requesting ACCNUM")
  17.     rednet.broadcast("accNum",proto)
  18.     senderID, acc = rednet.receive(proto)
  19.     sleep(.01)
  20.     print("Opening acc/"..acc.."/COLORS")
  21.     f = fs.open("acc/"..acc.."/COLORS","r")
  22.     BTC = tonumber(f.readLine())
  23.     BGC = tonumber(f.readLine())
  24.     TXC = tonumber(f.readLine())
  25.     TTC = tonumber(f.readLine())
  26.     f.close()
  27.     print("Giving BTC: "..BTC)
  28.     rednet.broadcast(BTC,proto)
  29.     senderID, message = rednet.receive(proto)
  30.     print("Giving BGC: "..BGC)
  31.     sleep(.01)
  32.     rednet.broadcast(BGC,proto)
  33.     senderID, message = rednet.receive(proto)
  34.     print("Giving TXC: "..TXC)
  35.     sleep(.01)
  36.     rednet.broadcast(TXC,proto)
  37.     senderID, message = rednet.receive(proto)
  38.     print("Giving TTC: "..TTC)
  39.     sleep(.01)
  40.     rednet.broadcast(TTC,proto)
  41.   elseif opt=="bal" then
  42.     rednet.broadcast("acc req", proto)
  43.     senderID, acc = rednet.receive(proto)
  44.     f = fs.open("acc/"..acc.."/BALANCE","r")
  45.     bal = f.readLine()
  46.     f.close()
  47.     rednet.broadcast(bal,proto)
  48.     sleep(.01)
  49.   elseif opt=="reqAcc" then
  50.     local FileList = fs.list("acc")
  51.     for _, file in ipairs(FileList) do
  52.       rednet.broadcast(file,proto)
  53.       sleep(.03)
  54.     end
  55.     rednet.broadcast("noFile",proto)
  56.   elseif opt=="makePayment" then
  57.     sleep(.02)
  58.     clear()
  59.     print("Ready")
  60.     rednet.broadcast("ready",proto)
  61.     print("Receiving payto information")
  62.     senderID, payTo = rednet.receive(proto)
  63.     sleep(.01)
  64.     rednet.broadcast("ready",proto)
  65.     print("Receiving payfrom information")
  66.     senderID, pay = rednet.receive(proto)
  67.     sleep(.01)
  68.     rednet.broadcast("ready",proto)
  69.     print("Getting payto balance.")
  70.     f = fs.open("acc/"..payTo.."/BALANCE","r")
  71.     prePayTo = tonumber(f.readLine())
  72.     f.close()
  73.     print("Getting payfrom balance")
  74.     f = fs.open("acc/"..acc.."/BALANCE","r")
  75.     prePay = tonumber(f.readLine())
  76.     f.close()
  77.     print("Calculating Payment")
  78.     if payTo==acc then
  79.       print("Same Account; no change made.")
  80.       payedTo = prePayTo
  81.       payedFro = prePay
  82.     else
  83.       payedTo = prePayTo + pay
  84.       payedFro = prePay - pay
  85.     end
  86.     print("Applying withdraw from "..acc)
  87.     f = fs.open("acc/"..acc.."/BALANCE","w")
  88.     f.writeLine(payedFro)
  89.     f.close()
  90.     print("Applying deposit to "..payTo)
  91.     f = fs.open("acc/"..payTo.."/BALANCE","w")
  92.     f.writeLine(payedTo)
  93.     f.close()
  94.     clear()
  95.   elseif opt=="personalize" then
  96.     print("Ready")
  97.     sleep(.01)
  98.     rednet.broadcast("ready",proto)
  99.     senderID, BTC = rednet.receive(proto)
  100.     sleep(.01)
  101.     rednet.broadcast("ready",proto)
  102.     senderID, BGC = rednet.receive(proto)
  103.     sleep(.01)
  104.     rednet.broadcast("ready",proto)
  105.     senderID, TXC = rednet.receive(proto)
  106.     sleep(.01)
  107.     rednet.broadcast("ready",proto)
  108.     senderID, TTC = rednet.receive(proto)
  109.     f = fs.open("acc/"..acc.."/COLORS","w")
  110.     f.writeLine(BTC)
  111.     f.writeLine(BGC)
  112.     f.writeLine(TXC)
  113.     f.writeLine(TTC)
  114.     f.close()
  115.     rednet.broadcast("saved",proto)
  116.   elseif opt=="newAcc" then
  117.     rednet.broadcast("accNum Req",proto)
  118.     senderID, newAccNum = rednet.receive(proto)
  119.     sleep(.01)
  120.     if fs.isDir("acc/"..tostring(newAccNum)) == true then
  121.       rednet.broadcast("ERROR",proto)
  122.     else
  123.       rednet.broadcast("pass Req",proto)
  124.       senderID, newAccPass = rednet.receive(proto)
  125.       sleep(.01)
  126.       fs.makeDir("acc/"..tostring(newAccNum))
  127.       file = fs.open("acc/"..tostring(newAccNum).."/BALANCE","w")
  128.       file.writeLine(0)
  129.       file.close()
  130.       file = fs.open("acc/"..tostring(newAccNum).."/COLORS","w")
  131.       file.writeLine(colors.white)
  132.       file.writeLine(colors.black)
  133.       file.writeLine(colors.white)
  134.       file.writeLine(colors.white)
  135.       file.close()
  136.       file = fs.open("acc/"..tostring(newAccNum).."/PASS","w")
  137.       file.writeLine(tostring(newAccPass))
  138.       file.close()
  139.       rednet.broadcast("finished",proto)
  140.     end
  141.   elseif opt=="noOpt" then
  142.     clear()
  143.   else
  144.     if fs.exists("acc/"..opt) then
  145.       f = fs.open("acc/"..opt.."/PASS","r")
  146.       pass = tostring(f.readLine())
  147.       f.close()
  148.       clear()
  149.       print("Sending password")
  150.       rednet.broadcast(pass,proto)
  151.     else
  152.       clear()
  153.       print("Sending EC0001")
  154.       rednet.broadcast("**ERROR_CODE_0001**",proto)
  155.     end
  156.   end
  157. end
Add Comment
Please, Sign In to add comment