[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 <stdlib.h>
#include <string.h> #include <string.h>
#include "../common/repositories/account_repository.h"
// Disgrace: for windows compile // Disgrace: for windows compile
#ifdef _WINDOWS #ifdef _WINDOWS
#include <windows.h> #include <windows.h>
@ -1643,25 +1645,20 @@ void Database::ClearGroupLeader(uint32 gid) {
std::cout << "Unable to clear group leader: " << results.ErrorMessage() << std::endl; std::cout << "Unable to clear group leader: " << results.ErrorMessage() << std::endl;
} }
uint8 Database::GetAgreementFlag(uint32 acctid) { uint8 Database::GetAgreementFlag(uint32 account_id)
{
std::string query = StringFormat("SELECT rulesflag FROM account WHERE id=%i",acctid); const auto& e = AccountRepository::FindOne(*this, account_id);
auto results = QueryDatabase(query); if (!e.id) {
if (!results.Success())
return 0; return 0;
}
if (results.RowCount() != 1) return e.rulesflag;
return 0;
auto row = results.begin();
return Strings::ToUnsignedInt(row[0]);
} }
void Database::SetAgreementFlag(uint32 acctid) { void Database::SetAgreementFlag(uint32 account_id) {
std::string query = StringFormat("UPDATE account SET rulesflag=1 where id=%i", acctid); auto e = AccountRepository::FindOne(*this, account_id);
QueryDatabase(query); e.rulesflag = 1;
AccountRepository::UpdateOne(*this, e);
} }
void Database::ClearRaid(uint32 rid) { 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 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 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); 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 GetAccountFromID(uint32 id, char* oAccountName, int16* oStatus);
void SetAgreementFlag(uint32 acctid); void SetAgreementFlag(uint32 account_id);
int GetIPExemption(std::string account_ip); int GetIPExemption(std::string account_ip);
void SetIPExemption(std::string account_ip, int exemption_amount); void SetIPExemption(std::string account_ip, int exemption_amount);

View File

@ -2,10 +2,12 @@
void command_acceptrules(Client *c, const Seperator *sep) void command_acceptrules(Client *c, const Seperator *sep)
{ {
if (!database.GetAgreementFlag(c->AccountID())) { if (database.GetAgreementFlag(c->AccountID())) {
database.SetAgreementFlag(c->AccountID()); c->Message(Chat::White, "You have already agreed to the rules.");
c->SendAppearancePacket(AT_Anim, ANIM_STAND); return;
c->Message(Chat::White, "It is recorded you have agreed to the rules.");
} }
}
database.SetAgreementFlag(c->AccountID());
c->SendAppearancePacket(AT_Anim, ANIM_STAND);
c->Message(Chat::White, "It is recorded you have agreed to the rules.");
}