feat(Core/DBLayer): replace char const* to std::string_view (#10211)

* feat(Core/DBLayer): replace `char const*` to `std::string_view`

* CString

* 1

* chore(Core/Misc): code cleanup

* cl

* db fix

* fmt style sql

* to fmt

* py

* del old

* 1

* 2

* 3

* 1

* 1
This commit is contained in:
Kargatum
2022-02-05 06:37:11 +07:00
committed by GitHub
parent d6ead1d1e0
commit de13bf426e
140 changed files with 5055 additions and 4882 deletions

View File

@@ -147,14 +147,14 @@ WorldSession::WorldSession(uint32 id, std::string&& name, std::shared_ptr<WorldS
{
m_Address = sock->GetRemoteIpAddress().to_string();
ResetTimeOutTime(false);
LoginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = %u;", GetAccountId()); // One-time query
LoginDatabase.Execute("UPDATE account SET online = 1 WHERE id = {};", GetAccountId()); // One-time query
}
}
/// WorldSession destructor
WorldSession::~WorldSession()
{
LoginDatabase.PExecute("UPDATE account SET totaltime = %u WHERE id = %u", GetTotalTime(), GetAccountId());
LoginDatabase.Execute("UPDATE account SET totaltime = {} WHERE id = {}", GetTotalTime(), GetAccountId());
///- unload player if not unloaded
if (_player)
@@ -173,7 +173,7 @@ WorldSession::~WorldSession()
delete packet;
if (GetShouldSetOfflineInDB())
LoginDatabase.PExecute("UPDATE account SET online = 0 WHERE id = %u;", GetAccountId()); // One-time query
LoginDatabase.Execute("UPDATE account SET online = 0 WHERE id = {};", GetAccountId()); // One-time query
}
std::string const& WorldSession::GetPlayerName() const
@@ -595,8 +595,8 @@ void WorldSession::LogoutPlayer(bool save)
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS))
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_DESERTER_TRACK);
stmt->setUInt32(0, _player->GetGUID().GetCounter());
stmt->setUInt8(1, BG_DESERTION_TYPE_INVITE_LOGOUT);
stmt->SetData(0, _player->GetGUID().GetCounter());
stmt->SetData(1, BG_DESERTION_TYPE_INVITE_LOGOUT);
CharacterDatabase.Execute(stmt);
}
sScriptMgr->OnBattlegroundDesertion(_player, BG_DESERTION_TYPE_INVITE_LOGOUT);
@@ -694,7 +694,7 @@ void WorldSession::LogoutPlayer(bool save)
//! Since each account can only have one online character at any given time, ensure all characters for active account are marked as offline
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ACCOUNT_ONLINE);
stmt->setUInt32(0, GetAccountId());
stmt->SetData(0, GetAccountId());
CharacterDatabase.Execute(stmt);
}
@@ -831,7 +831,7 @@ void WorldSession::SendAuthWaitQueue(uint32 position)
void WorldSession::LoadGlobalAccountData()
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ACCOUNT_DATA);
stmt->setUInt32(0, GetAccountId());
stmt->SetData(0, GetAccountId());
LoadAccountData(CharacterDatabase.Query(stmt), GLOBAL_CACHE_MASK);
}
@@ -847,7 +847,7 @@ void WorldSession::LoadAccountData(PreparedQueryResult result, uint32 mask)
do
{
Field* fields = result->Fetch();
uint32 type = fields[0].GetUInt8();
uint32 type = fields[0].Get<uint8>();
if (type >= NUM_ACCOUNT_DATA_TYPES)
{
LOG_ERROR("network", "Table `{}` have invalid account data type ({}), ignore.", mask == GLOBAL_CACHE_MASK ? "account_data" : "character_account_data", type);
@@ -860,8 +860,8 @@ void WorldSession::LoadAccountData(PreparedQueryResult result, uint32 mask)
continue;
}
m_accountData[type].Time = time_t(fields[1].GetUInt32());
m_accountData[type].Data = fields[2].GetString();
m_accountData[type].Time = time_t(fields[1].Get<uint32>());
m_accountData[type].Data = fields[2].Get<std::string>();
} while (result->NextRow());
}
@@ -885,10 +885,10 @@ void WorldSession::SetAccountData(AccountDataType type, time_t tm, std::string c
}
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(index);
stmt->setUInt32(0, id);
stmt->setUInt8(1, type);
stmt->setUInt32(2, uint32(tm));
stmt->setString(3, data);
stmt->SetData(0, id);
stmt->SetData(1, type);
stmt->SetData(2, uint32(tm));
stmt->SetData(3, data);
CharacterDatabase.Execute(stmt);
m_accountData[type].Time = tm;
@@ -912,10 +912,10 @@ void WorldSession::LoadTutorialsData()
memset(m_Tutorials, 0, sizeof(uint32) * MAX_ACCOUNT_TUTORIAL_VALUES);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_TUTORIALS);
stmt->setUInt32(0, GetAccountId());
stmt->SetData(0, GetAccountId());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
for (uint8 i = 0; i < MAX_ACCOUNT_TUTORIAL_VALUES; ++i)
m_Tutorials[i] = (*result)[i].GetUInt32();
m_Tutorials[i] = (*result)[i].Get<uint32>();
m_TutorialsChanged = false;
}
@@ -934,14 +934,14 @@ void WorldSession::SaveTutorialsData(CharacterDatabaseTransaction trans)
return;
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_HAS_TUTORIALS);
stmt->setUInt32(0, GetAccountId());
stmt->SetData(0, GetAccountId());
bool hasTutorials = bool(CharacterDatabase.Query(stmt));
stmt = CharacterDatabase.GetPreparedStatement(hasTutorials ? CHAR_UPD_TUTORIALS : CHAR_INS_TUTORIALS);
for (uint8 i = 0; i < MAX_ACCOUNT_TUTORIAL_VALUES; ++i)
stmt->setUInt32(i, m_Tutorials[i]);
stmt->setUInt32(MAX_ACCOUNT_TUTORIAL_VALUES, GetAccountId());
stmt->SetData(i, m_Tutorials[i]);
stmt->SetData(MAX_ACCOUNT_TUTORIAL_VALUES, GetAccountId());
trans->Append(stmt);
m_TutorialsChanged = false;

View File

@@ -48,7 +48,7 @@ void WorldSocket::Start()
std::string ip_address = GetRemoteIpAddress().to_string();
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_INFO);
stmt->setString(0, ip_address);
stmt->SetData(0, ip_address);
_queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSocket::CheckIpCallback, this, std::placeholders::_1)));
}
@@ -61,7 +61,7 @@ void WorldSocket::CheckIpCallback(PreparedQueryResult result)
do
{
Field* fields = result->Fetch();
if (fields[0].GetUInt64() != 0)
if (fields[0].Get<uint64>() != 0)
banned = true;
} while (result->NextRow());
@@ -278,20 +278,20 @@ struct AccountInfo
// LEFT JOIN account_banned ab ON a.id = ab.id
// LEFT JOIN account r ON a.id = r.recruiter
// WHERE a.username = ? ORDER BY aa.RealmID DESC LIMIT 1
Id = fields[0].GetUInt32();
SessionKey = fields[1].GetBinary<SESSION_KEY_LENGTH>();
LastIP = fields[2].GetString();
IsLockedToIP = fields[3].GetBool();
LockCountry = fields[4].GetString();
Expansion = fields[5].GetUInt8();
MuteTime = fields[6].GetInt64();
Locale = LocaleConstant(fields[7].GetUInt8());
Recruiter = fields[8].GetUInt32();
OS = fields[9].GetString();
TotalTime = fields[10].GetUInt32();
Security = AccountTypes(fields[11].GetUInt8());
IsBanned = fields[12].GetUInt64() != 0;
IsRectuiter = fields[13].GetUInt32() != 0;
Id = fields[0].Get<uint32>();
SessionKey = fields[1].Get<Binary, SESSION_KEY_LENGTH>();
LastIP = fields[2].Get<std::string>();
IsLockedToIP = fields[3].Get<bool>();
LockCountry = fields[4].Get<std::string>();
Expansion = fields[5].Get<uint8>();
MuteTime = fields[6].Get<int64>();
Locale = LocaleConstant(fields[7].Get<uint8>());
Recruiter = fields[8].Get<uint32>();
OS = fields[9].Get<std::string>();
TotalTime = fields[10].Get<uint32>();
Security = AccountTypes(fields[11].Get<uint8>());
IsBanned = fields[12].Get<uint64>() != 0;
IsRectuiter = fields[13].Get<uint32>() != 0;
uint32 world_expansion = sWorld->getIntConfig(CONFIG_EXPANSION);
if (Expansion > world_expansion)
@@ -443,8 +443,8 @@ void WorldSocket::HandleAuthSession(WorldPacket & recvPacket)
// Get the account information from the auth database
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME);
stmt->setInt32(0, int32(realm.Id.Realm));
stmt->setString(1, authSession->Account);
stmt->SetData(0, int32(realm.Id.Realm));
stmt->SetData(1, authSession->Account);
_queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSocket::HandleAuthSessionCallback, this, authSession, std::placeholders::_1)));
}
@@ -470,8 +470,8 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
// As we don't know if attempted login process by ip works, we update last_attempt_ip right away
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LAST_ATTEMPT_IP);
stmt->setString(0, address);
stmt->setString(1, authSession->Account);
stmt->SetData(0, address);
stmt->SetData(1, authSession->Account);
LoginDatabase.Execute(stmt);
// This also allows to check for possible "hack" attempts on account
@@ -560,8 +560,8 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
account.MuteTime = GameTime::GetGameTime().count() + llabs(account.MuteTime);
auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME_LOGIN);
stmt->setInt64(0, account.MuteTime);
stmt->setUInt32(1, account.Id);
stmt->SetData(0, account.MuteTime);
stmt->SetData(1, account.Id);
LoginDatabase.Execute(stmt);
}
@@ -590,8 +590,8 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
// Update the last_ip in the database as it was successful for login
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LAST_IP);
stmt->setString(0, address);
stmt->setString(1, authSession->Account);
stmt->SetData(0, address);
stmt->SetData(1, authSession->Account);
LoginDatabase.Execute(stmt);