Add persistent cross-game player bank (Refs #3)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace utils::bank
|
||||
{
|
||||
struct report { std::string id, decision, body; };
|
||||
struct acknowledgement
|
||||
{
|
||||
bool valid = false;
|
||||
std::string state, code, id;
|
||||
int amount = 0, balance = 0;
|
||||
};
|
||||
acknowledgement parse_acknowledgement(const std::string& response);
|
||||
// One game-thread writer; cancel intent is replaced by commit before points move.
|
||||
class outbox
|
||||
{
|
||||
public:
|
||||
outbox(std::filesystem::path root, std::string server, std::string endpoint);
|
||||
std::vector<report> load() const;
|
||||
void store(const std::string& body) const;
|
||||
void erase(const std::string& id) const;
|
||||
private:
|
||||
std::filesystem::path file_;
|
||||
std::string server_, endpoint_;
|
||||
report decode(const std::string& body) const;
|
||||
void save(const std::vector<report>& reports) const;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user