mirror of
https://github.com/EQEmu/Server.git
synced 2026-02-22 02:12:26 +00:00
[Account] Convert Get/Update Account Karma to Repositories (#3858)
* [Account] Convert Get/Update Account Karma to Repositories - Convert `GetKarma` and `UpdateKarma` to repositories. * Update zonedb.cpp
This commit is contained in:
parent
a724e92638
commit
b288202c96
@ -6,7 +6,7 @@
|
||||
* Any modifications to base repositories are to be made by the generator only
|
||||
*
|
||||
* @generator ./utils/scripts/generators/repository-generator.pl
|
||||
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories
|
||||
* @docs https://docs.eqemu.io/developer/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_ACCOUNT_REPOSITORY_H
|
||||
@ -16,6 +16,7 @@
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
class BaseAccountRepository {
|
||||
public:
|
||||
struct Account {
|
||||
@ -196,8 +197,9 @@ public:
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
account_id
|
||||
)
|
||||
);
|
||||
@ -547,6 +549,108 @@ public:
|
||||
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
||||
}
|
||||
|
||||
static std::string BaseReplace()
|
||||
{
|
||||
return fmt::format(
|
||||
"REPLACE INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static int ReplaceOne(
|
||||
Database& db,
|
||||
const Account &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.name) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.charname) + "'");
|
||||
v.push_back(std::to_string(e.sharedplat));
|
||||
v.push_back("'" + Strings::Escape(e.password) + "'");
|
||||
v.push_back(std::to_string(e.status));
|
||||
v.push_back("'" + Strings::Escape(e.ls_id) + "'");
|
||||
v.push_back(std::to_string(e.lsaccount_id));
|
||||
v.push_back(std::to_string(e.gmspeed));
|
||||
v.push_back(std::to_string(e.invulnerable));
|
||||
v.push_back(std::to_string(e.flymode));
|
||||
v.push_back(std::to_string(e.ignore_tells));
|
||||
v.push_back(std::to_string(e.revoked));
|
||||
v.push_back(std::to_string(e.karma));
|
||||
v.push_back("'" + Strings::Escape(e.minilogin_ip) + "'");
|
||||
v.push_back(std::to_string(e.hideme));
|
||||
v.push_back(std::to_string(e.rulesflag));
|
||||
v.push_back("FROM_UNIXTIME(" + (e.suspendeduntil > 0 ? std::to_string(e.suspendeduntil) : "null") + ")");
|
||||
v.push_back(std::to_string(e.time_creation));
|
||||
v.push_back("'" + Strings::Escape(e.ban_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.suspend_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_eqgame) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_skillcaps) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_basedata) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseReplace(),
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int ReplaceMany(
|
||||
Database& db,
|
||||
const std::vector<Account> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.name) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.charname) + "'");
|
||||
v.push_back(std::to_string(e.sharedplat));
|
||||
v.push_back("'" + Strings::Escape(e.password) + "'");
|
||||
v.push_back(std::to_string(e.status));
|
||||
v.push_back("'" + Strings::Escape(e.ls_id) + "'");
|
||||
v.push_back(std::to_string(e.lsaccount_id));
|
||||
v.push_back(std::to_string(e.gmspeed));
|
||||
v.push_back(std::to_string(e.invulnerable));
|
||||
v.push_back(std::to_string(e.flymode));
|
||||
v.push_back(std::to_string(e.ignore_tells));
|
||||
v.push_back(std::to_string(e.revoked));
|
||||
v.push_back(std::to_string(e.karma));
|
||||
v.push_back("'" + Strings::Escape(e.minilogin_ip) + "'");
|
||||
v.push_back(std::to_string(e.hideme));
|
||||
v.push_back(std::to_string(e.rulesflag));
|
||||
v.push_back("FROM_UNIXTIME(" + (e.suspendeduntil > 0 ? std::to_string(e.suspendeduntil) : "null") + ")");
|
||||
v.push_back(std::to_string(e.time_creation));
|
||||
v.push_back("'" + Strings::Escape(e.ban_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.suspend_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_eqgame) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_skillcaps) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_basedata) + "'");
|
||||
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
|
||||
}
|
||||
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES {}",
|
||||
BaseReplace(),
|
||||
Strings::Implode(",", insert_chunks)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_BASE_ACCOUNT_REPOSITORY_H
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
#include "../common/repositories/character_auras_repository.h"
|
||||
#include "../common/repositories/character_alt_currency_repository.h"
|
||||
#include "../common/repositories/character_item_recast_repository.h"
|
||||
#include "../common/repositories/account_repository.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
@ -2748,24 +2749,23 @@ int ZoneDatabase::getZoneShutDownDelay(uint32 zoneID, uint32 version)
|
||||
return z ? z->shutdowndelay : RuleI(Zone, AutoShutdownDelay);
|
||||
}
|
||||
|
||||
uint32 ZoneDatabase::GetKarma(uint32 acct_id)
|
||||
uint32 ZoneDatabase::GetKarma(uint32 account_id)
|
||||
{
|
||||
std::string query = StringFormat("SELECT `karma` FROM `account` WHERE `id` = '%i' LIMIT 1", acct_id);
|
||||
auto results = QueryDatabase(query);
|
||||
if (!results.Success())
|
||||
return 0;
|
||||
const auto& e = AccountRepository::FindOne(*this, account_id);
|
||||
|
||||
for (auto& row = results.begin(); row != results.end(); ++row) {
|
||||
return Strings::ToInt(row[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return !e.id ? 0 : e.karma;
|
||||
}
|
||||
|
||||
void ZoneDatabase::UpdateKarma(uint32 acct_id, uint32 amount)
|
||||
void ZoneDatabase::UpdateKarma(uint32 account_id, uint32 amount)
|
||||
{
|
||||
std::string query = StringFormat("UPDATE account SET karma = %i WHERE id = %i", amount, acct_id);
|
||||
QueryDatabase(query);
|
||||
auto e = AccountRepository::FindOne(*this, account_id);
|
||||
if (!e.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.karma = amount;
|
||||
|
||||
AccountRepository::UpdateOne(*this, e);
|
||||
}
|
||||
|
||||
void ZoneDatabase::ListAllInstances(Client* client, uint32 character_id)
|
||||
|
||||
@ -653,8 +653,8 @@ public:
|
||||
* PLEASE DO NOT ADD TO THIS COLLECTION OF CRAP UNLESS YOUR METHOD
|
||||
* REALLY HAS NO BETTER SECTION
|
||||
*/
|
||||
uint32 GetKarma(uint32 acct_id);
|
||||
void UpdateKarma(uint32 acct_id, uint32 amount);
|
||||
uint32 GetKarma(uint32 account_id);
|
||||
void UpdateKarma(uint32 account_id, uint32 amount);
|
||||
|
||||
// bot database add-on to eliminate the need for a second database connection
|
||||
BotDatabase botdb;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user