init
This commit is contained in:
commit
b887f15662
21 changed files with 1038 additions and 0 deletions
42
include/DatabaseManager.h
Normal file
42
include/DatabaseManager.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/awaitable.hpp>
|
||||
#include <boost/mysql.hpp>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
||||
class DatabaseManager {
|
||||
public:
|
||||
static DatabaseManager &GetInstance();
|
||||
|
||||
bool Init(boost::asio::io_context &io_context, const std::string &host,
|
||||
uint16_t port, const std::string &user, const std::string &password,
|
||||
const std::string &db);
|
||||
|
||||
struct UserData {
|
||||
std::string nickname;
|
||||
uint64_t gold;
|
||||
uint32_t swordLevel;
|
||||
};
|
||||
|
||||
boost::asio::awaitable<UserData> LoadUser(std::string nickname);
|
||||
boost::asio::awaitable<void> SaveUser(std::string nickname, uint64_t gold,
|
||||
uint32_t swordLevel);
|
||||
|
||||
private:
|
||||
DatabaseManager() = default;
|
||||
|
||||
// 비동기 Mutex 역할을 할 함수들
|
||||
boost::asio::awaitable<void> Lock();
|
||||
void Unlock();
|
||||
|
||||
std::unique_ptr<boost::mysql::tcp_ssl_connection> conn_;
|
||||
std::unique_ptr<boost::asio::strand<boost::asio::io_context::executor_type>>
|
||||
strand_;
|
||||
|
||||
// 비동기 락 시스템을 위한 상태 변수
|
||||
bool is_locked_ = false;
|
||||
std::queue<std::shared_ptr<boost::asio::steady_timer>> waiting_queue_;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue