mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 04:56:20 +00:00
[Feature] Add RoF2 Guild features (#3699)
* [Feature] Add additional Guild Features This adds the following guild features and design pattern - the existing guild system was used - guild features are based on RoF2 within source with translaters used to converted between client differences - backward compatible with Ti and UF, and allows for mixed client servers - Guild Back for Ti and UF is based on RoF2 Permissions for banking if Guild Leader does not use Ti/UF - Guild Ranks and Permissions are enabled. - Guild Tributes are enabled. - Event logging via rules for donating tribute items and plat - Rules to limit Guild Tributes based on max level of server - Rewrote guild communications to client using specific opcodes -- Server no longer sends a guild member list on each zone -- Guild window is updated when a member levels, rank changes, zone changes, banker/alt status using individual opcodes -- When a member is removed or added to a guild, a single opcode is sent to each guild member -- This reduces network traffic considerably Known issues: - Visual bug only. Guild Tributes window will display a 0 for level if tribute is above max level rule setting. - Visual bug only. Guild Mgmt Window will not display an online member if the player has 'show offline' unchecked and a guild member zones within the Notes/Tribute tab. This is resolved by selecting and de-selecting the 'Show Offline' checkbox. * Updated RoF2 Guild Comms Updated RoF2 Guild Comms Update RoF2 Opcodes Rewrote RoF2 Guild Communications using specific opcodes. Added database changes - they are irreversible * Formatting * Update base_guild_members_repository.h * Format GuildInfo * Format GuildAction enum * Formatting in clientlist * quantity vs quantity * desc vs description * Format structs * Inline struct values * Formatting * Formatting * Formatting fixes * Formatting items * Formatting * Formatting * struct formatting updates * Updated formatting * Updated - std:string items - naming conventions - magic numbers * Repo refactors Other formatting updates * Remove test guild commands * Updated #guild info command * Add new repo methods for Neckolla ReplaceOne and ReplaceMany * Fix guild_tributes repo * Update database_update_manifest.cpp * Phase 1 of final testing with RoF2 -> RoF2. Next phase will be inter compatibility review * Remove #guild testing commands * Fix uf translator error Rewrite LoadGuilds * Use extended repository * FIx guild window on member add * LoadGuild Changes * Update guild_base.cpp * Few small fixes for display issue with UF * Update guild_base.cpp * Update guild_members_repository.h * Update zoneserver.cpp * Update guild.cpp * Update entity.h * Switch formatting * Formatting * Update worldserver.cpp * Switch formatting * Formatting switch statement * Update guild.cpp * Formatting in guild_base * We don't need to validate m_db everywhere * More formatting / spacing issues * Switch format * Update guild_base.cpp * Fix an UF issue displaying incorrect guildtag as <> * Updated several constants, fixed a few issues with Ti/UF and guild tributes not being removed or sent when a member is removed/disbands from a guild. * Formatting and logging updates * Fix for Loadguilds and permissions after repo updates. * Cleanup unnecessary m_db checks * Updated logging to use player_event_logs * Updated to use the single opcodes for guild traffic for Ti/UF/RoF2. Several enhancements for guild functionality for more reusable code and readability. * Update to fix Demote Self and guild invites declining when option set to not accept guild invites * Potential fix for guild notes/tribute display issues when client has 'Show Offline' unchecked. * Updates to fox recent master changes Updates to fix recent master changes * Updates in response to comments * Further Updates in response to comments * Comment updates and refactor for SendAppearance functions * Comment updates * Update client spawn process for show guild name Add show guild tag to default spawn process * Update to use zone spawn packets for RoF2 Removed several unused functions as a result Updated MemberRankUpdate to properly update guild_show on rank change. Updated OP_GuildURLAndChannel opcode for UF/RoF2 * Cleanup of world changes Created function for repetitive zonelist sendpackets to only booted zones Re-Inserted accidental delete of scanclosemobs * Fixes * Further world cleanup * Fix a few test guild bank cases for backward compat Removed a duplicate db call Fixed a fallthrough issue * Update guild_mgr.cpp * Cleanup --------- Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
@@ -0,0 +1,404 @@
|
||||
/**
|
||||
* 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://eqemu.gitbook.io/server/in-development/developer-area/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_GUILD_BANK_REPOSITORY_H
|
||||
#define EQEMU_BASE_GUILD_BANK_REPOSITORY_H
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
class BaseGuildBankRepository {
|
||||
public:
|
||||
struct GuildBank {
|
||||
uint32_t id;
|
||||
uint32_t guildid;
|
||||
uint8_t area;
|
||||
uint32_t slot;
|
||||
uint32_t itemid;
|
||||
uint32_t qty;
|
||||
std::string donator;
|
||||
uint8_t permissions;
|
||||
std::string whofor;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"guildid",
|
||||
"area",
|
||||
"slot",
|
||||
"itemid",
|
||||
"qty",
|
||||
"donator",
|
||||
"permissions",
|
||||
"whofor",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"guildid",
|
||||
"area",
|
||||
"slot",
|
||||
"itemid",
|
||||
"qty",
|
||||
"donator",
|
||||
"permissions",
|
||||
"whofor",
|
||||
};
|
||||
}
|
||||
|
||||
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("guild_bank");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static GuildBank NewEntity()
|
||||
{
|
||||
GuildBank e{};
|
||||
|
||||
e.id = 0;
|
||||
e.guildid = 0;
|
||||
e.area = 0;
|
||||
e.slot = 0;
|
||||
e.itemid = 0;
|
||||
e.qty = 0;
|
||||
e.donator = "";
|
||||
e.permissions = 0;
|
||||
e.whofor = "";
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static GuildBank GetGuildBank(
|
||||
const std::vector<GuildBank> &guild_banks,
|
||||
int guild_bank_id
|
||||
)
|
||||
{
|
||||
for (auto &guild_bank : guild_banks) {
|
||||
if (guild_bank.id == guild_bank_id) {
|
||||
return guild_bank;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static GuildBank FindOne(
|
||||
Database& db,
|
||||
int guild_bank_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
guild_bank_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
GuildBank e{};
|
||||
|
||||
e.id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
|
||||
e.guildid = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
|
||||
e.area = static_cast<uint8_t>(strtoul(row[2], nullptr, 10));
|
||||
e.slot = static_cast<uint32_t>(strtoul(row[3], nullptr, 10));
|
||||
e.itemid = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
|
||||
e.qty = static_cast<uint32_t>(strtoul(row[5], nullptr, 10));
|
||||
e.donator = row[6] ? row[6] : "";
|
||||
e.permissions = static_cast<uint8_t>(strtoul(row[7], nullptr, 10));
|
||||
e.whofor = row[8] ? row[8] : "";
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int guild_bank_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
guild_bank_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
const GuildBank &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.guildid));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.area));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.slot));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.itemid));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.qty));
|
||||
v.push_back(columns[6] + " = '" + Strings::Escape(e.donator) + "'");
|
||||
v.push_back(columns[7] + " = " + std::to_string(e.permissions));
|
||||
v.push_back(columns[8] + " = '" + Strings::Escape(e.whofor) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static GuildBank InsertOne(
|
||||
Database& db,
|
||||
GuildBank e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.guildid));
|
||||
v.push_back(std::to_string(e.area));
|
||||
v.push_back(std::to_string(e.slot));
|
||||
v.push_back(std::to_string(e.itemid));
|
||||
v.push_back(std::to_string(e.qty));
|
||||
v.push_back("'" + Strings::Escape(e.donator) + "'");
|
||||
v.push_back(std::to_string(e.permissions));
|
||||
v.push_back("'" + Strings::Escape(e.whofor) + "'");
|
||||
|
||||
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<GuildBank> &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.guildid));
|
||||
v.push_back(std::to_string(e.area));
|
||||
v.push_back(std::to_string(e.slot));
|
||||
v.push_back(std::to_string(e.itemid));
|
||||
v.push_back(std::to_string(e.qty));
|
||||
v.push_back("'" + Strings::Escape(e.donator) + "'");
|
||||
v.push_back(std::to_string(e.permissions));
|
||||
v.push_back("'" + Strings::Escape(e.whofor) + "'");
|
||||
|
||||
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<GuildBank> All(Database& db)
|
||||
{
|
||||
std::vector<GuildBank> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
GuildBank e{};
|
||||
|
||||
e.id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
|
||||
e.guildid = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
|
||||
e.area = static_cast<uint8_t>(strtoul(row[2], nullptr, 10));
|
||||
e.slot = static_cast<uint32_t>(strtoul(row[3], nullptr, 10));
|
||||
e.itemid = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
|
||||
e.qty = static_cast<uint32_t>(strtoul(row[5], nullptr, 10));
|
||||
e.donator = row[6] ? row[6] : "";
|
||||
e.permissions = static_cast<uint8_t>(strtoul(row[7], nullptr, 10));
|
||||
e.whofor = row[8] ? row[8] : "";
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<GuildBank> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<GuildBank> 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) {
|
||||
GuildBank e{};
|
||||
|
||||
e.id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
|
||||
e.guildid = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
|
||||
e.area = static_cast<uint8_t>(strtoul(row[2], nullptr, 10));
|
||||
e.slot = static_cast<uint32_t>(strtoul(row[3], nullptr, 10));
|
||||
e.itemid = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
|
||||
e.qty = static_cast<uint32_t>(strtoul(row[5], nullptr, 10));
|
||||
e.donator = row[6] ? row[6] : "";
|
||||
e.permissions = static_cast<uint8_t>(strtoul(row[7], nullptr, 10));
|
||||
e.whofor = row[8] ? row[8] : "";
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_BASE_GUILD_BANK_REPOSITORY_H
|
||||
@@ -0,0 +1,416 @@
|
||||
/**
|
||||
* 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_GUILD_PERMISSIONS_REPOSITORY_H
|
||||
#define EQEMU_BASE_GUILD_PERMISSIONS_REPOSITORY_H
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
class BaseGuildPermissionsRepository {
|
||||
public:
|
||||
struct GuildPermissions {
|
||||
int32_t id;
|
||||
int32_t perm_id;
|
||||
int32_t guild_id;
|
||||
int32_t permission;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"perm_id",
|
||||
"guild_id",
|
||||
"permission",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"perm_id",
|
||||
"guild_id",
|
||||
"permission",
|
||||
};
|
||||
}
|
||||
|
||||
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("guild_permissions");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static GuildPermissions NewEntity()
|
||||
{
|
||||
GuildPermissions e{};
|
||||
|
||||
e.id = 0;
|
||||
e.perm_id = 0;
|
||||
e.guild_id = 0;
|
||||
e.permission = 0;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static GuildPermissions GetGuildPermissions(
|
||||
const std::vector<GuildPermissions> &guild_permissionss,
|
||||
int guild_permissions_id
|
||||
)
|
||||
{
|
||||
for (auto &guild_permissions : guild_permissionss) {
|
||||
if (guild_permissions.id == guild_permissions_id) {
|
||||
return guild_permissions;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static GuildPermissions FindOne(
|
||||
Database& db,
|
||||
int guild_permissions_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
guild_permissions_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
GuildPermissions e{};
|
||||
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.perm_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.guild_id = static_cast<int32_t>(atoi(row[2]));
|
||||
e.permission = static_cast<int32_t>(atoi(row[3]));
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int guild_permissions_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
guild_permissions_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
const GuildPermissions &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.perm_id));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.guild_id));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.permission));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static GuildPermissions InsertOne(
|
||||
Database& db,
|
||||
GuildPermissions e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.perm_id));
|
||||
v.push_back(std::to_string(e.guild_id));
|
||||
v.push_back(std::to_string(e.permission));
|
||||
|
||||
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<GuildPermissions> &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.perm_id));
|
||||
v.push_back(std::to_string(e.guild_id));
|
||||
v.push_back(std::to_string(e.permission));
|
||||
|
||||
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<GuildPermissions> All(Database& db)
|
||||
{
|
||||
std::vector<GuildPermissions> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
GuildPermissions e{};
|
||||
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.perm_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.guild_id = static_cast<int32_t>(atoi(row[2]));
|
||||
e.permission = static_cast<int32_t>(atoi(row[3]));
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<GuildPermissions> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<GuildPermissions> 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) {
|
||||
GuildPermissions e{};
|
||||
|
||||
e.id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.perm_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.guild_id = static_cast<int32_t>(atoi(row[2]));
|
||||
e.permission = static_cast<int32_t>(atoi(row[3]));
|
||||
|
||||
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 GuildPermissions &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.perm_id));
|
||||
v.push_back(std::to_string(e.guild_id));
|
||||
v.push_back(std::to_string(e.permission));
|
||||
|
||||
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<GuildPermissions> &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.perm_id));
|
||||
v.push_back(std::to_string(e.guild_id));
|
||||
v.push_back(std::to_string(e.permission));
|
||||
|
||||
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_GUILD_PERMISSIONS_REPOSITORY_H
|
||||
@@ -0,0 +1,453 @@
|
||||
/**
|
||||
* 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_GUILD_TRIBUTES_REPOSITORY_H
|
||||
#define EQEMU_BASE_GUILD_TRIBUTES_REPOSITORY_H
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
class BaseGuildTributesRepository {
|
||||
public:
|
||||
struct GuildTributes {
|
||||
uint32_t guild_id;
|
||||
uint32_t tribute_id_1;
|
||||
uint32_t tribute_id_1_tier;
|
||||
uint32_t tribute_id_2;
|
||||
uint32_t tribute_id_2_tier;
|
||||
uint32_t time_remaining;
|
||||
uint32_t enabled;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("guild_id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"guild_id",
|
||||
"tribute_id_1",
|
||||
"tribute_id_1_tier",
|
||||
"tribute_id_2",
|
||||
"tribute_id_2_tier",
|
||||
"time_remaining",
|
||||
"enabled",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"guild_id",
|
||||
"tribute_id_1",
|
||||
"tribute_id_1_tier",
|
||||
"tribute_id_2",
|
||||
"tribute_id_2_tier",
|
||||
"time_remaining",
|
||||
"enabled",
|
||||
};
|
||||
}
|
||||
|
||||
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("guild_tributes");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static GuildTributes NewEntity()
|
||||
{
|
||||
GuildTributes e{};
|
||||
|
||||
e.guild_id = 0;
|
||||
e.tribute_id_1 = 0;
|
||||
e.tribute_id_1_tier = 0;
|
||||
e.tribute_id_2 = 0;
|
||||
e.tribute_id_2_tier = 0;
|
||||
e.time_remaining = 0;
|
||||
e.enabled = 0;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static GuildTributes GetGuildTributes(
|
||||
const std::vector<GuildTributes> &guild_tributess,
|
||||
int guild_tributes_id
|
||||
)
|
||||
{
|
||||
for (auto &guild_tributes : guild_tributess) {
|
||||
if (guild_tributes.guild_id == guild_tributes_id) {
|
||||
return guild_tributes;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static GuildTributes FindOne(
|
||||
Database& db,
|
||||
int guild_tributes_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
guild_tributes_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
GuildTributes e{};
|
||||
|
||||
e.guild_id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
|
||||
e.tribute_id_1 = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
|
||||
e.tribute_id_1_tier = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
|
||||
e.tribute_id_2 = static_cast<uint32_t>(strtoul(row[3], nullptr, 10));
|
||||
e.tribute_id_2_tier = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
|
||||
e.time_remaining = static_cast<uint32_t>(strtoul(row[5], nullptr, 10));
|
||||
e.enabled = static_cast<uint32_t>(strtoul(row[6], nullptr, 10));
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int guild_tributes_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
guild_tributes_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
const GuildTributes &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
v.push_back(columns[0] + " = " + std::to_string(e.guild_id));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.tribute_id_1));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.tribute_id_1_tier));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.tribute_id_2));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.tribute_id_2_tier));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.time_remaining));
|
||||
v.push_back(columns[6] + " = " + std::to_string(e.enabled));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
e.guild_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static GuildTributes InsertOne(
|
||||
Database& db,
|
||||
GuildTributes e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.guild_id));
|
||||
v.push_back(std::to_string(e.tribute_id_1));
|
||||
v.push_back(std::to_string(e.tribute_id_1_tier));
|
||||
v.push_back(std::to_string(e.tribute_id_2));
|
||||
v.push_back(std::to_string(e.tribute_id_2_tier));
|
||||
v.push_back(std::to_string(e.time_remaining));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
e.guild_id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
e = NewEntity();
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
const std::vector<GuildTributes> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.guild_id));
|
||||
v.push_back(std::to_string(e.tribute_id_1));
|
||||
v.push_back(std::to_string(e.tribute_id_1_tier));
|
||||
v.push_back(std::to_string(e.tribute_id_2));
|
||||
v.push_back(std::to_string(e.tribute_id_2_tier));
|
||||
v.push_back(std::to_string(e.time_remaining));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
|
||||
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<GuildTributes> All(Database& db)
|
||||
{
|
||||
std::vector<GuildTributes> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
GuildTributes e{};
|
||||
|
||||
e.guild_id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
|
||||
e.tribute_id_1 = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
|
||||
e.tribute_id_1_tier = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
|
||||
e.tribute_id_2 = static_cast<uint32_t>(strtoul(row[3], nullptr, 10));
|
||||
e.tribute_id_2_tier = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
|
||||
e.time_remaining = static_cast<uint32_t>(strtoul(row[5], nullptr, 10));
|
||||
e.enabled = static_cast<uint32_t>(strtoul(row[6], nullptr, 10));
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<GuildTributes> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<GuildTributes> 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) {
|
||||
GuildTributes e{};
|
||||
|
||||
e.guild_id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
|
||||
e.tribute_id_1 = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
|
||||
e.tribute_id_1_tier = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
|
||||
e.tribute_id_2 = static_cast<uint32_t>(strtoul(row[3], nullptr, 10));
|
||||
e.tribute_id_2_tier = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
|
||||
e.time_remaining = static_cast<uint32_t>(strtoul(row[5], nullptr, 10));
|
||||
e.enabled = static_cast<uint32_t>(strtoul(row[6], nullptr, 10));
|
||||
|
||||
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 GuildTributes &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.guild_id));
|
||||
v.push_back(std::to_string(e.tribute_id_1));
|
||||
v.push_back(std::to_string(e.tribute_id_1_tier));
|
||||
v.push_back(std::to_string(e.tribute_id_2));
|
||||
v.push_back(std::to_string(e.tribute_id_2_tier));
|
||||
v.push_back(std::to_string(e.time_remaining));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
|
||||
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<GuildTributes> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.guild_id));
|
||||
v.push_back(std::to_string(e.tribute_id_1));
|
||||
v.push_back(std::to_string(e.tribute_id_1_tier));
|
||||
v.push_back(std::to_string(e.tribute_id_2));
|
||||
v.push_back(std::to_string(e.tribute_id_2_tier));
|
||||
v.push_back(std::to_string(e.time_remaining));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
|
||||
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_GUILD_TRIBUTES_REPOSITORY_H
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
class BaseGuildsRepository {
|
||||
public:
|
||||
struct Guilds {
|
||||
|
||||
@@ -3,286 +3,47 @@
|
||||
|
||||
#include "../database.h"
|
||||
#include "../strings.h"
|
||||
#include "base/base_guild_bank_repository.h"
|
||||
|
||||
class GuildBankRepository {
|
||||
class GuildBankRepository: public BaseGuildBankRepository {
|
||||
public:
|
||||
struct GuildBank {
|
||||
int guildid;
|
||||
int8 area;
|
||||
int slot;
|
||||
int itemid;
|
||||
int qty;
|
||||
std::string donator;
|
||||
int8 permissions;
|
||||
std::string whofor;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("");
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* GuildBankRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* GuildBankRepository::GetWhereNeverExpires()
|
||||
* GuildBankRepository::GetWhereXAndY()
|
||||
* GuildBankRepository::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
|
||||
*/
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"guildid",
|
||||
"area",
|
||||
"slot",
|
||||
"itemid",
|
||||
"qty",
|
||||
"donator",
|
||||
"permissions",
|
||||
"whofor",
|
||||
};
|
||||
}
|
||||
|
||||
static std::string ColumnsRaw()
|
||||
{
|
||||
return std::string(Strings::Implode(", ", Columns()));
|
||||
}
|
||||
|
||||
static std::string InsertColumnsRaw()
|
||||
{
|
||||
std::vector<std::string> insert_columns;
|
||||
|
||||
for (auto &column : Columns()) {
|
||||
if (column == PrimaryKey()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
insert_columns.push_back(column);
|
||||
}
|
||||
|
||||
return std::string(Strings::Implode(", ", insert_columns));
|
||||
}
|
||||
|
||||
static std::string TableName()
|
||||
{
|
||||
return std::string("guild_bank");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
ColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
InsertColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static GuildBank NewEntity()
|
||||
{
|
||||
GuildBank entry{};
|
||||
|
||||
entry.guildid = 0;
|
||||
entry.area = 0;
|
||||
entry.slot = 0;
|
||||
entry.itemid = 0;
|
||||
entry.qty = 0;
|
||||
entry.donator = 0;
|
||||
entry.permissions = 0;
|
||||
entry.whofor = 0;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static GuildBank GetGuildBankEntry(
|
||||
const std::vector<GuildBank> &guild_banks,
|
||||
int guild_bank_id
|
||||
)
|
||||
{
|
||||
for (auto &guild_bank : guild_banks) {
|
||||
if (guild_bank. == guild_bank_id) {
|
||||
return guild_bank;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static GuildBank FindOne(
|
||||
int guild_bank_id
|
||||
)
|
||||
{
|
||||
auto results = database.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
guild_bank_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
GuildBank entry{};
|
||||
|
||||
entry.guildid = atoi(row[0]);
|
||||
entry.area = atoi(row[1]);
|
||||
entry.slot = atoi(row[2]);
|
||||
entry.itemid = atoi(row[3]);
|
||||
entry.qty = atoi(row[4]);
|
||||
entry.donator = row[5];
|
||||
entry.permissions = atoi(row[6]);
|
||||
entry.whofor = row[7];
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
int guild_bank_id
|
||||
)
|
||||
{
|
||||
auto results = database.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
guild_bank_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
GuildBank guild_bank_entry
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[0] + " = " + std::to_string(guild_bank_entry.guildid));
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(guild_bank_entry.area));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(guild_bank_entry.slot));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(guild_bank_entry.itemid));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(guild_bank_entry.qty));
|
||||
update_values.push_back(columns[5] + " = '" + Strings::Escape(guild_bank_entry.donator) + "'");
|
||||
update_values.push_back(columns[6] + " = " + std::to_string(guild_bank_entry.permissions));
|
||||
update_values.push_back(columns[7] + " = '" + Strings::Escape(guild_bank_entry.whofor) + "'");
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
PrimaryKey(),
|
||||
guild_bank_entry.
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static GuildBank InsertOne(
|
||||
GuildBank guild_bank_entry
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.guildid));
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.area));
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.slot));
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.itemid));
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.qty));
|
||||
insert_values.push_back("'" + Strings::Escape(guild_bank_entry.donator) + "'");
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.permissions));
|
||||
insert_values.push_back("'" + Strings::Escape(guild_bank_entry.whofor) + "'");
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
guild_bank_entry.id = results.LastInsertedID();
|
||||
return guild_bank_entry;
|
||||
}
|
||||
|
||||
guild_bank_entry = InstanceListRepository::NewEntity();
|
||||
|
||||
return guild_bank_entry;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
std::vector<GuildBank> guild_bank_entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &guild_bank_entry: guild_bank_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.guildid));
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.area));
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.slot));
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.itemid));
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.qty));
|
||||
insert_values.push_back("'" + Strings::Escape(guild_bank_entry.donator) + "'");
|
||||
insert_values.push_back(std::to_string(guild_bank_entry.permissions));
|
||||
insert_values.push_back("'" + Strings::Escape(guild_bank_entry.whofor) + "'");
|
||||
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", insert_values) + ")");
|
||||
}
|
||||
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES {}",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_chunks)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static std::vector<GuildBank> All()
|
||||
{
|
||||
std::vector<GuildBank> all_entries;
|
||||
|
||||
auto results = database.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
GuildBank entry{};
|
||||
|
||||
entry.guildid = atoi(row[0]);
|
||||
entry.area = atoi(row[1]);
|
||||
entry.slot = atoi(row[2]);
|
||||
entry.itemid = atoi(row[3]);
|
||||
entry.qty = atoi(row[4]);
|
||||
entry.donator = row[5];
|
||||
entry.permissions = atoi(row[6]);
|
||||
entry.whofor = row[7];
|
||||
|
||||
all_entries.push_back(entry);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
// Custom extended repository methods here
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
#ifndef EQEMU_GUILD_MEMBERS_REPOSITORY_H
|
||||
#define EQEMU_GUILD_MEMBERS_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../strings.h"
|
||||
#include "base/base_guild_members_repository.h"
|
||||
|
||||
class GuildMembersRepository : public BaseGuildMembersRepository {
|
||||
public:
|
||||
|
||||
struct GuildMembersWithTributeOnStruct {
|
||||
int32_t char_id;
|
||||
uint32_t guild_id;
|
||||
uint8_t tribute_enable;
|
||||
std::string char_name;
|
||||
uint32_t char_level;
|
||||
};
|
||||
|
||||
struct GuildMembershipStatsStruct {
|
||||
uint32 leaders;
|
||||
uint32 senior_officers;
|
||||
uint32 officers;
|
||||
uint32 senior_members;
|
||||
uint32 members;
|
||||
uint32 junior_members;
|
||||
uint32 initates;
|
||||
uint32 recruits;
|
||||
uint32 tribute_enabled;
|
||||
};
|
||||
|
||||
static int UpdateMemberRank(Database &db, uint32 char_id, uint32 rank_id)
|
||||
{
|
||||
const auto guild_members = GetWhere(db, fmt::format("char_id = '{}'", char_id));
|
||||
if (guild_members.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto m = guild_members[0];
|
||||
m.rank_ = rank_id;
|
||||
|
||||
return UpdateOne(db, m);
|
||||
}
|
||||
|
||||
static int UpdateEnabled(Database &db, uint32 guild_id, uint32 char_id, uint32 enabled)
|
||||
{
|
||||
const auto guild_members = GetWhere(db, fmt::format("char_id = '{}' AND guild_id = '{}'", char_id, guild_id));
|
||||
if (guild_members.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto m = guild_members[0];
|
||||
m.tribute_enable = enabled ? 1 : 0;
|
||||
|
||||
return UpdateOne(db, m);
|
||||
}
|
||||
|
||||
static std::vector<GuildMembersWithTributeOnStruct> GetMembersWithTributeOn(Database &db, uint32 guild_id)
|
||||
{
|
||||
std::vector<GuildMembersWithTributeOnStruct> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT gm.char_id, gm.guild_id, gm.tribute_enable, cd.`name`, cd.`level`, cd.deleted_at "
|
||||
"FROM guild_members gm JOIN character_data cd ON cd.id = gm.char_id "
|
||||
"WHERE ISNULL(cd.deleted_at) AND gm.tribute_enable = 1 AND gm.guild_id = '{}';",
|
||||
guild_id
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
GuildMembersWithTributeOnStruct e{};
|
||||
|
||||
e.char_id = static_cast<int32_t>(atoi(row[0]));
|
||||
e.guild_id = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
|
||||
e.tribute_enable = static_cast<uint8_t>(strtoul(row[2], nullptr, 10));
|
||||
e.char_name = row[3] ? row[3] : "";
|
||||
e.char_level = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static int UpdateFavor(Database &db, uint32 guild_id, uint32 char_id, uint32 favor)
|
||||
{
|
||||
const auto guild_members = GetWhere(db, fmt::format("char_id = '{}' AND guild_id = '{}'", char_id, guild_id));
|
||||
if (guild_members.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto m = guild_members[0];
|
||||
m.total_tribute = favor;
|
||||
m.last_tribute = time(nullptr);
|
||||
|
||||
return UpdateOne(db, m);
|
||||
}
|
||||
|
||||
static int UpdateOnline(Database &db, uint32 char_id, bool status)
|
||||
{
|
||||
const auto guild_members = GetWhere(db, fmt::format("char_id = '{}'", char_id));
|
||||
if (guild_members.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto m = guild_members[0];
|
||||
m.online = status ? 1 : 0;
|
||||
|
||||
return UpdateOne(db, m);
|
||||
}
|
||||
|
||||
static int UpdateNote(Database &db, uint32 char_id, std::string &public_note)
|
||||
{
|
||||
const auto guild_members = GetWhere(db, fmt::format("char_id = '{}'", char_id));
|
||||
if (guild_members.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto m = guild_members[0];
|
||||
m.public_note = public_note;
|
||||
|
||||
return UpdateOne(db, m);
|
||||
}
|
||||
|
||||
static GuildMembershipStatsStruct GetGuildMembershipStats(Database &db, uint32 guild_id)
|
||||
{
|
||||
std::string query = fmt::format(
|
||||
"SELECT "
|
||||
"SUM(CASE WHEN gm.`rank` = 1 THEN 1 ELSE 0 END) AS RANK1, "
|
||||
"SUM(CASE WHEN gm.`rank` = 2 THEN 1 ELSE 0 END) AS RANK2, "
|
||||
"SUM(CASE WHEN gm.`rank` = 3 THEN 1 ELSE 0 END) AS RANK3, "
|
||||
"SUM(CASE WHEN gm.`rank` = 4 THEN 1 ELSE 0 END) AS RANK4, "
|
||||
"SUM(CASE WHEN gm.`rank` = 5 THEN 1 ELSE 0 END) AS RANK5, "
|
||||
"SUM(CASE WHEN gm.`rank` = 6 THEN 1 ELSE 0 END) AS RANK6, "
|
||||
"SUM(CASE WHEN gm.`rank` = 7 THEN 1 ELSE 0 END) AS RANK7, "
|
||||
"SUM(CASE WHEN gm.`rank` = 8 THEN 1 ELSE 0 END) AS RANK8, "
|
||||
"SUM(CASE WHEN gm.tribute_enable = 1 THEN 1 ELSE 0 END) AS TRIBUTE "
|
||||
"FROM guild_members gm "
|
||||
"WHERE gm.guild_id = '{}';",
|
||||
guild_id
|
||||
);
|
||||
|
||||
GuildMembershipStatsStruct gmss{};
|
||||
|
||||
auto results = db.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return gmss;
|
||||
}
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
|
||||
gmss.leaders = static_cast<uint32_t>(Strings::ToUnsignedInt(row[0]));
|
||||
gmss.senior_officers = static_cast<uint32_t>(Strings::ToUnsignedInt(row[1]));
|
||||
gmss.officers = static_cast<uint32_t>(Strings::ToUnsignedInt(row[2]));
|
||||
gmss.senior_members = static_cast<uint32_t>(Strings::ToUnsignedInt(row[3]));
|
||||
gmss.members = static_cast<uint32_t>(Strings::ToUnsignedInt(row[4]));
|
||||
gmss.junior_members = static_cast<uint32_t>(Strings::ToUnsignedInt(row[5]));
|
||||
gmss.initates = static_cast<uint32_t>(Strings::ToUnsignedInt(row[6]));
|
||||
gmss.recruits = static_cast<uint32_t>(Strings::ToUnsignedInt(row[7]));
|
||||
gmss.tribute_enabled = static_cast<uint32_t>(Strings::ToUnsignedInt(row[8]));
|
||||
}
|
||||
|
||||
return gmss;
|
||||
}
|
||||
|
||||
static int UpdateBankerFlag(Database &db, uint32 char_id, bool status)
|
||||
{
|
||||
const auto guild_members = GetWhere(db, fmt::format("char_id = {}", char_id));
|
||||
if (guild_members.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto m = guild_members[0];
|
||||
m.banker = status ? 1 : 0;
|
||||
|
||||
return UpdateOne(db, m);
|
||||
}
|
||||
|
||||
static int UpdateAltFlag(Database &db, uint32 char_id, bool status)
|
||||
{
|
||||
const auto guild_members = GetWhere(db, fmt::format("char_id = {}", char_id));
|
||||
if (guild_members.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto m = guild_members[0];
|
||||
m.alt = status ? 1 : 0;
|
||||
|
||||
return UpdateOne(db, m);
|
||||
}
|
||||
};
|
||||
#endif //EQEMU_GUILD_MEMBERS_REPOSITORY_H
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef EQEMU_GUILD_PERMISSIONS_REPOSITORY_H
|
||||
#define EQEMU_GUILD_PERMISSIONS_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../strings.h"
|
||||
#include "base/base_guild_permissions_repository.h"
|
||||
|
||||
class GuildPermissionsRepository: public BaseGuildPermissionsRepository {
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* GuildPermissionsRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* GuildPermissionsRepository::GetWhereNeverExpires()
|
||||
* GuildPermissionsRepository::GetWhereXAndY()
|
||||
* GuildPermissionsRepository::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_GUILD_PERMISSIONS_REPOSITORY_H
|
||||
@@ -45,6 +45,21 @@ public:
|
||||
|
||||
// Custom extended repository methods here
|
||||
|
||||
static int UpdateTitle(Database &db, uint32 guild_id, uint32 rank, std::string title)
|
||||
{
|
||||
auto guild_rank = GetWhere(db, fmt::format("guild_id = '{}' AND rank = '{}'", guild_id, rank));
|
||||
if (guild_rank.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto r = guild_rank[0];
|
||||
r.title = title;
|
||||
|
||||
DeleteWhere(db, fmt::format("guild_id = '{}' AND rank = '{}'", guild_id, rank));
|
||||
InsertOne(db, r);
|
||||
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_GUILD_RANKS_REPOSITORY_H
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef EQEMU_GUILD_TRIBUTES_REPOSITORY_H
|
||||
#define EQEMU_GUILD_TRIBUTES_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../strings.h"
|
||||
#include "base/base_guild_tributes_repository.h"
|
||||
|
||||
class GuildTributesRepository: public BaseGuildTributesRepository {
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* GuildTributesRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* GuildTributesRepository::GetWhereNeverExpires()
|
||||
* GuildTributesRepository::GetWhereXAndY()
|
||||
* GuildTributesRepository::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
|
||||
static int UpdateEnabled(Database& db, uint32 guild_id, uint32 enabled)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET `enabled` = '{}' WHERE `guild_id` = {}",
|
||||
TableName(),
|
||||
enabled,
|
||||
guild_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateTimeRemaining(Database& db, uint32 guild_id, uint32 time_remaining)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET `time_remaining` = '{}' WHERE `guild_id` = {}",
|
||||
TableName(),
|
||||
time_remaining,
|
||||
guild_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_GUILD_TRIBUTES_REPOSITORY_H
|
||||
@@ -5,46 +5,58 @@
|
||||
#include "../strings.h"
|
||||
#include "base/base_guilds_repository.h"
|
||||
|
||||
class GuildsRepository: public BaseGuildsRepository {
|
||||
class GuildsRepository : public BaseGuildsRepository {
|
||||
public:
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* GuildsRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* GuildsRepository::GetWhereNeverExpires()
|
||||
* GuildsRepository::GetWhereXAndY()
|
||||
* GuildsRepository::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
|
||||
*/
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* GuildsRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* GuildsRepository::GetWhereNeverExpires()
|
||||
* GuildsRepository::GetWhereXAndY()
|
||||
* GuildsRepository::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
|
||||
// Custom extended repository methods here
|
||||
|
||||
static int UpdateFavor(Database &db, uint32 guild_id, uint32 favor)
|
||||
{
|
||||
auto const guild = GetWhere(db, fmt::format("id = '{}'", guild_id));
|
||||
if (guild.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto g = guild[0];
|
||||
g.favor = favor;
|
||||
|
||||
return UpdateOne(db, g);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_GUILDS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user