fix
This commit is contained in:
64
src/character_creation_worker.h
Normal file
64
src/character_creation_worker.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "worker.h"
|
||||
#include <random>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class CharacterCreationWorker : public Worker {
|
||||
public:
|
||||
CharacterCreationWorker(ConnectionPool &pool, MessageBroker &broker);
|
||||
~CharacterCreationWorker() override;
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
std::mt19937 gen;
|
||||
std::uniform_int_distribution<int> dist;
|
||||
std::unordered_map<std::string, std::unordered_set<int>> first_name_cache;
|
||||
std::unordered_set<int> last_name_cache;
|
||||
|
||||
bool isPreviousDayCharacterCreated();
|
||||
void createCharactersForToday();
|
||||
void createCharactersForRegion(int region_id);
|
||||
void createCharacter(int region_id, const std::string &gender, int title_of_nobility);
|
||||
std::vector<int> getTownRegionIds();
|
||||
void loadNames();
|
||||
int getRandomFromSet(const std::unordered_set<int> &name_set);
|
||||
|
||||
static constexpr const char *QUERY_IS_PREVIOUS_DAY_CHARACTER_CREATED = R"(
|
||||
SELECT created_at
|
||||
FROM falukant_data."character"
|
||||
WHERE user_id IS NULL
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1;
|
||||
)";
|
||||
|
||||
static constexpr const char *QUERY_GET_TOWN_REGION_IDS = R"(
|
||||
SELECT fdr.id
|
||||
FROM falukant_data.region fdr
|
||||
JOIN falukant_type.region ftr ON fdr.region_type_id = ftr.id
|
||||
WHERE ftr.label_tr = 'city';
|
||||
)";
|
||||
|
||||
static constexpr const char *QUERY_LOAD_FIRST_NAMES = R"(
|
||||
SELECT id, gender
|
||||
FROM falukant_predefine.firstname;
|
||||
)";
|
||||
|
||||
static constexpr const char *QUERY_LOAD_LAST_NAMES = R"(
|
||||
SELECT id
|
||||
FROM falukant_predefine.lastname;
|
||||
)";
|
||||
|
||||
static constexpr const char *QUERY_INSERT_CHARACTER = R"(
|
||||
INSERT INTO falukant_data."character"(
|
||||
user_id, region_id, first_name, last_name,
|
||||
birthdate, gender, created_at, updated_at, title_of_nobility
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, NOW(), $5, NOW(), NOW(), $6);
|
||||
)";
|
||||
};
|
||||
Reference in New Issue
Block a user