mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 13:16:39 +00:00
Phase 1 Offline Trading
Cleanup and testing Zone updated builds ok World updated builds ok Update guild_base.h
This commit is contained in:
@@ -107,6 +107,45 @@ public:
|
||||
|
||||
return AccountRepository::UpdateOne(db, e);
|
||||
}
|
||||
|
||||
static void SetOfflineStatus(Database& db, const uint32 account_id, bool offline_status)
|
||||
{
|
||||
auto account = FindOne(db, account_id);
|
||||
if (!account.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
account.offline = offline_status;
|
||||
UpdateOne(db, account);
|
||||
}
|
||||
|
||||
static void ClearAllOfflineStatus(Database& db)
|
||||
{
|
||||
auto query = fmt::format("UPDATE {} SET `offline` = '0' WHERE `offline` = '1';",
|
||||
TableName()
|
||||
);
|
||||
|
||||
db.QueryDatabase(query);
|
||||
}
|
||||
|
||||
static bool GetAllOfflineStatus(Database& db, const uint32 character_id)
|
||||
{
|
||||
auto query = fmt::format("SELECT a.`offline` "
|
||||
"FROM `account` AS a "
|
||||
"INNER JOIN character_data AS c ON c.account_id = a.id "
|
||||
"WHERE c.id = '{}'",
|
||||
character_id
|
||||
);
|
||||
auto results = db.QueryDatabase(query);
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
bool const status = static_cast<int16>(Strings::ToInt(row[0]));
|
||||
|
||||
return status;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_ACCOUNT_REPOSITORY_H
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
uint8_t rulesflag;
|
||||
time_t suspendeduntil;
|
||||
uint32_t time_creation;
|
||||
uint8_t offline;
|
||||
std::string ban_reason;
|
||||
std::string suspend_reason;
|
||||
std::string crc_eqgame;
|
||||
@@ -74,6 +75,7 @@ public:
|
||||
"rulesflag",
|
||||
"suspendeduntil",
|
||||
"time_creation",
|
||||
"offline",
|
||||
"ban_reason",
|
||||
"suspend_reason",
|
||||
"crc_eqgame",
|
||||
@@ -105,6 +107,7 @@ public:
|
||||
"rulesflag",
|
||||
"UNIX_TIMESTAMP(suspendeduntil)",
|
||||
"time_creation",
|
||||
"offline",
|
||||
"ban_reason",
|
||||
"suspend_reason",
|
||||
"crc_eqgame",
|
||||
@@ -170,6 +173,7 @@ public:
|
||||
e.rulesflag = 0;
|
||||
e.suspendeduntil = 0;
|
||||
e.time_creation = 0;
|
||||
e.offline = 0;
|
||||
e.ban_reason = "";
|
||||
e.suspend_reason = "";
|
||||
e.crc_eqgame = "";
|
||||
@@ -231,11 +235,12 @@ public:
|
||||
e.rulesflag = row[17] ? static_cast<uint8_t>(strtoul(row[17], nullptr, 10)) : 0;
|
||||
e.suspendeduntil = strtoll(row[18] ? row[18] : "-1", nullptr, 10);
|
||||
e.time_creation = row[19] ? static_cast<uint32_t>(strtoul(row[19], nullptr, 10)) : 0;
|
||||
e.ban_reason = row[20] ? row[20] : "";
|
||||
e.suspend_reason = row[21] ? row[21] : "";
|
||||
e.crc_eqgame = row[22] ? row[22] : "";
|
||||
e.crc_skillcaps = row[23] ? row[23] : "";
|
||||
e.crc_basedata = row[24] ? row[24] : "";
|
||||
e.offline = row[20] ? static_cast<uint8_t>(strtoul(row[20], nullptr, 10)) : 0;
|
||||
e.ban_reason = row[21] ? row[21] : "";
|
||||
e.suspend_reason = row[22] ? row[22] : "";
|
||||
e.crc_eqgame = row[23] ? row[23] : "";
|
||||
e.crc_skillcaps = row[24] ? row[24] : "";
|
||||
e.crc_basedata = row[25] ? row[25] : "";
|
||||
|
||||
return e;
|
||||
}
|
||||
@@ -288,11 +293,12 @@ public:
|
||||
v.push_back(columns[17] + " = " + std::to_string(e.rulesflag));
|
||||
v.push_back(columns[18] + " = FROM_UNIXTIME(" + (e.suspendeduntil > 0 ? std::to_string(e.suspendeduntil) : "null") + ")");
|
||||
v.push_back(columns[19] + " = " + std::to_string(e.time_creation));
|
||||
v.push_back(columns[20] + " = '" + Strings::Escape(e.ban_reason) + "'");
|
||||
v.push_back(columns[21] + " = '" + Strings::Escape(e.suspend_reason) + "'");
|
||||
v.push_back(columns[22] + " = '" + Strings::Escape(e.crc_eqgame) + "'");
|
||||
v.push_back(columns[23] + " = '" + Strings::Escape(e.crc_skillcaps) + "'");
|
||||
v.push_back(columns[24] + " = '" + Strings::Escape(e.crc_basedata) + "'");
|
||||
v.push_back(columns[20] + " = " + std::to_string(e.offline));
|
||||
v.push_back(columns[21] + " = '" + Strings::Escape(e.ban_reason) + "'");
|
||||
v.push_back(columns[22] + " = '" + Strings::Escape(e.suspend_reason) + "'");
|
||||
v.push_back(columns[23] + " = '" + Strings::Escape(e.crc_eqgame) + "'");
|
||||
v.push_back(columns[24] + " = '" + Strings::Escape(e.crc_skillcaps) + "'");
|
||||
v.push_back(columns[25] + " = '" + Strings::Escape(e.crc_basedata) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -334,6 +340,7 @@ public:
|
||||
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(std::to_string(e.offline));
|
||||
v.push_back("'" + Strings::Escape(e.ban_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.suspend_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_eqgame) + "'");
|
||||
@@ -388,6 +395,7 @@ public:
|
||||
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(std::to_string(e.offline));
|
||||
v.push_back("'" + Strings::Escape(e.ban_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.suspend_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_eqgame) + "'");
|
||||
@@ -446,11 +454,12 @@ public:
|
||||
e.rulesflag = row[17] ? static_cast<uint8_t>(strtoul(row[17], nullptr, 10)) : 0;
|
||||
e.suspendeduntil = strtoll(row[18] ? row[18] : "-1", nullptr, 10);
|
||||
e.time_creation = row[19] ? static_cast<uint32_t>(strtoul(row[19], nullptr, 10)) : 0;
|
||||
e.ban_reason = row[20] ? row[20] : "";
|
||||
e.suspend_reason = row[21] ? row[21] : "";
|
||||
e.crc_eqgame = row[22] ? row[22] : "";
|
||||
e.crc_skillcaps = row[23] ? row[23] : "";
|
||||
e.crc_basedata = row[24] ? row[24] : "";
|
||||
e.offline = row[20] ? static_cast<uint8_t>(strtoul(row[20], nullptr, 10)) : 0;
|
||||
e.ban_reason = row[21] ? row[21] : "";
|
||||
e.suspend_reason = row[22] ? row[22] : "";
|
||||
e.crc_eqgame = row[23] ? row[23] : "";
|
||||
e.crc_skillcaps = row[24] ? row[24] : "";
|
||||
e.crc_basedata = row[25] ? row[25] : "";
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
@@ -495,11 +504,12 @@ public:
|
||||
e.rulesflag = row[17] ? static_cast<uint8_t>(strtoul(row[17], nullptr, 10)) : 0;
|
||||
e.suspendeduntil = strtoll(row[18] ? row[18] : "-1", nullptr, 10);
|
||||
e.time_creation = row[19] ? static_cast<uint32_t>(strtoul(row[19], nullptr, 10)) : 0;
|
||||
e.ban_reason = row[20] ? row[20] : "";
|
||||
e.suspend_reason = row[21] ? row[21] : "";
|
||||
e.crc_eqgame = row[22] ? row[22] : "";
|
||||
e.crc_skillcaps = row[23] ? row[23] : "";
|
||||
e.crc_basedata = row[24] ? row[24] : "";
|
||||
e.offline = row[20] ? static_cast<uint8_t>(strtoul(row[20], nullptr, 10)) : 0;
|
||||
e.ban_reason = row[21] ? row[21] : "";
|
||||
e.suspend_reason = row[22] ? row[22] : "";
|
||||
e.crc_eqgame = row[23] ? row[23] : "";
|
||||
e.crc_skillcaps = row[24] ? row[24] : "";
|
||||
e.crc_basedata = row[25] ? row[25] : "";
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
@@ -594,6 +604,7 @@ public:
|
||||
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(std::to_string(e.offline));
|
||||
v.push_back("'" + Strings::Escape(e.ban_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.suspend_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_eqgame) + "'");
|
||||
@@ -641,6 +652,7 @@ public:
|
||||
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(std::to_string(e.offline));
|
||||
v.push_back("'" + Strings::Escape(e.ban_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.suspend_reason) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.crc_eqgame) + "'");
|
||||
|
||||
@@ -0,0 +1,451 @@
|
||||
/**
|
||||
* DO NOT MODIFY THIS FILE
|
||||
*
|
||||
* This repository was automatically generated and is NOT to be modified directly.
|
||||
* Any repository modifications are meant to be made to the repository extending the base.
|
||||
* Any modifications to base repositories are to be made by the generator only
|
||||
*
|
||||
* @generator ./utils/scripts/generators/repository-generator.pl
|
||||
* @docs https://docs.eqemu.io/developer/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_CHARACTER_OFFLINE_TRANSACTIONS_REPOSITORY_H
|
||||
#define EQEMU_BASE_CHARACTER_OFFLINE_TRANSACTIONS_REPOSITORY_H
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
class BaseCharacterOfflineTransactionsRepository {
|
||||
public:
|
||||
struct CharacterOfflineTransactions {
|
||||
uint64_t id;
|
||||
uint32_t character_id;
|
||||
uint32_t type;
|
||||
std::string item_name;
|
||||
int32_t quantity;
|
||||
uint64_t price;
|
||||
std::string buyer_name;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"character_id",
|
||||
"type",
|
||||
"item_name",
|
||||
"quantity",
|
||||
"price",
|
||||
"buyer_name",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"character_id",
|
||||
"type",
|
||||
"item_name",
|
||||
"quantity",
|
||||
"price",
|
||||
"buyer_name",
|
||||
};
|
||||
}
|
||||
|
||||
static std::string ColumnsRaw()
|
||||
{
|
||||
return std::string(Strings::Implode(", ", Columns()));
|
||||
}
|
||||
|
||||
static std::string SelectColumnsRaw()
|
||||
{
|
||||
return std::string(Strings::Implode(", ", SelectColumns()));
|
||||
}
|
||||
|
||||
static std::string TableName()
|
||||
{
|
||||
return std::string("character_offline_transactions");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static CharacterOfflineTransactions NewEntity()
|
||||
{
|
||||
CharacterOfflineTransactions e{};
|
||||
|
||||
e.id = 0;
|
||||
e.character_id = 0;
|
||||
e.type = 0;
|
||||
e.item_name = "";
|
||||
e.quantity = 0;
|
||||
e.price = 0;
|
||||
e.buyer_name = "";
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static CharacterOfflineTransactions GetCharacterOfflineTransactions(
|
||||
const std::vector<CharacterOfflineTransactions> &character_offline_transactionss,
|
||||
int character_offline_transactions_id
|
||||
)
|
||||
{
|
||||
for (auto &character_offline_transactions : character_offline_transactionss) {
|
||||
if (character_offline_transactions.id == character_offline_transactions_id) {
|
||||
return character_offline_transactions;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static CharacterOfflineTransactions FindOne(
|
||||
Database& db,
|
||||
int character_offline_transactions_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
character_offline_transactions_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
CharacterOfflineTransactions e{};
|
||||
|
||||
e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0;
|
||||
e.character_id = row[1] ? static_cast<uint32_t>(strtoul(row[1], nullptr, 10)) : 0;
|
||||
e.type = row[2] ? static_cast<uint32_t>(strtoul(row[2], nullptr, 10)) : 0;
|
||||
e.item_name = row[3] ? row[3] : "";
|
||||
e.quantity = row[4] ? static_cast<int32_t>(atoi(row[4])) : 0;
|
||||
e.price = row[5] ? strtoull(row[5], nullptr, 10) : 0;
|
||||
e.buyer_name = row[6] ? row[6] : "";
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int character_offline_transactions_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
character_offline_transactions_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
const CharacterOfflineTransactions &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.character_id));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.type));
|
||||
v.push_back(columns[3] + " = '" + Strings::Escape(e.item_name) + "'");
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.quantity));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.price));
|
||||
v.push_back(columns[6] + " = '" + Strings::Escape(e.buyer_name) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static CharacterOfflineTransactions InsertOne(
|
||||
Database& db,
|
||||
CharacterOfflineTransactions e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.character_id));
|
||||
v.push_back(std::to_string(e.type));
|
||||
v.push_back("'" + Strings::Escape(e.item_name) + "'");
|
||||
v.push_back(std::to_string(e.quantity));
|
||||
v.push_back(std::to_string(e.price));
|
||||
v.push_back("'" + Strings::Escape(e.buyer_name) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
e = NewEntity();
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
const std::vector<CharacterOfflineTransactions> &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(std::to_string(e.character_id));
|
||||
v.push_back(std::to_string(e.type));
|
||||
v.push_back("'" + Strings::Escape(e.item_name) + "'");
|
||||
v.push_back(std::to_string(e.quantity));
|
||||
v.push_back(std::to_string(e.price));
|
||||
v.push_back("'" + Strings::Escape(e.buyer_name) + "'");
|
||||
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
|
||||
}
|
||||
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES {}",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_chunks)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static std::vector<CharacterOfflineTransactions> All(Database& db)
|
||||
{
|
||||
std::vector<CharacterOfflineTransactions> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
CharacterOfflineTransactions e{};
|
||||
|
||||
e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0;
|
||||
e.character_id = row[1] ? static_cast<uint32_t>(strtoul(row[1], nullptr, 10)) : 0;
|
||||
e.type = row[2] ? static_cast<uint32_t>(strtoul(row[2], nullptr, 10)) : 0;
|
||||
e.item_name = row[3] ? row[3] : "";
|
||||
e.quantity = row[4] ? static_cast<int32_t>(atoi(row[4])) : 0;
|
||||
e.price = row[5] ? strtoull(row[5], nullptr, 10) : 0;
|
||||
e.buyer_name = row[6] ? row[6] : "";
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<CharacterOfflineTransactions> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<CharacterOfflineTransactions> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {}",
|
||||
BaseSelect(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
CharacterOfflineTransactions e{};
|
||||
|
||||
e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0;
|
||||
e.character_id = row[1] ? static_cast<uint32_t>(strtoul(row[1], nullptr, 10)) : 0;
|
||||
e.type = row[2] ? static_cast<uint32_t>(strtoul(row[2], nullptr, 10)) : 0;
|
||||
e.item_name = row[3] ? row[3] : "";
|
||||
e.quantity = row[4] ? static_cast<int32_t>(atoi(row[4])) : 0;
|
||||
e.price = row[5] ? strtoull(row[5], nullptr, 10) : 0;
|
||||
e.buyer_name = row[6] ? row[6] : "";
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static int DeleteWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {}",
|
||||
TableName(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int Truncate(Database& db)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"TRUNCATE TABLE {}",
|
||||
TableName()
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int64 GetMaxId(Database& db)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT COALESCE(MAX({}), 0) FROM {}",
|
||||
PrimaryKey(),
|
||||
TableName()
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
||||
}
|
||||
|
||||
static int64 Count(Database& db, const std::string &where_filter = "")
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT COUNT(*) FROM {} {}",
|
||||
TableName(),
|
||||
(where_filter.empty() ? "" : "WHERE " + where_filter)
|
||||
)
|
||||
);
|
||||
|
||||
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 CharacterOfflineTransactions &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.character_id));
|
||||
v.push_back(std::to_string(e.type));
|
||||
v.push_back("'" + Strings::Escape(e.item_name) + "'");
|
||||
v.push_back(std::to_string(e.quantity));
|
||||
v.push_back(std::to_string(e.price));
|
||||
v.push_back("'" + Strings::Escape(e.buyer_name) + "'");
|
||||
|
||||
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<CharacterOfflineTransactions> &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(std::to_string(e.character_id));
|
||||
v.push_back(std::to_string(e.type));
|
||||
v.push_back("'" + Strings::Escape(e.item_name) + "'");
|
||||
v.push_back(std::to_string(e.quantity));
|
||||
v.push_back(std::to_string(e.price));
|
||||
v.push_back("'" + Strings::Escape(e.buyer_name) + "'");
|
||||
|
||||
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_CHARACTER_OFFLINE_TRANSACTIONS_REPOSITORY_H
|
||||
@@ -106,8 +106,13 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
auto buy_lines =
|
||||
BaseBuyerBuyLinesRepository::GetWhere(db, fmt::format("`buyer_id` = {}", buyer.front().id));
|
||||
auto buy_lines = BaseBuyerBuyLinesRepository::GetWhere(
|
||||
db,
|
||||
fmt::format("`buyer_id` = '{}'", buyer.front().id)
|
||||
);
|
||||
if (buy_lines.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> buy_line_ids{};
|
||||
for (auto const &bl: buy_lines) {
|
||||
@@ -175,6 +180,26 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool UpdateBuyerEntityID(Database &db, uint32 char_id, uint32 old_entity_id, uint32 new_entity_id)
|
||||
{
|
||||
if (!char_id || !old_entity_id || !new_entity_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto results = GetWhere(db, fmt::format("`char_id` = '{}' AND `char_entity_id` = '{}' LIMIT 1;", char_id, old_entity_id));
|
||||
|
||||
if (results.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto &e: results) {
|
||||
e.char_entity_id = new_entity_id;
|
||||
}
|
||||
|
||||
ReplaceMany(db, results);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_BUYER_REPOSITORY_H
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef EQEMU_CHARACTER_OFFLINE_TRANSACTIONS_REPOSITORY_H
|
||||
#define EQEMU_CHARACTER_OFFLINE_TRANSACTIONS_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../strings.h"
|
||||
#include "base/base_character_offline_transactions_repository.h"
|
||||
|
||||
class CharacterOfflineTransactionsRepository: public BaseCharacterOfflineTransactionsRepository {
|
||||
public:
|
||||
|
||||
#define TRADER_TRANSACTION 1
|
||||
#define BUYER_TRANSACTION 2
|
||||
|
||||
/**
|
||||
* This file was auto generated and can be modified and extended upon
|
||||
*
|
||||
* Base repository methods are automatically
|
||||
* generated in the "base" version of this repository. The base repository
|
||||
* is immutable and to be left untouched, while methods in this class
|
||||
* are used as extension methods for more specific persistence-layer
|
||||
* accessors or mutators.
|
||||
*
|
||||
* Base Methods (Subject to be expanded upon in time)
|
||||
*
|
||||
* Note: Not all tables are designed appropriately to fit functionality with all base methods
|
||||
*
|
||||
* InsertOne
|
||||
* UpdateOne
|
||||
* DeleteOne
|
||||
* FindOne
|
||||
* GetWhere(std::string where_filter)
|
||||
* DeleteWhere(std::string where_filter)
|
||||
* InsertMany
|
||||
* All
|
||||
*
|
||||
* Example custom methods in a repository
|
||||
*
|
||||
* CharacterOfflineTransactionsRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* CharacterOfflineTransactionsRepository::GetWhereNeverExpires()
|
||||
* CharacterOfflineTransactionsRepository::GetWhereXAndY()
|
||||
* CharacterOfflineTransactionsRepository::DeleteWhereXAndY()
|
||||
*
|
||||
* Most of the above could be covered by base methods, but if you as a developer
|
||||
* find yourself re-using logic for other parts of the code, its best to just make a
|
||||
* method that can be re-used easily elsewhere especially if it can use a base repository
|
||||
* method and encapsulate filters there
|
||||
*/
|
||||
|
||||
// Custom extended repository methods here
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_CHARACTER_OFFLINE_TRANSACTIONS_REPOSITORY_H
|
||||
@@ -395,6 +395,49 @@ public:
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static Trader GetAccountZoneIdAndInstanceIdByAccountId(Database &db, uint32 account_id)
|
||||
{
|
||||
auto trader_query = fmt::format(
|
||||
"SELECT t.id, t.char_id, t.char_zone_id, t.char_zone_instance_id "
|
||||
"FROM trader AS t "
|
||||
"WHERE t.char_id IN(SELECT c.id FROM character_data AS c WHERE c.account_id = '{}') "
|
||||
"LIMIT 1;",
|
||||
account_id
|
||||
);
|
||||
|
||||
auto buyer_query = fmt::format(
|
||||
"SELECT t.id, t.char_id, t.char_zone_id, t.char_zone_instance_id "
|
||||
"FROM buyer AS t "
|
||||
"WHERE t.char_id IN(SELECT c.id FROM character_data AS c WHERE c.account_id = '{}') "
|
||||
"LIMIT 1;",
|
||||
account_id
|
||||
);
|
||||
|
||||
Trader e{};
|
||||
|
||||
auto trader_results = db.QueryDatabase(trader_query);
|
||||
auto buyer_results = db.QueryDatabase(buyer_query);
|
||||
if (trader_results.RowCount() == 0 && buyer_results.RowCount() == 0) {
|
||||
return e;
|
||||
}
|
||||
|
||||
MySQLRequestRow row;
|
||||
if (trader_results.RowCount() > 0) {
|
||||
row = trader_results.begin();
|
||||
}
|
||||
|
||||
if (buyer_results.RowCount() > 0) {
|
||||
row = buyer_results.begin();
|
||||
}
|
||||
|
||||
e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0;
|
||||
e.char_id = row[1] ? static_cast<uint32_t>(strtoul(row[1], nullptr, 10)) : 0;
|
||||
e.char_zone_id = row[2] ? static_cast<uint32_t>(strtoul(row[2], nullptr, 10)) : 0;
|
||||
e.char_zone_instance_id = row[3] ? static_cast<int32_t>(atoi(row[3])) : 0;
|
||||
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_TRADER_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user