[Character] Convert Load/Update of Character Alternate Currencies to Repositories (#3856)

- Convert `LoadAltCurrencyValues` and `UpdateAltCurrencyValue` to repositories.
- Cleanup some other code and logic as well.
- Add `AlternateCurrencyMode` namespace for `AltCurrencyPopulate_Struct` opcode magic numbers.
This commit is contained in:
Alex King
2024-01-07 01:11:15 -05:00
committed by GitHub
parent 2ca50b339d
commit 0ea825e9a4
8 changed files with 119 additions and 43 deletions
+5
View File
@@ -727,6 +727,11 @@ namespace BuffEffectType {
constexpr uint8 InverseBuff = 4;
}
namespace AlternateCurrencyMode {
constexpr uint32 Update = 7;
constexpr uint32 Populate = 8;
}
typedef enum {
FilterNone = 0,
FilterGuildChat = 1, //0=hide, 1=show
-2
View File
@@ -5134,8 +5134,6 @@ struct GroupMakeLeader_Struct
//ex for a blank crowns window you would send:
//999999|1|999999|0
//any items come after in much the same way adventure merchant items do except there is no theme included
#define ALT_CURRENCY_OP_POPULATE 8
#define ALT_CURRENCY_OP_UPDATE 7
//Server -> Client
//Populates the initial Alternate Currency Window
+1 -1
View File
@@ -202,7 +202,7 @@ namespace RoF
unsigned char *emu_buffer = in->pBuffer;
uint32 opcode = *((uint32*)emu_buffer);
if (opcode == 8) {
if (opcode == AlternateCurrencyMode::Populate) {
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
auto outapp = new EQApplicationPacket(
+1 -1
View File
@@ -274,7 +274,7 @@ namespace RoF2
unsigned char *emu_buffer = in->pBuffer;
uint32 opcode = *((uint32*)emu_buffer);
if (opcode == 8) {
if (opcode == AlternateCurrencyMode::Populate) {
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
auto outapp = new EQApplicationPacket(
+1 -1
View File
@@ -195,7 +195,7 @@ namespace UF
unsigned char *emu_buffer = in->pBuffer;
uint32 opcode = *((uint32*)emu_buffer);
if (opcode == 8) {
if (opcode == AlternateCurrencyMode::Populate) {
AltCurrencyPopulate_Struct *populate = (AltCurrencyPopulate_Struct*)emu_buffer;
auto outapp = new EQApplicationPacket(
@@ -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_CHARACTER_ALT_CURRENCY_REPOSITORY_H
@@ -16,6 +16,7 @@
#include "../../strings.h"
#include <ctime>
class BaseCharacterAltCurrencyRepository {
public:
struct CharacterAltCurrency {
@@ -112,8 +113,9 @@ public:
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
character_alt_currency_id
)
);
@@ -338,6 +340,66 @@ 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 CharacterAltCurrency &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.currency_id));
v.push_back(std::to_string(e.amount));
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<CharacterAltCurrency> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &e: entries) {
std::vector<std::string> v;
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.currency_id));
v.push_back(std::to_string(e.amount));
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_ALT_CURRENCY_REPOSITORY_H