Advertisement
Ceziy

data.lua

Nov 27th, 2023 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. os.loadAPI("DBApi.lua")
  2.  
  3. db_path = "client_base.txt"
  4.  
  5. while true do
  6.     cl_log_f = io.open("client_logs.txt","a")
  7.     rednet.open("top")
  8.     id, message = rednet.receive()
  9.     temp = {}
  10.     temp = string.gmatch(message, "[^ ]+")
  11.     c = 0
  12.     client_log = "0"
  13.     rec_arr = {call_op = "", card_num = "", row = "", new_val = ""}
  14.     for i in temp do
  15.         if c == 0 then rec_arr.call_op = i
  16.         elseif c == 1 then rec_arr.card_num = i
  17.         elseif c == 2 then rec_arr.row = i
  18.         elseif c == 3 then rec_arr.new_val = i
  19.         end
  20.         c = c + 1
  21.     end
  22.     confirm_atm = false
  23.     for line in io.lines("atms_base.txt") do
  24.         if tostring(id) == line then confirm_atm = true end
  25.     end
  26.     --atm is confirmed
  27.     if confirm_atm == true then
  28.  
  29.         client_arr = DBApi.getDB(rec_arr.card_num)
  30.         --send client info
  31.         if rec_arr.call_op == "client" then
  32.             rednet.send(id, client_arr)
  33.             client_log = tostring(client_arr.name .. "'s info was send to " .. id .. " atm")
  34.         elseif rec_arr.call_op == "edit" then
  35.             if rec_arr.row == "balance" then
  36.                 edited_line = client_arr.num .. " " .. client_arr.name .. " " .. rec_arr.new_val .. " " .. client_arr.pass
  37.                 DBApi.editLine(db_path, tonumber(client_arr.index), tostring(edited_line))  
  38.                 past_bal = client_arr.bal
  39.                 pres_bal =  rec_arr.new_val
  40.                 new_bal_log = ""
  41.  
  42.                 if past_bal < pres_bal then new_bal_log = tostring("+" .. pres_bal - past_bal)
  43.                 elseif pres_bal < past_bal then new_bal_log = tostring("-" .. past_bal - pres_bal)
  44.  
  45.                 end
  46.                
  47.                 client_log = tostring(client_arr.num .. " bal " .. new_bal_log)  
  48.             end
  49.         end
  50.          
  51.        
  52.     --atm isn't confirmed          
  53.     elseif confirm_atm == false then
  54.         client_log = tostring("access denied to atm " .. id)
  55.     end        
  56.    
  57.    
  58.     cl_log_f:write(tostring(client_log .. "\n"))
  59.     print(client_log)
  60.    
  61.     --io.close("atms_base.txt")
  62.     --io.close("client_logs.txt")
  63. end
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement