[Commands] Cleanup #acceptrules Command (#3716)

# Note
- Cleanup messages and logic.
- Utilize repositories in database methods.
This commit is contained in:
Alex King 2023-11-26 01:13:08 -05:00 committed by GitHub
parent 93ddffa57f
commit f9f45eedcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 22 deletions

View File

@ -29,6 +29,8 @@
#include <stdlib.h>
#include <string.h>
#include "../common/repositories/account_repository.h"
// Disgrace: for windows compile
#ifdef _WINDOWS
#include <windows.h>
@ -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) {

View File

@ -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);

View File

@ -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.");
}