diff --git a/common/repositories/character_data_repository.h b/common/repositories/character_data_repository.h index d95ac2fda..68390fc35 100644 --- a/common/repositories/character_data_repository.h +++ b/common/repositories/character_data_repository.h @@ -191,6 +191,22 @@ public: return character_ids; } + + static uint32_t GetTotalTimePlayed(Database& db, uint32_t account_id) + { + auto query = fmt::format( + "SELECT SUM(time_played) FROM `character_data` WHERE `account_id` = {}", + account_id + ); + + auto results = db.QueryDatabase(query); + if (!results.Success()) { + return 0; + } + + auto row = results.begin(); + return Strings::ToUnsignedInt(row[0]); + } }; #endif //EQEMU_CHARACTER_DATA_REPOSITORY_H diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 4039551fd..5570a1d36 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -122,16 +122,6 @@ bool SharedDatabase::SetGMFlymode(uint32 account_id, uint8 flymode) return a.id > 0; } -uint32 SharedDatabase::GetTotalTimeEntitledOnAccount(uint32 AccountID) { - uint32 EntitledTime = 0; - const std::string query = StringFormat("SELECT `time_played` FROM `character_data` WHERE `account_id` = %u", AccountID); - auto results = QueryDatabase(query); - for (auto& row = results.begin(); row != results.end(); ++row) { - EntitledTime += Strings::ToUnsignedInt(row[0]); - } - return EntitledTime; -} - void SharedDatabase::SetMailKey(int CharID, int IPAddress, int MailKey) { char mail_key[17]; diff --git a/common/shareddb.h b/common/shareddb.h index fa86f859e..bad19eb8e 100644 --- a/common/shareddb.h +++ b/common/shareddb.h @@ -82,7 +82,6 @@ public: bool UpdateInjectedCommandSettings(const std::vector> &injected); bool UpdateOrphanedCommandSettings(const std::vector &orphaned); bool GetCommandSubSettings(std::vector &command_subsettings); - uint32 GetTotalTimeEntitledOnAccount(uint32 AccountID); bool SetGMInvul(uint32 account_id, bool gminvul); bool SetGMFlymode(uint32 account_id, uint8 flymode); void SetMailKey(int CharID, int IPAddress, int MailKey); diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 42f0b8bbe..441b4a538 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -1713,7 +1713,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) if (zone->IsPVPZone()) m_pp.pvp = 1; /* Time entitled on Account: Move to account */ - m_pp.timeentitledonaccount = database.GetTotalTimeEntitledOnAccount(AccountID()) / 1440; + m_pp.timeentitledonaccount = CharacterDataRepository::GetTotalTimePlayed(database, AccountID()) / 1440; /* Reset rest timer if the durations have been lowered in the database */ if ((m_pp.RestTimer > RuleI(Character, RestRegenTimeToActivate)) && (m_pp.RestTimer > RuleI(Character, RestRegenRaidTimeToActivate))) m_pp.RestTimer = 0; @@ -7988,7 +7988,7 @@ void Client::Handle_OP_GuildCreate(const EQApplicationPacket *app) if ((Admin() < RuleI(Guild, PlayerCreationRequiredStatus)) || (GetLevel() < RuleI(Guild, PlayerCreationRequiredLevel)) || - (database.GetTotalTimeEntitledOnAccount(AccountID()) < (unsigned int)RuleI(Guild, PlayerCreationRequiredTime))) + (CharacterDataRepository::GetTotalTimePlayed(database, AccountID()) < (unsigned int)RuleI(Guild, PlayerCreationRequiredTime))) { Message(Chat::Red, "Your status, level or time playing on this account are insufficient to use this feature."); return;