[Repositories] Convert Mail Key to Repositories (#5007)

* [Repositories] Convert Mail Key to Repositories

* Update shareddb.cpp

---------

Co-authored-by: JJ <3617814+joligario@users.noreply.github.com>
This commit is contained in:
Alex King 2025-09-15 14:23:48 -04:00 committed by GitHub
parent 0bbb5b90e7
commit 044b9c1420
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 41 deletions

View File

@ -122,56 +122,37 @@ bool SharedDatabase::SetGMFlymode(uint32 account_id, uint8 flymode)
return a.id > 0; return a.id > 0;
} }
void SharedDatabase::SetMailKey(int CharID, int IPAddress, int MailKey) void SharedDatabase::SetMailKey(uint32 character_id, int ip_address, int mail_key)
{ {
char mail_key[17]; std::string full_mail_key;
if (RuleB(Chat, EnableMailKeyIPVerification) == true) { if (RuleB(Chat, EnableMailKeyIPVerification)) {
sprintf(mail_key, "%08X%08X", IPAddress, MailKey); full_mail_key = fmt::format("{:08X}{:08X}", ip_address, mail_key);
} } else {
else { full_mail_key = fmt::format("{:08X}", mail_key);
sprintf(mail_key, "%08X", MailKey);
} }
const std::string query = StringFormat( auto e = CharacterDataRepository::FindOne(*this, character_id);
"UPDATE character_data SET mailkey = '%s' WHERE id = '%i'",
mail_key, CharID
);
const auto results = QueryDatabase(query); e.mailkey = full_mail_key;
if (!results.Success()) {
LogError("SharedDatabase::SetMailKey({}, {}) : {}", CharID, mail_key, results.ErrorMessage().c_str()); if (!CharacterDataRepository::UpdateOne(*this, e)) {
LogError("Failed to set mailkey to [{}] for character_id [{}]", full_mail_key, character_id);
} }
} }
SharedDatabase::MailKeys SharedDatabase::GetMailKey(int character_id) SharedDatabase::MailKeys SharedDatabase::GetMailKey(uint32 character_id)
{ {
const std::string query = StringFormat("SELECT `mailkey` FROM `character_data` WHERE `id`='%i' LIMIT 1", character_id); auto e = CharacterDataRepository::FindOne(*this, character_id);
auto results = QueryDatabase(query);
if (!results.Success()) {
return MailKeys{};
}
if (!results.RowCount()) { if (!e.id) {
Log(Logs::General, return MailKeys{ };
Logs::ClientLogin,
"Error: Mailkey for character id [%i] does not exist or could not be found",
character_id
);
return MailKeys{};
} }
auto &row = results.begin();
if (row != results.end()) {
std::string mail_key = row[0];
return MailKeys{ return MailKeys{
.mail_key = mail_key.substr(8), .mail_key = e.mailkey.substr(8),
.mail_key_full = mail_key .mail_key_full = e.mailkey
}; };
}
return MailKeys{};
} }
bool SharedDatabase::SaveCursor( bool SharedDatabase::SaveCursor(

View File

@ -84,12 +84,12 @@ public:
bool GetCommandSubSettings(std::vector<CommandSubsettingsRepository::CommandSubsettings> &command_subsettings); bool GetCommandSubSettings(std::vector<CommandSubsettingsRepository::CommandSubsettings> &command_subsettings);
bool SetGMInvul(uint32 account_id, bool gminvul); bool SetGMInvul(uint32 account_id, bool gminvul);
bool SetGMFlymode(uint32 account_id, uint8 flymode); bool SetGMFlymode(uint32 account_id, uint8 flymode);
void SetMailKey(int CharID, int IPAddress, int MailKey); void SetMailKey(uint32 character_id, int ip_address, int mail_key);
struct MailKeys { struct MailKeys {
std::string mail_key; std::string mail_key;
std::string mail_key_full; std::string mail_key_full;
}; };
MailKeys GetMailKey(int character_id); MailKeys GetMailKey(uint32 character_id);
bool SaveCursor( bool SaveCursor(
uint32 char_id, uint32 char_id,
std::list<EQ::ItemInstance *>::const_iterator &start, std::list<EQ::ItemInstance *>::const_iterator &start,