Hey dude <3,
While coding the system, I was coding it with id but
When I started coding the block list, it occurred to me that not every player I blocked would always be in the game.
Now let's come to the scenarios I would experience if I coded with id.
* I send the list packet when the player teleports. If the blocked player is not in the game, I cannot write their name there. However, if I only saved the id in memory and saved the player's name along with the id in the database, then I would send the packet of the list by pulling it from the database, not from memory. But I didn't want to use the database every time a player teleported. Additionally, if you change a player name, I will need to correct it in the database.
* If a player I want to unblock is not in the game, I will have to query the player table with the player's name in the database and get his id
In short, I did not use id because I wanted to minimize database usage. Can it be used? Yes, it can be used, but with 2-3 database queries.
When I write systems, I always write them in a way that high-player games can use and I think very carefully. That's why it made more sense to me to code it this way, so I preferred to code it with names.
I don't use name changing in my own active game, so I didn't feel the need to do it. But if you use it, just do this ?
// Open player_block.h
// Search:
auto DeletePlayerBlock(const std::string &strBlockingPlayerName, const std::string &strBlockedPlayerName) -> void;
// Add below:
auto ChangeName(const std::string &strOldName, const std::string &strNewName) -> void;
// Open player_block.cpp
// Search:
auto CPlayerBlock::DeletePlayerBlock(const std::string &strBlockingPlayerName, const std::string &strBlockedPlayerName) -> void
{
DBManager::Instance().DirectQuery("DELETE FROM player.player_block_list WHERE blockingplayername = '%s' AND blockedplayername = '%s'", strBlockingPlayerName.c_str(), strBlockedPlayerName.c_str());
}
// Add below:
auto CPlayerBlock::ChangeName(const std::string &strOldName, const std::string &strNewName) -> void
{
auto it = m_map_PlayerBlock.find(strOldName);
if (it != m_map_PlayerBlock.end())
{
m_map_PlayerBlock[strNewName] = std::move(it->second);
m_map_PlayerBlock.erase(it);
}
for (auto &it : m_map_PlayerBlock)
{
auto it2 = it.second.find(strOldName);
if (it2 != it.second.end())
{
it.second.erase(it2);
it.second.emplace(strNewName);
}
}
DBManager::Instance().DirectQuery("UPDATE player.player_block_list SET blockingplayername = '%s' WHERE blockingplayername = '%s'", strNewName.c_str(), strOldName.c_str());
DBManager::Instance().DirectQuery("UPDATE player.player_block_list SET blockedplayername = '%s' WHERE blockedplayername = '%s'", strNewName.c_str(), strOldName.c_str());
sys_log(0, "PLAYER_BLOCK: ChangeName: %s -> %s", strOldName.c_str(), strNewName.c_str());
}
// Open questlua_pc.cpp
// Add includes:
#ifdef ENABLE_PLAYER_BLOCK_SYSTEM
#include "player_block.h"
#endif
// Search:
/* delete messenger list */
MessengerManager::instance().RemoveAllList(ch->GetName());
// Add below:
#ifdef ENABLE_PLAYER_BLOCK_SYSTEM
/* player block list */
CPlayerBlock::Instance().ChangeName(ch->GetName(), szName);
#endif