Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("DBApi.lua")
- db_path = "client_base.txt"
- while true do
- cl_log_f = io.open("client_logs.txt","a")
- rednet.open("top")
- id, message = rednet.receive()
- temp = {}
- temp = string.gmatch(message, "[^ ]+")
- c = 0
- client_log = "0"
- rec_arr = {call_op = "", card_num = "", row = "", new_val = ""}
- for i in temp do
- if c == 0 then rec_arr.call_op = i
- elseif c == 1 then rec_arr.card_num = i
- elseif c == 2 then rec_arr.row = i
- elseif c == 3 then rec_arr.new_val = i
- end
- c = c + 1
- end
- confirm_atm = false
- for line in io.lines("atms_base.txt") do
- if tostring(id) == line then confirm_atm = true end
- end
- --atm is confirmed
- if confirm_atm == true then
- client_arr = DBApi.getDB(rec_arr.card_num)
- --send client info
- if rec_arr.call_op == "client" then
- rednet.send(id, client_arr)
- client_log = tostring(client_arr.name .. "'s info was send to " .. id .. " atm")
- elseif rec_arr.call_op == "edit" then
- if rec_arr.row == "balance" then
- edited_line = client_arr.num .. " " .. client_arr.name .. " " .. rec_arr.new_val .. " " .. client_arr.pass
- DBApi.editLine(db_path, tonumber(client_arr.index), tostring(edited_line))
- past_bal = client_arr.bal
- pres_bal = rec_arr.new_val
- new_bal_log = ""
- if past_bal < pres_bal then new_bal_log = tostring("+" .. pres_bal - past_bal)
- elseif pres_bal < past_bal then new_bal_log = tostring("-" .. past_bal - pres_bal)
- end
- client_log = tostring(client_arr.num .. " bal " .. new_bal_log)
- end
- end
- --atm isn't confirmed
- elseif confirm_atm == false then
- client_log = tostring("access denied to atm " .. id)
- end
- cl_log_f:write(tostring(client_log .. "\n"))
- print(client_log)
- --io.close("atms_base.txt")
- --io.close("client_logs.txt")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement