Skip to content

Commit

Permalink
fix: circular inclusion related to network/protocol/connection (#2924)
Browse files Browse the repository at this point in the history
Bug Fixes and Improvements

• Fixed a minor bug in the unit test.
• Improved the tests build and run scripts.
• Removed all redundant pch.hpp includes from the .cpp files as the
directive ```target_precompile_headers(${PROJECT_NAME}_lib PUBLIC
pch.hpp)``` now handles that automatically.
• Added the precompiled file correctly in the visual studio solution
• Resolved several circular dependencies involving the following
components:
- Connection
- KV
- Protocol
  • Loading branch information
dudantas committed Sep 29, 2024
1 parent 899c1eb commit e938b75
Show file tree
Hide file tree
Showing 198 changed files with 486 additions and 674 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ option(RUN_TESTS_AFTER_BUILD "Run tests when building" OFF) # By default, tests
# *****************************************************************************
add_subdirectory(src)

if(BUILD_TESTS)
if(BUILD_TESTS OR PACKAGE_TESTS)
add_subdirectory(tests)
endif()
4 changes: 1 addition & 3 deletions cmake/modules/CanaryLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ add_subdirectory(utils)
target_sources(${PROJECT_NAME}_lib PRIVATE canary_server.cpp)

# Add public pre compiler header to lib, to pass down to related targets
if (NOT SPEED_UP_BUILD_UNITY)
target_precompile_headers(${PROJECT_NAME}_lib PUBLIC pch.hpp)
endif()
target_precompile_headers(${PROJECT_NAME}_lib PUBLIC pch.hpp)

if(NOT SPEED_UP_BUILD_UNITY AND USE_PRECOMPILED_HEADERS)
target_compile_definitions(${PROJECT_NAME}_lib PUBLIC -DUSE_PRECOMPILED_HEADERS)
Expand Down
2 changes: 0 additions & 2 deletions src/account/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "account/account.hpp"

#include "account/account_repository_db.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/account/account_repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "account/account_repository.hpp"

#include "lib/di/container.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/account/account_repository_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "account/account_repository_db.hpp"

#include "database/database.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "canary_server.hpp"

#include "declarations.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "config/configmanager.hpp"
#include "lib/di/container.hpp"
#include "game/game.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/appearance/mounts/mounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/appearance/mounts/mounts.hpp"
#include "game/game.hpp"
#include "utils/pugicast.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/appearance/outfit/outfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/appearance/outfit/outfit.hpp"
#include "utils/pugicast.hpp"
#include "utils/tools.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "declarations.hpp"
#include "creatures/combat/combat.hpp"
#include "lua/creature/events.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/combat/condition.hpp"
#include "game/game.hpp"
#include "game/scheduling/dispatcher.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/combat/combat.hpp"
#include "creatures/combat/spells.hpp"
#include "creatures/monsters/monster.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/creature.hpp"
#include "declarations.hpp"
#include "game/scheduling/dispatcher.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/interactions/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/interactions/chat.hpp"
#include "game/game.hpp"
#include "utils/pugicast.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/monsters/monster.hpp"
#include "creatures/combat/spells.hpp"
#include "creatures/players/wheel/player_wheel.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/monsters/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/monsters/monsters.hpp"

#include "creatures/combat/spells.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/monsters/spawns/spawn_monster.hpp"
#include "game/game.hpp"
#include "creatures/monsters/monster.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/npcs/npc.hpp"
#include "creatures/npcs/npcs.hpp"
#include "declarations.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/npcs/npcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "declarations.hpp"
#include "creatures/combat/combat.hpp"
#include "lua/scripts/lua_environment.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/npcs/spawns/spawn_npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/npcs/spawns/spawn_npc.hpp"
#include "creatures/npcs/npc.hpp"
#include "game/game.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/achievement/player_achievement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "player_achievement.hpp"

#include "creatures/players/player.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/cyclopedia/player_badge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "player_badge.hpp"

#include "creatures/players/player.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/cyclopedia/player_cyclopedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "player_cyclopedia.hpp"

#include "database/databasetasks.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "player_title.hpp"

#include "creatures/players/player.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/grouping/familiars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/players/grouping/familiars.hpp"
#include "lib/di/container.hpp"
#include "config/configmanager.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/grouping/groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "config/configmanager.hpp"
#include "game/game.hpp"
#include "creatures/players/grouping/groups.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/grouping/guild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/players/grouping/guild.hpp"
#include "game/game.hpp"

Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/grouping/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

#include <utility>

#include "pch.hpp"

#include "creatures/players/grouping/party.hpp"
#include "game/game.hpp"
#include "lua/creature/events.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/creatures/players/imbuements/imbuements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"
#include "creatures/players/imbuements/imbuements.hpp"
#include "lua/creature/events.hpp"
#include "utils/pugicast.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/management/ban.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/players/management/ban.hpp"
#include "database/database.hpp"
#include "database/databasetasks.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/management/waitlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/players/management/waitlist.hpp"
#include "game/game.hpp"

Expand Down
6 changes: 3 additions & 3 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/combat/combat.hpp"
#include "creatures/interactions/chat.hpp"
#include "creatures/monsters/monster.hpp"
Expand Down Expand Up @@ -6206,7 +6204,9 @@ void Player::sendIcons() {
// Remove the last icon so that Bakragore's is added
auto iconSet = getClientIcons();
if (iconSet.size() >= 9 && iconBakragore != IconBakragore::None) {
iconSet.erase(std::prev(iconSet.end()));
std::vector<PlayerIcon> tempVector(iconSet.begin(), iconSet.end());
tempVector.pop_back();
iconSet = std::unordered_set<PlayerIcon>(tempVector.begin(), tempVector.end());
}

client->sendIcons(iconSet, iconBakragore);
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/storages/storages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/players/storages/storages.hpp"

#include "config/configmanager.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/vip/player_vip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/players/vip/player_vip.hpp"

#include "io/iologindata.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/players/vocations/vocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/players/vocations/vocation.hpp"

#include "utils/pugicast.hpp"
Expand Down
52 changes: 47 additions & 5 deletions src/creatures/players/wheel/player_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
* Website: https://docs.opentibiabr.org/
*/

#include "pch.hpp"

#include "creatures/players/wheel/player_wheel.hpp"

#include "config/configmanager.hpp"
#include "io/io_wheel.hpp"

#include "game/game.hpp"
#include "server/network/message/networkmessage.hpp"
#include "creatures/players/player.hpp"
#include "creatures/combat/spells.hpp"

#include "config/configmanager.hpp"
#include "kv/kv.hpp"
#include "creatures/players/wheel/wheel_gems.hpp"

const static std::vector<WheelGemBasicModifier_t> wheelGemBasicSlot1Allowed = {
WheelGemBasicModifier_t::General_FireResistance,
Expand Down Expand Up @@ -3151,3 +3150,46 @@ WheelGemBasicModifier_t PlayerWheel::selectBasicModifier2(WheelGemBasicModifier_
}
return modifier;
}

void PlayerWheelGem::save(const std::shared_ptr<KV> &kv) const {
kv->scoped("revealed")->set(uuid, serialize());
}
void PlayerWheelGem::remove(const std::shared_ptr<KV> &kv) const {
kv->scoped("revealed")->remove(uuid);
}

PlayerWheelGem PlayerWheelGem::load(const std::shared_ptr<KV> &kv, const std::string &uuid) {
auto val = kv->scoped("revealed")->get(uuid);
if (!val || !val.has_value()) {
return {};
}
return deserialize(uuid, val.value());
}

ValueWrapper PlayerWheelGem::serialize() const {
return {
{ "uuid", uuid },
{ "locked", locked },
{ "affinity", static_cast<IntType>(affinity) },
{ "quality", static_cast<IntType>(quality) },
{ "basicModifier1", static_cast<IntType>(basicModifier1) },
{ "basicModifier2", static_cast<IntType>(basicModifier2) },
{ "supremeModifier", static_cast<IntType>(supremeModifier) }
};
}

PlayerWheelGem PlayerWheelGem::deserialize(const std::string &uuid, const ValueWrapper &val) {
auto map = val.get<MapType>();
if (map.empty()) {
return {};
}
return {
uuid,
map["locked"]->get<BooleanType>(),
static_cast<WheelGemAffinity_t>(map["affinity"]->get<IntType>()),
static_cast<WheelGemQuality_t>(map["quality"]->get<IntType>()),
static_cast<WheelGemBasicModifier_t>(map["basicModifier1"]->get<IntType>()),
static_cast<WheelGemBasicModifier_t>(map["basicModifier2"]->get<IntType>()),
static_cast<WheelGemSupremeModifier_t>(map["supremeModifier"]->get<IntType>())
};
}
Loading

0 comments on commit e938b75

Please sign in to comment.