mirror of
https://github.com/EQEmu/Server.git
synced 2026-01-03 06:23:53 +00:00
[Performance] Mail key is now cached during player load (#3339)
* [Performance] Mail key is now cached during player load * More refactoring
This commit is contained in:
parent
93a4153a4b
commit
dbc6346fe8
@ -133,55 +133,54 @@ uint32 SharedDatabase::GetTotalTimeEntitledOnAccount(uint32 AccountID) {
|
||||
|
||||
void SharedDatabase::SetMailKey(int CharID, int IPAddress, int MailKey)
|
||||
{
|
||||
char MailKeyString[17];
|
||||
char mail_key[17];
|
||||
|
||||
if (RuleB(Chat, EnableMailKeyIPVerification) == true)
|
||||
sprintf(MailKeyString, "%08X%08X", IPAddress, MailKey);
|
||||
else
|
||||
sprintf(MailKeyString, "%08X", MailKey);
|
||||
if (RuleB(Chat, EnableMailKeyIPVerification) == true) {
|
||||
sprintf(mail_key, "%08X%08X", IPAddress, MailKey);
|
||||
}
|
||||
else {
|
||||
sprintf(mail_key, "%08X", MailKey);
|
||||
}
|
||||
|
||||
const std::string query = StringFormat("UPDATE character_data SET mailkey = '%s' WHERE id = '%i'",
|
||||
MailKeyString, CharID);
|
||||
const auto results = QueryDatabase(query);
|
||||
if (!results.Success())
|
||||
LogError("SharedDatabase::SetMailKey({}, {}) : {}", CharID, MailKeyString, results.ErrorMessage().c_str());
|
||||
const std::string query = StringFormat(
|
||||
"UPDATE character_data SET mailkey = '%s' WHERE id = '%i'",
|
||||
mail_key, CharID
|
||||
);
|
||||
|
||||
const auto results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
LogError("SharedDatabase::SetMailKey({}, {}) : {}", CharID, mail_key, results.ErrorMessage().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::string SharedDatabase::GetMailKey(int CharID, bool key_only)
|
||||
SharedDatabase::MailKeys SharedDatabase::GetMailKey(int character_id)
|
||||
{
|
||||
const std::string query = StringFormat("SELECT `mailkey` FROM `character_data` WHERE `id`='%i' LIMIT 1", CharID);
|
||||
auto results = QueryDatabase(query);
|
||||
|
||||
const std::string query = StringFormat("SELECT `mailkey` FROM `character_data` WHERE `id`='%i' LIMIT 1", character_id);
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
|
||||
Log(Logs::Detail, Logs::MySQLError, "Error retrieving mailkey from database: %s", results.ErrorMessage().c_str());
|
||||
return std::string();
|
||||
return MailKeys{};
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
|
||||
Log(Logs::General, Logs::ClientLogin, "Error: Mailkey for character id [%i] does not exist or could not be found", CharID);
|
||||
return std::string();
|
||||
Log(Logs::General,
|
||||
Logs::ClientLogin,
|
||||
"Error: Mailkey for character id [%i] does not exist or could not be found",
|
||||
character_id
|
||||
);
|
||||
return MailKeys{};
|
||||
}
|
||||
|
||||
auto& row = results.begin();
|
||||
auto &row = results.begin();
|
||||
if (row != results.end()) {
|
||||
|
||||
std::string mail_key = row[0];
|
||||
|
||||
if (mail_key.length() > 8 && key_only) {
|
||||
return mail_key.substr(8);
|
||||
}
|
||||
else {
|
||||
return mail_key;
|
||||
}
|
||||
return MailKeys{
|
||||
.mail_key = mail_key.substr(8),
|
||||
.mail_key_full = mail_key
|
||||
};
|
||||
}
|
||||
else {
|
||||
|
||||
Log(Logs::General, Logs::MySQLError, "Internal MySQL error in SharedDatabase::GetMailKey(int, bool)");
|
||||
return std::string();
|
||||
}
|
||||
return MailKeys{};
|
||||
}
|
||||
|
||||
bool SharedDatabase::SaveCursor(uint32 char_id, std::list<EQ::ItemInstance*>::const_iterator &start, std::list<EQ::ItemInstance*>::const_iterator &end)
|
||||
|
||||
@ -81,7 +81,11 @@ public:
|
||||
bool SetGMInvul(uint32 account_id, bool gminvul);
|
||||
bool SetGMFlymode(uint32 account_id, uint8 flymode);
|
||||
void SetMailKey(int CharID, int IPAddress, int MailKey);
|
||||
std::string GetMailKey(int CharID, bool key_only = false);
|
||||
struct MailKeys {
|
||||
std::string mail_key;
|
||||
std::string mail_key_full;
|
||||
};
|
||||
MailKeys GetMailKey(int character_id);
|
||||
bool SaveCursor(
|
||||
uint32 char_id,
|
||||
std::list<EQ::ItemInstance *>::const_iterator &start,
|
||||
|
||||
@ -11238,7 +11238,7 @@ void Client::ReconnectUCS()
|
||||
{
|
||||
EQApplicationPacket *outapp = nullptr;
|
||||
std::string buffer;
|
||||
std::string mail_key = database.GetMailKey(CharacterID(), true);
|
||||
std::string mail_key = m_mail_key;
|
||||
EQ::versions::UCSVersion connection_type = EQ::versions::ucsUnknown;
|
||||
|
||||
// chat server packet
|
||||
|
||||
@ -2038,6 +2038,13 @@ private:
|
||||
bool CanTradeFVNoDropItem();
|
||||
void SendMobPositions();
|
||||
void PlayerTradeEventLog(Trade *t, Trade *t2);
|
||||
|
||||
// full and partial mail key cache
|
||||
std::string m_mail_key_full;
|
||||
std::string m_mail_key;
|
||||
public:
|
||||
const std::string &GetMailKeyFull() const;
|
||||
const std::string &GetMailKey() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -1267,6 +1267,12 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app)
|
||||
database.LoadCharacterLeadershipAA(cid, &m_pp); /* Load Character Leadership AA's */
|
||||
database.LoadCharacterTribute(cid, &m_pp); /* Load CharacterTribute */
|
||||
|
||||
// this pattern is strange
|
||||
// this is remnants of the old way of doing things
|
||||
auto mail_keys = database.GetMailKey(CharacterID());
|
||||
m_mail_key_full = mail_keys.mail_key_full;
|
||||
m_mail_key = mail_keys.mail_key;
|
||||
|
||||
/* Load AdventureStats */
|
||||
AdventureStats_Struct as;
|
||||
if (database.GetAdventureStats(cid, &as))
|
||||
@ -11677,7 +11683,7 @@ void Client::Handle_OP_QueryUCSServerStatus(const EQApplicationPacket *app)
|
||||
EQApplicationPacket* outapp = nullptr;
|
||||
std::string buffer;
|
||||
|
||||
std::string MailKey = database.GetMailKey(CharacterID(), true);
|
||||
std::string MailKey = GetMailKey();
|
||||
EQ::versions::UCSVersion ConnectionType = EQ::versions::ucsUnknown;
|
||||
|
||||
// chat server packet
|
||||
|
||||
@ -3018,3 +3018,13 @@ void Client::BuyerItemSearch(const EQApplicationPacket *app) {
|
||||
QueuePacket(outapp);
|
||||
safe_delete(outapp);
|
||||
}
|
||||
|
||||
const std::string &Client::GetMailKeyFull() const
|
||||
{
|
||||
return m_mail_key_full;
|
||||
}
|
||||
|
||||
const std::string &Client::GetMailKey() const
|
||||
{
|
||||
return m_mail_key;
|
||||
}
|
||||
|
||||
@ -1132,8 +1132,6 @@ bool ZoneDatabase::SaveCharacterData(
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto mail_key = database.GetMailKey(c->CharacterID());
|
||||
|
||||
clock_t t = std::clock(); /* Function timer start */
|
||||
const auto query = fmt::format(
|
||||
"REPLACE INTO `character_data` ("
|
||||
@ -1427,7 +1425,7 @@ bool ZoneDatabase::SaveCharacterData(
|
||||
m_epp->perAA,
|
||||
m_epp->expended_aa,
|
||||
m_epp->last_invsnapshot_time,
|
||||
mail_key.c_str()
|
||||
c->GetMailKeyFull()
|
||||
);
|
||||
auto results = database.QueryDatabase(query);
|
||||
LogDebug(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user