From 0b10a51a191848e3ad9cec845e76dcf93368754a Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Sun, 20 Jun 2021 21:54:32 -0700 Subject: [PATCH] :sparkles: Return to Reserve Feature --- include/consts.hpp | 6 +++++- src/bank.cpp | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/consts.hpp b/include/consts.hpp index 83fcff0..9545808 100644 --- a/include/consts.hpp +++ b/include/consts.hpp @@ -7,4 +7,8 @@ constexpr unsigned pre_log_size = 10; constexpr unsigned max_name_size = 50; constexpr const char *users_location = "../users.json"; -constexpr const char *config_location = "../config.json"; \ No newline at end of file +constexpr const char *config_location = "../config.json"; + +//returns money to an account on deletion +constexpr bool return_on_del = false; +constexpr const char *return_account = ""; \ No newline at end of file diff --git a/src/bank.cpp b/src/bank.cpp index c2bd211..5015488 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -43,7 +43,16 @@ int_fast8_t Bank::DelUser(const std::string &name, const std::string &attempt) n { std::shared_lock lock{size_l}; bool state = false; - if (users.erase_if(name, [&state, &attempt](User &u) { return state = (XXH3_64bits(attempt.data(), attempt.size()) == u.password); })) + if (users.erase_if(name, [this, &name, &state, &attempt](User &u) { + if constexpr (return_on_del) + { + if (SendFunds(name, return_account, u.balance, attempt) == 1) + { + return true; + } + } + return state = (XXH3_64bits(attempt.data(), attempt.size()) == u.password); + })) { return (state) ? true : ErrorResponse::WrongPassword; } @@ -56,7 +65,16 @@ int_fast8_t Bank::AdminDelUser(const std::string &name, const std::string &attem { std::shared_lock lock{size_l}; bool state = false; - if (users.erase_if(name, [this, &state, &attempt](const User &) { return state = (admin_pass == attempt); })) + if (users.erase_if(name, [this, &name, &state, &attempt](const User &u) { + if constexpr (return_on_del) + { + if (SendFunds(name, return_account, u.balance, attempt) == 1) + { + return true; + } + } + return state = (XXH3_64bits(attempt.data(), attempt.size()) == u.password); + })) { return (state) ? true : ErrorResponse::WrongPassword; }