Skip to content

Commit

Permalink
fix: remove loading of basic info only (#2937)
Browse files Browse the repository at this point in the history
Some database tables are completely deleted to add the "new" one, which
replaces the existing data with empty data. In the future I will make an
improvement to remove the DELETE FROM and come back with the feature.
  • Loading branch information
dudantas authored Oct 3, 2024
1 parent d94e23a commit f2f52cc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ std::shared_ptr<Player> Game::getPlayerByName(const std::string &s, bool allowOf
return nullptr;
}
std::shared_ptr<Player> tmpPlayer = std::make_shared<Player>(nullptr);
if (!IOLoginData::loadPlayerByName(tmpPlayer, s, allowOffline)) {
if (!IOLoginData::loadPlayerByName(tmpPlayer, s)) {
if (!isNewName) {
g_logger().error("Failed to load player {} from database", s);
} else {
Expand Down Expand Up @@ -1014,7 +1014,7 @@ std::shared_ptr<Player> Game::getPlayerByGUID(const uint32_t &guid, bool allowOf
}

std::shared_ptr<Player> tmpPlayer = std::make_shared<Player>(nullptr);
if (!IOLoginData::loadPlayerById(tmpPlayer, guid, false)) {
if (!IOLoginData::loadPlayerById(tmpPlayer, guid)) {
return nullptr;
}
tmpPlayer->setOnline(false);
Expand Down
14 changes: 5 additions & 9 deletions src/io/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,21 @@ void IOLoginData::updateOnlineStatus(uint32_t guid, bool login) {
Database::getInstance().executeQuery(query.str());
}

// The boolean "loadBasicInfoOnly" will deactivate the loading of information that is not relevant to the preload, for example, forge, bosstiary, etc. None of this we need to access if the player is offline
bool IOLoginData::loadPlayerById(std::shared_ptr<Player> player, uint32_t id, bool loadBasicInfoOnly /* = true*/) {
bool IOLoginData::loadPlayerById(std::shared_ptr<Player> player, uint32_t id) {
Database &db = Database::getInstance();
std::ostringstream query;
query << "SELECT * FROM `players` WHERE `id` = " << id;
return loadPlayer(player, db.storeQuery(query.str()), loadBasicInfoOnly);
return loadPlayer(player, db.storeQuery(query.str()));
}

bool IOLoginData::loadPlayerByName(std::shared_ptr<Player> player, const std::string &name, bool loadBasicInfoOnly /* = true*/) {
bool IOLoginData::loadPlayerByName(std::shared_ptr<Player> player, const std::string &name) {
Database &db = Database::getInstance();
std::ostringstream query;
query << "SELECT * FROM `players` WHERE `name` = " << db.escapeString(name);
return loadPlayer(player, db.storeQuery(query.str()), loadBasicInfoOnly);
return loadPlayer(player, db.storeQuery(query.str()));
}

bool IOLoginData::loadPlayer(std::shared_ptr<Player> player, DBResult_ptr result, bool loadBasicInfoOnly /* = false*/) {
bool IOLoginData::loadPlayer(std::shared_ptr<Player> player, DBResult_ptr result) {
if (!result || !player) {
std::string nullptrType = !result ? "Result" : "Player";
g_logger().warn("[{}] - {} is nullptr", __FUNCTION__, nullptrType);
Expand All @@ -117,9 +116,6 @@ bool IOLoginData::loadPlayer(std::shared_ptr<Player> player, DBResult_ptr result
try {
// First
IOLoginDataLoad::loadPlayerBasicInfo(player, result);
if (loadBasicInfoOnly) {
return true;
}

// Blessings load
IOLoginDataLoad::loadPlayerBlessings(player, result);
Expand Down
6 changes: 3 additions & 3 deletions src/io/iologindata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class IOLoginData {
static bool gameWorldAuthentication(const std::string &accountDescriptor, const std::string &sessionOrPassword, std::string &characterName, uint32_t &accountId, bool oldProcotol, const uint32_t ip);
static uint8_t getAccountType(uint32_t accountId);
static void updateOnlineStatus(uint32_t guid, bool login);
static bool loadPlayerById(std::shared_ptr<Player> player, uint32_t id, bool loadBasicInfoOnly = true);
static bool loadPlayerByName(std::shared_ptr<Player> player, const std::string &name, bool loadBasicInfoOnly = true);
static bool loadPlayer(std::shared_ptr<Player> player, DBResult_ptr result, bool loadBasicInfoOnly = false);
static bool loadPlayerById(std::shared_ptr<Player> player, uint32_t id);
static bool loadPlayerByName(std::shared_ptr<Player> player, const std::string &name);
static bool loadPlayer(std::shared_ptr<Player> player, DBResult_ptr result);
static bool savePlayer(std::shared_ptr<Player> player);
static uint32_t getGuidByName(const std::string &name);
static bool getGuidByNameEx(uint32_t &guid, bool &specialVip, std::string &name);
Expand Down
2 changes: 1 addition & 1 deletion src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS
return;
}

if (!IOLoginData::loadPlayerById(player, player->getGUID(), false)) {
if (!IOLoginData::loadPlayerById(player, player->getGUID())) {
g_game().removePlayerUniqueLogin(player);
disconnectClient("Your character could not be loaded.");
g_logger().warn("Player {} could not be loaded", player->getName());
Expand Down

0 comments on commit f2f52cc

Please sign in to comment.