From 22fb7b22b4244d0e3277094d66d6a529020961a3 Mon Sep 17 00:00:00 2001 From: KimLS Date: Sun, 16 Feb 2025 22:33:15 -0800 Subject: [PATCH] Add opcode and repo --- common/CMakeLists.txt | 2 + common/emu_oplist.h | 1 + .../base/base_find_location_repository.h | 511 ++++++++++++++++++ .../repositories/find_location_repository.h | 50 ++ 4 files changed, 564 insertions(+) create mode 100644 common/repositories/base/base_find_location_repository.h create mode 100644 common/repositories/find_location_repository.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 457180fdf..b12fadcd3 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -222,6 +222,7 @@ SET(repositories repositories/base/base_faction_list_repository.h repositories/base/base_faction_list_mod_repository.h repositories/base/base_faction_values_repository.h + repositories/base/base_find_location_repository.h repositories/base/base_fishing_repository.h repositories/base/base_forage_repository.h repositories/base/base_friends_repository.h @@ -419,6 +420,7 @@ SET(repositories repositories/faction_list_repository.h repositories/faction_list_mod_repository.h repositories/faction_values_repository.h + repositories/find_location_repository.h repositories/fishing_repository.h repositories/forage_repository.h repositories/friends_repository.h diff --git a/common/emu_oplist.h b/common/emu_oplist.h index f91bf235f..c524d372a 100644 --- a/common/emu_oplist.h +++ b/common/emu_oplist.h @@ -473,6 +473,7 @@ N(OP_SendAATable), N(OP_SendCharInfo), N(OP_SendExpZonein), N(OP_SendFindableNPCs), +N(OP_SendFindableLocations), N(OP_SendGuildTributes), N(OP_SendLoginInfo), N(OP_SendMaxCharacters), diff --git a/common/repositories/base/base_find_location_repository.h b/common/repositories/base/base_find_location_repository.h new file mode 100644 index 000000000..6fa6750d7 --- /dev/null +++ b/common/repositories/base/base_find_location_repository.h @@ -0,0 +1,511 @@ +/** + * 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_FIND_LOCATION_REPOSITORY_H +#define EQEMU_BASE_FIND_LOCATION_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseFindLocationRepository { +public: + struct FindLocation { + uint32_t id; + std::string zone; + int32_t version; + int8_t min_expansion; + int8_t max_expansion; + std::string content_flags; + std::string content_flags_disabled; + int32_t type; + int32_t zone_id; + float x; + float y; + float z; + }; + + static std::string PrimaryKey() + { + return std::string("id"); + } + + static std::vector Columns() + { + return { + "id", + "zone", + "version", + "min_expansion", + "max_expansion", + "content_flags", + "content_flags_disabled", + "type", + "zone_id", + "x", + "y", + "z", + }; + } + + static std::vector SelectColumns() + { + return { + "id", + "zone", + "version", + "min_expansion", + "max_expansion", + "content_flags", + "content_flags_disabled", + "type", + "zone_id", + "x", + "y", + "z", + }; + } + + 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("find_location"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static FindLocation NewEntity() + { + FindLocation e{}; + + e.id = 0; + e.zone = ""; + e.version = 0; + e.min_expansion = -1; + e.max_expansion = -1; + e.content_flags = ""; + e.content_flags_disabled = ""; + e.type = 0; + e.zone_id = 0; + e.x = 0; + e.y = 0; + e.z = 0; + + return e; + } + + static FindLocation GetFindLocation( + const std::vector &find_locations, + int find_location_id + ) + { + for (auto &find_location : find_locations) { + if (find_location.id == find_location_id) { + return find_location; + } + } + + return NewEntity(); + } + + static FindLocation FindOne( + Database& db, + int find_location_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {} = {} LIMIT 1", + BaseSelect(), + PrimaryKey(), + find_location_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + FindLocation e{}; + + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.zone = row[1] ? row[1] : ""; + e.version = row[2] ? static_cast(atoi(row[2])) : 0; + e.min_expansion = row[3] ? static_cast(atoi(row[3])) : -1; + e.max_expansion = row[4] ? static_cast(atoi(row[4])) : -1; + e.content_flags = row[5] ? row[5] : ""; + e.content_flags_disabled = row[6] ? row[6] : ""; + e.type = row[7] ? static_cast(atoi(row[7])) : 0; + e.zone_id = row[8] ? static_cast(atoi(row[8])) : 0; + e.x = row[9] ? strtof(row[9], nullptr) : 0; + e.y = row[10] ? strtof(row[10], nullptr) : 0; + e.z = row[11] ? strtof(row[11], nullptr) : 0; + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int find_location_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + find_location_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const FindLocation &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[1] + " = '" + Strings::Escape(e.zone) + "'"); + v.push_back(columns[2] + " = " + std::to_string(e.version)); + v.push_back(columns[3] + " = " + std::to_string(e.min_expansion)); + v.push_back(columns[4] + " = " + std::to_string(e.max_expansion)); + v.push_back(columns[5] + " = '" + Strings::Escape(e.content_flags) + "'"); + v.push_back(columns[6] + " = '" + Strings::Escape(e.content_flags_disabled) + "'"); + v.push_back(columns[7] + " = " + std::to_string(e.type)); + v.push_back(columns[8] + " = " + std::to_string(e.zone_id)); + v.push_back(columns[9] + " = " + std::to_string(e.x)); + v.push_back(columns[10] + " = " + std::to_string(e.y)); + v.push_back(columns[11] + " = " + std::to_string(e.z)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static FindLocation InsertOne( + Database& db, + FindLocation e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.min_expansion)); + v.push_back(std::to_string(e.max_expansion)); + v.push_back("'" + Strings::Escape(e.content_flags) + "'"); + v.push_back("'" + Strings::Escape(e.content_flags_disabled) + "'"); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + + 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 &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.min_expansion)); + v.push_back(std::to_string(e.max_expansion)); + v.push_back("'" + Strings::Escape(e.content_flags) + "'"); + v.push_back("'" + Strings::Escape(e.content_flags_disabled) + "'"); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseInsert(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static std::vector All(Database& db) + { + std::vector all_entries; + + auto results = db.QueryDatabase( + fmt::format( + "{}", + BaseSelect() + ) + ); + + all_entries.reserve(results.RowCount()); + + for (auto row = results.begin(); row != results.end(); ++row) { + FindLocation e{}; + + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.zone = row[1] ? row[1] : ""; + e.version = row[2] ? static_cast(atoi(row[2])) : 0; + e.min_expansion = row[3] ? static_cast(atoi(row[3])) : -1; + e.max_expansion = row[4] ? static_cast(atoi(row[4])) : -1; + e.content_flags = row[5] ? row[5] : ""; + e.content_flags_disabled = row[6] ? row[6] : ""; + e.type = row[7] ? static_cast(atoi(row[7])) : 0; + e.zone_id = row[8] ? static_cast(atoi(row[8])) : 0; + e.x = row[9] ? strtof(row[9], nullptr) : 0; + e.y = row[10] ? strtof(row[10], nullptr) : 0; + e.z = row[11] ? strtof(row[11], nullptr) : 0; + + all_entries.push_back(e); + } + + return all_entries; + } + + static std::vector GetWhere(Database& db, const std::string &where_filter) + { + std::vector 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) { + FindLocation e{}; + + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.zone = row[1] ? row[1] : ""; + e.version = row[2] ? static_cast(atoi(row[2])) : 0; + e.min_expansion = row[3] ? static_cast(atoi(row[3])) : -1; + e.max_expansion = row[4] ? static_cast(atoi(row[4])) : -1; + e.content_flags = row[5] ? row[5] : ""; + e.content_flags_disabled = row[6] ? row[6] : ""; + e.type = row[7] ? static_cast(atoi(row[7])) : 0; + e.zone_id = row[8] ? static_cast(atoi(row[8])) : 0; + e.x = row[9] ? strtof(row[9], nullptr) : 0; + e.y = row[10] ? strtof(row[10], nullptr) : 0; + e.z = row[11] ? strtof(row[11], nullptr) : 0; + + 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 FindLocation &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.min_expansion)); + v.push_back(std::to_string(e.max_expansion)); + v.push_back("'" + Strings::Escape(e.content_flags) + "'"); + v.push_back("'" + Strings::Escape(e.content_flags_disabled) + "'"); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + + 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 &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.min_expansion)); + v.push_back(std::to_string(e.max_expansion)); + v.push_back("'" + Strings::Escape(e.content_flags) + "'"); + v.push_back("'" + Strings::Escape(e.content_flags_disabled) + "'"); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); + } + + std::vector v; + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES {}", + BaseReplace(), + Strings::Implode(",", insert_chunks) + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } +}; + +#endif //EQEMU_BASE_FIND_LOCATION_REPOSITORY_H diff --git a/common/repositories/find_location_repository.h b/common/repositories/find_location_repository.h new file mode 100644 index 000000000..2c3ac8583 --- /dev/null +++ b/common/repositories/find_location_repository.h @@ -0,0 +1,50 @@ +#ifndef EQEMU_FIND_LOCATION_REPOSITORY_H +#define EQEMU_FIND_LOCATION_REPOSITORY_H + +#include "../database.h" +#include "../strings.h" +#include "base/base_find_location_repository.h" + +class FindLocationRepository: public BaseFindLocationRepository { +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 + * + * FindLocationRepository::GetByZoneAndVersion(int zone_id, int zone_version) + * FindLocationRepository::GetWhereNeverExpires() + * FindLocationRepository::GetWhereXAndY() + * FindLocationRepository::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_FIND_LOCATION_REPOSITORY_H