Skip to content

Commit

Permalink
Merge ioguild into guild (#3949)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranisalt authored and DSpeichert committed May 9, 2022
1 parent 8c3e171 commit ff54e22
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 111 deletions.
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(tfs_SRC
${CMAKE_CURRENT_LIST_DIR}/house.cpp
${CMAKE_CURRENT_LIST_DIR}/housetile.cpp
${CMAKE_CURRENT_LIST_DIR}/inbox.cpp
${CMAKE_CURRENT_LIST_DIR}/ioguild.cpp
${CMAKE_CURRENT_LIST_DIR}/iologindata.cpp
${CMAKE_CURRENT_LIST_DIR}/iomap.cpp
${CMAKE_CURRENT_LIST_DIR}/iomapserialize.cpp
Expand Down Expand Up @@ -77,4 +76,3 @@ set(tfs_SRC
${CMAKE_CURRENT_LIST_DIR}/wildcardtree.cpp
${CMAKE_CURRENT_LIST_DIR}/xtea.cpp
PARENT_SCOPE)

27 changes: 27 additions & 0 deletions src/guild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,30 @@ void Guild::addRank(uint32_t rankId, const std::string& rankName, uint8_t level)
{
ranks.emplace_back(std::make_shared<GuildRank>(rankId, rankName, level));
}

Guild* IOGuild::loadGuild(uint32_t guildId)
{
Database& db = Database::getInstance();
if (DBResult_ptr result = db.storeQuery(fmt::format("SELECT `name` FROM `guilds` WHERE `id` = {:d}", guildId))) {
Guild* guild = new Guild(guildId, result->getString("name"));

if ((result = db.storeQuery(fmt::format("SELECT `id`, `name`, `level` FROM `guild_ranks` WHERE `guild_id` = {:d}", guildId)))) {
do {
guild->addRank(result->getNumber<uint32_t>("id"), result->getString("name"), result->getNumber<uint16_t>("level"));
} while (result->next());
}
return guild;
}
return nullptr;
}

uint32_t IOGuild::getGuildIdByName(const std::string& name)
{
Database& db = Database::getInstance();

DBResult_ptr result = db.storeQuery(fmt::format("SELECT `id` FROM `guilds` WHERE `name` = {:s}", db.escapeString(name)));
if (!result) {
return 0;
}
return result->getNumber<uint32_t>("id");
}
8 changes: 8 additions & 0 deletions src/guild.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ class Guild
uint32_t memberCount = 0;
};

using GuildWarVector = std::vector<uint32_t>;

namespace IOGuild
{
Guild* loadGuild(uint32_t guildId);
uint32_t getGuildIdByName(const std::string& name);
};

#endif
70 changes: 0 additions & 70 deletions src/ioguild.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions src/ioguild.h

This file was deleted.

22 changes: 20 additions & 2 deletions src/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,25 @@ bool IOLoginData::loadPlayerByName(Player* player, const std::string& name)
return loadPlayer(player, db.storeQuery(fmt::format("SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `blessings`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `conditions`, `skulltime`, `skull`, `town_id`, `balance`, `offlinetraining_time`, `offlinetraining_skill`, `stamina`, `skill_fist`, `skill_fist_tries`, `skill_club`, `skill_club_tries`, `skill_sword`, `skill_sword_tries`, `skill_axe`, `skill_axe_tries`, `skill_dist`, `skill_dist_tries`, `skill_shielding`, `skill_shielding_tries`, `skill_fishing`, `skill_fishing_tries`, `direction` FROM `players` WHERE `name` = {:s}", db.escapeString(name))));
}

static GuildWarVector getWarList(uint32_t guildId)
{
DBResult_ptr result = Database::getInstance().storeQuery(fmt::format("SELECT `guild1`, `guild2` FROM `guild_wars` WHERE (`guild1` = {:d} OR `guild2` = {:d}) AND `ended` = 0 AND `status` = 1", guildId, guildId));
if (!result) {
return {};
}

GuildWarVector guildWarVector;
do {
uint32_t guild1 = result->getNumber<uint32_t>("guild1");
if (guildId != guild1) {
guildWarVector.push_back(guild1);
} else {
guildWarVector.push_back(result->getNumber<uint32_t>("guild2"));
}
} while (result->next());
return std::move(guildWarVector);
}

bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
{
if (!result) {
Expand Down Expand Up @@ -402,8 +421,7 @@ bool IOLoginData::loadPlayer(Player* player, DBResult_ptr result)
}

player->guildRank = rank;

IOGuild::getWarList(guildId, player->guildWarVector);
player->guildWarVector = getWarList(guildId);

if ((result = db.storeQuery(fmt::format("SELECT COUNT(*) AS `members` FROM `guild_membership` WHERE `guild_id` = {:d}", guildId)))) {
guild->setMemberCount(result->getNumber<uint32_t>("members"));
Expand Down
1 change: 0 additions & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "enums.h"
#include "vocation.h"
#include "protocolgame.h"
#include "ioguild.h"
#include "party.h"
#include "inbox.h"
#include "depotchest.h"
Expand Down
2 changes: 0 additions & 2 deletions vc17/theforgottenserver.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
<ClCompile Include="..\src\house.cpp" />
<ClCompile Include="..\src\housetile.cpp" />
<ClCompile Include="..\src\inbox.cpp" />
<ClCompile Include="..\src\ioguild.cpp" />
<ClCompile Include="..\src\iologindata.cpp" />
<ClCompile Include="..\src\iomap.cpp" />
<ClCompile Include="..\src\iomapserialize.cpp" />
Expand Down Expand Up @@ -275,7 +274,6 @@
<ClInclude Include="..\src\house.h" />
<ClInclude Include="..\src\housetile.h" />
<ClInclude Include="..\src\inbox.h" />
<ClInclude Include="..\src\ioguild.h" />
<ClInclude Include="..\src\iologindata.h" />
<ClInclude Include="..\src\iomap.h" />
<ClInclude Include="..\src\iomapserialize.h" />
Expand Down

0 comments on commit ff54e22

Please sign in to comment.