Rehti MMORPG  1.0.0
Rehti MMORPG is a free and open source MMORPG game.
DatabaseManager.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <pqxx/pqxx>
4 
5 class PlayerCharacter;
6 
7 struct Coordinates;
8 
9 struct PlayerTable
10 {
11  int id;
12  std::string username;
13  std::string password;
16  int hp;
17 };
18 
23 {
24 public:
26 
27  ~DatabaseManager() = default;
28 
33  int createConnection();
34 
42  PlayerTable loadPlayerDataFromDb(std::string username, std::string password, Coordinates spawnCoordinate);
43 
49  std::vector<int> loadInventoryDataFromDb(int playerId);
50 
56  std::vector<int> loadEquipmentDataFromDb(int playerId);
57 
63  std::vector<std::pair<int, int>> loadSkillDataFromDb(int playerId);
64 
70  bool savePlayerToDb(std::shared_ptr<PlayerCharacter> player);
71 
72 private:
77  pqxx::work getTransaction();
78 
79  std::unique_ptr<pqxx::connection> pConnectionM;
80 };
Class for handling database queries.
Definition: DatabaseManager.hpp:23
bool savePlayerToDb(std::shared_ptr< PlayerCharacter > player)
Save player's basic data, items and skills to the database.
Definition: DatabaseManager.cpp:123
~DatabaseManager()=default
std::vector< std::pair< int, int > > loadSkillDataFromDb(int playerId)
Load player's skill data from the database.
Definition: DatabaseManager.cpp:110
pqxx::work getTransaction()
Get a transaction object.
DatabaseManager()
Definition: DatabaseManager.cpp:13
std::vector< int > loadInventoryDataFromDb(int playerId)
Load player's inventory items from the database.
Definition: DatabaseManager.cpp:81
std::vector< int > loadEquipmentDataFromDb(int playerId)
Load player's equipment items from the database.
Definition: DatabaseManager.cpp:97
PlayerTable loadPlayerDataFromDb(std::string username, std::string password, Coordinates spawnCoordinate)
Fetches player basic data from the database (table player) by username. Creates a new player with giv...
Definition: DatabaseManager.cpp:37
std::unique_ptr< pqxx::connection > pConnectionM
Definition: DatabaseManager.hpp:79
int createConnection()
Create connection to the database.
Definition: DatabaseManager.cpp:18
Class for a human player character.
Definition: PlayerCharacter.hpp:12
Struct for coordinates.
Definition: Coordinates.hpp:7
Definition: DatabaseManager.hpp:10
int id
Definition: DatabaseManager.hpp:11
int hp
Definition: DatabaseManager.hpp:16
std::string username
Definition: DatabaseManager.hpp:12
std::string password
Definition: DatabaseManager.hpp:13
int position_y
Definition: DatabaseManager.hpp:15
int position_x
Definition: DatabaseManager.hpp:14