Skip to content

Commit f6a9357

Browse files
fix some warnings
1 parent 47d7766 commit f6a9357

15 files changed

Lines changed: 236 additions & 41 deletions

include/database/DbManager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class DbManager {
4646
void Shutdown();
4747
bool IsInitialized() const { return initialized_; }
4848

49+
std::string EscapeString(const std::string& input);
50+
4951
// Backend Management
5052
bool SaveGameState(const std::string& key, const nlohmann::json& state);
5153
bool SetBackend(DatabaseType type, const nlohmann::json& config);

include/game/LogicCore.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
//#include "config/ConfigManager.hpp"
2222
//#include "logging/Logger.hpp"
2323
#include "database/DbManager.hpp"
24-
//#include "game/RAIIThread.hpp"
24+
25+
#include "game/RAIIThread.hpp"
2526
#include "game/LogicWorld.hpp"
2627
#include "game/LogicEntity.hpp"
28+
29+
//class PlayerManager;
2730
#include "game/PlayerManager.hpp"
2831

29-
class PythonScripting;
30-
class ScriptHotReloader;
32+
//class PythonScripting;
33+
//class ScriptHotReloader;
3134
#include "scripting/PythonScripting.hpp"
3235

3336
class LogicCore {

include/game/LogicWorld.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class LogicWorld {
6060
int GetActiveChunkCount() const { return activeChunkCount_; }
6161
void SaveChunkData();
6262

63+
void SetTimeOfDay(float time); // 0.0 to 1.0
64+
float GetTimeOfDay() const;
65+
6366
private:
6467
LogicWorld();
6568
~LogicWorld();
@@ -80,4 +83,5 @@ class LogicWorld {
8083
// Entity storage
8184
std::unordered_map<uint64_t, std::shared_ptr<GameEntity>> entities_;
8285
mutable std::mutex entitiesMutex_;
86+
std::atomic<float> currentTimeOfDay_{0.0f}; // 0.0 to 1.0
8387
};

include/game/LootItem.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#pragma once
22

3+
#include <algorithm>
34
#include <string>
45
#include <vector>
5-
#include <nlohmann/json.hpp>
6+
67
#include <glm/glm.hpp>
8+
#include <nlohmann/json.hpp>
79

810
enum class LootRarity {
911
COMMON = 0,

include/game/Player.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "game/SkillSystem.hpp"
2424
#include "game/QuestManager.hpp"
2525

26-
class InventorySystem;
27-
class SkillSystem;
26+
//class InventorySystem;
27+
//class SkillSystem;
2828

2929
struct PlayerAttributes {
3030
int strength = 10; // Physical power

include/game/PlayerManager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "logging/Logger.hpp"
2020
#include "network/ConnectionManager.hpp"
2121
#include "network/GameSession.hpp"
22+
#include "utils/Passwords.hpp"
2223

2324
#include "database/DbManager.hpp"
2425
#include "game/RAIIThread.hpp"

include/game/QuestManager.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
#include "logging/Logger.hpp"
2020
#include "config/ConfigManager.hpp"
21-
#include "game/LogicCore.hpp"
21+
22+
//TODO: we need refactor architecture, else it do cyclic include there
23+
//#include "game/LogicCore.hpp"
2224

2325
// =============== Enums ===============
2426

include/game/SkillSystem.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414

1515
#include <nlohmann/json.hpp>
1616

17-
#include "game/PlayerTypes.hpp"
1817
#include "logging/Logger.hpp"
1918
#include "config/ConfigManager.hpp"
20-
21-
2219
#include "database/DbManager.hpp"
2320

21+
#include "game/PlayerTypes.hpp"
22+
2423
enum class SkillType {
2524
ACTIVE = 0,
2625
PASSIVE = 1,

include/utils/Passwords.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <unistd.h>
5+
#include <crypt.h>
6+
7+
namespace Passwords {
8+
9+
inline bool VerifyPassword(const std::string& plain, const std::string& hash) {
10+
// crypt() returns a string starting with the salt (first two characters of hash)
11+
// We assume the hash includes the salt (e.g., "$2y$...")
12+
std::string salt = hash.substr(0, 2); // Not correct for bcrypt – adjust as needed
13+
// Actually, for crypt() the salt is the entire hash up to the last '$'
14+
// Better: use a library that understands the hash format.
15+
// This is a placeholder – you must adapt to your actual hash format.
16+
char* encrypted = crypt(plain.c_str(), hash.c_str());
17+
return encrypted && hash == encrypted;
18+
}
19+
20+
inline std::string HashPassword(const std::string& plain) {
21+
// Generate a random salt (simplified – use a proper random source)
22+
std::string salt = "$2y$10$" + std::to_string(rand()) + std::to_string(rand());
23+
char* hash = crypt(plain.c_str(), salt.c_str());
24+
return hash ? std::string(hash) : "";
25+
}
26+
27+
} // namespace Passwords

src/database/DbManager.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,18 @@ bool DbManager::SetBackend(DatabaseType type, const nlohmann::json& config) {
259259
return true;
260260
}
261261

262+
std::string DbManager::EscapeString(const std::string& input) {
263+
// Use your database client's escaping function.
264+
// For PostgreSQL via libpq, you might use PQescapeLiteral.
265+
// For simplicity, this example doubles single quotes.
266+
std::string escaped;
267+
for (char c : input) {
268+
if (c == '\'') escaped += "''";
269+
else escaped += c;
270+
}
271+
return escaped;
272+
}
273+
262274
bool DbManager::SaveGameState(const std::string& key, const nlohmann::json& state) {
263275
return backend_->SaveGameState(key, state);
264276
}

0 commit comments

Comments
 (0)