diff --git a/common/database.cpp b/common/database.cpp index e9fb58dac..a31ea62d1 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -29,6 +29,8 @@ #include #include +#include "../common/repositories/account_repository.h" + // Disgrace: for windows compile #ifdef _WINDOWS #include @@ -1643,25 +1645,20 @@ void Database::ClearGroupLeader(uint32 gid) { std::cout << "Unable to clear group leader: " << results.ErrorMessage() << std::endl; } -uint8 Database::GetAgreementFlag(uint32 acctid) { - - std::string query = StringFormat("SELECT rulesflag FROM account WHERE id=%i",acctid); - auto results = QueryDatabase(query); - - if (!results.Success()) +uint8 Database::GetAgreementFlag(uint32 account_id) +{ + const auto& e = AccountRepository::FindOne(*this, account_id); + if (!e.id) { return 0; + } - if (results.RowCount() != 1) - return 0; - - auto row = results.begin(); - - return Strings::ToUnsignedInt(row[0]); + return e.rulesflag; } -void Database::SetAgreementFlag(uint32 acctid) { - std::string query = StringFormat("UPDATE account SET rulesflag=1 where id=%i", acctid); - QueryDatabase(query); +void Database::SetAgreementFlag(uint32 account_id) { + auto e = AccountRepository::FindOne(*this, account_id); + e.rulesflag = 1; + AccountRepository::UpdateOne(*this, e); } void Database::ClearRaid(uint32 rid) { diff --git a/common/database.h b/common/database.h index ad9e80c7a..65cf07547 100644 --- a/common/database.h +++ b/common/database.h @@ -188,10 +188,10 @@ public: uint32 CheckLogin(const char* name, const char* password, const char *loginserver, int16* oStatus = 0); uint32 CreateAccount(const char* name, const char* password, int16 status, const char* loginserver, uint32 lsaccount_id); uint32 GetAccountIDFromLSID(const std::string& in_loginserver_id, uint32 in_loginserver_account_id, char* in_account_name = 0, int16* in_status = 0); - uint8 GetAgreementFlag(uint32 acctid); + uint8 GetAgreementFlag(uint32 account_id); void GetAccountFromID(uint32 id, char* oAccountName, int16* oStatus); - void SetAgreementFlag(uint32 acctid); + void SetAgreementFlag(uint32 account_id); int GetIPExemption(std::string account_ip); void SetIPExemption(std::string account_ip, int exemption_amount); diff --git a/zone/gm_commands/acceptrules.cpp b/zone/gm_commands/acceptrules.cpp index a73e098a2..4deda24f8 100755 --- a/zone/gm_commands/acceptrules.cpp +++ b/zone/gm_commands/acceptrules.cpp @@ -2,10 +2,12 @@ void command_acceptrules(Client *c, const Seperator *sep) { - if (!database.GetAgreementFlag(c->AccountID())) { - database.SetAgreementFlag(c->AccountID()); - c->SendAppearancePacket(AT_Anim, ANIM_STAND); - c->Message(Chat::White, "It is recorded you have agreed to the rules."); + if (database.GetAgreementFlag(c->AccountID())) { + c->Message(Chat::White, "You have already agreed to the rules."); + return; } -} + database.SetAgreementFlag(c->AccountID()); + c->SendAppearancePacket(AT_Anim, ANIM_STAND); + c->Message(Chat::White, "It is recorded you have agreed to the rules."); +}